qcp QCP pad
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

57 lines
1.2 KiB

import type { IUser } from '@/types/user'
import { defineStore } from 'pinia'
import { store } from '@/store'
interface UserState {
user: null | IUser // 用户信息
}
export const useUserStore = defineStore({
id: 'user',
state: (): UserState => ({
user: null,
}),
getters: {},
actions: {
// 登录
async login(padNo: string) {
console.log('store: login')
try {
const res = await uni.$u.api.login(padNo)
console.log(res)
if (res?.length) {
uni.setStorageSync('user', JSON.stringify(res[0]))
this.user = res[0]
uni.$u.toast('登录成功')
// this.getStationInfo(this.user!.jczbh)
// setTimeout(() => {
// uni.switchTab({ url: '/pages/index/index' })
// }, 1500)
return
}
uni.removeStorageSync('user')
this.user = null
} catch (error: any) {
this.user = null
uni.removeStorageSync('user')
}
},
setUser(data) {
this.user = data || null
},
},
})
// Need to be used outside the setup
export function useUserStoreWidthOut() {
return useUserStore(store)
}