From 6a37b1f5cfffe8ca60602e950416fc30ad88d9ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=A2=A6=E8=BF=9C?= <1063331231@qq.com> Date: Sun, 6 Jul 2025 22:14:55 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=97=E8=A1=A8=E4=B8=8D=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E9=80=89=E4=B8=AD=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/formula/HomeFormulaConfig.vue | 3 ++- src/stores/formulaStore.ts | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/components/formula/HomeFormulaConfig.vue b/src/components/formula/HomeFormulaConfig.vue index 3a64a47..1379d1b 100644 --- a/src/components/formula/HomeFormulaConfig.vue +++ b/src/components/formula/HomeFormulaConfig.vue @@ -18,6 +18,7 @@ const getFormData = () => { */ const registerGrandsonMethods = inject<(methods: any) => void>('registerGrandsonMethods', () => {}) onMounted(() => { + formulaStore.initFormulaList() registerGrandsonMethods && registerGrandsonMethods({ getFormData }) }) /** @@ -35,7 +36,7 @@ const labelUnitMap: Record = formulaStore.labelUnitMap watchEffect(() => { formData.value = formulaStore.selectedFormulaInfo !== null - ? convertValuesToInt(formulaStore.selectedFormulaInfo) + ? convertValuesToInt(formulaStore.selectedFormulaInfo as Record) : convertValuesToInt(formulaStore.defaultFormulaInfo as Record) }) /** diff --git a/src/stores/formulaStore.ts b/src/stores/formulaStore.ts index 442963c..a097d8a 100644 --- a/src/stores/formulaStore.ts +++ b/src/stores/formulaStore.ts @@ -185,7 +185,7 @@ export const useFormulaStore = defineStore('formula', () => { * @function initFormulaList * @desc 初始化配方列表,从服务器获取所有配方 */ - const initFormulaList = async (flag: 'add' | 'edit') => { + const initFormulaList = async (flag?: 'add' | 'edit') => { try { const params = { className: 'SettingMgrService', @@ -197,8 +197,10 @@ export const useFormulaStore = defineStore('formula', () => { formulaList.value = res.rely if (res.rely.length > 0) { console.log('selectedIndex.value--', currentSelectedIndex.value) - flag === 'add' && (currentSelectedFormulaInfo.value = res.rely[res.rely.length - 1]) - flag === 'add' && (currentSelectedIndex.value = res.rely.length - 1) + if (flag !== 'edit') { + currentSelectedFormulaInfo.value = res.rely[res.rely.length - 1] + currentSelectedIndex.value = res.rely.length - 1 + } } else { currentSelectedIndex.value = null