diff --git a/src/router/index.js b/src/router/index.js index 1bf88a3..f43ff87 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -46,8 +46,8 @@ const routes = [ ]; const router = new VueRouter({ - routes - // mode: 'history' + routes, + mode: 'history' }); export default router; diff --git a/src/utils/request.js b/src/utils/request.js index e1e9307..906d1dd 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -63,7 +63,16 @@ service.interceptors.response.use(res => { } ).then(() => { store.dispatch('LogOut').then(() => { - location.href = '/index'; + try { + const targetPath = window.location.pathname; + console.log(window.location) + if(targetPath) + location.href = '/login?redirect=' + encodeURIComponent(targetPath); + else + location.href = '/index'; + } catch(e) { + location.href = '/index'; + } }) }) } else if (code === 500) { diff --git a/src/views/login/index.js b/src/views/login/index.js index fd00451..e9d74a5 100644 --- a/src/views/login/index.js +++ b/src/views/login/index.js @@ -31,8 +31,56 @@ export default { code: [{ required: true, trigger: "blur", message: "验证码不能为空" }], // smsCode: [{ required: true, trigger: "blur", message: "验证码不能为空" }] }, + redirect: undefined, }; }, + watch: { + $route: { + handler: function (route) { + this.redirect = route.query && route.query.redirect; + console.log(route) + if (route.query && route.query.code && route.query.exiturl) { + let obj = { + code: route.query.code, + }; + this.singleLoading = true; + this.$store + .dispatch("SingleLogin", obj) + .then((res) => { + Cookies.set("singleUrl", route.query.exiturl, { expires: 30 }); + this.singleLoading = false; + if (this.viewChecked == true) { + this.$router.push({ path: "/viewPages/profile" }); + } else { + if (res && res.code && res.code == 200) { + let requireUpdatePassword = res.requireUpdatePassword; + if (requireUpdatePassword) { + //重置密码 + this.$set(this.resetPwd, "open", true); + } else { + this.$router + .push({ path: this.redirect || "/" }) + .catch(() => {}); + } + } + } + }) + .catch((error) => { + const errorString = error + ""; + this.loading = false; + if (errorString.indexOf("证书无效") > -1) { + loginError().then((res) => { + this.upload.open = true; + this.upload.loginJson = res.msg; + }); + } + this.singleLoading = false; + }); + } + }, + immediate: true, + }, + }, computed: { }, created () { @@ -136,8 +184,8 @@ export default { //重置密码 this.$set(this.resetPwd, "open", true); } else { - this.$router - .push({ path: this.redirect || "/nav" }) + console.log(this.redirect + 11111111111); + this.$router.push({ path: this.redirect || "/nav" }) } } }