Browse Source

博物馆单点登录

shenji 2 years ago
parent
commit
9f19c85fba

+ 1 - 0
public/index.html

@@ -271,6 +271,7 @@
     window._CONFIG['domianURL'] = 'http://127.0.0.1:8090/jeecg-boot'; // 本地测试
     // window._CONFIG['domianURL'] = 'http://106.15.206.14:8087/jeecg-boot';// 测试服务器
     // window._CONFIG['domianURL'] = 'http://220.191.168.86:18087/jeecg-boot';// 森语外网
+    // window._CONFIG['domianURL'] = 'http://172.18.91.36:8081/jeecg-boot';// 博物馆oa
     window._CONFIG['casPrefixUrl'] = 'http://cas.example.org:8443/cas';
     window._CONFIG['onlinePreviewDomainURL'] = 'http://fileview.jeecg.com/onlinePreview'
     window._CONFIG['staticDomainURL'] = window._CONFIG['domianURL'] + '/sys/common/static';

+ 3 - 1
src/components/tools/UserMenu.vue

@@ -168,8 +168,10 @@
           content: '真的要注销登录吗 ?',
           onOk() {
             return that.Logout({}).then(() => {
-                window.location.href="/";
+              window.location.href="/";
               //window.location.reload()
+                //博物馆单点登录注销
+                // window.location.href="http://172.18.91.12:8888/sso";
             }).catch(err => {
               that.$message.error({
                 title: '错误',

+ 15 - 0
src/config/router.config.js

@@ -298,6 +298,8 @@ export const constantRouterMap = [
     path: '/user',
     component: UserLayout,
     redirect: '/user/login',
+    // 博物馆单点登录
+    // component: () => import('@/views/Index'),
     hidden: true,
     children: [
       {
@@ -347,6 +349,19 @@ export const constantRouterMap = [
   //   ]
   // },
 
+  {
+    path: '/redirect/login',
+    name: 'redirectLogin',
+    hidden: true,
+    component: () => import('@/views/Redirect')
+  },
+  {
+    path: '/index',
+    name: 'index',
+    hidden: true,
+    component: () => import('@/views/Index')
+  },
+
   {
     path: '/test',
     component: BlankLayout,

+ 1 - 1
src/permission.js

@@ -9,7 +9,7 @@ import { generateIndexRouter } from "@/utils/util"
 
 NProgress.configure({ showSpinner: false }) // NProgress Configuration
 
-const whiteList = ['/user/login', '/user/register', '/user/register-result','/user/alteration','/activiti/commencementSchedule','/automaticLogin'] // no redirect whitelist
+const whiteList = ['/user/login', '/user/register', '/user/register-result','/user/alteration','/activiti/commencementSchedule','/automaticLogin','/redirect/login','/redirect/login/try','/index'] // no redirect whitelist
 
 router.beforeEach((to, from, next) => {
   NProgress.start() // start progress bar

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

@@ -3,7 +3,7 @@ import { automaticLogin,login, logout, phoneLogin } from "@/api/login"
 import { ACCESS_TOKEN, USER_NAME,USER_INFO,USER_AUTH,SYS_BUTTON_AUTH } from "@/store/mutation-types"
 import { welcome } from "@/utils/util"
 import { queryPermissionsByUser } from '@/api/api'
-import { getAction } from '@/api/manage'
+import { getAction,postAction } from '@/api/manage'
 
 const user = {
   state: {
@@ -61,6 +61,31 @@ const user = {
         })
       })
     },
+    //单点登录重定向
+    redirectLogin({ commit }, param) {
+      return new Promise((resolve, reject) => {
+        postAction("/sys/redirect/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) => {

+ 43 - 0
src/views/Index.vue

@@ -0,0 +1,43 @@
+<template>
+  <div class="home">
+  </div>
+</template>
+
+<script>
+  // @ is an alias to /src
+
+  import Trend from '@/components/Trend'
+import { WindowsFill } from '@ant-design/icons/lib/dist';
+
+
+  export default {
+    name: 'Index',
+    components: {
+      Trend,
+    },
+    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'
+    },
+    methods: {
+      
+    }
+  }
+</script>
+
+<style scoped>
+  .home {
+    width: 900px;
+    margin: 0 auto;
+    padding: 25px 0;
+  }
+  .home > .banner {
+    text-align: center;
+    padding: 25px 0;
+    margin: 25px 0;
+  }
+</style>

+ 130 - 0
src/views/Redirect.vue

@@ -0,0 +1,130 @@
+<template>
+  <div class="home">
+  </div>
+</template>
+
+<script>
+  // @ is an alias to /src
+
+  import Trend from '@/components/Trend'
+  import { axios } from '@/utils/request'
+  // import axios from 'axios'
+  import { postAction } from '@/api/manage'
+
+  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 {
+    name: 'Redirect',
+    components: {
+      Trend,
+    },
+    data () {
+      return {
+        code: ''
+      }
+    },
+    created(){
+      this.getCode();
+    },
+    methods: {
+        ...mapActions(['redirectLogin']),
+      getCode() {
+        
+        var url = window.location.href ;             //获取当前url
+        
+        var dz_url = url.split('#')[0];                //获取#/之前的字符串
+
+        var cs = dz_url.split('?')[1];                //获取?之后的参数字符串
+
+        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.code = cs.code;
+        this.redirectLogin({'code':this.code}).then(res=>{
+
+          this.departConfirm(res)
+        }).catch(err=>{
+          this.requestFailed(err)
+        })
+        // var params = {
+        //   "client_id":"OAManager",
+        //   "client_secret":"Password123",
+        //   "grant_type":"authorization_code",
+        //   "code":this.code,
+        //   "redirect_uri":"http://localhost:8083/"
+        // }
+        // axios.post("/sso/oauth/token", params)
+      },
+      requestFailed (err) {
+          this.$notification['error']({
+              message: '登录失败',
+              description: ((err.response || {}).data || {}).message || err.message || '请求出现错误,请稍后再试',
+              duration: 4
+          })
+          this.loginBtn = false
+      },
+      departConfirm (res) {
+          if (res.success) {
+              console.log('用户信息', res)
+              let multi_depart = res.result.multi_depart
+              // 0:无部门 1:一个部门 2:多个部门
+              if (multi_depart == 0) {
+                  this.loginSuccess()
+                  this.$notification.warn({
+                      message: '提示',
+                      // description: `您尚未归属部门,请确认账号信息`,
+                      description: `您尚未归属公司,请确认账号信息`,
+                      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)
+                  this.loginSuccess()
+              }
+          } else {
+              this.requestFailed(res)
+              setTimeout(()=>{
+                window.location.href="http://172.18.91.12:8888/sso"
+              },3000)
+          }
+      },
+      loginSuccess () {
+          this.$router.push({ name: 'dashboard' })
+          this.$notification.success({
+              message: '欢迎',
+              description: `${timeFix()},欢迎回来`
+          })
+          // this.$store.dispatch('delVisitedViews',this.$route)
+          // this.$router.go(-1)
+          // this.$store.state.tagsView.visitedViews.splice(this.$store.state.tagsView.visitedViews.findIndex(item => item.path === this.$route.path), 1)
+          // this.$router.push(this.$store.state.tagsView.visitedViews[this.$store.state.tagsView.visitedViews.length-1].path)
+      },
+    }
+  }
+</script>
+
+<style scoped>
+  .home {
+    width: 900px;
+    margin: 0 auto;
+    padding: 25px 0;
+  }
+  .home > .banner {
+    text-align: center;
+    padding: 25px 0;
+    margin: 25px 0;
+  }
+</style>

+ 1 - 0
url.config.js

@@ -3,6 +3,7 @@ export function getEditorJumpUrl () {
     //let url ="http://106.15.206.14:8089";//测试服务器
     // let url ="http://192.168.1.158:8089";//森宇服务器
     let url = "http://220.191.168.86:18089"; // 森语外网
+    // let url = 'http://172.18.91.36:8082' // 博物馆OA
     return url
   }