|
@ -10,13 +10,11 @@ import { convertValuesToInt } from '@/libs/utils' |
|
|
import { useFormulaStore } from '@/stores/formulaStore' |
|
|
import { useFormulaStore } from '@/stores/formulaStore' |
|
|
|
|
|
|
|
|
const formulaStore = useFormulaStore() |
|
|
const formulaStore = useFormulaStore() |
|
|
const selectedIndex = ref<number | null>(formulaStore.selectedIndex) |
|
|
|
|
|
const recipes = ref<Formula.FormulaItem[]>([]) |
|
|
|
|
|
const currentFormula = ref<Formula.FormulaItem>(formulaStore.currentSelectedFormulaInfo) |
|
|
const currentFormula = ref<Formula.FormulaItem>(formulaStore.currentSelectedFormulaInfo) |
|
|
|
|
|
|
|
|
// 移除列表的选中 |
|
|
// 移除列表的选中 |
|
|
const selectedIndexRest = async () => { |
|
|
const selectedIndexRest = async () => { |
|
|
selectedIndex.value = null |
|
|
|
|
|
|
|
|
formulaStore.updateSelectedIndex(null) |
|
|
console.log('子组件方法被调用') |
|
|
console.log('子组件方法被调用') |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -28,36 +26,33 @@ defineExpose({ |
|
|
onMounted(() => { |
|
|
onMounted(() => { |
|
|
initFormulaList() |
|
|
initFormulaList() |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
watch(() => formulaStore.formulaList.length, () => { |
|
|
|
|
|
recipes.value = formulaStore.formulaList |
|
|
|
|
|
if (formulaStore.formulaList && formulaStore.formulaList.length > 0) { |
|
|
|
|
|
selectedIndex.value = formulaStore.formulaList.length - 1 |
|
|
|
|
|
|
|
|
watch(() => formulaStore.selectedIndex, () => { |
|
|
|
|
|
if (formulaStore.selectedIndex == null) { |
|
|
|
|
|
if (formulaStore.formulaList && formulaStore.formulaList.length > 0) { |
|
|
|
|
|
formulaStore.updateSelectedIndex(formulaStore.formulaList.length - 1) |
|
|
|
|
|
const currentIndex: number | null = formulaStore.selectedIndex |
|
|
|
|
|
const selectItem: Formula.FormulaItem = formulaStore.formulaList[currentIndex] |
|
|
|
|
|
const item = convertValuesToInt(selectItem) as Formula.FormulaItem |
|
|
|
|
|
formulaStore.updateSelectedFormulaData(item) |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
const formData = cloneDeep(formulaStore.resetFormulaInfo) |
|
|
|
|
|
formulaStore.updateSelectedFormulaData(convertValuesToInt(formData) as Formula.FormulaItem) |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
selectedIndex.value = null |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
|
|
|
watch(() => selectedIndex.value, () => { |
|
|
|
|
|
if (selectedIndex.value != null) { |
|
|
|
|
|
const currentIndex: number = selectedIndex.value |
|
|
|
|
|
const selectItem: Formula.FormulaItem = recipes.value[currentIndex] |
|
|
|
|
|
|
|
|
const currentIndex: number = formulaStore.selectedIndex |
|
|
|
|
|
const selectItem: Formula.FormulaItem = formulaStore.formulaList[currentIndex] |
|
|
const item = convertValuesToInt(selectItem) as Formula.FormulaItem |
|
|
const item = convertValuesToInt(selectItem) as Formula.FormulaItem |
|
|
formulaStore.updateSelectedFormulaData(item) |
|
|
formulaStore.updateSelectedFormulaData(item) |
|
|
} |
|
|
} |
|
|
else { |
|
|
|
|
|
const formData = cloneDeep(formulaStore.resetFormulaInfo) |
|
|
|
|
|
formulaStore.updateSelectedFormulaData(convertValuesToInt(formData) as Formula.FormulaItem) |
|
|
|
|
|
} |
|
|
|
|
|
}) |
|
|
}) |
|
|
const initFormulaList = () => { |
|
|
const initFormulaList = () => { |
|
|
formulaStore.initFormulaList() |
|
|
formulaStore.initFormulaList() |
|
|
recipes.value = formulaStore.formulaList as Formula.FormulaItem[] |
|
|
|
|
|
} |
|
|
} |
|
|
const selectRecipe = (item: Formula.FormulaItem, index: number) => { |
|
|
const selectRecipe = (item: Formula.FormulaItem, index: number) => { |
|
|
selectedIndex.value = index |
|
|
|
|
|
formulaStore.updateSelectedIndex(index) |
|
|
formulaStore.updateSelectedIndex(index) |
|
|
console.log('selectedIndex--', selectedIndex.value) |
|
|
|
|
|
|
|
|
formulaStore.updateSelectedIndex(index) |
|
|
item = convertValuesToInt(item) as Formula.FormulaItem |
|
|
item = convertValuesToInt(item) as Formula.FormulaItem |
|
|
formulaStore.updateSelectedFormulaData(item) |
|
|
formulaStore.updateSelectedFormulaData(item) |
|
|
} |
|
|
} |
|
@ -106,7 +101,6 @@ const deleteRecipe = (item: Formula.FormulaItem) => { |
|
|
} |
|
|
} |
|
|
syncSendCmd(delParams).then(() => { |
|
|
syncSendCmd(delParams).then(() => { |
|
|
FtMessage.success('操作成功') |
|
|
FtMessage.success('操作成功') |
|
|
formulaStore.updateSelectedIndex(0) |
|
|
|
|
|
formulaStore.initFormulaList() |
|
|
formulaStore.initFormulaList() |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
@ -115,12 +109,12 @@ const deleteRecipe = (item: Formula.FormulaItem) => { |
|
|
</script> |
|
|
</script> |
|
|
|
|
|
|
|
|
<template> |
|
|
<template> |
|
|
<div v-if="recipes.length" class="recipe-management"> |
|
|
|
|
|
|
|
|
<div v-if="formulaStore.formulaList.length" class="recipe-management"> |
|
|
<ul class="recipe-list"> |
|
|
<ul class="recipe-list"> |
|
|
<li |
|
|
<li |
|
|
v-for="(item, index) in recipes" |
|
|
|
|
|
|
|
|
v-for="(item, index) in formulaStore.formulaList" |
|
|
:key="index" |
|
|
:key="index" |
|
|
:class="{ selected: selectedIndex === index }" |
|
|
|
|
|
|
|
|
:class="{ selected: formulaStore.selectedIndex === index }" |
|
|
@click="selectRecipe(item, index)" |
|
|
@click="selectRecipe(item, index)" |
|
|
> |
|
|
> |
|
|
<span class="formula-name">{{ item.name }}</span> |
|
|
<span class="formula-name">{{ item.name }}</span> |
|
|