|
@@ -1,9 +1,10 @@
|
|
|
import { defineStore } from "pinia"
|
|
import { defineStore } from "pinia"
|
|
|
-import { removeToken, setToken, setCODE401 } from "@/libs/auth"
|
|
|
|
|
|
|
+import { removeToken, setToken } from "@/libs/auth"
|
|
|
import router from "@/router"
|
|
import router from "@/router"
|
|
|
import { httpAjax } from "@/plugins/httpAjax"
|
|
import { httpAjax } from "@/plugins/httpAjax"
|
|
|
import { store } from "./index"
|
|
import { store } from "./index"
|
|
|
import { getUserInfoApi } from "@/api/user"
|
|
import { getUserInfoApi } from "@/api/user"
|
|
|
|
|
+import { getCurrentUrlParams, normalizeAuthorization } from "@/utils/urlParams"
|
|
|
interface userType {
|
|
interface userType {
|
|
|
userInfo: {
|
|
userInfo: {
|
|
|
nickname?: string
|
|
nickname?: string
|
|
@@ -22,15 +23,7 @@ const useStore = defineStore("user", {
|
|
|
actions: {
|
|
actions: {
|
|
|
/** 登录 */
|
|
/** 登录 */
|
|
|
async login() {
|
|
async login() {
|
|
|
- function getAuthorizationFromUrl() {
|
|
|
|
|
- const fullUrl = window.location.href
|
|
|
|
|
- const queryIndex = fullUrl.indexOf("?")
|
|
|
|
|
- if (queryIndex === -1) return undefined
|
|
|
|
|
- const queryString = fullUrl.slice(queryIndex + 1)
|
|
|
|
|
- const params = new URLSearchParams(queryString)
|
|
|
|
|
- return params.get("Authorization") || undefined
|
|
|
|
|
- }
|
|
|
|
|
- const token = getAuthorizationFromUrl()
|
|
|
|
|
|
|
+ const token = normalizeAuthorization(getCurrentUrlParams().get("Authorization"))
|
|
|
token && setToken(token)
|
|
token && setToken(token)
|
|
|
},
|
|
},
|
|
|
/** 获取用户信息 */
|
|
/** 获取用户信息 */
|