Browse Source

TBtools-登录优化

panyong 4 năm trước cách đây
mục cha
commit
6d13f0fc24

+ 5 - 1
htmldev/TBTools/src/store/modules/user.js

@@ -2,7 +2,8 @@ export default {
   namespaced: true,
   state: {
     id: 0,
-    name: ''
+    name: '',
+    token: '' // 登录返回的token
   },
   mutations: {
     updateId (state, id) {
@@ -10,6 +11,9 @@ export default {
     },
     updateName (state, name) {
       state.name = name
+    },
+    updateToken (state, val) {
+      state.token = val
     }
   }
 }

+ 5 - 36
htmldev/TBTools/src/views/main-navbar.vue

@@ -22,23 +22,16 @@
           </el-dropdown>
         </li>
       </ul>
-      <el-dropdown class="TT-login" :show-timeout="0" placement="bottom" style="cursor: pointer;" v-if="userName">
-        <span class="el-dropdown-link">{{ userName }}</span>
-        <el-dropdown-menu slot="dropdown">
-          <el-dropdown-item @click.native="updatePasswordHandle()">修改密码</el-dropdown-item>
-          <el-dropdown-item @click.native="logoutHandle()">退出</el-dropdown-item>
-        </el-dropdown-menu>
-      </el-dropdown>
+      <a href="javascript:;" @click="logoutHandle" v-if="token">退出</a>
       <router-link :to="{name: 'login'}" replace v-else>登录</router-link>
+      <router-link class="ml-20" :to="{name: 'register'}" replace>/注册</router-link>
     </div>
-    <!-- 弹窗, 修改密码 -->
-    <update-password v-if="updatePassowrdVisible" ref="updatePassowrd"></update-password>
   </nav>
 </template>
 
 <script>
-import UpdatePassword from './main-navbar-update-password'
 import { clearLoginInfo } from '@/utils'
+import Vue from 'vue'
 
 export default {
   data () {
@@ -46,36 +39,12 @@ export default {
       updatePassowrdVisible: false
     }
   },
-  components: {
-    UpdatePassword
-  },
   computed: {
-    navbarLayoutType: {
-      get () { return this.$store.state.common.navbarLayoutType }
-    },
-    sidebarFold: {
-      get () { return this.$store.state.common.sidebarFold },
-      set (val) { this.$store.commit('common/updateSidebarFold', val) }
-    },
-    mainTabs: {
-      get () { return this.$store.state.common.mainTabs },
-      set (val) { this.$store.commit('common/updateMainTabs', val) }
-    },
-    userName: {
-      get () { return this.$store.state.user.name }
+    token () {
+      return this.$store.state.user.token || Vue.cookie.get('token')
     }
   },
   methods: {
-    handleSelect (key, keyPath) {
-      console.log(key, keyPath)
-    },
-    // 修改密码
-    updatePasswordHandle () {
-      this.updatePassowrdVisible = true
-      this.$nextTick(() => {
-        this.$refs.updatePassowrd.init()
-      })
-    },
     // 退出
     logoutHandle () {
       this.$confirm(`确定进行[退出]操作?`, '提示', {

+ 2 - 1
htmldev/TBTools/src/views/modules/account/login.vue

@@ -81,13 +81,14 @@ export default {
           }
           this.isDisabled = true
           this.$http({
-            url: this.$http.adornUrl('/user/login11'),
+            url: this.$http.adornUrl('/user/login'),
             method: 'post',
             data: this.$http.adornData(postData)
           }).then(({ data }) => {
             this.isDisabled = false
             if (data.status) {
               const { token } = data.data
+              this.$store.commit('user/updateToken', token)
               this.$cookie.set('token', token)
               this.$router.replace({ name: 'home' })
               return