Commit aa798e51416763de9956b35fbbe8d3921cdd73f1

Authored by ww
1 parent f69b51d7

fix: 修复数据看板未保存物模型名称

@@ -34,6 +34,7 @@ export enum DataSourceField { @@ -34,6 +34,7 @@ export enum DataSourceField {
34 DEVICE_ID = 'deviceId', 34 DEVICE_ID = 'deviceId',
35 DEVICE_PROFILE_ID = 'deviceProfileId', 35 DEVICE_PROFILE_ID = 'deviceProfileId',
36 ATTRIBUTE = 'attribute', 36 ATTRIBUTE = 'attribute',
  37 + ATTRIBUTE_NAME = 'attributeName',
37 ATTRIBUTE_RENAME = 'attributeRename', 38 ATTRIBUTE_RENAME = 'attributeRename',
38 DEVICE_NAME = 'deviceName', 39 DEVICE_NAME = 'deviceName',
39 DEVICE_RENAME = 'deviceRename', 40 DEVICE_RENAME = 'deviceRename',
@@ -113,6 +114,7 @@ export const commonDataSourceSchemas = (): FormSchema[] => { @@ -113,6 +114,7 @@ export const commonDataSourceSchemas = (): FormSchema[] => {
113 [DataSourceField.DEVICE_PROFILE_ID]: null, 114 [DataSourceField.DEVICE_PROFILE_ID]: null,
114 [DataSourceField.DEVICE_ID]: null, 115 [DataSourceField.DEVICE_ID]: null,
115 [DataSourceField.ATTRIBUTE]: null, 116 [DataSourceField.ATTRIBUTE]: null,
  117 + [DataSourceField.ATTRIBUTE_NAME]: null,
116 [DataSourceField.TRANSPORT_TYPE]: null, 118 [DataSourceField.TRANSPORT_TYPE]: null,
117 }); 119 });
118 }, 120 },
@@ -147,6 +149,7 @@ export const commonDataSourceSchemas = (): FormSchema[] => { @@ -147,6 +149,7 @@ export const commonDataSourceSchemas = (): FormSchema[] => {
147 setFieldsValue({ 149 setFieldsValue({
148 [DataSourceField.DEVICE_ID]: null, 150 [DataSourceField.DEVICE_ID]: null,
149 [DataSourceField.ATTRIBUTE]: null, 151 [DataSourceField.ATTRIBUTE]: null,
  152 + [DataSourceField.ATTRIBUTE_NAME]: null,
150 [DataSourceField.TRANSPORT_TYPE]: option[DataSourceField.TRANSPORT_TYPE], 153 [DataSourceField.TRANSPORT_TYPE]: option[DataSourceField.TRANSPORT_TYPE],
151 }); 154 });
152 }, 155 },
@@ -223,6 +226,12 @@ export const commonDataSourceSchemas = (): FormSchema[] => { @@ -223,6 +226,12 @@ export const commonDataSourceSchemas = (): FormSchema[] => {
223 }, 226 },
224 }, 227 },
225 { 228 {
  229 + field: DataSourceField.ATTRIBUTE_NAME,
  230 + component: 'Input',
  231 + label: '属性名',
  232 + show: false,
  233 + },
  234 + {
226 field: DataSourceField.ATTRIBUTE, 235 field: DataSourceField.ATTRIBUTE,
227 component: 'ApiSelect', 236 component: 'ApiSelect',
228 label: '属性', 237 label: '属性',
@@ -230,7 +239,8 @@ export const commonDataSourceSchemas = (): FormSchema[] => { @@ -230,7 +239,8 @@ export const commonDataSourceSchemas = (): FormSchema[] => {
230 rules: [{ required: true, message: '请选择属性' }], 239 rules: [{ required: true, message: '请选择属性' }],
231 ifShow: ({ model }) => 240 ifShow: ({ model }) =>
232 !(isTcpProfile(model[DataSourceField.TRANSPORT_TYPE]) && isControlComponent(category!)), 241 !(isTcpProfile(model[DataSourceField.TRANSPORT_TYPE]) && isControlComponent(category!)),
233 - componentProps({ formModel }) { 242 + componentProps({ formModel, formActionType }) {
  243 + const { setFieldsValue } = formActionType;
234 const deviceProfileId = formModel[DataSourceField.DEVICE_PROFILE_ID]; 244 const deviceProfileId = formModel[DataSourceField.DEVICE_PROFILE_ID];
235 return { 245 return {
236 api: async () => { 246 api: async () => {
@@ -246,6 +256,9 @@ export const commonDataSourceSchemas = (): FormSchema[] => { @@ -246,6 +256,9 @@ export const commonDataSourceSchemas = (): FormSchema[] => {
246 }, 256 },
247 placeholder: '请选择属性', 257 placeholder: '请选择属性',
248 getPopupContainer: () => document.body, 258 getPopupContainer: () => document.body,
  259 + onChange(value: string, option: Record<'label' | 'value', string>) {
  260 + setFieldsValue({ [DataSourceField.ATTRIBUTE_NAME]: value ? option.label : null });
  261 + },
249 }; 262 };
250 }, 263 },
251 }, 264 },
  1 +import { DataSource } from '../../palette/types';
  2 +import { PublicComponentOptions } from '../index.type';
  3 +import { isArray } from '/@/utils/is';
  4 +
  5 +export const getAttributeName = (option: PublicComponentOptions & DataSource) => {
  6 + const { attribute, attributeRename, attributeName } = option || {};
  7 + return attributeRename || attributeName || attribute;
  8 +};
  9 +
  10 +export const useExtractValueByKeys = <T = Recordable>(
  11 + keys: string[] | string,
  12 + sourceValue: T = {} as T,
  13 + defaultValue: Recordable = {} as Recordable
  14 +): T => {
  15 + keys = isArray(keys) ? keys : [keys];
  16 + return keys.reduce((prev, next) => {
  17 + return { ...prev, [next]: sourceValue[next] || defaultValue[next] };
  18 + }, {} as T);
  19 +};
@@ -19,6 +19,7 @@ export interface DataSource { @@ -19,6 +19,7 @@ export interface DataSource {
19 deviceId: string; 19 deviceId: string;
20 deviceType: string; 20 deviceType: string;
21 attribute: string; 21 attribute: string;
  22 + attributeName: string;
22 deviceName: string; 23 deviceName: string;
23 gatewayDevice: boolean; 24 gatewayDevice: boolean;
24 slaveDeviceId: string; 25 slaveDeviceId: string;