Otsuka-APP/store/modules/orderManager.js
2025-09-01 22:43:08 +08:00

46 lines
1.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// store/orderManager.js
import { defineStore } from 'pinia';
import { ref } from 'vue';
export const useOrderManagerStore = defineStore('orderManager', () => {
const orders = ref([]);
const addOrder = (order) => {
orders.value = [order]
};
const removeOrder = (orderId) => {
orders.value = orders.value.filter(order => order.id !== orderId);
};
const clearOrders = () => {
orders.value = [];
};
return {
orders,
addOrder,
removeOrder,
clearOrders
};
}, {
// persist: {
// storage: {
// // 读取:从 uni.storage 获取
// getItem(key) {
// const value = uni.getStorageSync(key);
// // 如果有值,解析 JSON否则返回 nullPinia 会处理默认值)
// return value ? JSON.parse(value) : null;
// },
// // 写入:保存到 uni.storage
// setItem(key, value) {
// uni.setStorageSync(key, JSON.stringify(value));
// },
// // 可选:删除(一般不需要手动调用)
// removeItem(key) {
// uni.removeStorageSync(key);
// }
// }
// }
persist: true
});