gaoluyang
2026-06-24 c0cb161bb52ce0fbdce5c66ec391d107c75e2452
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<!-- dataType:array 数组类型 -->
<script lang="ts" setup>
import type { Ref } from 'vue';
 
import { getDataTypeOptions, IoTDataSpecsDataTypeEnum } from '..\..\..\..\..\packages\constants\src';
 
import { useVModel } from '@vueuse/core';
import { Form, Input, Radio } from 'ant-design-vue';
 
import { ThingModelFormRules } from '#/api/iot/thingmodel';
 
import ThingModelStructDataSpecs from './struct.vue';
 
const props = defineProps<{ modelValue: any }>();
const emits = defineEmits(['update:modelValue']);
/** 数组元素禁止选择的类型 */
const EXCLUDED_CHILD_TYPES = new Set<string>([
  IoTDataSpecsDataTypeEnum.ARRAY,
  IoTDataSpecsDataTypeEnum.DATE,
  IoTDataSpecsDataTypeEnum.ENUM,
]);
const childDataTypeOptions = getDataTypeOptions().filter(
  (item) => !EXCLUDED_CHILD_TYPES.has(item.value),
);
 
const dataSpecs = useVModel(props, 'modelValue', emits) as Ref<any>;
 
/** 元素类型切换时,清理旧子类型的结构体属性配置 */
function handleChange(e: any) {
  const val = e?.target?.value ?? e;
  dataSpecs.value.dataSpecsList = [];
  dataSpecs.value.childDataType = val;
}
</script>
 
<template>
  <Form.Item
    :name="['property', 'dataSpecs', 'childDataType']"
    :rules="ThingModelFormRules.childDataType"
    label="元素类型"
  >
    <Radio.Group v-model:value="dataSpecs.childDataType" @change="handleChange">
      <Radio
        v-for="item in childDataTypeOptions"
        :key="item.value"
        :value="item.value"
        class="w-1/3"
      >
        {{ `${item.value}(${item.label})` }}
      </Radio>
    </Radio.Group>
  </Form.Item>
  <Form.Item
    :name="['property', 'dataSpecs', 'size']"
    :rules="ThingModelFormRules.size"
    label="元素个数"
  >
    <Input
      v-model:value="dataSpecs.size"
      placeholder="请输入数组中的元素个数"
    />
  </Form.Item>
  <!-- Struct 型配置-->
  <ThingModelStructDataSpecs
    v-if="dataSpecs.childDataType === IoTDataSpecsDataTypeEnum.STRUCT"
    v-model="dataSpecs.dataSpecsList"
    :field-path="['property', 'dataSpecs', 'dataSpecsList']"
  />
</template>