Browse Source

爱思打通单点登录

sunlupeng 1 year ago
parent
commit
078f7c3e77
5 changed files with 61 additions and 14 deletions
  1. 3 3
      config/dev.env.js
  2. 19 3
      src/permission.js
  3. 4 0
      src/store/modules/user.js
  4. 16 2
      src/utils/request.js
  5. 19 6
      src/views/sys/admin.vue

+ 3 - 3
config/dev.env.js

@@ -2,9 +2,9 @@ module.exports = {
 	NODE_ENV: '"development"',
 	ENV_CONFIG: '"dev"',
   // 本地数据库:登录用户名 admin123,密码 admin123
-  // BASE_API: '"http://192.168.100.208:9083/admin"',
-  BASE_API: '"http://47.103.79.143:9085/admin"',
-  OS_API: '"http://47.103.79.143:9085/admin"',
+  BASE_API: '"http://192.168.100.208:9083/admin"',
+  // BASE_API: '"http://47.103.79.143:9085/admin"',
+  OS_API: '"http://192.168.100.208:9083/admin"',
   // OS_API: '"https://xiaoyou.dgtis.com/admin"',
   // BASE_API: '"https://xiaoyou.dgtis.com/admin"',
   

+ 19 - 3
src/permission.js

@@ -63,8 +63,9 @@ router.beforeEach((to, from, next) => {
   debugger
   NProgress.start() // start progress bar
   const path = to.path;
-  const token = to.query.Authorization
+  const token = to.query.xToken;
   if (path.indexOf('auth') != -1 && token) { 
+    store.dispatch('SetToken', token);
     setToken(token);
   }
   if (getToken()) { // determine if there has token
@@ -81,12 +82,20 @@ router.beforeEach((to, from, next) => {
             store.dispatch('GenerateRoutes', { roles }).then(() => { // 根据roles权限生成可访问的路由表
               router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表
               next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record
+              next({ path: '/' });
             })
           })
         }).catch(() => {
           store.dispatch('FedLogOut').then(() => {
             Message.error('Verification failed, please login again')
-            next({ path: '/login' })
+            // const prodHref = 'http://dgt.dgtis.com/oneportal/login';//正式地址
+
+            const prodHref = 'http://dgtcloud.dgtis.com/oneportal/login';//阿里云地址
+            
+            const devHref = 'http://192.168.100.208:8080/oneportal/login';//测试地址
+
+            location.href = process.env.NODE_ENV === 'production' ? prodHref : devHref;
+            // next({ path: '/login' })
           })
         })
       } else {
@@ -104,7 +113,14 @@ router.beforeEach((to, from, next) => {
     if (whiteList.indexOf(to.path) !== -1) { // 在免登录白名单,直接进入
       next()
     } else {
-      next('/login') // 否则全部重定向到登录页
+      // const prodHref = 'http://dgt.dgtis.com/oneportal/login';//正式地址
+
+      const prodHref = 'http://dgtcloud.dgtis.com/oneportal/login';//阿里云地址
+      
+      const devHref = 'http://192.168.100.208:8080/oneportal/login';//测试地址
+
+      location.href = process.env.NODE_ENV === 'production' ? prodHref : devHref;
+      // next('/login') // 否则全部重定向到登录页
       NProgress.done() // if current page is login will not trigger afterEach hook, so manually handle it
     }
   }

+ 4 - 0
src/store/modules/user.js

@@ -44,6 +44,10 @@ const user = {
   },
 
   actions: {
+    //保存token
+    SetToken({ commit }, token){
+      commit('SET_TOKEN', token)
+    },
     // 用户名登录
     LoginByUsername({ commit }, userInfo) {
       const username = userInfo.username.trim()

+ 16 - 2
src/utils/request.js

@@ -34,7 +34,14 @@ service.interceptors.response.use(
           type: 'error'
         }).then(() => {
           store.dispatch('FedLogOut').then(() => {
-            location.reload()
+            // const prodHref = 'http://dgt.dgtis.com/oneportal/login';//正式地址
+
+            const prodHref = 'http://dgtcloud.dgtis.com/oneportal/login';//阿里云地址
+            
+            const devHref = 'http://192.168.100.208:8080/oneportal/login';//测试地址
+
+            location.href = process.env.NODE_ENV === 'production' ? prodHref : devHref;
+            // location.reload()
           })
         })
       }else if(res.errno==403){
@@ -43,7 +50,14 @@ service.interceptors.response.use(
           type: 'error'
         }).then(() => {
           store.dispatch('FedLogOut').then(() => {
-            location.reload()
+             // const prodHref = 'http://dgt.dgtis.com/oneportal/login';//正式地址
+
+             const prodHref = 'http://dgtcloud.dgtis.com/oneportal/login';//阿里云地址
+            
+             const devHref = 'http://192.168.100.208:8080/oneportal/login';//测试地址
+ 
+             location.href = process.env.NODE_ENV === 'production' ? prodHref : devHref;
+             // location.reload()
           })
         })
       }else{

+ 19 - 6
src/views/sys/admin.vue

@@ -46,9 +46,15 @@
     <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible">
       <template v-if="!dialogFlag">
         <el-form :rules="rules" ref="dataForm" :model="dataForm" status-icon label-position="left" label-width="120px" style='width: 400px; margin-left:50px;'>
-          <el-form-item label="管理员名称" prop="username">
+          <!-- <el-form-item label="管理员名称" prop="username">
             <el-input v-if="dialogStatus=='create'" v-model="dataForm.username" auto-complete="off"></el-input>
             <el-input v-else v-model="dataForm.username" disabled auto-complete="off"></el-input>
+          </el-form-item> -->
+          <el-form-item label="管理员" prop="username">
+                    <el-select :disabled="dialogStatus=='create'?false:true" v-model="dataForm.username" filterable clearable placeholder="请选择" style="width: 280px">
+                        <el-option :key="item.loginId" v-for="item in recipientsList" :label="item.userName" :value="item.loginId">
+                        </el-option>
+                    </el-select>
           </el-form-item>
           <el-form-item label="管理员密码" prop="password">
             <el-input type="password" v-model="dataForm.password"  auto-complete="off"></el-input>
@@ -67,6 +73,7 @@
           </el-form-item>-->
           <el-form-item label="关联微信用户" prop="userId">
             <el-select
+            style="width: 280px"
               v-model="dataForm.userId"
               :filterable="selectfilterable"
               :remote="selectremote"
@@ -151,6 +158,7 @@ import { listAdmin, createAdmin, updateAdmin, deleteAdmin, getWxUserId, getUser}
 import { selectUserByUserName } from "@/api/organize"
 import { roleList, selectAdminRole, addAdminRole } from '@/api/role'
 import { createStorage } from '@/api/storage'
+import { allUserList } from "@/api/public";
 import waves from '@/directive/waves' // 水波纹指令
 
 export default {
@@ -202,6 +210,7 @@ export default {
       }
     }
     return {
+      recipientsList: [],
       list: null,
       role: undefined,
       total: null,
@@ -237,9 +246,7 @@ export default {
         create: '创建'
       },
       rules: {
-        username: [
-          { required: true, message: '管理员名称不能为空', trigger: 'blur' },
-          { validator: validateUserName, trigger: 'blur'}],
+        username: [{ required: true, message: '管理员不能为空', trigger: 'blur' }],
         nickname: [{ required: true, message: '管理员昵称不能为空', trigger: 'blur' }],
         password: [
           { required: true, message: '密码不能为空', trigger: 'blur' },
@@ -264,10 +271,16 @@ export default {
     }
   },
   created() {
-    this.getList()
-    this.getRoleList()
+    this.getList();
+    this.getRoleList();
+    this.getAllUserList(); 
   },
   methods: {
+    getAllUserList() {
+            allUserList().then(response => {
+                this.recipientsList = response.data.data;
+            }).catch(() => {});
+        },
     getList() {
       this.listLoading = true
       listAdmin(this.listQuery).then(response => {