wy 11 месяцев назад
Родитель
Сommit
08fa4fee22

+ 3 - 0
src/api/oauth2/oauth2.js

@@ -62,6 +62,9 @@ var processToken = function(that, callback) {
       return callback(err, data, res)
     }
     data.create_at = createAt
+    if (res.variables && res.variables.licJson) {
+      data.licJson = JSON.parse(res.variables.licJson)
+  }
     // 存储token
     that.saveToken(data.uid, data, function(err) {
       callback(err, new AccessToken(data))

+ 22 - 72
src/store/getters.js

@@ -1,100 +1,50 @@
 export default {
     // ===========  用户相关
-    userId: (state) =>
-        state.ibps.user.info && state.ibps.user.info.user
-            ? state.ibps.user.info.user.id
-            : "", // 用户ID
-    name: (state) =>
-        state.ibps.user.info && state.ibps.user.info.employee
-            ? state.ibps.user.info.employee.name
-            : "", // 姓名
-    status: (state) =>
-        state.ibps.user.info && state.ibps.user.info.employee
-            ? state.ibps.user.info.employee.status
-            : "", // 用户状态
+    userId: (state) =>state.ibps.user.info && state.ibps.user.info.user? state.ibps.user.info.user.id : "", // 用户ID
+    name: (state) =>state.ibps.user.info && state.ibps.user.info.employee? state.ibps.user.info.employee.name: "", // 姓名
+    status: (state) =>state.ibps.user.info && state.ibps.user.info.employee? state.ibps.user.info.employee.status : "", // 用户状态
     org: (state) => (state.ibps.user.info ? state.ibps.user.info.org : {}), // 用户部门信息
-    position: (state) =>
-        state.ibps.user.info && state.ibps.user.info.employee
-            ? state.ibps.user.info.employee.positions
-            : "", // 用户部门信息
-    isSuper: (state) =>
-        state.ibps.user.info && state.ibps.user.info.user
-            ? state.ibps.user.info.user.isSuper === "Y"
-            : false, // 是否超级管理员
-    account: (state) =>
-        state.ibps.user.info && state.ibps.user.info.user
-            ? state.ibps.user.info.user.account
-            : "", // 用户名
+    position: (state) =>state.ibps.user.info && state.ibps.user.info.employee? state.ibps.user.info.employee.positions: "", // 用户部门信息
+    isSuper: (state) => state.ibps.user.info && state.ibps.user.info.user ? state.ibps.user.info.user.isSuper === "Y" : false, // 是否超级管理员
+    account: (state) =>state.ibps.user.info && state.ibps.user.info.user ? state.ibps.user.info.user.account : "", // 用户名
     regOpen: (state) => state.ibps.user.regOpen, // 注册状态
 
     userInfo: (state) => state.ibps.user.info, // 用户信息
 
     // =========== 租户
-    tenant: (state) =>
-        state.ibps.user.info && state.ibps.user.info.mainTenant
-            ? state.ibps.user.info.mainTenant || {}
-            : {}, // 当前租户
-    tenants: (state) =>
-        state.ibps.user.info && state.ibps.user.info.tenants
-            ? state.ibps.user.info.tenants || []
-            : [], // 当前拥有的租户
-    tenantid: (state) =>
-        state.ibps.user.info && state.ibps.user.info.tenantId
-            ? state.ibps.user.info.tenantId || ""
-            : "", // 租户id
-    isTenantAdmin: (state) =>
-        state.ibps.user.info && state.ibps.user.info.isTenantAdmin
-            ? state.ibps.user.info.isTenantAdmin || false
-            : false, // 是否租户管理员
+    tenant: (state) => state.ibps.user.info && state.ibps.user.info.mainTenant ? state.ibps.user.info.mainTenant || {} : {}, // 当前租户
+    tenants: (state) => state.ibps.user.info && state.ibps.user.info.tenants ? state.ibps.user.info.tenants || [] : [], // 当前拥有的租户
+    tenantid: (state) => state.ibps.user.info && state.ibps.user.info.tenantId ? state.ibps.user.info.tenantId || "": "", // 租户id
+    isTenantAdmin: (state) => state.ibps.user.info && state.ibps.user.info.isTenantAdmin? state.ibps.user.info.isTenantAdmin || false : false, // 是否租户管理员
 
     single: (state) => state.ibps.api.single, // 单体应用
     baseApi: (state) => state.ibps.api.base, // baseAPI地址
     websocket: (state) => state.ibps.api.websocket, // websocket地址
 
-    isTenantOpen: (state) =>
-        state.ibps.sass ? state.ibps.sass.tenantOpen : false, // 是否租户模式
+    isTenantOpen: (state) =>state.ibps.sass ? state.ibps.sass.tenantOpen : false, // 是否租户模式
 
-    designTenantid: (state) =>
-        state.ibps.user && state.ibps.user.designTenantid
-            ? state.ibps.user.designTenantid || ""
-            : "",
+    designTenantid: (state) =>state.ibps.user && state.ibps.user.designTenantid ? state.ibps.user.designTenantid || "" : "",
     // =========== 菜单
     menus: (state) => state.ibps.menu.menus, // 菜单
     routers: (state) => state.ibps.menu.routers, // 新增的路由表
     // =========== 子系统
     system: (state) => state.ibps.system.system, // 子系统
-    systemid: (state) =>
-        state.ibps.system.system ? state.ibps.system.system.id : "", // 子系统id
+    systemid: (state) =>state.ibps.system.system ? state.ibps.system.system.id : "", // 子系统id
 
     permissions: (state) => state.ibps.menu.permissions, //  拥有的权限
-    jianCeDuiXiangId: (state) =>
-        state.ibps.jianCeDuiXiangId ? state.ibps.jianCeDuiXiangId : "",
+    jianCeDuiXiangId: (state) =>state.ibps.jianCeDuiXiangId ? state.ibps.jianCeDuiXiangId : "",
     myform: (state) => (state.ibps.myform ? state.ibps.myform : ""),
-    jianCeCanShuId: (state) =>
-        state.ibps.jianCeCanShuId ? state.ibps.jianCeCanShuId : "",
+    jianCeCanShuId: (state) => state.ibps.jianCeCanShuId ? state.ibps.jianCeCanShuId : "",
     // 所有检测项目名称及流程key数组
-    testingList: (state) =>
-        state.ibps.param && state.ibps.param.testingList
-            ? state.ibps.param.testingList
-            : [],
+    testingList: (state) => state.ibps.param && state.ibps.param.testingList ? state.ibps.param.testingList : [],
     // 获取所有用户信息
-    userList: (state) =>
-        state.ibps.param && state.ibps.param.userList
-            ? state.ibps.param.userList
-            : [],
+    userList: (state) =>state.ibps.param && state.ibps.param.userList ? state.ibps.param.userList : [],
     // 获取用户最高层级
-    level: (state) =>
-        state.ibps.param && state.ibps.param.level
-            ? state.ibps.param.level
-            : [],
+    level: (state) => state.ibps.param && state.ibps.param.level ? state.ibps.param.level : [],
     // 获取所有部门信息
-    deptList: (state) =>
-        state.ibps.param && state.ibps.param.deptList
-            ? state.ibps.param.deptList
-            : [],
+    deptList: (state) => state.ibps.param && state.ibps.param.deptList ? state.ibps.param.deptList : [],
     // 获取所有岗位信息
-    positionList: (state) =>
-        state.ibps.param && state.ibps.param.positionList
-            ? state.ibps.param.positionList
-            : []
+    positionList: (state) =>state.ibps.param && state.ibps.param.positionList ? state.ibps.param.positionList : [],
+    // 获取认证信息
+    licence: state => state.ibps.licence ? state.ibps.licence.licJson : {}
 }

+ 13 - 1
src/store/modules/ibps/modules/account.js

@@ -49,10 +49,22 @@ export default {
         // 开始请求登录接口
         login(form).then(async response => {
           const data = response.data
+          const tokenInfo = JSON.parse(JSON.stringify(data))
+          tokenInfo.licJson = undefined
+          const licenceData = data.licJson || { isTrialVersion: false }
+          const { isTrialVersion, notAfter, reminderDays, notBefore } = licenceData
+          const now = Date.now()
+          // 判定是否超时
+          licenceData.overtime = isTrialVersion && (notBefore > now || notAfter < now)
+          // 判定是否提醒
+          licenceData.needRemind = isTrialVersion && notBefore < now && notAfter > now && now + reminderDays * 86400000 > notAfter
+           // 更新token
            dispatch('updataTokenInfo', data)
           // 设置 vuex 用户信息
            dispatch('ibps/user/setAccount', form.username, { root: true })
-
+          // 设置认证信息
+          dispatch('ibps/licence/setLicence', licenceData, { root: true })
+          localStorage.setItem('licence', JSON.stringify(licenceData))
           // 结束
           resolve(data)
         }).catch(err => {

+ 16 - 0
src/store/modules/ibps/modules/licence.js

@@ -0,0 +1,16 @@
+export default {
+    namespaced: true,
+    state: {
+        licJson: {}
+    },
+    mutations: {
+        updateLicJson (state, data) {
+            state.licJson = data
+        }
+    },
+    actions: {
+        setLicence ({ commit }, data) {
+            commit('updateLicJson', data)
+        }
+    }
+}