3 changed files with 83 additions and 55 deletions
-
55src/components/home/HomeSetting.vue
-
81src/components/home/PressureControl.vue
-
2src/views/home/index.vue
@ -0,0 +1,81 @@ |
|||
<script lang="ts" setup> |
|||
import { syncSendCmd } from 'apis/system' |
|||
import { useDeviceStore } from 'stores/deviceStore' |
|||
import { computed, onMounted, ref } from 'vue' |
|||
|
|||
import { useHomeStore } from '@/stores/homeStore' |
|||
|
|||
const selected = ref<string[]>([]) |
|||
// 级联数据:[{ label, value, children: [{ label, value }] }] |
|||
const cascaderOptions = ref<{ label: string, value: string, children: { label: string, value: string }[] }[]>([]) |
|||
|
|||
const homeStore = useHomeStore() |
|||
const deviceStore = useDeviceStore() |
|||
|
|||
// 拉取配置并构建 cascaderOptions |
|||
const getPressureConfig = async () => { |
|||
const res = await syncSendCmd({ className: 'PipelinePressureControl', fnName: 'getConfig' }) |
|||
if (res.ackcode === 0) { |
|||
homeStore.updatePressureConfig(res.rely) |
|||
const { typeDisplayNames, types, intensitys } = res.rely |
|||
cascaderOptions.value = typeDisplayNames.map((name: string, idx: number) => { |
|||
const children = (intensitys[types[idx]] || []).map((val: string) => ({ label: `${val}%`, value: val })) |
|||
return { label: name, value: types[idx], children } |
|||
}) |
|||
|
|||
// 初始化当前状态 |
|||
const stateRes = await syncSendCmd({ className: 'PipelinePressureControl', fnName: 'getState' }) |
|||
if (stateRes.ackcode === 0) { |
|||
const { type, intensity } = stateRes.rely |
|||
selected.value = intensity ? [type, intensity] : [type] |
|||
} |
|||
} |
|||
} |
|||
|
|||
onMounted(getPressureConfig) |
|||
|
|||
const deviceType = computed(() => { |
|||
return __DEVICE_TYPE__ |
|||
}) |
|||
|
|||
// 用户选择后立即更新压力配置(支持仅选择类型的情况) |
|||
const confirm = (val: string[]) => { |
|||
if (!val || !val.length) |
|||
return |
|||
homeStore.updatePressure(val) |
|||
} |
|||
</script> |
|||
|
|||
<template> |
|||
<div v-if="deviceType === deviceStore.deviceTypeMap.PipeDM" class="pressure-wrapper"> |
|||
<el-cascader |
|||
v-model="selected" |
|||
:options="cascaderOptions" |
|||
placeholder="请选择压力类型和强度" |
|||
class="pressure-cascader" |
|||
input-props="{ style: 'text-align: center;' }" |
|||
popper-class="pressure-cascader-popper" |
|||
@change="confirm" |
|||
/> |
|||
</div> |
|||
</template> |
|||
|
|||
<style scoped> |
|||
.pressure-wrapper { |
|||
display: flex; |
|||
justify-content: center; |
|||
padding: 0.5rem 0; |
|||
} |
|||
|
|||
.pressure-cascader { |
|||
width: 100%; |
|||
max-width: 7.5rem; |
|||
} |
|||
</style> |
|||
|
|||
<!-- 全局样式,作用于弹出面板 --> |
|||
<style> |
|||
.pressure-cascader-popper .el-cascader-menu__item { |
|||
text-align: center; |
|||
} |
|||
</style> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue