|
@@ -77,18 +77,10 @@ export default {
|
|
|
},
|
|
|
mounted() {
|
|
|
const currentUrl = window.location.href
|
|
|
- const queryIndex = currentUrl.indexOf('?')
|
|
|
- const hashIndex = currentUrl.indexOf('#')
|
|
|
- // https://boot.aizuda.com/?token=4T6pF9V4fNnG8Jh3MpLeXQ==#/login?redirect=/dashboard
|
|
|
-
|
|
|
- // 检查是否有两个问号
|
|
|
- if (queryIndex !== -1 && hashIndex !== -1 && currentUrl.indexOf('?', queryIndex + 1) !== -1) {
|
|
|
- // 提取 token
|
|
|
- const token = currentUrl.substring(queryIndex + 7, hashIndex)
|
|
|
- const protocol = window.location.protocol // 获取协议,例如 "https:"
|
|
|
- const hostname = window.location.hostname // 获取域名,例如 "www.baidu.com"
|
|
|
- const port = window.location.port // 获取端口号,如果没有指定端口则为空字符串
|
|
|
-
|
|
|
+ const token = this.extractToken(currentUrl)
|
|
|
+ console.log(token, 'token', typeof token)
|
|
|
+ if (token) {
|
|
|
+ const { protocol, hostname, port } = window.location
|
|
|
// 构建完整的协议+域名+端口
|
|
|
const baseUrl = `${protocol}//${hostname}${port ? `:${port}` : ''}`
|
|
|
|
|
@@ -96,18 +88,36 @@ export default {
|
|
|
const newUrl = `${baseUrl}/#/login?redirect=/dashboard&token=${token}`
|
|
|
// 更新浏览器地址栏
|
|
|
window.location.replace(newUrl)
|
|
|
- return // 确保不执行后续代码
|
|
|
- }
|
|
|
- alert('-----', route)
|
|
|
- const { token } = route.query
|
|
|
- if (token) {
|
|
|
- this.loading = true
|
|
|
- user.loginTokenEv({ token }).finally(() => {
|
|
|
- this.loading = false
|
|
|
- })
|
|
|
+ return
|
|
|
+ } else {
|
|
|
+ const queryParams = this.getQueryParams(currentUrl)
|
|
|
+ if (queryParams.token) {
|
|
|
+ this.loading = true
|
|
|
+ user.loginTokenEv({ token: queryParams.token }).finally(() => {
|
|
|
+ this.loading = false
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
+ getQueryParams(url) {
|
|
|
+ const queryString = url.split('?')[1]
|
|
|
+ if (!queryString) return {}
|
|
|
+
|
|
|
+ const params = new URLSearchParams(queryString)
|
|
|
+ const result = {}
|
|
|
+
|
|
|
+ for (const [key, value] of params.entries()) {
|
|
|
+ result[key] = value
|
|
|
+ }
|
|
|
+
|
|
|
+ return result
|
|
|
+ },
|
|
|
+ extractToken(url) {
|
|
|
+ const regex = /\?token=([^#]*)#/
|
|
|
+ const match = url.match(regex)
|
|
|
+ return match ? match[1] : ''
|
|
|
+ },
|
|
|
async login() {
|
|
|
let validate = await this.$refs.loginForm.validate().catch(() => {})
|
|
|
if (!validate) {
|