Przeglądaj źródła

登录和逻辑修改

zhaoke 1 rok temu
rodzic
commit
2c96aa5f5c

+ 1 - 0
package.json

@@ -22,6 +22,7 @@
     "element-ui": "^2.15.6",
     "file-saver": "^2.0.5",
     "js-cookie": "2.2.0",
+    "jsencrypt": "^3.3.2",
     "lodash": "^4.17.21",
     "normalize.css": "7.0.0",
     "nprogress": "0.2.0",

+ 8 - 0
pnpm-lock.yaml

@@ -32,6 +32,9 @@ dependencies:
   js-cookie:
     specifier: 2.2.0
     version: 2.2.0
+  jsencrypt:
+    specifier: ^3.3.2
+    version: 3.3.2
   lodash:
     specifier: ^4.17.21
     version: 4.17.21
@@ -5696,6 +5699,7 @@ packages:
 
   /file-uri-to-path@1.0.0:
     resolution: {integrity: sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==}
+    requiresBuild: true
     dev: true
 
   /filename-regex@2.0.1:
@@ -7818,6 +7822,10 @@ packages:
       - utf-8-validate
     dev: true
 
+  /jsencrypt@3.3.2:
+    resolution: {integrity: sha512-arQR1R1ESGdAxY7ZheWr12wCaF2yF47v5qpB76TtV64H1pyGudk9Hvw8Y9tb/FiTIaaTRUyaSnm5T/Y53Ghm/A==}
+    dev: false
+
   /jsesc@0.5.0:
     resolution: {integrity: sha512-uZz5UnB7u4T9LvwmFqXii7pZSouaRPorGs5who1Ip7VO0wxanFvBL7GkM6dTHlgX+jhBApRetaWpnDabOeTcnA==}
     hasBin: true

+ 50 - 3
src/api/login.js

@@ -7,6 +7,7 @@
  * @FilePath: \CABaggageData\src\api\login.js
  */
 import request from '@/utils/request-new'
