Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
谢斯
Model_Library_Front_End
提交
daf406fd
M
Model_Library_Front_End
项目概览
谢斯
/
Model_Library_Front_End
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
Model_Library_Front_End
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
daf406fd
编写于
6月 27, 2021
作者:
X
xiesi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
增加登录判断,并添加页面的判断是否为登录状态
Signed-off-by:
N
xiesi
<
305492881@qq.com
>
上级
524cdffb
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
122 addition
and
22 deletion
+122
-22
src/main.js
src/main.js
+18
-18
src/router/index.js
src/router/index.js
+1
-1
src/views/Home.vue
src/views/Home.vue
+15
-1
src/views/Login.vue
src/views/Login.vue
+88
-2
未找到文件。
src/main.js
浏览文件 @
daf406fd
...
...
@@ -8,30 +8,30 @@ import ElementPlus from 'element-plus';
import
'
element-plus/lib/theme-chalk/index.css
'
;
import
axios
from
'
axios
'
import
VueAxios
from
'
vue-axios
'
import
{
isLogin
}
from
"
@/api/api.js
"
;
createApp
(
App
).
use
(
store
).
use
(
router
).
use
(
ElementPlus
).
use
(
VueAxios
,
axios
).
mount
(
"
#app
"
);
router
.
beforeEach
((
to
,
from
,
next
)
=>
{
// to and from are both route objects. must call `next`.
if
(
to
.
meta
.
needLogin
)
{
axios
.
get
(
"
http://localhost:8070/login
"
,
{
withCredentials
:
true
})
.
then
((
response
)
=>
{
console
.
log
(
response
.
data
);
if
(
response
.
data
.
Code
==
0
)
{
//显示用户名
console
.
log
(
response
.
data
.
data
.
name
);
next
();
}
else
{
//当前为有课,不允许登录
console
.
log
(
"
需要跳转到登录页面
"
);
router
.
push
(
"
Login
"
);
next
({
path
:
"
Login
"
,
});
}
});
isLogin
().
then
((
response
)
=>
{
console
.
log
(
response
.
data
);
if
(
response
.
data
.
Code
==
0
)
{
//显示用户名
console
.
log
(
response
.
data
.
data
.
name
);
next
();
}
else
{
//当前为有课,不允许登录
console
.
log
(
"
需要跳转到登录页面
"
);
router
.
push
(
"
Login
"
);
next
({
path
:
"
Login
"
,
});
}
});
next
();
}
else
{
next
();
...
...
src/router/index.js
浏览文件 @
daf406fd
...
...
@@ -9,7 +9,7 @@ const routes = [{
name
:
"
Home
"
,
component
:
Home
,
meta
:
{
needLogin
:
fals
e
,
needLogin
:
tru
e
,
}
},
{
...
...
src/views/Home.vue
浏览文件 @
daf406fd
...
...
@@ -64,6 +64,7 @@ import { isLogin } from "@/api/api.js";
import
LoadFBX
from
"
@/components/LoadFBX.vue
"
;
import
qs
from
"
qs
"
;
//import { useRouter } from "vue-router";
import
{
ElMessage
}
from
"
element-plus
"
;
export
default
{
name
:
"
Home
"
,
...
...
@@ -104,7 +105,20 @@ export default {
this
.
axios
.
post
(
"
http://localhost:8070/logout
"
,
{},
{
withCredentials
:
true
})
.
then
((
response
)
=>
{
console
.
log
(
response
.
data
);
if
(
response
.
data
.
Code
==
0
)
{
ElMessage
({
type
:
"
info
"
,
message
:
"
退出成功
"
,
showClose
:
"
true
"
,
});
this
.
$router
.
push
(
"
Login
"
);
}
else
{
ElMessage
({
type
:
"
info
"
,
message
:
"
退出失败
"
,
showClose
:
"
true
"
,
});
}
});
},
},
...
...
src/views/Login.vue
浏览文件 @
daf406fd
<
template
>
<div>
登录界面
</div>
<el-form
:model=
"ruleForm"
status-icon
:rules=
"rules"
ref=
"ruleForm"
label-width=
"100px"
class=
"demo-ruleForm"
>
<el-form-item
label=
"工号"
prop=
"name"
>
<el-input
v-model=
"ruleForm.name"
autocomplete=
"off"
></el-input>
</el-form-item>
<el-form-item
label=
"密码"
prop=
"password"
>
<el-input
type=
"password"
v-model=
"ruleForm.password"
autocomplete=
"off"
show-password=
"true"
></el-input>
</el-form-item>
<el-form-item>
<el-button
type=
"primary"
@
click=
"submitForm(ruleForm)"
>
登录
</el-button>
</el-form-item>
</el-form>
</
template
>
<
script
>
export
default
{};
import
{
Login
}
from
"
@/api/api.js
"
;
import
{
ElMessage
}
from
"
element-plus
"
;
export
default
{
data
()
{
var
validateHaveWorkNumber
=
(
rule
,
value
,
callback
)
=>
{
if
(
!
value
)
{
return
callback
(
new
Error
(
"
工号不能为空
"
));
}
else
{
// console.log(value);
}
callback
();
};
var
validatePass
=
(
rule
,
value
,
callback
)
=>
{
if
(
value
===
""
)
{
callback
(
new
Error
(
"
请输入密码
"
));
}
else
{
if
(
this
.
ruleForm
.
checkPass
!==
""
)
{
this
.
$refs
.
ruleForm
.
validateField
(
"
checkPass
"
);
}
callback
();
}
};
return
{
ruleForm
:
{
name
:
""
,
password
:
""
,
},
rules
:
{
password
:
[
{
required
:
true
,
validator
:
validatePass
,
trigger
:
"
blur
"
},
],
name
:
[
{
required
:
true
,
validator
:
validateHaveWorkNumber
,
trigger
:
"
blur
"
,
},
],
},
};
},
methods
:
{
submitForm
(
formName
)
{
Login
(
formName
).
then
((
response
)
=>
{
if
(
response
.
data
.
Code
==
0
)
{
ElMessage
({
showClose
:
true
,
message
:
"
登录成功
"
,
type
:
"
info
"
,
});
this
.
$router
.
push
(
"
/
"
);
}
else
{
ElMessage
({
showClose
:
true
,
message
:
"
登录失败[工号]或[密码]错误
"
,
type
:
"
error
"
,
});
}
});
},
},
};
</
script
>
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录