|
@@ -2,31 +2,41 @@
|
|
|
* @Author: wjc
|
|
|
* @Date: 2024-06-05 17:13:30
|
|
|
* @LastEditors: wjc
|
|
|
- * @LastEditTime: 2024-06-12 17:08:53
|
|
|
+ * @LastEditTime: 2024-06-17 15:11:47
|
|
|
* @Description:
|
|
|
*/
|
|
|
import { defineStore } from 'pinia'
|
|
|
|
|
|
import { UserState, ILogin, LoginRes, Employees } from '@/models/userTypes'
|
|
|
-import { login, getUserInfo } from '@/api/userApi'
|
|
|
+import { login, logout, getUserInfo } from '@/api/userApi'
|
|
|
|
|
|
export const useUserStore = defineStore('user', {
|
|
|
state: (): UserState => {
|
|
|
return {
|
|
|
- isDialogShowed: false,
|
|
|
+ isPrivacyShowed: false,
|
|
|
isInstall: false,
|
|
|
token: '',
|
|
|
userInfo: new Employees({}),
|
|
|
}
|
|
|
},
|
|
|
+ getters: {
|
|
|
+ getIsInstall(state) {
|
|
|
+ return state.isInstall || uni.getStorageSync('isInstall')
|
|
|
+ },
|
|
|
+ getIsPrivacyShowed(state) {
|
|
|
+ return state.isPrivacyShowed || uni.getStorageSync('isPrivacyShowed')
|
|
|
+ },
|
|
|
+ },
|
|
|
actions: {
|
|
|
loginAction(data: ILogin): Promise<LoginRes> {
|
|
|
return new Promise((resolve, reject) => {
|
|
|
login(data)
|
|
|
.then((res) => {
|
|
|
if (res && res.data) {
|
|
|
- this.isDialogShowed = true
|
|
|
+ this.isPrivacyShowed = true
|
|
|
this.isInstall = true
|
|
|
+ uni.setStorageSync('isPrivacyShowed', this.isPrivacyShowed)
|
|
|
+ uni.setStorageSync('isInstall', this.isInstall)
|
|
|
uni.setStorageSync('storage-loginInfo', data)
|
|
|
uni.setStorageSync('storage-user-id', res.data.id)
|
|
|
resolve(res.data)
|
|
@@ -37,6 +47,20 @@ export const useUserStore = defineStore('user', {
|
|
|
})
|
|
|
})
|
|
|
},
|
|
|
+ logoutAction(): Promise<string> {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ logout()
|
|
|
+ .then((res) => {
|
|
|
+ if (res && res.data) {
|
|
|
+ uni.clearStorageSync()
|
|
|
+ resolve(res.data)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ .catch((error) => {
|
|
|
+ reject(error)
|
|
|
+ })
|
|
|
+ })
|
|
|
+ },
|
|
|
getUserInfoAction(): Promise<Employees> {
|
|
|
return new Promise((resolve, reject) => {
|
|
|
const id = uni.getStorageSync('storage-user-id')
|