+import requsetNew from '@/utils/request'
 
 //获取权限
 export function getAuth (params) {
@@ -28,8 +29,8 @@ export function signIn (params) {
 
 //登出
 export function loginOut (params) {
-    return request({
-        url: '/foxlibc/loginOut',
+    return requsetNew({
+        url: '/foxlibc/sign-out',
         method: 'post',
         data: params
     })
@@ -47,7 +48,7 @@ export function getVCode (params) {
 //重置token
 export function refreshToken (params) {
     return request({
-        url: '/foxlibc/refreshToken',
+        url: '/foxlibc/testToken',
         method: 'post',
         data: params
     })
@@ -62,3 +63,49 @@ export function getToken (params) {
         istoken: true
     })
 }
+
+//获取加密公匙
+export function getKey (params) {
+    return request({
+        url: '/user/publicKey',
+        method: 'post',
+        data: params,
+    })
+}
+
+//获取加密公匙
+export function forceLogin (params) {
+    return request({
+        url: '/foxlibc/force_sign',
+        method: 'post',
+        data: params,
+    })
+}
+
+//获取用户权限
+export function getPermissions (params) {
+    return requsetNew({
+        url: '/foxlibc/permissions',
+        method: 'post',
+        data: params,
+    })
+}
+
+//修改密码
+export function resetPasswd (params) {
+    return requsetNew({
+        url: '/foxlibc/reset-passwd',
+        method: 'post',
+        data: params,
+    })
+}
+
+//用户心跳
+export function userHealth (params) {
+    return requsetNew({
+        url: '/foxlibc/health',
+        method: 'post',
+        data: params,
+    })
+}
+

BIN
src/assets/home/BG_.jpg


+ 27 - 31
src/getMenu.js

@@ -37,7 +37,6 @@ router.beforeEach(async (to, from, next) => {
 
   // determine whether the user has logged in
   const hasToken = getToken()
-
   if (hasToken) {
     if (to.path === '/login') {
       // if is logged in, redirect to the home page
@@ -50,12 +49,12 @@ router.beforeEach(async (to, from, next) => {
       } else {
         try {
           const treeData = await store.dispatch('user/getMenuInfo')
-          const nd = treeData.filter(item => item.auth_id)
+          const nd = treeData.filter(item => item.pageid)
           store.dispatch('auth/changeAuthArrs', nd)
           // const typeData = setType(treeData, 'up_auth_id', 'auth_id')
           const menusArray = parseMenuItem(nd)
-          const treeMenu = listToTree(menusArray, 'up_auth_id', 'auth_id')
-          const dataMenu = _.unionBy(treeMenu, 'auth_id')
+          const treeMenu = listToTree(menusArray, 'superiorid', 'pageid')
+          const dataMenu = _.unionBy(treeMenu, 'pageid')
           const menus = parseMenu(dataMenu)
           store.dispatch('permission/setRoutes', menus)
           router.addRoutes(menus)
@@ -86,36 +85,40 @@ router.beforeEach(async (to, from, next) => {
 function parseMenuItem (data) {
   const menus = []
   data.map(item => {
-    if (item.auth_type == 1) {
+    if (item.opentype == 1) {
       menus.push({
-        auth_id: item.auth_id,
-        up_auth_id: item.up_auth_id,
-        path: item.route_info,
-        name: item.auth_ident,
+        auth_id: item.pageid,
+        up_auth_id: item.superiorid,
+        path: item.router,
+        name: item.pagedescribe,
         meta: {
-          title: item.auth_name,
-          elSvgIcon: item.show_icon ?? 'Fold',
-          show_index: item.show_index,
-          qid: item.queryTemplateID,
+          title: item.pagename,
+          elSvgIcon: item.icon ?? 'Fold',
+          show_index: item.defaultindex,
+          qid: item.serviceid,
         },
         component: Layout,
         hidden: !item.is_show,
       })
-    } else if (item.auth_type == 2) {
+    } else if (item.opentype == 2) {
       menus.push({
-        auth_id: item.auth_id,
-        up_auth_id: item.up_auth_id,
-        path: item.route_info,
-        name: item.auth_ident,
+        auth_id: item.pageid,
+        up_auth_id: item.superiorid,
+        path: item.router,
+        name: item.pagedescribe,
         meta: {
-          title: item.auth_name,
-          elSvgIcon: item.show_icon ?? 'Fold',
-          show_index: item.show_index,
+          title: item.pagename,
+          elSvgIcon: item.icon ?? 'Fold',
+          show_index: item.defaultindex,
           qid: item.queryTemplateID,
-          auth_id: item.auth_id,
-          up_auth_id: item.up_auth_id,
+          auth_id: item.pageid,
+          up_auth_id: item.superiorid,
+          pagecode: item.pagecode,
+          superiorcode: item.superiorcode,
+          sort: item.sort,
+          tagetpageid: item.tagetpageid
         },
-        component: resolve => require(['@/views' + item.file_link], resolve),
+        component: resolve => require(['@/views' + item.filepath], resolve),
         // component: () => import('./views/table/index.vue'),
         hidden: !item.is_show,
       })
@@ -154,13 +157,6 @@ function parseMenu (arr) {
     redirect: '/404',
     hidden: true,
   })
-  if (allMenus[0].children && allMenus[0].children.length) {
-    allMenus[0].redirect = allMenus[0].children[0].path
-    allMenus[0].path = '/'
-  } else {
-    allMenus[0].redirect = allMenus[0].path
-    allMenus[0].path = '/'
-  }
   return allMenus
 }
 

+ 15 - 1
src/layout/components/Navbar.vue

@@ -52,6 +52,7 @@ import Breadcrumb from '@/components/Breadcrumb'
 import Hamburger from '@/components/Hamburger'
 // import { Format } from "../../config/util";
 import { timeInZone } from '@/utils/table'
+import { userHealth } from "@/api/login";
 // import TagsView from "./TagsView";
 
 export default {
@@ -61,8 +62,9 @@ export default {
       newData: '',
       breadList: this.getBreadcrumb(),
       getTimeInterval: null,
+      usertHeart: null,
       imgSrc: window.location.origin + sessionStorage.getItem('appLog'),
-      pageTitle: sessionStorage.getItem('appName'),
+      pageTitle: sessionStorage.getItem('appName') ?? '行李全流程跟踪系统',
       name: sessionStorage.getItem('userName')
     }
   },
@@ -84,15 +86,27 @@ export default {
       // this.newData = Format("yyyy/MM/dd hh:mm:ss", new Date());
       this.newData = timeInZone(new Date(), this.timeZone).replaceAll('-', '/')
     })
+    this.usertHeart = setInterval(() => {
+      this.setUserHeart()
+    }, 1000 * 10);
   },
   beforeDestroy () {
     this.getTimeInterval && clearInterval(this.getTimeInterval)
     this.getTimeInterval = null
+    this.usertHeart && clearInterval(this.usertHeart)
+    this.usertHeart = null
   },
   methods: {
     errorHandler () {
       return true
     },
+    //心跳连接
+    async setUserHeart () {
+      const { code, message } = await userHealth();
+      if (code != 0) {
+        this.$message.error(message);
+      }
+    },
     toggleSideBar () {
       this.$store.dispatch('app/toggleSideBar')
     },

+ 9 - 26
src/layout/index.vue

@@ -61,6 +61,8 @@ import Dialog from '@/layout/components/Dialog'
 import MD5 from 'blueimp-md5'
 import PassengerDialog from '@/components/PassengerDialog'
 import AbnormalBaggageDialog from '@/components/AbnormalBaggageDialog'
+import { resetPasswd } from '@/api/login'
+import JSEncrypt from "jsencrypt"
 export default {
   name: 'Layout',
   components: {
@@ -147,33 +149,14 @@ export default {
     // 修改密码
     async editPwd () {
       try {
-        const res = await modifyData({
-          serviceId: SERVICE_ID.changePwd,
-          dataContent: {
-            filter: [
-              {
-                left: '(',
-                column: 'user_id',
-                comparator: '=',
-                value: sessionStorage.getItem('User_Id'),
-                right: ')',
-                connector: 'and',
-              },
-              {
-                left: '(',
-                column: 'user_pwd',
-                comparator: '=',
-                value: MD5(this.dataForm.old),
-                right: ')',
-                connector: 'and',
-              },
-            ],
-            Value: {
-              user_pwd: MD5(this.dataForm.again),
-            },
-          },
+        const pubKeyStr = sessionStorage.getItem('pubKeyStr')
+        const jse = new JSEncrypt()
+        jse.setPublicKey(pubKeyStr)
+        const res = await resetPasswd({
+          oldpassword: jse.encrypt(this.dataForm.old),
+          password: jse.encrypt(this.dataForm.again)
         })
-        if (res.code == 0 && res.sql.includes('update')) {
+        if (res.code == 0) {
           this.$message.success(res.message ?? '成功')
           this.$store.dispatch('app/togglePwdflag', false)
           setTimeout(() => {

+ 14 - 1
src/router/index.js

@@ -8,6 +8,7 @@
  */
 import Vue from 'vue'
 import Router from 'vue-router'
+import Layout from '@/layout'
 
 Vue.use(Router)
 
@@ -52,7 +53,19 @@ export const constantRoutes = [
     path: '/404',
     component: () => import('@/views/404'),
     hidden: true
-  }
+  },
+  {
+    path: '/',
+    component: Layout,
+    hidden: true,
+    children: [
+      {
+        path: '',
+        name: 'HomePage',
+        component: () => import('@/views/HomePage/index.vue'),
+      },
+    ],
+  },
   // { path: '/', redirect: '/nopower', component: () => import('@/views/noPower'), hidden: true }
   // 404 page must be placed at the end !!!
 ]

+ 10 - 21
src/store/modules/user.js

@@ -2,10 +2,10 @@ import { getToken, setToken, removeToken, setUserId, TokenKey } from '@/utils/au
 import { resetRouter } from '@/router'
 import { Query } from "@/api/webApi"
 import { isValue } from "@/utils/validate"
-import { getAuth, signIn, loginOut } from '@/api/login'
+import { getAuth, signIn, loginOut, getPermissions } from '@/api/login'
 const getDefaultState = () => {
   return {
-    token: getToken(),
+    token: getToken(TokenKey),
     name: '',
     avatar: '',
     isLogin: false,
@@ -66,14 +66,12 @@ const actions = {
       signIn(userInfo)
         .then(response => {
           if (response.code == 0 && isValue(response.returnData)) {
-            const { user_token, user_id } = response.returnData
-            commit('SET_TOKEN', user_token)
-            commit('SET_UserType', 1)
-            commit('SET_UserId', user_id)
-            setToken('userName', userInfo.username)
-            setToken(TokenKey, user_token)
-            setUserId(user_id)
-            setToken('userid', user_id)
+            const { userstatus, userid } = response.returnData
+            commit('SET_UserType', userstatus)
+            commit('SET_UserId', userid)
+            setToken('userName', userInfo.account)
+            setUserId(userid)
+            setToken('userid', userid)
             resolve(true)
           } else {
             reject(false)
@@ -87,13 +85,7 @@ const actions = {
 
   getMenuInfo ({ commit }) {
     return new Promise((resolve, reject) => {
-      Query({
-        serviceId: SERVICE_ID.sysAuthId,
-        dataContent: [{ user_id: getToken('userid') }],
-        page: 1,
-        pageSize: 999,
-        event: '0'
-      })
+      getPermissions()
         .then((res) => {
           if (res.code == 0 && isValue(res.returnData)) {
             commit('SET_ROLES', ['admin'])
@@ -111,10 +103,7 @@ const actions = {
   // user logout
   logout ({ commit }) {
     return new Promise((resolve, reject) => {
-      loginOut({
-        user_id: getToken('userid'),
-        user_token: getToken(TokenKey)
-      }).then(result => {
+      loginOut().then(result => {
         if (result) {
           sessionStorage.clear()
           removeToken() // must remove  token  first

+ 2 - 2
src/utils/request-new.js

@@ -23,8 +23,8 @@ service.interceptors.request.use(
     if (config.istoken) {
       config.headers['appSecret'] = PLATFROM_CONFIG.appKeyString
       isMttoken = config.istoken
-    } else if (getCodeToken()) {
-      config.headers["token"] = getCodeToken();
+    } else if (getToken()) {
+      config.headers["token"] = getToken();
     }
     return config
   },

+ 2 - 3
src/utils/request.js

@@ -23,9 +23,8 @@ service.interceptors.request.use(
   (config) => {
     // do something before request is sent
     // config.headers['Content-Type'] = 'text/plain'
-    if (store.getters.token) {
-      config.headers["user_id"] = getToken('userid');
-      config.headers["user_token"] = getToken(TokenKey);
+    if (getToken('usertoken')) {
+      config.headers["usertoken"] = getToken('usertoken');
     }
     return config;
   },

+ 34 - 0
src/views/HomePage/index.vue

@@ -0,0 +1,34 @@
+<template>
+  <div class="home-wrapper">
+    <div class="home-title">
+      <h1 class="home-title-main">欢迎使用</h1>
+      <h2 class="home-title-sub">行李全流程跟踪数据系统</h2>
+    </div>
+  </div>
+</template>
+
+<style scoped lang="scss">
+.home-wrapper {
+  margin: calc(var(--app-main-padding) * -1);
+  width: calc(100% + var(--app-main-padding) * 2);
+  height: calc(100vh - 80px);
+  background: url("../../assets/home/BG_.jpg") no-repeat center center;
+  background-size: cover;
+  display: flex;
+  align-items: center;
+  .home-title {
+    width: 100%;
+    text-align: center;
+    font-family: Microsoft YaHei;
+    font-weight: bold;
+    color: #ffffff;
+    &-main {
+      font-size: 40px;
+      margin-bottom: 16px;
+    }
+    &-sub {
+      font-size: 24px;
+    }
+  }
+}
+</style>

+ 91 - 34
src/views/login/index.vue

@@ -1,7 +1,11 @@
 <template>
-  <div class="login-container">
+  <div :style="{'background':backgroundImg ? 'url('+backgroundImg+')' :'url('+defaultBgImg+')'}" class="login-container">
     <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form" auto-complete="on" label-position="left">
       <div class="title-container flex-wrap">
+        <el-avatar :size="36" :src="imgSrc" @error="errorHandler">
+          <img src="@/assets/logo/error.png">
+        </el-avatar>
+        <!-- <el-divider direction="vertical"></el-divider> -->
         <div class="content-box">
           <div class="title">{{ pageTitle }}</div>
         </div>
@@ -29,9 +33,11 @@
 
 <script>
 import { isValue } from "@/utils/validate";
-import { getVCode, getToken } from "@/api/login";
-import { setCodeToken, getCodeToken, setToken } from '@/utils/auth';
+import { getVCode, getToken, getKey, forceLogin } from "@/api/login";
+import { setToken, TokenKey, getUserId, removeToken } from '@/utils/auth';
 import MD5 from 'blueimp-md5'
+import JSEncrypt from "jsencrypt";
+const defaultBgImg = require('@/assets/loginpage/bg.jpg')
 export default {
   name: "Login",
   data () {
@@ -59,7 +65,9 @@ export default {
       pageTitle: '',
       imgSrc: '',
       baseImg: '',
-      appId: ''
+      appId: '',
+      backgroundImg: '',
+      defaultBgImg
     };
   },
   async created () {
@@ -69,15 +77,16 @@ export default {
         'appsecret': PLATFROM_CONFIG.appKeyString
       })
       if (code == 0 && isValue(returnData)) {
-        const { appenname, appname, background, expirestime, logo, securitycoderule, smalllogo, token } = returnData;
-        this.imgSrc = window.location.origin + logo
-        this.pageTitle = appname
+        const { appname, background, logo, securitycoderule, smalllogo, token } = returnData;
+        this.imgSrc = logo
+        this.pageTitle = appname ?? '行李全流程跟踪系统'
         this.isCode = securitycoderule
-        setCodeToken(token);
+        this.backgroundImg = background
+        setToken(TokenKey, token);
         sessionStorage.setItem('appConfig', JSON.stringify({ ...returnData }))
         // setToken('active_duration', active_duration);
         sessionStorage.setItem('appLog', logo)
-        sessionStorage.setItem('appName', appname)
+        sessionStorage.setItem('appName', this.pageTitle)
         if (securitycoderule) {
           this.getCheckCode()
         }
@@ -99,41 +108,86 @@ export default {
         this.$refs.password.focus();
       });
     },
-    // 登录
+    // 登录前获取公匙
     handleLogin () {
-      this.$refs.loginForm.validate((valid) => {
+      this.$refs.loginForm.validate(async (valid) => {
         if (valid) {
-          this.loading = true;
-          const params = {
-            app_token: getCodeToken(),
-            username: this.loginForm.username.replace(/\s+/g, ""),
-            password: MD5(this.loginForm.password.replace(/\s+/g, "")),
-            // password: this.loginForm.password.replace(/\s+/g, ""),
-            verifyCode: this.loginForm.identify.replace(/\s+/g, ""),
-          };
-          this.$store
-            .dispatch("user/login", params)
-            .then(async () => {
-              this.$store.dispatch("app/toggleOutcheck", false);
-              sessionStorage.setItem("userName", params.username);
-              this.$router.push({ path: this.redirect || "/" });
-              this.loading = false;
-            })
-            .catch(() => {
-              this.getCheckCode();
-              this.loading = false;
-            });
+          const { code, message, returnData } = await getKey();
+          if (code == 0 && isValue(returnData)) {
+            const { pubKeyStr } = returnData
+            sessionStorage.setItem('pubKeyStr', pubKeyStr)
+            this.qdLogin(pubKeyStr)
+          } else {
+            this.$message.error(message);
+          }
+
         } else {
           return false;
         }
       });
     },
+    //确认登录
+    qdLogin (pubKeyStr) {
+      this.loading = true;
+      const jse = new JSEncrypt()
+      jse.setPublicKey(pubKeyStr)
+      const params = {
+        account: this.loginForm.username.replace(/\s+/g, ""),
+        password: jse.encrypt(this.loginForm.password.replace(/\s+/g, "")),
+      };
+      if (this.isCode) {
+        params.verifycode = jse.encrypt(this.loginForm.identify.replace(/\s+/g, ""))
+      }
+      this.$store
+        .dispatch("user/login", params)
+        .then(async (res) => {
+          if (res) {
+            this.dialogOpen()
+          } else {
+            this.userLogin()
+          }
+          this.loading = false;
+        })
+        .catch(() => {
+          this.getCheckCode();
+          this.loading = false;
+        });
+    },
+    //账号已经登录弹框
+    dialogOpen () {
+      this.$confirm('该账号已登录, 是否强制登录?', '提示', {
+        confirmButtonText: '确定',
+        cancelButtonText: '取消',
+        type: 'warning'
+      }).then(() => {
+        this.userLogin()
+      }).catch(() => {
+        this.$message({
+          type: 'info',
+          message: '已取消登录'
+        });
+      });
+    },
+    //账号强制登录
+    async userLogin () {
+      const { code, message, returnData } = await forceLogin({
+        userid: getUserId()
+      });
+      if (code == 0 && isValue(returnData)) {
+        setToken('usertoken', returnData.usertoken)
+        this.$store.dispatch("app/toggleOutcheck", false);
+        sessionStorage.setItem("userName", this.loginForm.username.replace(/\s+/g, ""));
+        this.$router.push({ path: this.redirect || "/" });
+      } else {
+        this.$message.error(message);
+      }
+    },
     //获取动态验证码
     async getCheckCode () {
       const { code, message, returnData } = await getVCode();
       if (code == 0 && isValue(returnData)) {
-        const { verifyCode } = returnData;
-        this.baseImg = "data:image/gif;base64," + verifyCode;
+        const { verifyCodeImage } = returnData;
+        this.baseImg = verifyCodeImage;
       } else {
         this.$message.error(message);
       }
@@ -142,6 +196,9 @@ export default {
     changeCode () {
       this.getCheckCode();
     },
+    errorHandler () {
+      return true
+    }
   },
 };
 </script>
@@ -156,7 +213,7 @@ $light_gray: #eee;
   width: 100%;
   background-color: $bg;
   overflow: hidden;
-  background-image: url("../../assets/loginpage/bg.jpg");
+  //background-image: url("../../assets/loginpage/bg.jpg");
   background-repeat: no-repeat;
   background-size: cover;
   display: flex;