|
|
@@ -20,11 +20,10 @@ export const useAuthStore = defineStore('auth', {
|
|
|
try {
|
|
|
const query = route.query.internalAuth as string|undefined;
|
|
|
let res = localStorage.getItem(STORAGE_KEY);
|
|
|
- this.loginFromEmbed = false;
|
|
|
if (!res && query) {
|
|
|
res = decodeURIComponent(query);
|
|
|
this.loginFromEmbed = true;
|
|
|
- localStorage.setItem(STORAGE_KEY, res);
|
|
|
+ this.saveLoginData();
|
|
|
}
|
|
|
if (!res)
|
|
|
throw 'no storage';
|
|
|
@@ -34,6 +33,7 @@ export const useAuthStore = defineStore('auth', {
|
|
|
this.expireAt = authInfo.expireAt;
|
|
|
this.userInfo = authInfo.userInfo;
|
|
|
this.loginType = authInfo.loginType;
|
|
|
+ this.loginFromEmbed = authInfo.loginFromEmbed;
|
|
|
|
|
|
// 检查token是否过期,如果快要过期,则刷新token
|
|
|
/*if (canRefresh && Date.now() > this.expireAt + 1000 * 3600 * 5) {
|
|
|
@@ -48,16 +48,16 @@ export const useAuthStore = defineStore('auth', {
|
|
|
console.log('loadLoginState', error);
|
|
|
}
|
|
|
},
|
|
|
- async login(mobile: string, password: string, loginType: number) {
|
|
|
+ async login(account: string, password: string, loginType: number) {
|
|
|
let loginResult;
|
|
|
if (loginType == 0) {
|
|
|
loginResult = await UserApi.login({
|
|
|
- mobile,
|
|
|
+ account,
|
|
|
password,
|
|
|
})
|
|
|
} else if (loginType == 1) {
|
|
|
loginResult = await UserApi.loginAdmin({
|
|
|
- account: mobile,
|
|
|
+ account,
|
|
|
password,
|
|
|
})
|
|
|
} else
|
|
|
@@ -70,14 +70,16 @@ export const useAuthStore = defineStore('auth', {
|
|
|
this.userInfo = loginResult.userInfo;
|
|
|
this.loginType = loginType;
|
|
|
this.expireAt = (loginResult.expiresIn || 0) + Date.now();
|
|
|
-
|
|
|
+ },
|
|
|
+ saveLoginData() {
|
|
|
localStorage.setItem(STORAGE_KEY,
|
|
|
JSON.stringify({
|
|
|
token: this.token,
|
|
|
userId: this.userId ,
|
|
|
expireAt: this.expireAt,
|
|
|
userInfo: this.userInfo,
|
|
|
- loginType,
|
|
|
+ loginType: this.loginType,
|
|
|
+ loginFromEmbed: this.loginFromEmbed,
|
|
|
})
|
|
|
);
|
|
|
},
|