From 6f2c9b66e9679dc4eff30a07c6e78887375a33bd Mon Sep 17 00:00:00 2001 From: zengchenxi Date: Thu, 22 Feb 2024 16:19:52 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BC=98=E5=8C=96=E3=80=91=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E6=9C=AC=E5=9C=B0=E7=BC=93=E5=AD=98=20=E5=88=B7?= =?UTF-8?q?=E6=96=B0=E5=90=8E=E4=BF=9D=E7=95=99=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mes-ui/mes-ui-admin-vue3/package.json | 3 +- mes-ui/mes-ui-admin-vue3/src/store/index.ts | 2 + .../src/store/modules/common.ts | 52 +++++++++++++------ .../src/views/heli/processdesign/detail.vue | 5 +- .../src/views/heli/processdesign/index.vue | 4 +- 5 files changed, 44 insertions(+), 22 deletions(-) diff --git a/mes-ui/mes-ui-admin-vue3/package.json b/mes-ui/mes-ui-admin-vue3/package.json index ffc07e52..851e4db6 100644 --- a/mes-ui/mes-ui-admin-vue3/package.json +++ b/mes-ui/mes-ui-admin-vue3/package.json @@ -56,6 +56,7 @@ "mitt": "^3.0.1", "nprogress": "^0.2.0", "pinia": "^2.1.7", + "pinia-plugin-persist": "^1.0.0", "qrcode": "^1.5.3", "qs": "^6.11.2", "sortablejs": "^1.15.0", @@ -86,8 +87,8 @@ "@types/sortablejs": "^1.15.5", "@typescript-eslint/eslint-plugin": "^6.11.0", "@typescript-eslint/parser": "^6.11.0", - "@unocss/transformer-variant-group": "^0.57.4", "@unocss/eslint-config": "^0.57.4", + "@unocss/transformer-variant-group": "^0.57.4", "@vitejs/plugin-legacy": "^4.1.1", "@vitejs/plugin-vue": "^4.4.1", "@vitejs/plugin-vue-jsx": "^3.0.2", diff --git a/mes-ui/mes-ui-admin-vue3/src/store/index.ts b/mes-ui/mes-ui-admin-vue3/src/store/index.ts index 65964ea8..7740bdd3 100644 --- a/mes-ui/mes-ui-admin-vue3/src/store/index.ts +++ b/mes-ui/mes-ui-admin-vue3/src/store/index.ts @@ -1,7 +1,9 @@ import type { App } from 'vue' import { createPinia } from 'pinia' +import piniaPersist from 'pinia-plugin-persist' const store = createPinia() +store.use(piniaPersist) export const setupStore = (app: App) => { app.use(store) diff --git a/mes-ui/mes-ui-admin-vue3/src/store/modules/common.ts b/mes-ui/mes-ui-admin-vue3/src/store/modules/common.ts index 2b86ce72..8a35d2bc 100644 --- a/mes-ui/mes-ui-admin-vue3/src/store/modules/common.ts +++ b/mes-ui/mes-ui-admin-vue3/src/store/modules/common.ts @@ -3,27 +3,45 @@ import { store } from '../index' export interface CommonStoreState { storeMap: object - showWarning: boolean; + showWarning: boolean; } -export const useCommonStore = defineStore('commonStore', () => { - const storeMap = ref({}) - const showWarning = ref(true); - const getStore = (key) => { - return key === 'showWarning' ? showWarning.value : storeMap.value[key]; - return storeMap.value[key] - } - const setStore = (key, value) => { - if (key === 'showWarning') { - showWarning.value = value; - } else { - storeMap.value[key] = value; +export const useCommonStore = defineStore( + 'commonStore', + { + state: (): CommonStoreState => { + return { + storeMap: {}, + showWarning: true + } + }, + actions: { + setStore(key: String, value: any) { + if(key == 'showWarning'){ + this.showWarning = value; + }else{ + this.storeMap[key] = value; + } + }, + getStore(key: string){ + if(key == 'showWarning'){ + return this.showWarning; + }else{ + return this.storeMap[key]; + } + } + }, + persist: { + enabled: true, + strategies: [ + { + key: "commonStore", + storage: localStorage + } + ] } - return storeMap.value[key] = value } - - return {getStore, setStore,showWarning} -}) +) export const useCommonStateWithOut = () => { return useCommonStore(store) diff --git a/mes-ui/mes-ui-admin-vue3/src/views/heli/processdesign/detail.vue b/mes-ui/mes-ui-admin-vue3/src/views/heli/processdesign/detail.vue index 61ec4e5f..dfa411ab 100644 --- a/mes-ui/mes-ui-admin-vue3/src/views/heli/processdesign/detail.vue +++ b/mes-ui/mes-ui-admin-vue3/src/views/heli/processdesign/detail.vue @@ -197,18 +197,18 @@