wwf
7 小时以前 a1d7e81859f554f3a53680cc35f0f49bf1f77098
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
<!-- dataType:array 数组类型 -->
<template>
  <el-form-item label="元素类型" prop="property.dataSpecs.childDataType">
    <el-radio-group v-model="dataSpecs.childDataType" @change="handleChange">
      <template v-for="item in getDataTypeOptions()" :key="item.value">
        <el-radio
          v-if="
            !(
              [
                IoTDataSpecsDataTypeEnum.ENUM,
                IoTDataSpecsDataTypeEnum.ARRAY,
                IoTDataSpecsDataTypeEnum.DATE
              ] as any[]
            ).includes(item.value)
          "
          :value="item.value"
          class="w-1/3"
        >
          {{ `${item.value}(${item.label})` }}
        </el-radio>
      </template>
    </el-radio-group>
  </el-form-item>
  <el-form-item label="元素个数" prop="property.dataSpecs.size">
    <el-input v-model="dataSpecs.size" placeholder="请输入数组中的元素个数" />
  </el-form-item>
  <!-- Struct 型配置-->
  <ThingModelStructDataSpecs
    v-if="dataSpecs.childDataType === IoTDataSpecsDataTypeEnum.STRUCT"
    v-model="dataSpecs.dataSpecsList"
  />
</template>
 
<script lang="ts" setup>
import { useVModel } from '@vueuse/core'
import ThingModelStructDataSpecs from './ThingModelStructDataSpecs.vue'
import { getDataTypeOptions, IoTDataSpecsDataTypeEnum } from '@/views/iot/utils/constants'
 
/** 数组型的 dataSpecs 配置组件 */
defineOptions({ name: 'ThingModelArrayDataSpecs' })
 
const props = defineProps<{ modelValue: any }>()
const emits = defineEmits(['update:modelValue'])
const dataSpecs = useVModel(props, 'modelValue', emits) as Ref<any>
 
/** 元素类型改变时间。当值为 struct 时,对 dataSpecs 中的 dataSpecsList 进行初始化 */
const handleChange = (val: string) => {
  if (val !== IoTDataSpecsDataTypeEnum.STRUCT) {
    return
  }
 
  dataSpecs.value.dataSpecsList = []
}
</script>
 
<style lang="scss" scoped></style>