Commit 0de36dc037cfaadbb69d5c9ca6356a2091d2a29e
Merge branch 'dev-fix-ww' into 'main_dev'
fix(动态请求/公共接口): DEFECT-1269修复动态请求切换公共接口为清空表单 See merge request yunteng/thingskit-view!54
Showing
2 changed files
with
15 additions
and
9 deletions
src/views/chart/ContentConfigurations/components/ChartData/external/components/DynamicForm/index.vue
... | ... | @@ -4,7 +4,7 @@ import { FormItemInst, NDatePicker, NForm, NFormItem, NInput, NSelect, NTreeSele |
4 | 4 | import { computed, nextTick, ref, unref, watch } from 'vue'; |
5 | 5 | import { ComponentType, useDynamicPublicForm } from './useDynamicPublicForm'; |
6 | 6 | import { Help } from '@vicons/ionicons5' |
7 | -import { SelectTimeAggregation } from '../SelectTImeAggregation'; | |
7 | +import { SelectTimeAggregation } from '../SelectTImeAggregation'; | |
8 | 8 | |
9 | 9 | const props = defineProps<{ |
10 | 10 | paramsItemList: ParamsItemType[] |
... | ... | @@ -41,12 +41,16 @@ const setConfigurationData = async (params: Recordable) => { |
41 | 41 | setDynamicFormValue(params) |
42 | 42 | } |
43 | 43 | |
44 | +const recreate = ref(false) | |
45 | + | |
44 | 46 | watch( |
45 | 47 | () => props.paramsItemList, |
46 | 48 | (newValue) => { |
47 | 49 | if (newValue) { |
50 | + recreate.value = true | |
48 | 51 | clearParams() |
49 | 52 | createForm() |
53 | + recreate.value = false | |
50 | 54 | } |
51 | 55 | } |
52 | 56 | ) |
... | ... | @@ -61,8 +65,8 @@ defineExpose({ |
61 | 65 | |
62 | 66 | <template> |
63 | 67 | <NForm> |
64 | - <template v-for="item in getDynamicFormSchemas" :key="item.key"> | |
65 | - <NFormItem ref="dynamicFormItemEl" :required="item.required" :rule="item.rules"> | |
68 | + <template v-for="item in getDynamicFormSchemas" :key="item.uuid"> | |
69 | + <NFormItem v-if="!recreate" ref="dynamicFormItemEl" :required="item.required" :rule="item.rules"> | |
66 | 70 | <template #label> |
67 | 71 | <div class="label-container"> |
68 | 72 | <span>{{ item.name }}</span> | ... | ... |
... | ... | @@ -31,6 +31,7 @@ export enum ComponentType { |
31 | 31 | |
32 | 32 | |
33 | 33 | export interface DynamicFormSchema { |
34 | + uuid?: string | |
34 | 35 | key: string |
35 | 36 | name?: string |
36 | 37 | component: ComponentType, |
... | ... | @@ -336,6 +337,7 @@ export const useDynamicPublicForm = (paramsItemList: Ref<ParamsItemType[]>) => { |
336 | 337 | }] as FormItemRule |
337 | 338 | } |
338 | 339 | |
340 | + const uuid = () => Number(Math.random().toString().substring(2)).toString(32) | |
339 | 341 | const toFormSchemas = (builtInVariableKey: string, required: boolean, value: any, mores: boolean) => { |
340 | 342 | const groupList = (builtInVariableKey || '').split(GROUP_SEPARATOR) |
341 | 343 | return groupList.reduce((prev, next) => { |
... | ... | @@ -351,6 +353,7 @@ export const useDynamicPublicForm = (paramsItemList: Ref<ParamsItemType[]>) => { |
351 | 353 | |
352 | 354 | schema = { |
353 | 355 | ...result, |
356 | + // uuid: uuid(), | |
354 | 357 | props, |
355 | 358 | name, |
356 | 359 | required, |
... | ... | @@ -358,6 +361,7 @@ export const useDynamicPublicForm = (paramsItemList: Ref<ParamsItemType[]>) => { |
358 | 361 | } as DynamicFormSchema |
359 | 362 | } else { |
360 | 363 | schema = { |
364 | + // uuid: uuid(), | |
361 | 365 | key: value, |
362 | 366 | name: value, |
363 | 367 | component: ComponentType.INPUT, |
... | ... | @@ -377,22 +381,19 @@ export const useDynamicPublicForm = (paramsItemList: Ref<ParamsItemType[]>) => { |
377 | 381 | const schemas = toFormSchemas(key, required, value, mores) |
378 | 382 | return [...prev, ...schemas] |
379 | 383 | }, [] as DynamicFormSchema[]) |
380 | - console.log(result) | |
381 | 384 | return result |
382 | 385 | }) |
383 | 386 | |
384 | 387 | const createForm = async () => { |
385 | - console.log('enter') | |
386 | 388 | await getBuiltInVariable() |
387 | 389 | await getOrgOption() |
388 | 390 | getDeviceProfileOption() |
389 | 391 | getDeviceOption() |
390 | - clearParams() | |
391 | 392 | } |
392 | 393 | |
393 | 394 | const setParams = (Params: Recordable = {}) => { |
394 | 395 | for (const { key, value, mores } of unref(getParams)) { |
395 | - const splitKeys = value ? value.split(GROUP_SEPARATOR) : key.split(GROUP_SEPARATOR) | |
396 | + const splitKeys = value ? value.split(GROUP_SEPARATOR) : (key || '').split(GROUP_SEPARATOR) | |
396 | 397 | if (isDateComponent(key as BuiltInVariable)) { |
397 | 398 | if (key as BuiltInVariable === BuiltInVariable.DATE_FIXED) { |
398 | 399 | params[key] = Params[splitKeys[0]] || null |
... | ... | @@ -417,9 +418,10 @@ export const useDynamicPublicForm = (paramsItemList: Ref<ParamsItemType[]>) => { |
417 | 418 | |
418 | 419 | const clearParams = () => { |
419 | 420 | Object.keys(params).forEach(key => { |
420 | - // Reflect.deleteProperty(params, key) | |
421 | - params[key] = null | |
421 | + Reflect.deleteProperty(params, key) | |
422 | + // params[key] = null | |
422 | 423 | }) |
424 | + // params[BuiltInVariable.SELECT_TIME_AGGREGATION] = { startTs: null, endTs: null, limit: null, interval: null } | |
423 | 425 | params[BuiltInVariable.SELECT_TIME_AGGREGATION] = {} |
424 | 426 | } |
425 | 427 | ... | ... |