Files
iot-device-management-frontend/apps/web-antd/src/views/iot/thingmodel/modules/dataSpecs/ThingModelEnumDataSpecs.vue

68 lines
1.8 KiB
Vue
Raw Normal View History

<!-- dataTypeenum 数组类型 -->
<script lang="ts" setup>
2025-10-13 10:17:19 +08:00
import type { Ref } from 'vue';
2025-10-10 20:26:17 +08:00
import { useVModel } from '@vueuse/core';
2025-10-13 10:17:19 +08:00
import { Button, Form, Input, message } from 'ant-design-vue';
2025-10-10 20:26:17 +08:00
/** 枚举型的 dataSpecs 配置组件 */
defineOptions({ name: 'ThingModelEnumDataSpecs' });
2025-10-10 20:26:17 +08:00
const props = defineProps<{ modelValue: any }>();
const emits = defineEmits(['update:modelValue']);
const dataSpecsList = useVModel(props, 'modelValue', emits) as Ref<any[]>;
/** 添加枚举项 */
2025-10-13 10:17:19 +08:00
function addEnum() {
dataSpecsList.value.push({
name: '', // 枚举项的名称
2025-10-13 10:17:19 +08:00
value: '', // 枚举值
} as any);
2025-10-13 10:17:19 +08:00
}
/** 删除枚举项 */
2025-10-13 10:17:19 +08:00
function deleteEnum(index: number) {
if (dataSpecsList.value.length === 1) {
2025-10-10 20:26:17 +08:00
message.warning('至少需要一个枚举项');
return;
}
2025-10-10 20:26:17 +08:00
dataSpecsList.value.splice(index, 1);
2025-10-13 10:17:19 +08:00
}
</script>
2025-10-10 20:26:17 +08:00
<template>
<Form.Item label="枚举项">
2025-10-10 20:26:17 +08:00
<div class="flex flex-col">
<div class="flex items-center">
<span class="flex-1"> 参数值 </span>
<span class="flex-1"> 参数描述 </span>
</div>
<div
v-for="(item, index) in dataSpecsList"
:key="index"
2025-10-20 10:37:23 +08:00
class="mb-5px flex items-center justify-between"
2025-10-10 20:26:17 +08:00
>
<div class="flex-1">
<Input v-model:value="item.value" placeholder="请输入枚举值,如'0'" />
</div>
2025-10-10 20:26:17 +08:00
<span class="mx-2">~</span>
<div class="flex-1">
<Input v-model:value="item.name" placeholder="对该枚举项的描述" />
</div>
<Button class="ml-10px" type="link" @click="deleteEnum(index)">
2025-10-10 20:26:17 +08:00
删除
2025-10-13 10:17:19 +08:00
</Button>
2025-10-10 20:26:17 +08:00
</div>
<Button type="link" @click="addEnum">+添加枚举项</Button>
2025-10-10 20:26:17 +08:00
</div>
2025-10-13 10:17:19 +08:00
</Form.Item>
2025-10-10 20:26:17 +08:00
</template>
<style lang="scss" scoped>
:deep(.ant-form-item) {
.ant-form-item {
margin-bottom: 0;
}
}
</style>