purchase-let/store/user.js

50 lines
1.1 KiB
JavaScript
Raw Normal View History

2024-04-25 18:02:30 +08:00
// 导入定义仓库的方法
2024-05-07 13:35:30 +08:00
import {
defineStore
} from 'pinia';
2024-04-25 18:02:30 +08:00
// 导入响应式和计算
2024-05-07 13:35:30 +08:00
import {
ref
} from 'vue';
2024-04-25 18:02:30 +08:00
const useUserStore = defineStore("user", () => {
2024-05-06 17:58:41 +08:00
2024-05-07 13:35:30 +08:00
// 定义一个状态用户信息
const userInfo = ref(uni.getStorageSync('userInfo') || {});
// 定义一个设置状态的方法
const setUserInfo = (data) => {
userInfo.value = data;
uni.setStorageSync('userInfo', data)
}
2024-05-06 17:58:41 +08:00
2024-05-07 13:35:30 +08:00
const token = ref(uni.getStorageSync('token') || '');
const setToken = (data) => {
token.value = data;
uni.setStorageSync('token', data)
}
2024-05-06 17:58:41 +08:00
2024-06-08 15:27:58 +08:00
// token.value = "18b6683cd772261fd119c813705ee0f1"
2024-05-07 15:11:40 +08:00
// #ifdef H5
2024-06-03 16:45:07 +08:00
// token.value = "3bff209b32d1f1c36e293b9f166bfa0b"
2024-05-07 19:02:43 +08:00
// token.value = "95b24dd6d2dda836fe07854b08ba0944"
2024-05-07 15:11:40 +08:00
userInfo.value = {
avatar: "https://lihaiim.oss-cn-chengdu.aliyuncs.com/image/admin/default_avatar.png",
id: 9,
is_disable: 0,
is_new_user: 1,
mobile: "19330904744",
nickname: "用户1714964250",
supplier: null,
2024-06-08 17:04:53 +08:00
token: "e5561a79d439a061a3cca3f780d996e2"
2024-05-07 15:11:40 +08:00
}
// #endif
2024-05-06 17:58:41 +08:00
2024-05-07 13:35:30 +08:00
return {
userInfo,
setUserInfo,
token,
setToken
}
2024-04-25 18:02:30 +08:00
})
export default useUserStore;