Răsfoiți Sursa

修改退出登录重置密码

ljh 2 ani în urmă
părinte
comite
4723eca399

+ 1 - 0
chuanyi-admin/src/App.vue

@@ -16,6 +16,7 @@ export default {
     this.beforeUnload()
   },
   methods: {
+    /** 页面刷新前缓存标签栏 */
     beforeUnload() {
       window.addEventListener('beforeunload', () => {
         const tabViews = this.visitedViews.map(item => {

+ 10 - 3
chuanyi-admin/src/layout/components/Navbar.vue

@@ -183,20 +183,27 @@ export default {
      * @returns {Promise<void>}
      */
     async logout() {
-      await this.$store.dispatch('user/Logout')
-      this.$router.push(`/login?redirect=${this.$route.fullPath}`)
+      const res = await this.$store.dispatch('user/Logout')
+      if (res.code === 200) {
+        this.$message({
+          type: 'success',
+          message: '退出成功'
+        })
+        this.$router.push(`/login?redirect=${this.$route.fullPath}`)
+      }
     },
     /** 修改密码 */
     submit() {
       this.$refs.psdForm.validate((valid) => {
         if (valid) {
           const data = this.$store.dispatch('user/UpdatePassword', this.form)
-          data.then(res => {
+          data.then(async(res) => {
             if (res.code === 200) {
               this.$message({
                 type: 'success',
                 message: '修改成功'
               })
+              await this.logout()
               this.dialogVisible = false
             }
           })

+ 4 - 4
chuanyi-admin/src/permission.js

@@ -20,10 +20,10 @@ router.beforeEach(async(to, from, next) => {
       removeToken()
       NProgress.done()
     } else {
-      if (to.matched.length === 0) {
-        // next('/404')
-        // NProgress.done()
-      }
+      // if (to.matched.length === 0) {
+      //   // next('/404')
+      //   // NProgress.done()
+      // }
       const hasRoles = store.getters.roles && store.getters.roles.length > 0
 
       if (hasRoles) {

+ 2 - 3
chuanyi-admin/src/store/modules/user.js

@@ -126,7 +126,7 @@ const actions = {
    */
   Logout({ commit, state, dispatch }) {
     return new Promise((resolve, reject) => {
-      logout().then(() => {
+      logout().then((res) => {
         commit('SET_TOKEN', '')
         commit('SET_ROLES', [])
         removeAll()
@@ -135,8 +135,7 @@ const actions = {
         // reset visited views and cached views
         // to fixed https://github.com/PanJiaChen/vue-element-admin/issues/2485
         dispatch('tagsView/delAllViews', null, { root: true })
-
-        resolve()
+        resolve(res)
       }).catch(error => {
         reject(error)
       })

+ 8 - 2
chuanyi-admin/src/views/system/user/index.vue

@@ -359,7 +359,9 @@ export default {
     },
     /** 重置密码按钮操作 */
     handleResetPwd(row) {
-      if (row.userId === this.defaultAdminId) {
+      const uid = this.$store.getters.uid
+      const userId = row.userId
+      if (userId === this.defaultAdminId) {
         this.$message({
           message: '系统管理员帐号无法进行密码重置操作',
           type: 'warning'
@@ -377,12 +379,16 @@ export default {
           userId: row.userId,
           newPassword: 'cy123456'
         })
-        data.then(res => {
+        data.then(async(res) => {
           if (res.code === 200) {
             this.$message({
               type: 'success',
               message: '重置成功'
             })
+            if (userId === uid) {
+              await this.$store.dispatch('user/Logout')
+              this.$router.push(`/login?redirect=${this.$route.fullPath}`)
+            }
           }
         })
       }).catch(() => {