Commit 11b31233759209b38c5e9b10b518ef63866eaa0c

Authored by xp.Huang
2 parents 8e3acda9 54c692b4

Merge branch 'feat/object-model-enums-type' into 'main_dev'

feat: 物模型新增枚举类型

See merge request yunteng/thingskit-scada!200
1 -import type { FunctionType, TransportTypeEnum } from '@/enums/datasource' 1 +import type { DataTypeEnum, FunctionType, TransportTypeEnum } from '@/enums/datasource'
2 2
3 export interface DeviceProfileItemType { 3 export interface DeviceProfileItemType {
4 id: string 4 id: string
@@ -147,6 +147,7 @@ export interface Detail { @@ -147,6 +147,7 @@ export interface Detail {
147 export interface DataType { 147 export interface DataType {
148 type: string 148 type: string
149 specs: Specs | StructJSON[] 149 specs: Specs | StructJSON[]
  150 + specsList: Specs[]
150 } 151 }
151 152
152 export interface Specs { 153 export interface Specs {
@@ -158,6 +159,9 @@ export interface Specs { @@ -158,6 +159,9 @@ export interface Specs {
158 length?: string 159 length?: string
159 min: string 160 min: string
160 max: string 161 max: string
  162 + name?: string
  163 + value?: string
  164 + dataType?: DataTypeEnum
161 } 165 }
162 166
163 export interface ValueRange { 167 export interface ValueRange {
@@ -93,6 +93,27 @@ export const getFormSchemas = ({ structJSON: structJson, required, transportType @@ -93,6 +93,27 @@ export const getFormSchemas = ({ structJSON: structJson, required, transportType
93 } 93 }
94 } 94 }
95 95
  96 + const createEnumSelect = ({ identifier, functionName, dataType }: StructJSON): FormSchema => {
  97 + const { specsList } = dataType || {}
  98 +
  99 + return {
  100 + field: identifier,
  101 + label: functionName,
  102 + component: ComponentEnum.SELECT,
  103 + rules: [
  104 + {
  105 + required,
  106 + message: `${functionName}是必填项`,
  107 + type: 'number',
  108 + },
  109 + ],
  110 + componentProps: {
  111 + options: specsList,
  112 + fieldNames: { label: 'name', value: 'value' },
  113 + },
  114 + }
  115 + }
  116 +
96 const createStructJson = ({ identifier, functionName, dataType }: StructJSON): FormSchema => { 117 const createStructJson = ({ identifier, functionName, dataType }: StructJSON): FormSchema => {
97 return { 118 return {
98 field: identifier, 119 field: identifier,
@@ -129,6 +150,8 @@ export const getFormSchemas = ({ structJSON: structJson, required, transportType @@ -129,6 +150,8 @@ export const getFormSchemas = ({ structJSON: structJson, required, transportType
129 schemas.push(createTCPServiceCommandInput(item)) 150 schemas.push(createTCPServiceCommandInput(item))
130 if (type === DataTypeEnum.BOOL) 151 if (type === DataTypeEnum.BOOL)
131 schemas.push(createSelect(item)) 152 schemas.push(createSelect(item))
  153 + else if (type === DataTypeEnum.ENUM)
  154 + schemas.push(createEnumSelect(item))
132 else if (type === DataTypeEnum.NUMBER_INT) 155 else if (type === DataTypeEnum.NUMBER_INT)
133 schemas.push(createInputNumber(item)) 156 schemas.push(createInputNumber(item))
134 else if (type === DataTypeEnum.NUMBER_DOUBLE) 157 else if (type === DataTypeEnum.NUMBER_DOUBLE)
@@ -29,7 +29,7 @@ const thingsModelFormListElMap = reactive<Record<string, { el: InstanceType<type @@ -29,7 +29,7 @@ const thingsModelFormListElMap = reactive<Record<string, { el: InstanceType<type
29 const [register, formActionType] = useForm({ 29 const [register, formActionType] = useForm({
30 schemas: getFormSchemas({ structJSON: props.inputData || [], required: props.required, transportType: props.transportType }), 30 schemas: getFormSchemas({ structJSON: props.inputData || [], required: props.required, transportType: props.transportType }),
31 showActionButtonGroup: false, 31 showActionButtonGroup: false,
32 - // labelWidth: getLabelWidth() || 80, 32 + labelWidth: 100,
33 labelAlign: FormLabelAlignEnum.RIGHT, 33 labelAlign: FormLabelAlignEnum.RIGHT,
34 layout: FormLayoutEnum.HORIZONTAL, 34 layout: FormLayoutEnum.HORIZONTAL,
35 }) 35 })
@@ -105,19 +105,34 @@ defineExpose<ComponentExposeType>({ @@ -105,19 +105,34 @@ defineExpose<ComponentExposeType>({
105 <Card class="!border-2 !border-dashed" :title="title"> 105 <Card class="!border-2 !border-dashed" :title="title">
106 <BasicForm class="things-model-form" @register="register"> 106 <BasicForm class="things-model-form" @register="register">
107 <template v-for="item in getStructFormItem" #[item.identifier]="{ model, field }" :key="item.identifier"> 107 <template v-for="item in getStructFormItem" #[item.identifier]="{ model, field }" :key="item.identifier">
108 - <ThingsModelForm :ref="(el) => setFormElRef(el as InstanceType<typeof ThingsModelForm>, item) " v-model:value="model[field]" :input-data="(item.dataType?.specs as StructJSON[]) || []" :title="item.functionName" /> 108 + <ThingsModelForm
  109 + :ref="(el) => setFormElRef(el as InstanceType<typeof ThingsModelForm>, item)"
  110 + v-model:value="model[field]" :input-data="(item.dataType?.specs as StructJSON[]) || []"
  111 + :title="item.functionName"
  112 + />
109 </template> 113 </template>
110 </BasicForm> 114 </BasicForm>
111 </Card> 115 </Card>
112 </template> 116 </template>
113 117
114 <style lang="less" scoped> 118 <style lang="less" scoped>
115 - .things-model-form {  
116 - :deep(.ant-input-number) {  
117 - width: 100%;  
118 - } 119 +.things-model-form {
  120 + :deep(.ant-input-number) {
  121 + width: 100%;
119 } 122 }
120 - :deep(.ant-form-item-control){  
121 - margin-left: 6px; 123 +
  124 + :deep(.ant-form-item-label) {
  125 + >label {
  126 + display: block;
  127 + text-align: right;
  128 + white-space: nowrap;
  129 + text-overflow: ellipsis;
  130 + overflow: hidden;
  131 + }
122 } 132 }
  133 +}
  134 +
  135 +:deep(.ant-form-item-control) {
  136 + margin-left: 6px;
  137 +}
123 </style> 138 </style>
@@ -314,6 +314,7 @@ export enum DataTypeEnum { @@ -314,6 +314,7 @@ export enum DataTypeEnum {
314 STRING = 'TEXT', 314 STRING = 'TEXT',
315 STRUCT = 'STRUCT', 315 STRUCT = 'STRUCT',
316 BOOL = 'BOOL', 316 BOOL = 'BOOL',
  317 + ENUM = 'ENUM',
317 } 318 }
318 319
319 export enum AggregateTypeEnum { 320 export enum AggregateTypeEnum {