[update 单点登录] 测试飞书单点登录

This commit is contained in:
danshihao
2024-07-22 14:48:38 +08:00
parent f44b65e0e4
commit 6f8191bee8
3 changed files with 41 additions and 1 deletions
+8
View File
@@ -19,6 +19,14 @@ export function login (parameter) {
data: parameter
})
}
// 飞书登录
export function feiShuLogin (parameter) {
return axios({
url: '/feishu/getUserInfoByCode',
method: 'post',
data: parameter
})
}
export function phoneLogin (parameter) {
return axios({
+6
View File
@@ -92,6 +92,12 @@ function main () {
store.commit('TOGGLE_COLOR', Vue.ls.get(DEFAULT_COLOR, config.primaryColor))
store.commit('SET_TOKEN', Vue.ls.get(ACCESS_TOKEN))
store.commit('SET_MULTI_PAGE', Vue.ls.get(DEFAULT_MULTI_PAGE, config.multipage))
// 如果没有登录,state是飞书,并且有code,就请求飞书单点登录
if (!Vue.ls.get(ACCESS_TOKEN) && this.$route.query.code && this.$route.query.state === 'feishu') {
store.dispatch('FeiShuLogin').catch((e) => {
this.$message.warn(e.message)
})
}
},
render: h => h(App),
data: {
+27 -1
View File
@@ -1,5 +1,5 @@
import Vue from 'vue'
import { login, logout, phoneLogin, thirdLogin } from '@/api/login'
import { feiShuLogin, login, logout, phoneLogin, thirdLogin } from '@/api/login'
import { ACCESS_TOKEN, USER_NAME, USER_INFO, USER_AUTH, SYS_BUTTON_AUTH, UI_CACHE_DB_DICT_DATA, TENANT_ID, CACHE_INCLUDED_ROUTES } from '@/store/mutation-types'
import store from '@/store'
import { welcome } from '@/utils/util'
@@ -90,6 +90,32 @@ const user = {
})
})
},
// 飞书单点登录
FeiShuLogin ({ commit }, code) {
return new Promise((resolve, reject) => {
if (code) {
feiShuLogin({ code }).then(response => {
if (response.code + '' === '200') {
const result = response.result
const userInfo = result.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)
Vue.ls.set(UI_CACHE_DB_DICT_DATA, result.sysAllDictItems, 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 {
reject(response)
}
}).catch(error => {
reject(error)
})
}
})
},
// 手机号登录
PhoneLogin ({ commit }, userInfo) {
return new Promise((resolve, reject) => {