|
@@ -11,7 +11,7 @@ export const useAuthStore = defineStore("auth", () => {
|
|
|
|
|
|
|
|
const isAuthenticated = ref(!!JwtService.getToken())
|
|
const isAuthenticated = ref(!!JwtService.getToken())
|
|
|
//oR0I65C3nS6KlxF2UHcKOq5-oqmE
|
|
//oR0I65C3nS6KlxF2UHcKOq5-oqmE
|
|
|
- const openid = ref("oR0I65C3nS6KlxF2UHcKOq5-oqmE")
|
|
|
|
|
|
|
+ const openid = ref("")
|
|
|
function setToken(authToken: string) {
|
|
function setToken(authToken: string) {
|
|
|
isAuthenticated.value = true
|
|
isAuthenticated.value = true
|
|
|
user.value.token = authToken
|
|
user.value.token = authToken
|
|
@@ -56,6 +56,7 @@ export const useAuthStore = defineStore("auth", () => {
|
|
|
function purgeAuth() {
|
|
function purgeAuth() {
|
|
|
isAuthenticated.value = false
|
|
isAuthenticated.value = false
|
|
|
user.value = {} as User
|
|
user.value = {} as User
|
|
|
|
|
+ openid.value = ""
|
|
|
localCache.setJSON(USER_KEY, user.value)
|
|
localCache.setJSON(USER_KEY, user.value)
|
|
|
appStore.amProfileStore.clean()
|
|
appStore.amProfileStore.clean()
|
|
|
JwtService.destroyToken()
|
|
JwtService.destroyToken()
|
|
@@ -70,8 +71,10 @@ export const useAuthStore = defineStore("auth", () => {
|
|
|
console.log("openid", res)
|
|
console.log("openid", res)
|
|
|
if (res.code === 200) {
|
|
if (res.code === 200) {
|
|
|
setToken(res.data.token)
|
|
setToken(res.data.token)
|
|
|
- getInfo()
|
|
|
|
|
- appStore.amProfileStore.loadProfile()
|
|
|
|
|
|
|
+ getInfo().then(() => {
|
|
|
|
|
+ appStore.amProfileStore.loadProfile()
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
resolve(true)
|
|
resolve(true)
|
|
|
} else if (res.code === 401) {
|
|
} else if (res.code === 401) {
|
|
|
openid.value = res.data.openid
|
|
openid.value = res.data.openid
|
|
@@ -87,13 +90,14 @@ export const useAuthStore = defineStore("auth", () => {
|
|
|
function login(userInfo: any) {
|
|
function login(userInfo: any) {
|
|
|
const username = userInfo.username.trim()
|
|
const username = userInfo.username.trim()
|
|
|
const password = userInfo.password
|
|
const password = userInfo.password
|
|
|
|
|
+ const openid = userInfo.openid
|
|
|
const code = userInfo.code
|
|
const code = userInfo.code
|
|
|
const uuid = userInfo.uuid
|
|
const uuid = userInfo.uuid
|
|
|
return new Promise((resolve, reject) => {
|
|
return new Promise((resolve, reject) => {
|
|
|
apis.loginApi
|
|
apis.loginApi
|
|
|
- .login(username, password, code, uuid)
|
|
|
|
|
|
|
+ .login(username, password, openid, code, uuid)
|
|
|
.then((res: any) => {
|
|
.then((res: any) => {
|
|
|
- console.log("---", res)
|
|
|
|
|
|
|
+ //console.log("---", res)
|
|
|
setToken(res.token)
|
|
setToken(res.token)
|
|
|
resolve(true)
|
|
resolve(true)
|
|
|
})
|
|
})
|
|
@@ -132,6 +136,20 @@ export const useAuthStore = defineStore("auth", () => {
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ function logoutWechat() {
|
|
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
|
|
+ apis.loginApi
|
|
|
|
|
+ .logoutWechat()
|
|
|
|
|
+ .then(() => {
|
|
|
|
|
+ purgeAuth()
|
|
|
|
|
+ resolve(true)
|
|
|
|
|
+ })
|
|
|
|
|
+ .catch((error: any) => {
|
|
|
|
|
+ reject(error)
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
function getUser() {
|
|
function getUser() {
|
|
|
return user.value
|
|
return user.value
|
|
|
}
|
|
}
|
|
@@ -150,6 +168,7 @@ export const useAuthStore = defineStore("auth", () => {
|
|
|
xcxLogin,
|
|
xcxLogin,
|
|
|
login,
|
|
login,
|
|
|
logout,
|
|
logout,
|
|
|
|
|
+ logoutWechat,
|
|
|
getInfo,
|
|
getInfo,
|
|
|
changeAvatar,
|
|
changeAvatar,
|
|
|
getUser,
|
|
getUser,
|