2025-10-07 19:58:59 +08:00
|
|
|
|
<!-- dataType:enum 数组类型 -->
|
|
|
|
|
|
<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-07 19:58:59 +08:00
|
|
|
|
|
2025-10-10 20:26:17 +08:00
|
|
|
|
const props = defineProps<{ modelValue: any }>();
|
|
|
|
|
|
const emits = defineEmits(['update:modelValue']);
|
2025-10-17 00:13:48 +08:00
|
|
|
|
const dataSpecsList = useVModel(props, 'modelValue', emits) as Ref<any[]>;
|
2025-10-07 19:58:59 +08:00
|
|
|
|
|
|
|
|
|
|
/** 添加枚举项 */
|
2025-10-13 10:17:19 +08:00
|
|
|
|
function addEnum() {
|
2025-10-07 19:58:59 +08:00
|
|
|
|
dataSpecsList.value.push({
|
|
|
|
|
|
name: '', // 枚举项的名称
|
2025-10-13 10:17:19 +08:00
|
|
|
|
value: '', // 枚举值
|
2025-10-17 00:13:48 +08:00
|
|
|
|
} as any);
|
2025-10-13 10:17:19 +08:00
|
|
|
|
}
|
2025-10-07 19:58:59 +08:00
|
|
|
|
|
|
|
|
|
|
/** 删除枚举项 */
|
2025-10-13 10:17:19 +08:00
|
|
|
|
function deleteEnum(index: number) {
|
2025-10-07 19:58:59 +08:00
|
|
|
|
if (dataSpecsList.value.length === 1) {
|
2025-10-10 20:26:17 +08:00
|
|
|
|
message.warning('至少需要一个枚举项');
|
|
|
|
|
|
return;
|
2025-10-07 19:58:59 +08:00
|
|
|
|
}
|
2025-10-10 20:26:17 +08:00
|
|
|
|
dataSpecsList.value.splice(index, 1);
|
2025-10-13 10:17:19 +08:00
|
|
|
|
}
|
2025-10-07 19:58:59 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
2025-10-10 20:26:17 +08:00
|
|
|
|
<template>
|
2025-10-17 00:13:48 +08:00
|
|
|
|
<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
|
|
|
|
>
|
2025-10-17 00:13:48 +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>
|
2025-10-17 00:13:48 +08:00
|
|
|
|
<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>
|
2025-10-17 00:13:48 +08:00
|
|
|
|
<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>
|
|
|
|
|
|
|
2025-10-07 19:58:59 +08:00
|
|
|
|
<style lang="scss" scoped>
|
2025-10-17 00:13:48 +08:00
|
|
|
|
:deep(.ant-form-item) {
|
|
|
|
|
|
.ant-form-item {
|
2025-10-07 19:58:59 +08:00
|
|
|
|
margin-bottom: 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
</style>
|