import {
	defineStore
} from 'pinia';
import storage from "@/utils/storage.js"

export const useUserStore = defineStore('user', {
	state: () => {
		return {
			token: storage.getCache('token') || '',
			status: 'init',
			userInfo: {},
			bankcard: {},
			notice: null
		};
	},
	actions: {
		setToken(token) {
			storage.setCache('token', token)
			this.token = token
			this.status = 'logined'
		},
		setLogout() {
			this.status = 'logout';
			this.userInfo = {}
			this.token = ''
			storage.removeCache('token')
		},
		setUserInfo(data) {
			this.userInfo = data
		},
		setBankcard(data) {
			this.bankcard = data
		},

		setNotice(data) {
			this.notice = data
		},
	},
	// 开始数据持久化
	persist: true,
});