feat: base 退出后可重定向

This commit is contained in:
caoqianming 2024-03-11 13:34:09 +08:00
parent efe3bb7777
commit 767e2d8048
4 changed files with 31 additions and 85 deletions

View File

@ -36,7 +36,7 @@ router.beforeEach(async (to, from, next) => {
//动态标题
document.title = to.meta.title ? `${to.meta.title} - ${config.APP_NAME}` : `${config.APP_NAME}`
let token = tool.cookie.get("TOKEN");
let token = tool.data.get("TOKEN");
//去往登录页
if (to.path === "/login") {
//删除路由(替换当前layout路由)

View File

@ -24,7 +24,7 @@
</el-form-item>
<el-form-item>
<el-button type="primary" style="width: 100%" :loading="islogin" round @click="login">{{ $t("login.signIn")
}}</el-button>
}}</el-button>
</el-form-item>
<!-- <div class="login-reg">
@ -62,6 +62,7 @@
export default {
data() {
return {
redirect: undefined,
userType: "admin",
visitorsdialog: false,
visitorform: {},
@ -99,6 +100,12 @@ export default {
this.form.password = "user";
}
},
$route: {
handler: function (route) {
this.redirect = route.query && route.query.redirect;
},
immediate: true,
},
},
mounted() { },
methods: {
@ -117,19 +124,19 @@ export default {
//token
try {
var res = await that.$API.auth.token.post(data);
that.$TOOL.cookie.set("TOKEN", res.access, {
expires: that.form.autologin ? 24 * 60 * 60 : 0,
});
that.$TOOL.data.set("TOKEN", res.access);
that.$TOOL.data.set("TOKEN_REFRESH", res.refresh);
that.$TOOL.cookie.set("TOKEN_REFRESH", res.refresh);
that.$TOOL.data.set("TOKEN_TIME", new Date().getTime());
try {
var res1 = await that.$API.auth.info.get();
that.$TOOL.data.set("USER_INFO", res1);
that.$TOOL.data.set("PERMISSIONS", Object.keys(res1.perms));
let base_dashboard = this.$TOOL.data.get('BASE_INFO').base.base_dashboard;
if (base_dashboard == null || base_dashboard == undefined) {
if (this.redirect) {
base_dashboard = this.redirect;
}
else if (base_dashboard == null || base_dashboard == undefined) {
base_dashboard = '/dashboard'
}
if (this.$TOOL.data.get('BASE_INFO').base.base_name_short.indexOf('曲阳') != -1) {
@ -157,31 +164,6 @@ export default {
path: base_dashboard,
});
}
// if(this.$TOOL.data.get('BASE_INFO').base.base_name_short==''){//
// this.$router.replace({
// path: "/dashboard_enm",
// });
// }else{//
// that.$API.am.area.list.req({page_size:999}).then(res => {
// if (res.err_msg) {
// } else {
// debugger;
// let areaList = res.results;
// that.$TOOL.data.set("qyjyAreaList", areaList);
// if(res1.type==='employee'){
// this.$router.replace({
// path: "/",
// });
// }else{
// this.$router.replace({
// path: "/rpm/rpj",
// });
// }
// that.$message.success("Login Success ");
// that.islogin = false;
// }
// })
// }
} catch (err) {
that.islogin = false;
console.log(err);
@ -192,52 +174,6 @@ export default {
} finally {
that.islogin = false;
}
// var res = await this.$API.auth.token.post(data)
// console.log(res, err)
// if(!res){
// this.islogin = false
// this.$message.warning(res.err_msg)
// return false
// }else{
// this.$TOOL.cookie.set("TOKEN", res.token, {
// expires: this.form.autologin? 24*60*60 : 0
// })
// }
// if(user.code == 200){
// this.$TOOL.data.set("USER_INFO", user.data.userInfo)
// }else{
// }
//
// var menu = null
// if(this.form.user == 'admin'){
// menu = await this.$API.system.menu.myMenus.get()
// }else{
// menu = await this.$API.demo.menu.get()
// }
// if(menu.code == 200){
// if(menu.data.menu.length==0){
// this.islogin = false
// this.$alert("", "访", {
// type: 'error',
// center: true
// })
// return false
// }
// this.$TOOL.data.set("MENU", menu.data.menu)
// this.$TOOL.data.set("PERMISSIONS", menu.data.permissions)
// }else{
// this.islogin = false
// this.$message.warning(menu.message)
// return false
// }
// this.$router.replace({
// path: '/'
// })
// this.$message.success("Login Success ")
// this.islogin = false
},
visitors() {
this.visitorsdialog = true;

View File

@ -16,7 +16,7 @@
</el-form-item>
<el-form-item>
<el-button type="primary" style="width: 100%;" :loading="islogin" round @click="login">{{ $t('login.signIn')
}}</el-button>
}}</el-button>
</el-form-item>
<!-- <div class="login-reg">
{{$t('login.noAccount')}} <router-link to="/user_register">{{$t('login.createAccount')}}</router-link>
@ -28,6 +28,7 @@
export default {
data() {
return {
redirect: undefined,
form: {
phone: "",
code: "",
@ -58,6 +59,14 @@ export default {
},
mounted() {
},
watch: {
$route: {
handler: function (route) {
this.redirect = route.query && route.query.redirect;
},
immediate: true,
},
},
methods: {
async getYzm() {
@ -86,18 +95,17 @@ export default {
this.$refs.loginForm.validate(async (valid) => {
if (valid) {
this.$API.auth.login_sms_code.req(that.form).then(res => {
that.$TOOL.cookie.set("TOKEN", res.access, {
expires: that.form.autologin ? 24 * 60 * 60 : 0,
});
that.$TOOL.data.set("TOKEN", res.access);
that.$TOOL.data.set("TOKEN_REFRESH", res.refresh);
that.$TOOL.cookie.set("TOKEN_REFRESH", res.refresh);
that.$TOOL.data.set("TOKEN_TIME", new Date().getTime());
that.$API.auth.info.get().then(res1 => {
that.$TOOL.data.set("USER_INFO", res1);
that.$TOOL.data.set("PERMISSIONS", Object.keys(res1.perms));
let base_dashboard = this.$TOOL.data.get('BASE_INFO').base.base_dashboard;
if (base_dashboard == null || base_dashboard == undefined) {
if (this.redirect) {
base_dashboard = this.redirect;
}
else if (base_dashboard == null || base_dashboard == undefined) {
base_dashboard = '/dashboard'
}
if (this.$TOOL.data.get('BASE_INFO').base.base_name_short.indexOf('曲阳') != -1) {

View File

@ -138,7 +138,9 @@ export default {
}
},
created: function () {
this.$TOOL.cookie.remove("TOKEN")
this.$TOOL.data.remove("TOKEN")
this.$TOOL.data.remove("TOKEN_TIME")
this.$TOOL.data.remove("TOKEN_REFRESH")
this.$TOOL.data.remove("USER_INFO")
this.$TOOL.data.remove("MENU")
this.$TOOL.data.remove("PERMISSIONS")