Commit aa798e51416763de9956b35fbbe8d3921cdd73f1

Authored by ww
1 parent f69b51d7

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

... ... @@ -34,6 +34,7 @@ export enum DataSourceField {
34 34 DEVICE_ID = 'deviceId',
35 35 DEVICE_PROFILE_ID = 'deviceProfileId',
36 36 ATTRIBUTE = 'attribute',
  37 + ATTRIBUTE_NAME = 'attributeName',
37 38 ATTRIBUTE_RENAME = 'attributeRename',
38 39 DEVICE_NAME = 'deviceName',
39 40 DEVICE_RENAME = 'deviceRename',
... ... @@ -113,6 +114,7 @@ export const commonDataSourceSchemas = (): FormSchema[] => {
113 114 [DataSourceField.DEVICE_PROFILE_ID]: null,
114 115 [DataSourceField.DEVICE_ID]: null,
115 116 [DataSourceField.ATTRIBUTE]: null,
  117 + [DataSourceField.ATTRIBUTE_NAME]: null,
116 118 [DataSourceField.TRANSPORT_TYPE]: null,
117 119 });
118 120 },
... ... @@ -147,6 +149,7 @@ export const commonDataSourceSchemas = (): FormSchema[] => {
147 149 setFieldsValue({
148 150 [DataSourceField.DEVICE_ID]: null,
149 151 [DataSourceField.ATTRIBUTE]: null,
  152 + [DataSourceField.ATTRIBUTE_NAME]: null,
150 153 [DataSourceField.TRANSPORT_TYPE]: option[DataSourceField.TRANSPORT_TYPE],
151 154 });
152 155 },
... ... @@ -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 235 field: DataSourceField.ATTRIBUTE,
227 236 component: 'ApiSelect',
228 237 label: '属性',
... ... @@ -230,7 +239,8 @@ export const commonDataSourceSchemas = (): FormSchema[] => {
230 239 rules: [{ required: true, message: '请选择属性' }],
231 240 ifShow: ({ model }) =>
232 241 !(isTcpProfile(model[DataSourceField.TRANSPORT_TYPE]) && isControlComponent(category!)),
233   - componentProps({ formModel }) {
  242 + componentProps({ formModel, formActionType }) {
  243 + const { setFieldsValue } = formActionType;
234 244 const deviceProfileId = formModel[DataSourceField.DEVICE_PROFILE_ID];
235 245 return {
236 246 api: async () => {
... ... @@ -246,6 +256,9 @@ export const commonDataSourceSchemas = (): FormSchema[] => {
246 256 },
247 257 placeholder: '请选择属性',
248 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 19 deviceId: string;
20 20 deviceType: string;
21 21 attribute: string;
  22 + attributeName: string;
22 23 deviceName: string;
23 24 gatewayDevice: boolean;
24 25 slaveDeviceId: string;
... ...