Parcourir la source

Merge branch 'master' of http://116.63.33.55/git/read_opc

FinalYu il y a 2 ans
Parent
commit
2dcc2535fa

+ 1 - 0
chuanyi-admin/src/permission.js

@@ -60,6 +60,7 @@ router.beforeEach(async(to, from, next) => {
     if (whiteList.indexOf(to.path) !== -1) {
       next()
     } else {
+      console.log(to)
       next(`/login?redirect=${to.fullPath}`)
       NProgress.done()
     }

+ 3 - 1
chuanyi-admin/src/store/getters.js

@@ -13,6 +13,8 @@ const getters = {
   introduction: state => state.user.introduction,
   roles: state => state.user.roles,
   permission_routes: state => state.permission.routes,
-  errorLogs: state => state.errorLog.logs
+  errorLogs: state => state.errorLog.logs,
+  publicKey: state => state.user.publicKey,
+  verifyCode: state => state.user.verifyCode
 }
 export default getters

+ 1 - 1
chuanyi-admin/src/store/modules/permission.js

@@ -130,7 +130,7 @@ const actions = {
           resolve(accessedRoutes)
         } catch (error) {
           console.log(error)
-          router.push({ path: '/login' })
+          router.replace('/login')
           NProgress.done()
           reject(error)
         }

+ 26 - 5
chuanyi-admin/src/store/modules/user.js

@@ -4,6 +4,7 @@ import { encrypt } from '@/utils/jsencrypt'
 import { Message } from 'element-ui'
 import router, { resetRouter } from '@/router'
 import errorCode from '@/utils/errorCode'
+import { getCode } from '@/api/user'
 
 const state = {
   token: getToken(),
@@ -28,7 +29,9 @@ const state = {
   }, {
     'name': '管理端用户',
     'value': 1
-  }]
+  }],
+  // 验证码路径
+  verifyCode: ''
 }
 
 const mutations = {
@@ -49,10 +52,29 @@ const mutations = {
   },
   SET_ROLES: (state, roles) => {
     state.roles = roles
+  },
+  SET_VERIFYCODE: (state, code) => {
+    state.verifyCode = 'data:image/gif;base64,' + code
   }
 }
 
 const actions = {
+
+  /** 获取验证码 */
+  GetCode({ state, commit }) {
+    return new Promise((resolve, reject) => {
+      getCode(true).then(res => {
+        console.log(res)
+        const { publicKey, verifyCode } = res.data
+        setPubKey(publicKey)
+        commit('SET_VERIFYCODE', verifyCode)
+        resolve()
+      }).catch(err => {
+        reject(err)
+      })
+    })
+  },
+
   /**
    * 用户登录
    * @param commit
@@ -60,10 +82,9 @@ const actions = {
    * @returns {Promise<unknown>}
    * @constructor
    */
-  Login({ commit }, userInfo) {
-    const { userName, password, code, uid, publicKey } = userInfo
-    setPubKey(publicKey)
-    const pwd = encrypt(password, publicKey)
+  Login({ commit, state }, userInfo) {
+    const { userName, password, code, uid } = userInfo
+    const pwd = encrypt(password, state.publicKey)
     return new Promise((resolve, reject) => {
       login(userName, pwd, code, uid).then(response => {
         const { token, user } = response.data

+ 1 - 1
chuanyi-admin/src/utils/request.js

@@ -16,7 +16,7 @@ export const isRelogin = {
 axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
 // create an axios instance
 const service = axios.create({
-  baseURL: 'http://192.168.0.4:8081', // url = base url + request url
+  baseURL: 'http://192.168.1.226:8081', // url = base url + request url
   // withCredentials: true, // send cookies when cross-domain requests
   timeout: 30000 // request timeout
 })

+ 17 - 21
chuanyi-admin/src/views/login/index.vue

@@ -72,7 +72,7 @@
           />
         </div>
         <div class="login-code">
-          <img :src="codeUrl" class="login-code-img" @click="getCode">
+          <img :src="url" class="login-code-img" @click="getCode">
         </div>
       </el-form-item>
       <el-button
@@ -88,7 +88,7 @@
 </template>
 
 <script>
-import { getCode } from '@/api/user'
+// import { getCode } from "@/api/user";
 import { Message } from 'element-ui'
 import errorCode from '@/utils/errorCode'
 
@@ -96,7 +96,7 @@ export default {
   name: 'Login',
   data() {
     return {
-      codeUrl: '',
+      // codeUrl: "",
       loginForm: {
         publicKey: '',
         userName: '',
@@ -141,6 +141,11 @@ export default {
       otherQuery: {}
     }
   },
+  computed: {
+    url() {
+      return this.$store.getters.verifyCode
+    }
+  },
   watch: {
     $route: {
       handler: function(route) {
@@ -156,27 +161,22 @@ export default {
   created() {
     this.getCode()
   },
-  mounted() {},
-  destroyed() {},
   methods: {
-    getCode() {
+    async getCode() {
       const loading = this.$loading({
         lock: true,
         text: 'Loading',
         spinner: 'el-icon-loading',
         background: 'rgba(0, 0, 0, 0.7)'
       })
-      getCode(true).then((res) => {
-        this.captchaEnabled =
-          res.captchaEnabled === undefined ? true : res.captchaEnabled
-        if (this.captchaEnabled) {
-          const data = res.data
-          this.loginForm.uid = data.uid
-          this.loginForm.publicKey = data.publicKey
-          this.codeUrl = 'data:image/gif;base64,' + data.verifyCode
-        }
-        loading.close()
-      })
+      // getCode(true).then((res) => {
+      //   const data = res.data;
+      //   this.loginForm.uid = data.uid;
+      //   this.loginForm.publicKey = data.publicKey;
+      //   this.codeUrl = "data:image/gif;base64," + data.verifyCode;
+      // });
+      await this.$store.dispatch('user/GetCode')
+      loading.close()
     },
     checkCapslock(e) {
       const { key } = e
@@ -227,10 +227,6 @@ export default {
         return acc
       }, {})
     }
-  },
-  beforeRouteUpdate(to, from, next) {
-    this.getCode()
-    next()
   }
 }
 </script>