Browse Source

单点登录

shenji 2 năm trước cách đây
mục cha
commit
5f4dc7392b
2 tập tin đã thay đổi với 87 bổ sung5 xóa
  1. 26 1
      src/store/modules/user.js
  2. 61 4
      src/views/Index.vue

+ 26 - 1
src/store/modules/user.js

@@ -86,6 +86,31 @@ const user = {
         })
       })
     },
+    //单点登录uuid
+    uuidLogin({ commit }, param) {
+      return new Promise((resolve, reject) => {
+        postAction("/sys/uuid/login",param).then(response => {
+          if(response.success){
+            const result = response.result
+            const userInfo = result.userInfo
+            console.log(result)
+            console.log(userInfo)
+            Vue.ls.set(ACCESS_TOKEN, result.token, 7 * 24 * 60 * 60 * 1000)
+            Vue.ls.set(USER_NAME, userInfo.username, 7 * 24 * 60 * 60 * 1000)
+            Vue.ls.set(USER_INFO, userInfo, 7 * 24 * 60 * 60 * 1000)
+            commit('SET_TOKEN', result.token)
+            commit('SET_INFO', userInfo)
+            commit('SET_NAME', { username: userInfo.username,realname: userInfo.realname, welcome: welcome() })
+            commit('SET_AVATAR', userInfo.avatar)
+            resolve(response)
+          }else{
+            resolve(response)
+          }
+        }).catch(error => {
+          reject(error)
+        })
+      })
+    },
     // 登录
     Login({ commit }, userInfo) {
       return new Promise((resolve, reject) => {
@@ -244,4 +269,4 @@ const user = {
   }
 }
 
-export default user
+export default user

+ 61 - 4
src/views/Index.vue

@@ -7,7 +7,12 @@
   // @ is an alias to /src
 
   import Trend from '@/components/Trend'
-import { WindowsFill } from '@ant-design/icons/lib/dist';
+  import { WindowsFill } from '@ant-design/icons/lib/dist';
+  import { mapActions } from 'vuex'
+  import Vue from 'vue'
+  import { ACCESS_TOKEN, ENCRYPTED_STRING, USER_INFO } from '@/store/mutation-types'
+  import store from '@/store/'
+  import { timeFix } from '@/utils/util'
 
 
   export default {
@@ -17,14 +22,66 @@ import { WindowsFill } from '@ant-design/icons/lib/dist';
     },
     data () {
       return {
-        targetTime: new Date().getTime() + 3900000
       }
     },
     created(){
-      window.location.href = 'http://172.18.91.12:8888/sso/oauth/authorize?client_id=OAManager&response_type=code&redirect_url=http://172.18.91.36:8083/#/redirect/login'
+      this.getUUID();
     },
+    // created(){
+    //   window.location.href = 'http://172.18.91.12:8888/sso/oauth/authorize?client_id=OAManager&response_type=code&redirect_url=http://172.18.91.36:8083/#/redirect/login'
+    // },
     methods: {
-      
+      ...mapActions(['uuidLogin']),
+      getUUID(){
+        var url = window.location.href ;     
+        // var dz_url = url.split('#')[0];                //获取#/之前的字符串
+        var cs = url.split('?')[1];                //获取?之后的参数字符串
+        if(cs==undefined){
+          window.location.href = 'http://172.18.91.12:8888/sso/oauth/authorize?client_id=OAManager&response_type=code&redirect_url=http://172.18.91.36:8083/#/redirect/login'
+        }
+        var cs_arr = cs.split('&');                    //参数字符串分割为数组
+        var cs={};
+        for(var i=0;i<cs_arr.length;i++){         //遍历数组,拿到json对象
+          cs[cs_arr[i].split('=')[0]] = cs_arr[i].split('=')[1]
+        }
+
+        this.uuid = cs.uuid;
+        this.redirect = cs.redirect;
+        if(this.uuid){
+          this.uuidLogin({'uuid':this.uuid}).then(res=>{
+            if (res.success) {
+              console.log('用户信息', res)
+              let multi_depart = res.result.multi_depart
+              // 0:无部门 1:一个部门 2:多个部门
+              if (multi_depart == 0) {
+                  this.$notification.warn({
+                      message: '提示',
+                      description: `您尚未归属公司,请确认OA账号信息`,
+                      duration: 3
+                  })
+              } else {
+                  console.log('登录')
+                  const userInfo = res.result.userInfo
+                  Vue.ls.set(USER_INFO, userInfo, 7 * 24 * 60 * 60 * 1000)
+                  store.commit('SET_INFO', userInfo)
+                  if(this.redirect){
+                    this.$router.push({ name: this.redirect })
+                  }else{
+                    this.$router.push({ name: 'dashboard' })
+                  }
+              }
+            }
+          }).catch(err=>{
+            this.$notification['error']({
+              message: '认证失败',
+              description: ((err.response || {}).data || {}).message || err.message || '请求出现错误,请稍后再试',
+              duration: 4
+            })
+          })
+        }else{
+          window.location.href = 'http://172.18.91.12:8888/sso/oauth/authorize?client_id=OAManager&response_type=code&redirect_url=http://172.18.91.36:8083/#/redirect/login'
+        }
+      },
     }
   }
 </script>