Skip to content

Commit

Permalink
feature: 实现根据缓存加载功能模板
Browse files Browse the repository at this point in the history
  • Loading branch information
VON0000 committed Dec 29, 2023
1 parent 704eb89 commit cc83c4b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,27 @@ const store = useStore();
const {introduceTextHandler} = useIntroducer();
const showConfigDrawer = ref(false);
const refTextHandlerArray = ref<TextHandlerWithName[]>(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<TextHandlerWithName[]>(store.textHandlerArray(TextHandlerArray))
} else {
return ref<TextHandlerWithName[]>(store.textHandlerArray());
}
}
const refTextHandlerArray = getTextHandlerArray();
watch(() => refTextHandlerArray.value, (ths) => {
let handlerOptions: typeof store.storage.copy.handlerOptions = {};
Expand Down
25 changes: 15 additions & 10 deletions src/store/useStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit cc83c4b

Please sign in to comment.