Files
web/app/stores/index.js
anhduy-tech 1283757903 changes
2026-05-18 11:45:21 +07:00

50 lines
1.1 KiB
JavaScript

import { defineStore } from "pinia";
export const useStore = defineStore("main", {
state: () => ({
viewport: undefined,
login: undefined,
token: undefined,
common: undefined,
settings: [],
showmodal: undefined,
snackbar: undefined,
productdocument: undefined,
applicationstatus: undefined,
applicationproduct: undefined,
country: undefined,
lang: "vi",
branch: {},
rights: [],
product: [],
}),
actions: {
commit(name, data) {
// console.trace("commit", name, data);
this[name] = data;
},
updateProduct(products) {
this.product = products;
},
updateSingleProduct(updatedProduct) {
const index = this.product.findIndex((p) => p.id === updatedProduct.id);
if (index !== -1) {
this.product[index] = updatedProduct;
} else {
this.product.push(updatedProduct);
}
},
removeProduct(productId) {
this.product = this.product.filter((p) => p.id !== productId);
},
},
persist: {
pick: ["token", "login", "lang"],
storage: piniaPluginPersistedstate.localStorage(),
},
});