Files
shoot-miniprograms/src/store.js

52 lines
969 B
JavaScript
Raw Normal View History

2025-05-25 23:51:10 +08:00
import { defineStore } from "pinia";
// 定义游戏相关的 store
export default defineStore("store", {
// 状态
state: () => ({
user: {
2025-05-26 16:28:13 +08:00
id: "",
nickName: "游客",
2025-05-28 15:00:31 +08:00
avatarUrl: "../static/avatar.png",
2025-05-29 23:45:44 +08:00
trio: 0, // 大于1表示完成了新手引导
},
device: {
id: "",
deviceName: "",
2025-05-25 23:51:10 +08:00
},
2025-06-02 14:42:07 +08:00
config: {},
2025-05-25 23:51:10 +08:00
}),
// 计算属性
getters: {
getUsername: (state) => {
return state.user.username;
},
},
// 方法
actions: {
2025-05-26 16:28:13 +08:00
updateUser(user) {
this.user = user;
},
2025-05-29 23:45:44 +08:00
updateDevice(deviceId, deviceName) {
this.device.id = deviceId;
this.device.deviceName = deviceName;
},
2025-06-02 14:42:07 +08:00
updateConfig(config) {
this.config = config;
},
2025-05-25 23:51:10 +08:00
},
// 开启数据持久化
persist: {
enabled: true,
strategies: [
{
storage: uni.getStorageSync,
2025-06-02 14:42:07 +08:00
paths: ["user", "device", "config"], // 只持久化用户信息
2025-05-25 23:51:10 +08:00
},
],
},
});