diff --git a/src/store/modules/user.ts b/src/store/modules/user.ts index f2464cb..674932b 100644 --- a/src/store/modules/user.ts +++ b/src/store/modules/user.ts @@ -6,35 +6,62 @@ import { watch } from 'vue'; const { VITE_TOKEN_KEY } = import.meta.env; const token = useCookies().get(VITE_TOKEN_KEY as string); -interface StoreUser { - token: string; - info: Record; -} +// interface StoreUser { +// token: string; +// info: Record; +// } -export const useUserStore = defineStore({ - id: 'app-user', - state: (): StoreUser => ({ - token: token, - info: {}, - }), - getters: { - getUserInfo(): any { - return this.info || {}; - }, - }, - actions: { - setInfo(info: any) { - this.info = info ? info : ''; - }, - login() { - return new Promise((resolve) => { - const { data } = loginPassword(); - watch(data, () => { - this.setInfo(data.value); - // useCookies().set(VITE_TOKEN_KEY as string, data.value.token); - resolve(data.value); - }); +// export const useUserStore = defineStore({ +// id: 'app-user', +// state: (): StoreUser => ({ +// token: token, +// info: {}, +// }), +// getters: { +// getUserInfo(): any { +// return this.info || {}; +// }, +// }, +// actions: { +// setInfo(info: any) { +// this.info = info ? info : ''; +// }, +// login() { +// return new Promise((resolve) => { +// const { data } = loginPassword(); +// watch(data, () => { +// this.setInfo(data.value); +// // useCookies().set(VITE_TOKEN_KEY as string, data.value.token); +// resolve(data.value); +// }); +// }); +// }, +// }, +// }); +export const useUserStore = defineStore('app-user', () => { + const Token = ref(token); + const info = ref>({}); + const setInfo = (info: any) => { + info.value = info ? info : ''; + }; + const getUserInfo = () => { + return info || {}; + }; + const login = () => { + return new Promise((resolve) => { + const { data } = loginPassword(); + watch(data, () => { + setInfo(data.value); + // useCookies().set(VITE_TOKEN_KEY as string, data.value.token); + resolve(data.value); }); - }, - }, + }); + }; + return { + Token, + info, + setInfo, + login, + getUserInfo, + }; });