diff --git a/src/components/formula/FormulaConfig.vue b/src/components/formula/FormulaConfig.vue index 82dbe50..38cbc6b 100644 --- a/src/components/formula/FormulaConfig.vue +++ b/src/components/formula/FormulaConfig.vue @@ -269,6 +269,7 @@ const onAddFormula = () => { onEditFormula(item.formula_id, formulaForm as Formula.FormulaItem) } }) + formulaStore.initFormulaList() } /** @@ -386,7 +387,7 @@ defineExpose({
- + import { syncSendCmd } from 'apis/system' import { ElMessageBox } from 'element-plus' -import { onMounted, ref, watch } from 'vue' +import { onMounted, ref, watch, watchEffect } from 'vue' import { FtMessage } from '@/libs/message' import { FtMessageBox } from '@/libs/messageBox' @@ -28,18 +28,20 @@ onMounted(() => { initFormulaList() }) -watch(formulaStore.formulaList, () => { +watchEffect(() => { recipes.value = formulaStore.formulaList if (formulaStore.formulaList) { - if (formulaStore.selectedIndex != null) { - selectedIndex.value = formulaStore.selectedIndex - } - else { - selectedIndex.value = formulaStore.formulaList.length - 1 - } + selectedIndex.value = formulaStore.formulaList.length - 1 + } +}) +watch(selectedIndex, () => { + if (selectedIndex.value != null) { + const currentIndex: number = selectedIndex.value + const selectItem: Formula.FormulaItem = recipes.value[currentIndex] + const item = convertValuesToInt(selectItem) as Formula.FormulaItem + formulaStore.updateSelectedFormulaData(item) } }) - const initFormulaList = () => { if (formulaStore.formulaList && formulaStore.formulaList.length) { recipes.value = formulaStore.formulaList as Formula.FormulaItem[] @@ -48,7 +50,6 @@ const initFormulaList = () => { formulaStore.initFormulaList() } } -watch(selectedIndex, () => {}) const selectRecipe = (item: Formula.FormulaItem, index: number) => { selectedIndex.value = index formulaStore.updateSelectedIndex(index)