|
@@ -1,16 +1,12 @@
|
|
|
<template>
|
|
|
<div v-loading="loading" class="hc-body-loading" element-loading-text="授权登录中...">
|
|
|
<div v-if="isErrorShow" class="error-page">
|
|
|
- <div :style="`background-image: url(${svg403});`" class="img" />
|
|
|
+ <div class="img" :style="`background-image: url(${svg403});`" />
|
|
|
<div class="content">
|
|
|
<h1>403</h1>
|
|
|
- <div class="desc">
|
|
|
- 抱歉,token授权登录异常,请重新进入
|
|
|
- </div>
|
|
|
+ <div class="desc">抱歉,token授权登录异常,请重新进入</div>
|
|
|
<div class="actions">
|
|
|
- <el-button block size="large" type="primary" @click="toLoginTap">
|
|
|
- 手动登录
|
|
|
- </el-button>
|
|
|
+ <el-button type="primary" block size="large" @click="toLoginTap">手动登录</el-button>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
@@ -20,20 +16,17 @@
|
|
|
<script setup>
|
|
|
import { onMounted, ref } from 'vue'
|
|
|
import { useAppStore } from '~src/store'
|
|
|
-import { loginByToken } from '~api/user'
|
|
|
-import { setAppName } from '~uti/tools'
|
|
|
+import { useAppLogin } from '~sto/user'
|
|
|
import { useRoute, useRouter } from 'vue-router'
|
|
|
+import { getObjValue, isNullES } from 'js-fast-way'
|
|
|
+
|
|
|
import svg403 from '~src/assets/view/403.svg'
|
|
|
-import { initUserConfigInfo, setRouterData } from '~sto/user'
|
|
|
-import { getObjVal } from 'js-fast-way'
|
|
|
+import userApi from '~api/userInfo'
|
|
|
|
|
|
//初始变量
|
|
|
const router = useRouter()
|
|
|
const useRoutes = useRoute()
|
|
|
-const useAppState = useAppStore()
|
|
|
-
|
|
|
-//先清理下缓存
|
|
|
-useAppState.clearStoreData()
|
|
|
+const store = useAppStore()
|
|
|
|
|
|
//变量
|
|
|
const loading = ref(true)
|
|
@@ -41,50 +34,54 @@ const isErrorShow = ref(false)
|
|
|
|
|
|
//渲染完成
|
|
|
onMounted(() => {
|
|
|
- // 域名后加 /#/auth?token=xxxxxxx&account=aaaa×tamp=1670233144838&timeInterval=300&moduleCode=UTF-8
|
|
|
- // eslint-disable-next-line no-unsafe-optional-chaining
|
|
|
- const { token, account, timestamp, timeInterval, moduleCode } = useRoutes?.query
|
|
|
- if (token && account && timestamp && timeInterval && moduleCode) {
|
|
|
+ // 域名后加 /#/auth?token=xxxxxxx
|
|
|
+ const { token } = getObjValue(useRoutes.query)
|
|
|
+ if (token) {
|
|
|
isErrorShow.value = false
|
|
|
- loginByTokenApi({
|
|
|
- token: token,
|
|
|
- account: account,
|
|
|
- timestamp: timestamp,
|
|
|
- timeInterval: timeInterval,
|
|
|
- moduleCode: moduleCode,
|
|
|
- })
|
|
|
+ store.setTokenVal(token)
|
|
|
+ queryCurrentUserData()
|
|
|
} else {
|
|
|
loading.value = false
|
|
|
isErrorShow.value = true
|
|
|
}
|
|
|
})
|
|
|
|
|
|
-//请求授权登录
|
|
|
-const loginByTokenApi = async (form) => {
|
|
|
- const { error, code, data } = await loginByToken(form)
|
|
|
- const res = getObjVal(data)
|
|
|
- if (!error && code === 200 && res) {
|
|
|
- useAppState.setTokenVal(res['access_token'])
|
|
|
- useAppState.setRefreshTokenVal(res['refresh_token'])
|
|
|
- useAppState.setTenantId(res['tenant_id'])
|
|
|
- useAppState.setUserInfo(res)
|
|
|
- await setRouterData()
|
|
|
- await initUserConfigInfo()
|
|
|
- loading.value = false
|
|
|
- isErrorShow.value = false
|
|
|
- //设置标题
|
|
|
- useAppState.setTitle('')
|
|
|
- useAppState.setLogoIcon('')
|
|
|
- useAppState.setLogoName('')
|
|
|
- setAppName('')
|
|
|
- window?.$message?.success('授权登录成功')
|
|
|
- await router.push({ path: '/home/index' })
|
|
|
-
|
|
|
+//获取用户信息
|
|
|
+const queryCurrentUserData = async () => {
|
|
|
+ const { error, code, data } = await userApi.queryCurrentUserData()
|
|
|
+ if (!error && code === 200) {
|
|
|
+ await useAppLoginApi({
|
|
|
+ tenantId: '000000',
|
|
|
+ username: data.account,
|
|
|
+ password: data.plaintextPassword,
|
|
|
+ type: 'account',
|
|
|
+ })
|
|
|
} else {
|
|
|
+ window.$message?.error('授权信息异常')
|
|
|
+ isErrorShow.value = true
|
|
|
+ loading.value = false
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+//请求授权登录
|
|
|
+const useAppLoginApi = async (form) => {
|
|
|
+ loading.value = true
|
|
|
+ const { error, msg } = await useAppLogin(form)
|
|
|
+ if (error && !isNullES(msg)) {
|
|
|
window.$message?.error('授权登录失败')
|
|
|
isErrorShow.value = true
|
|
|
loading.value = false
|
|
|
+ return false
|
|
|
}
|
|
|
+ //授权登录成功
|
|
|
+ setTimeout(() => {
|
|
|
+ loading.value = false
|
|
|
+ isErrorShow.value = false
|
|
|
+ window?.$message?.success('授权登录成功')
|
|
|
+ router.push({
|
|
|
+ name: store.homeUrl,
|
|
|
+ })
|
|
|
+ }, 1500)
|
|
|
}
|
|
|
|
|
|
//跳转登陆
|