Commit 1ce3d0e6f5d78161e292c38acc51bfc6a9b27d53

Authored by ww
1 parent 09977928

fix: DEFECT-685 update component info component not recalculate

1 1 import {
2 2 AddDataBoardParams,
3 3 AddDataComponentParams,
  4 + ComponentInfoDetail,
4 5 DataBoardList,
5 6 DataComponentRecord,
6 7 GetDataBoardParams,
... ... @@ -103,12 +104,10 @@ export const updateDataBoardLayout = (params: UpdateDataBoardLayoutParams) => {
103 104 * @returns
104 105 */
105 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 113 export const addDataComponent = (params: AddDataComponentParams) => {
... ... @@ -151,7 +150,7 @@ export const updateDataComponent = (params: UpdateDataComponentParams) => {
151 150 */
152 151 export const getShareBoardComponentInfo = (params: { boardId: string; tenantId: string }) => {
153 152 const { boardId, tenantId } = params;
154   - return defHttp.get({
  153 + return defHttp.get<ComponentInfoDetail>({
155 154 url: `${DataBoardShareUrl.GET_DATA_COMPONENT}/${boardId}/${tenantId}`,
156 155 });
157 156 };
... ...
... ... @@ -136,3 +136,7 @@ export interface MasterDeviceList {
136 136 id: string;
137 137 name: string;
138 138 }
  139 +
  140 +export interface ComponentInfoDetail {
  141 + data: { componentData: DataComponentRecord[]; componentLayout: Layout[] };
  142 +}
... ...
... ... @@ -10,6 +10,7 @@
10 10 import { TextComponentDefaultConfig, TextComponentLayout, TextComponentValue } from './config';
11 11 import { SvgIcon } from '/@/components/Icon';
12 12 import { dateUtil } from '/@/utils/dateUtil';
  13 + import { min } from 'lodash';
13 14 const props = defineProps({
14 15 layout: {
15 16 type: Object as PropType<TextComponentLayout>,
... ... @@ -66,8 +67,8 @@
66 67 prefix="iconfont"
67 68 :style="{
68 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 74 </div>
... ...
... ... @@ -15,7 +15,7 @@
15 15 id: string;
16 16 }
17 17
18   - const emit = defineEmits(['submit', 'register']);
  18 + const emit = defineEmits(['submit', 'update', 'create', 'register']);
19 19
20 20 const ROUTE = useRoute();
21 21
... ... @@ -75,7 +75,7 @@
75 75 const handleUpdateComponent = async (value: Recordable) => {
76 76 try {
77 77 changeOkLoading(true);
78   - await updateDataComponent({
  78 + const res = await updateDataComponent({
79 79 boardId: unref(boardId),
80 80 record: {
81 81 id: unref(componentRecord).i,
... ... @@ -86,7 +86,8 @@
86 86 });
87 87 createMessage.success('修改成功');
88 88 closeModal();
89   - emit('submit');
  89 + // emit('submit');
  90 + emit('update', res.data.id);
90 91 } catch (error) {
91 92 // createMessage.error('修改失败');
92 93 } finally {
... ...
... ... @@ -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 53 let res = basic * radio;
44 54 if (max && res > max) res = max;
  55 + if (min && res < min) res = min;
45 56 return res + 'px';
46 57 };
... ...
... ... @@ -24,7 +24,12 @@
24 24 } from '/@/api/dataBoard';
25 25 import { useRoute, useRouter } from 'vue-router';
26 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 33 import { frontComponentMap } from './config/help';
29 34 import { calcScale } from './config/util';
30 35 import { useMessage } from '/@/hooks/web/useMessage';
... ... @@ -98,6 +103,9 @@
98 103 width = 100;
99 104 }
100 105
  106 + data.width = newWPx;
  107 + data.height = newHPx;
  108 +
101 109 data.record.dataSource = data?.record.dataSource.map((item) => {
102 110 if (!item.uuid) item.uuid = buildUUID();
103 111 return {
... ... @@ -194,7 +202,7 @@
194 202 try {
195 203 return await getDataComponent(unref(getBoardId));
196 204 } catch (error) {}
197   - return [];
  205 + return {} as ComponentInfoDetail;
198 206 };
199 207
200 208 const getSharePageComponentData = async () => {
... ... @@ -202,7 +210,7 @@
202 210 const params = unref(getSharePageParams);
203 211 return await getShareBoardComponentInfo(params);
204 212 } catch (error) {}
205   - return [];
  213 + return {} as ComponentInfoDetail;
206 214 };
207 215
208 216 const getDataBoradDetail = async () => {
... ... @@ -211,7 +219,7 @@
211 219 ? await getSharePageComponentData()
212 220 : await getBasePageComponentData();
213 221 } catch (error) {}
214   - return [];
  222 + return {} as ComponentInfoDetail;
215 223 };
216 224
217 225 const loading = ref(false);
... ... @@ -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 285 const getComponent = (record: DataComponentRecord) => {
249 286 const frontComponent = record.frontId;
250 287 const component = frontComponentMap.get(frontComponent as WidgetComponentType);
... ... @@ -392,7 +429,11 @@
392 429 <Empty v-if="!dataBoardList.length" />
393 430 </Spin>
394 431 </section>
395   - <DataBindModal @register="register" @submit="getDataBoardComponent" />
  432 + <DataBindModal
  433 + @register="register"
  434 + @update="handleUpdateComponent"
  435 + @submit="getDataBoardComponent"
  436 + />
396 437 <HistoryTrendModal @register="registerHistoryDataModal" />
397 438 </section>
398 439 </template>
... ...
... ... @@ -5,4 +5,6 @@ export type FrontDataSourceRecord = DataSource;
5 5
6 6 export type DataBoardLayoutInfo = Layout & {
7 7 record: DataComponentRecord;
  8 + width?: number;
  9 + height?: number;
8 10 };
... ...