Commit 1ce3d0e6f5d78161e292c38acc51bfc6a9b27d53
1 parent
09977928
fix: DEFECT-685 update component info component not recalculate
Showing
7 changed files
with
77 additions
and
18 deletions
1 | import { | 1 | import { |
2 | AddDataBoardParams, | 2 | AddDataBoardParams, |
3 | AddDataComponentParams, | 3 | AddDataComponentParams, |
4 | + ComponentInfoDetail, | ||
4 | DataBoardList, | 5 | DataBoardList, |
5 | DataComponentRecord, | 6 | DataComponentRecord, |
6 | GetDataBoardParams, | 7 | GetDataBoardParams, |
@@ -103,12 +104,10 @@ export const updateDataBoardLayout = (params: UpdateDataBoardLayoutParams) => { | @@ -103,12 +104,10 @@ export const updateDataBoardLayout = (params: UpdateDataBoardLayoutParams) => { | ||
103 | * @returns | 104 | * @returns |
104 | */ | 105 | */ |
105 | export const getDataComponent = (params: string) => { | 106 | export const getDataComponent = (params: string) => { |
106 | - return defHttp.get<{ data: { componentData: DataComponentRecord[]; componentLayout: Layout[] } }>( | ||
107 | - { | ||
108 | - url: `${DataComponentUrl.GET_DATA_COMPONENT}/${params}`, | ||
109 | - // params: { boardId: params }, | ||
110 | - } | ||
111 | - ); | 107 | + return defHttp.get<ComponentInfoDetail>({ |
108 | + url: `${DataComponentUrl.GET_DATA_COMPONENT}/${params}`, | ||
109 | + // params: { boardId: params }, | ||
110 | + }); | ||
112 | }; | 111 | }; |
113 | 112 | ||
114 | export const addDataComponent = (params: AddDataComponentParams) => { | 113 | export const addDataComponent = (params: AddDataComponentParams) => { |
@@ -151,7 +150,7 @@ export const updateDataComponent = (params: UpdateDataComponentParams) => { | @@ -151,7 +150,7 @@ export const updateDataComponent = (params: UpdateDataComponentParams) => { | ||
151 | */ | 150 | */ |
152 | export const getShareBoardComponentInfo = (params: { boardId: string; tenantId: string }) => { | 151 | export const getShareBoardComponentInfo = (params: { boardId: string; tenantId: string }) => { |
153 | const { boardId, tenantId } = params; | 152 | const { boardId, tenantId } = params; |
154 | - return defHttp.get({ | 153 | + return defHttp.get<ComponentInfoDetail>({ |
155 | url: `${DataBoardShareUrl.GET_DATA_COMPONENT}/${boardId}/${tenantId}`, | 154 | url: `${DataBoardShareUrl.GET_DATA_COMPONENT}/${boardId}/${tenantId}`, |
156 | }); | 155 | }); |
157 | }; | 156 | }; |
@@ -136,3 +136,7 @@ export interface MasterDeviceList { | @@ -136,3 +136,7 @@ export interface MasterDeviceList { | ||
136 | id: string; | 136 | id: string; |
137 | name: string; | 137 | name: string; |
138 | } | 138 | } |
139 | + | ||
140 | +export interface ComponentInfoDetail { | ||
141 | + data: { componentData: DataComponentRecord[]; componentLayout: Layout[] }; | ||
142 | +} |
@@ -10,6 +10,7 @@ | @@ -10,6 +10,7 @@ | ||
10 | import { TextComponentDefaultConfig, TextComponentLayout, TextComponentValue } from './config'; | 10 | import { TextComponentDefaultConfig, TextComponentLayout, TextComponentValue } from './config'; |
11 | import { SvgIcon } from '/@/components/Icon'; | 11 | import { SvgIcon } from '/@/components/Icon'; |
12 | import { dateUtil } from '/@/utils/dateUtil'; | 12 | import { dateUtil } from '/@/utils/dateUtil'; |
13 | + import { min } from 'lodash'; | ||
13 | const props = defineProps({ | 14 | const props = defineProps({ |
14 | layout: { | 15 | layout: { |
15 | type: Object as PropType<TextComponentLayout>, | 16 | type: Object as PropType<TextComponentLayout>, |
@@ -66,8 +67,8 @@ | @@ -66,8 +67,8 @@ | ||
66 | prefix="iconfont" | 67 | prefix="iconfont" |
67 | :style="{ | 68 | :style="{ |
68 | color: props.value.iconColor, | 69 | color: props.value.iconColor, |
69 | - width: fontSize({ radio: getRadio, basic: 50 }), | ||
70 | - height: fontSize({ radio: getRadio, basic: 50 }), | 70 | + width: fontSize({ radio: getRadio, basic: 50, min: 16 }), |
71 | + height: fontSize({ radio: getRadio, basic: 50, min: 16 }), | ||
71 | }" | 72 | }" |
72 | /> | 73 | /> |
73 | </div> | 74 | </div> |
@@ -15,7 +15,7 @@ | @@ -15,7 +15,7 @@ | ||
15 | id: string; | 15 | id: string; |
16 | } | 16 | } |
17 | 17 | ||
18 | - const emit = defineEmits(['submit', 'register']); | 18 | + const emit = defineEmits(['submit', 'update', 'create', 'register']); |
19 | 19 | ||
20 | const ROUTE = useRoute(); | 20 | const ROUTE = useRoute(); |
21 | 21 | ||
@@ -75,7 +75,7 @@ | @@ -75,7 +75,7 @@ | ||
75 | const handleUpdateComponent = async (value: Recordable) => { | 75 | const handleUpdateComponent = async (value: Recordable) => { |
76 | try { | 76 | try { |
77 | changeOkLoading(true); | 77 | changeOkLoading(true); |
78 | - await updateDataComponent({ | 78 | + const res = await updateDataComponent({ |
79 | boardId: unref(boardId), | 79 | boardId: unref(boardId), |
80 | record: { | 80 | record: { |
81 | id: unref(componentRecord).i, | 81 | id: unref(componentRecord).i, |
@@ -86,7 +86,8 @@ | @@ -86,7 +86,8 @@ | ||
86 | }); | 86 | }); |
87 | createMessage.success('修改成功'); | 87 | createMessage.success('修改成功'); |
88 | closeModal(); | 88 | closeModal(); |
89 | - emit('submit'); | 89 | + // emit('submit'); |
90 | + emit('update', res.data.id); | ||
90 | } catch (error) { | 91 | } catch (error) { |
91 | // createMessage.error('修改失败'); | 92 | // createMessage.error('修改失败'); |
92 | } finally { | 93 | } finally { |
@@ -39,8 +39,19 @@ export const calcScale = ( | @@ -39,8 +39,19 @@ export const calcScale = ( | ||
39 | }; | 39 | }; |
40 | }; | 40 | }; |
41 | 41 | ||
42 | -export const fontSize = ({ radio, basic, max }: { radio: number; basic: number; max?: number }) => { | 42 | +export const fontSize = ({ |
43 | + radio, | ||
44 | + basic, | ||
45 | + max, | ||
46 | + min, | ||
47 | +}: { | ||
48 | + radio: number; | ||
49 | + basic: number; | ||
50 | + max?: number; | ||
51 | + min?: number; | ||
52 | +}) => { | ||
43 | let res = basic * radio; | 53 | let res = basic * radio; |
44 | if (max && res > max) res = max; | 54 | if (max && res > max) res = max; |
55 | + if (min && res < min) res = min; | ||
45 | return res + 'px'; | 56 | return res + 'px'; |
46 | }; | 57 | }; |
@@ -24,7 +24,12 @@ | @@ -24,7 +24,12 @@ | ||
24 | } from '/@/api/dataBoard'; | 24 | } from '/@/api/dataBoard'; |
25 | import { useRoute, useRouter } from 'vue-router'; | 25 | import { useRoute, useRouter } from 'vue-router'; |
26 | import { computed, unref } from '@vue/reactivity'; | 26 | import { computed, unref } from '@vue/reactivity'; |
27 | - import { DataComponentRecord, DataSource, Layout } from '/@/api/dataBoard/model'; | 27 | + import { |
28 | + ComponentInfoDetail, | ||
29 | + DataComponentRecord, | ||
30 | + DataSource, | ||
31 | + Layout, | ||
32 | + } from '/@/api/dataBoard/model'; | ||
28 | import { frontComponentMap } from './config/help'; | 33 | import { frontComponentMap } from './config/help'; |
29 | import { calcScale } from './config/util'; | 34 | import { calcScale } from './config/util'; |
30 | import { useMessage } from '/@/hooks/web/useMessage'; | 35 | import { useMessage } from '/@/hooks/web/useMessage'; |
@@ -98,6 +103,9 @@ | @@ -98,6 +103,9 @@ | ||
98 | width = 100; | 103 | width = 100; |
99 | } | 104 | } |
100 | 105 | ||
106 | + data.width = newWPx; | ||
107 | + data.height = newHPx; | ||
108 | + | ||
101 | data.record.dataSource = data?.record.dataSource.map((item) => { | 109 | data.record.dataSource = data?.record.dataSource.map((item) => { |
102 | if (!item.uuid) item.uuid = buildUUID(); | 110 | if (!item.uuid) item.uuid = buildUUID(); |
103 | return { | 111 | return { |
@@ -194,7 +202,7 @@ | @@ -194,7 +202,7 @@ | ||
194 | try { | 202 | try { |
195 | return await getDataComponent(unref(getBoardId)); | 203 | return await getDataComponent(unref(getBoardId)); |
196 | } catch (error) {} | 204 | } catch (error) {} |
197 | - return []; | 205 | + return {} as ComponentInfoDetail; |
198 | }; | 206 | }; |
199 | 207 | ||
200 | const getSharePageComponentData = async () => { | 208 | const getSharePageComponentData = async () => { |
@@ -202,7 +210,7 @@ | @@ -202,7 +210,7 @@ | ||
202 | const params = unref(getSharePageParams); | 210 | const params = unref(getSharePageParams); |
203 | return await getShareBoardComponentInfo(params); | 211 | return await getShareBoardComponentInfo(params); |
204 | } catch (error) {} | 212 | } catch (error) {} |
205 | - return []; | 213 | + return {} as ComponentInfoDetail; |
206 | }; | 214 | }; |
207 | 215 | ||
208 | const getDataBoradDetail = async () => { | 216 | const getDataBoradDetail = async () => { |
@@ -211,7 +219,7 @@ | @@ -211,7 +219,7 @@ | ||
211 | ? await getSharePageComponentData() | 219 | ? await getSharePageComponentData() |
212 | : await getBasePageComponentData(); | 220 | : await getBasePageComponentData(); |
213 | } catch (error) {} | 221 | } catch (error) {} |
214 | - return []; | 222 | + return {} as ComponentInfoDetail; |
215 | }; | 223 | }; |
216 | 224 | ||
217 | const loading = ref(false); | 225 | const loading = ref(false); |
@@ -245,6 +253,35 @@ | @@ -245,6 +253,35 @@ | ||
245 | } | 253 | } |
246 | }; | 254 | }; |
247 | 255 | ||
256 | + const handleUpdateComponent = async (id: string) => { | ||
257 | + try { | ||
258 | + loading.value = true; | ||
259 | + const data = await getDataBoradDetail(); | ||
260 | + const updateIndex = data.data.componentData.findIndex((item) => item.id === id); | ||
261 | + const originalIndex = unref(dataBoardList).findIndex((item) => item.i === id); | ||
262 | + | ||
263 | + const newUpdateData = data.data.componentData[updateIndex]; | ||
264 | + const originalData = unref(dataBoardList)[originalIndex]; | ||
265 | + dataBoardList.value[updateIndex] = { | ||
266 | + i: id, | ||
267 | + w: originalData.w || DEFAULT_WIDGET_WIDTH, | ||
268 | + h: originalData.h || DEFAULT_WIDGET_HEIGHT, | ||
269 | + x: originalData.x || 0, | ||
270 | + y: originalData.y || 0, | ||
271 | + width: originalData.width, | ||
272 | + height: originalData.height, | ||
273 | + record: newUpdateData, | ||
274 | + }; | ||
275 | + console.log(dataBoardList.value[updateIndex]); | ||
276 | + updateSize(id, 0, 0, originalData.height || 0, originalData.width || 0); | ||
277 | + | ||
278 | + // beginSendMessage(); | ||
279 | + } catch (error) { | ||
280 | + } finally { | ||
281 | + loading.value = false; | ||
282 | + } | ||
283 | + }; | ||
284 | + | ||
248 | const getComponent = (record: DataComponentRecord) => { | 285 | const getComponent = (record: DataComponentRecord) => { |
249 | const frontComponent = record.frontId; | 286 | const frontComponent = record.frontId; |
250 | const component = frontComponentMap.get(frontComponent as WidgetComponentType); | 287 | const component = frontComponentMap.get(frontComponent as WidgetComponentType); |
@@ -392,7 +429,11 @@ | @@ -392,7 +429,11 @@ | ||
392 | <Empty v-if="!dataBoardList.length" /> | 429 | <Empty v-if="!dataBoardList.length" /> |
393 | </Spin> | 430 | </Spin> |
394 | </section> | 431 | </section> |
395 | - <DataBindModal @register="register" @submit="getDataBoardComponent" /> | 432 | + <DataBindModal |
433 | + @register="register" | ||
434 | + @update="handleUpdateComponent" | ||
435 | + @submit="getDataBoardComponent" | ||
436 | + /> | ||
396 | <HistoryTrendModal @register="registerHistoryDataModal" /> | 437 | <HistoryTrendModal @register="registerHistoryDataModal" /> |
397 | </section> | 438 | </section> |
398 | </template> | 439 | </template> |
@@ -5,4 +5,6 @@ export type FrontDataSourceRecord = DataSource; | @@ -5,4 +5,6 @@ export type FrontDataSourceRecord = DataSource; | ||
5 | 5 | ||
6 | export type DataBoardLayoutInfo = Layout & { | 6 | export type DataBoardLayoutInfo = Layout & { |
7 | record: DataComponentRecord; | 7 | record: DataComponentRecord; |
8 | + width?: number; | ||
9 | + height?: number; | ||
8 | }; | 10 | }; |