Commit ac92b6efe135d0db4efc692933d71430f5804af5
Merge branch 'fix/data-board-save-attribute-name' into 'main_dev'
fix: 修复数据看板未保存物模型名称 See merge request yunteng/thingskit-front!698
Showing
3 changed files
with
34 additions
and
1 deletions
| ... | ... | @@ -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', |
| ... | ... | @@ -118,6 +119,7 @@ export const commonDataSourceSchemas = (): FormSchema[] => { |
| 118 | 119 | [DataSourceField.DEVICE_PROFILE_ID]: null, |
| 119 | 120 | [DataSourceField.DEVICE_ID]: null, |
| 120 | 121 | [DataSourceField.ATTRIBUTE]: null, |
| 122 | + [DataSourceField.ATTRIBUTE_NAME]: null, | |
| 121 | 123 | [DataSourceField.TRANSPORT_TYPE]: null, |
| 122 | 124 | }); |
| 123 | 125 | }, |
| ... | ... | @@ -152,6 +154,7 @@ export const commonDataSourceSchemas = (): FormSchema[] => { |
| 152 | 154 | setFieldsValue({ |
| 153 | 155 | [DataSourceField.DEVICE_ID]: null, |
| 154 | 156 | [DataSourceField.ATTRIBUTE]: null, |
| 157 | + [DataSourceField.ATTRIBUTE_NAME]: null, | |
| 155 | 158 | [DataSourceField.TRANSPORT_TYPE]: option[DataSourceField.TRANSPORT_TYPE], |
| 156 | 159 | }); |
| 157 | 160 | }, |
| ... | ... | @@ -228,6 +231,12 @@ export const commonDataSourceSchemas = (): FormSchema[] => { |
| 228 | 231 | }, |
| 229 | 232 | }, |
| 230 | 233 | { |
| 234 | + field: DataSourceField.ATTRIBUTE_NAME, | |
| 235 | + component: 'Input', | |
| 236 | + label: '属性名', | |
| 237 | + show: false, | |
| 238 | + }, | |
| 239 | + { | |
| 231 | 240 | field: DataSourceField.ATTRIBUTE, |
| 232 | 241 | component: 'ApiSelect', |
| 233 | 242 | label: '属性', |
| ... | ... | @@ -235,7 +244,8 @@ export const commonDataSourceSchemas = (): FormSchema[] => { |
| 235 | 244 | rules: [{ required: true, message: '请选择属性' }], |
| 236 | 245 | ifShow: ({ model }) => |
| 237 | 246 | !(isTcpProfile(model[DataSourceField.TRANSPORT_TYPE]) && isControlComponent(category!)), |
| 238 | - componentProps({ formModel }) { | |
| 247 | + componentProps({ formModel, formActionType }) { | |
| 248 | + const { setFieldsValue } = formActionType; | |
| 239 | 249 | const deviceProfileId = formModel[DataSourceField.DEVICE_PROFILE_ID]; |
| 240 | 250 | return { |
| 241 | 251 | api: async () => { |
| ... | ... | @@ -256,6 +266,9 @@ export const commonDataSourceSchemas = (): FormSchema[] => { |
| 256 | 266 | }, |
| 257 | 267 | placeholder: '请选择属性', |
| 258 | 268 | getPopupContainer: () => document.body, |
| 269 | + onChange(value: string, option: Record<'label' | 'value', string>) { | |
| 270 | + setFieldsValue({ [DataSourceField.ATTRIBUTE_NAME]: value ? option.label : null }); | |
| 271 | + }, | |
| 259 | 272 | }; |
| 260 | 273 | }, |
| 261 | 274 | }, | ... | ... |
src/views/visual/packages/utils/index.ts
0 → 100644
| 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 | +}; | ... | ... |