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