Browse Source

配方bug

master
王梦远 2 weeks ago
parent
commit
22b400b0da
  1. 30
      src/components/formula/FormulaConfig.vue
  2. 40
      src/components/formula/FormulaTable.vue
  3. 19
      src/stores/formulaStore.ts

30
src/components/formula/FormulaConfig.vue

@ -6,7 +6,7 @@ import { ElMessage } from 'element-plus'
import { formulaNameMap } from 'libs/constant' import { formulaNameMap } from 'libs/constant'
import { cloneDeep } from 'lodash' import { cloneDeep } from 'lodash'
import { useHomeStore } from 'stores/homeStore' import { useHomeStore } from 'stores/homeStore'
import { computed, inject, nextTick, onMounted, ref, watch } from 'vue'
import { computed, inject, nextTick, onMounted, ref, watch, watchEffect } from 'vue'
import { FtMessage } from '@/libs/message' import { FtMessage } from '@/libs/message'
import { compareJSON, convertValuesToInt, convertValuesToString } from '@/libs/utils' import { compareJSON, convertValuesToInt, convertValuesToString } from '@/libs/utils'
@ -100,12 +100,14 @@ const labelUnitMap: Record<string, any> = {
} }
const currentFormulaItem = ref() const currentFormulaItem = ref()
onMounted(() => {
initFormulaConfig()
registerGrandsonMethods && registerGrandsonMethods({ getFormData })
})
/** /**
* 组件挂载时注册方法供父组件调用 * 组件挂载时注册方法供父组件调用
*/ */
onMounted(() => {
initFormulaConfig()
watchEffect(() => {
if (props.type === 'home') { if (props.type === 'home') {
formData.value = cloneDeep(formulaStore.selectedFormulaInfo) || cloneDeep(formulaStore.defaultFormulaInfo) formData.value = cloneDeep(formulaStore.selectedFormulaInfo) || cloneDeep(formulaStore.defaultFormulaInfo)
} }
@ -123,10 +125,6 @@ onMounted(() => {
isFlip.value = formulaStore.flip isFlip.value = formulaStore.flip
// int. // int.
formData.value = convertValuesToInt(formData.value) formData.value = convertValuesToInt(formData.value)
registerGrandsonMethods && registerGrandsonMethods({ getFormData })
})
watch(() => formulaStore.currentSelectedFormulaInfo, () => {
formData.value = cloneDeep(formulaStore.currentSelectedFormulaInfo)
}) })
const initFormulaConfig = () => { const initFormulaConfig = () => {
if (!formulaStore.formulaList.length) { if (!formulaStore.formulaList.length) {
@ -468,6 +466,22 @@ defineExpose({
</template> </template>
</el-input> </el-input>
</template> </template>
<template v-if="item.val_type === 'float'">
<el-input
v-model.number="formData[item.setting_id]"
v-prevent-keyboard
style="width: 80%"
type="number"
:name="item.setting_id"
:controls="false"
:disabled="!item.is_visible_in_setting_page"
@focus="e => openKeyboard(e, item)"
>
<template v-if="labelUnitMap[item.setting_id]" #append>
{{ labelUnitMap[item.setting_id] }}
</template>
</el-input>
</template>
<template v-else-if="item.val_type === 'enum'"> <template v-else-if="item.val_type === 'enum'">
<el-input <el-input
v-model="formData[item.setting_id]" v-model="formData[item.setting_id]"

40
src/components/formula/FormulaTable.vue

@ -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,20 +26,12 @@ defineExpose({
onMounted(() => { onMounted(() => {
initFormulaList() initFormulaList()
}) })
watch(() => formulaStore.formulaList.length, () => {
recipes.value = formulaStore.formulaList
watch(() => formulaStore.selectedIndex, () => {
if (formulaStore.selectedIndex == null) {
if (formulaStore.formulaList && formulaStore.formulaList.length > 0) { if (formulaStore.formulaList && formulaStore.formulaList.length > 0) {
selectedIndex.value = formulaStore.formulaList.length - 1
}
else {
selectedIndex.value = null
}
})
watch(() => selectedIndex.value, () => {
if (selectedIndex.value != null) {
const currentIndex: number = selectedIndex.value
const selectItem: Formula.FormulaItem = recipes.value[currentIndex]
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 const item = convertValuesToInt(selectItem) as Formula.FormulaItem
formulaStore.updateSelectedFormulaData(item) formulaStore.updateSelectedFormulaData(item)
} }
@ -49,15 +39,20 @@ watch(() => selectedIndex.value, () => {
const formData = cloneDeep(formulaStore.resetFormulaInfo) const formData = cloneDeep(formulaStore.resetFormulaInfo)
formulaStore.updateSelectedFormulaData(convertValuesToInt(formData) as Formula.FormulaItem) formulaStore.updateSelectedFormulaData(convertValuesToInt(formData) as Formula.FormulaItem)
} }
}
else {
const currentIndex: number = formulaStore.selectedIndex
const selectItem: Formula.FormulaItem = formulaStore.formulaList[currentIndex]
const item = convertValuesToInt(selectItem) as Formula.FormulaItem
formulaStore.updateSelectedFormulaData(item)
}
}) })
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>

19
src/stores/formulaStore.ts

@ -30,7 +30,7 @@ const createDefaultFormulaInfo = (): Formula.FormulaItem => ({
stoped_gs: 300, stoped_gs: 300,
stoped_humi: 85, stoped_humi: 85,
stoped_satur: 85, stoped_satur: 85,
name: '默认配置',
name: '',
}) })
// 清空配方函数 // 清空配方函数
const createResetFormulaInfo = (): Formula.FormulaItem => ({ const createResetFormulaInfo = (): Formula.FormulaItem => ({
@ -62,7 +62,7 @@ export const useFormulaStore = defineStore('formula', () => {
const formulaList = ref<Formula.FormulaItem[]>([]) const formulaList = ref<Formula.FormulaItem[]>([])
const loglevel = ref<string>('1') const loglevel = ref<string>('1')
const flip = ref(true) const flip = ref(true)
const selectedIndex = ref<number | null>(0) // 左侧列表选中值 从0开始
const selectedIndex = ref<number | null>(null) // 左侧列表选中值 从0开始
watch( watch(
defaultFormulaInfo, defaultFormulaInfo,
@ -87,7 +87,7 @@ export const useFormulaStore = defineStore('formula', () => {
updateLogLevels(item) updateLogLevels(item)
} }
}) })
formulaMap.name = '默认配置'
formulaMap.name = ''
return formulaMap as Formula.FormulaItem return formulaMap as Formula.FormulaItem
} }
@ -182,15 +182,18 @@ export const useFormulaStore = defineStore('formula', () => {
const res = await syncSendCmd(params) const res = await syncSendCmd(params)
if (res.rely) { if (res.rely) {
formulaList.value = res.rely formulaList.value = res.rely
if (res.rely.length) {
if (res.rely.length > 0) {
console.log('selectedIndex.value--', selectedIndex.value) console.log('selectedIndex.value--', selectedIndex.value)
currentSelectedFormulaInfo.value = selectedIndex.value
? res.rely[selectedIndex.value]
: res.rely[res.rely.length - 1]
currentSelectedFormulaInfo.value = res.rely[res.rely.length - 1]
selectedIndex.value = res.rely.length - 1
}
else {
selectedIndex.value = null
} }
} }
else { else {
formulaList.value = [] formulaList.value = []
selectedIndex.value = null
} }
} }
catch (error) { catch (error) {
@ -242,7 +245,7 @@ export const useFormulaStore = defineStore('formula', () => {
flip.value = data flip.value = data
} }
const updateSelectedIndex = (index: number) => {
const updateSelectedIndex = (index: number | null) => {
selectedIndex.value = index selectedIndex.value = index
} }

Loading…
Cancel
Save