From 6f4e6b8e42039bc4c39d00fc4cbf3369919891f4 Mon Sep 17 00:00:00 2001 From: huangwentao Date: Mon, 22 Aug 2022 10:22:46 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20=E6=96=B0=E5=A2=9Epinia?= =?UTF-8?q?=E7=BB=84=E5=90=88=E5=BC=8Fapi=E7=9A=84=E7=BC=96=E7=A8=8B?= =?UTF-8?q?=EF=BC=8Coptions=E4=BB=A3=E7=A0=81=E6=B3=A8=E9=87=8A=E8=B5=B7?= =?UTF-8?q?=E6=9D=A5,=E4=B8=A4=E7=A7=8D=E6=A8=A1=E5=BC=8F=E9=83=BD?= =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E4=BD=BF=E7=94=A8,=E6=8E=A8=E8=8D=90?= =?UTF-8?q?=E8=B7=9Fvue3.x=E4=BD=BF=E7=94=A8=E7=BB=84=E5=90=88=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/modules/user.ts | 85 ++++++++++++++++++++++++++------------- 1 file changed, 56 insertions(+), 29 deletions(-) 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, + }; });