From cc83c4b9f11b98251fdeec90f8639ba073ab6fe6 Mon Sep 17 00:00:00 2001 From: VON0000 Date: Sat, 30 Dec 2023 01:43:39 +0800 Subject: [PATCH] =?UTF-8?q?feature:=20=E5=AE=9E=E7=8E=B0=E6=A0=B9=E6=8D=AE?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E5=8A=A0=E8=BD=BD=E5=8A=9F=E8=83=BD=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/TextHandlerConfig.vue | 22 +++++++++++++++- src/store/useStore.ts | 25 +++++++++++-------- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/src/pages/article-copy-tool/components/HeaderArea/components/TextHandlerConfig.vue b/src/pages/article-copy-tool/components/HeaderArea/components/TextHandlerConfig.vue index a99ceed..162df56 100644 --- a/src/pages/article-copy-tool/components/HeaderArea/components/TextHandlerConfig.vue +++ b/src/pages/article-copy-tool/components/HeaderArea/components/TextHandlerConfig.vue @@ -10,7 +10,27 @@ const store = useStore(); const {introduceTextHandler} = useIntroducer(); const showConfigDrawer = ref(false); -const refTextHandlerArray = ref(store.textHandlerArray); + + +const localStorageHandlerOptions = localStorage.getItem("laorange_PA"); + +function getTextHandlerArray() { + if (localStorageHandlerOptions) { + const TextHandlerArray = JSON.parse(JSON.stringify(textHandlers)); + const localStorgeValue = JSON.parse(localStorageHandlerOptions); + const handlerOptions = localStorgeValue.value.copy.handlerOptions; + Object.keys(TextHandlerArray).map((handlerName) => { + TextHandlerArray[handlerName].activate = handlerOptions[handlerName].activate; + TextHandlerArray[handlerName].order = handlerOptions[handlerName].order; + }); + console.log(store.storage.copy.handlerOptions); + return ref(store.textHandlerArray(TextHandlerArray)) + } else { + return ref(store.textHandlerArray()); + } +} + +const refTextHandlerArray = getTextHandlerArray(); watch(() => refTextHandlerArray.value, (ths) => { let handlerOptions: typeof store.storage.copy.handlerOptions = {}; diff --git a/src/store/useStore.ts b/src/store/useStore.ts index 7d7557c..d3fdc4e 100644 --- a/src/store/useStore.ts +++ b/src/store/useStore.ts @@ -72,16 +72,21 @@ export const useStore = defineStore("store", { }; }, getters: { - textHandlerArray(): TextHandlerWithName[] { - return Object.entries(textHandlers).map(([handlerName, handler], index) => { - return { - handlerName: handlerName, - handler: {...handler, activate: this.storage.copy.handlerOptions[handlerName]?.activate ?? handler.activate}, - order: this.storage.copy.handlerOptions[handlerName]?.order ?? Object.keys(textHandlers).length + index, - }; - }).sort((a, b) => a.order - b.order).map(data => { - return {...data.handler, handlerName: data.handlerName}; - }); + textHandlerArray() { + return (textType = textHandlers): TextHandlerWithName[] => { + return Object.entries(textType).map(([handlerName, handler], index) => { + return { + handlerName: handlerName, + handler: {...handler, activate: this.storage.copy.handlerOptions[handlerName]?.activate ?? handler.activate}, + order: this.storage.copy.handlerOptions[handlerName]?.order ?? (() => { + return textType[handlerName].order?? Object.keys(textHandlers).length + index + })() + + }; + }).sort((a, b) => a.order - b.order).map(data => { + return {...data.handler, handlerName: data.handlerName}; + }); + }; }, }, actions: {