Commit de4055bb30c87b0cadf1a83d3172135a99749753

Authored by ww
1 parent 02391826

fix: reset layout on create component && copy component

@@ -2,6 +2,7 @@ import { EChartsOption } from 'echarts'; @@ -2,6 +2,7 @@ import { EChartsOption } from 'echarts';
2 import { fontSize } from '../../detail/config/util'; 2 import { fontSize } from '../../detail/config/util';
3 import { Gradient, visualOptionField } from '../../detail/config/visualOptions'; 3 import { Gradient, visualOptionField } from '../../detail/config/visualOptions';
4 import { DataComponentRecord, DataSource, GradientInfo } from '/@/api/dataBoard/model'; 4 import { DataComponentRecord, DataSource, GradientInfo } from '/@/api/dataBoard/model';
  5 +import { isArray } from '/@/utils/is';
5 import { buildUUID } from '/@/utils/uuid'; 6 import { buildUUID } from '/@/utils/uuid';
6 7
7 export type InstrumentComponentType = 'instrument-component-1' | 'instrument-component-2'; 8 export type InstrumentComponentType = 'instrument-component-1' | 'instrument-component-2';
@@ -179,12 +180,9 @@ export const instrumentComponent2 = (params?: { @@ -179,12 +180,9 @@ export const instrumentComponent2 = (params?: {
179 lineStyle: { 180 lineStyle: {
180 width: 20, 181 width: 20,
181 color: [ 182 color: [
182 - [firstGradient, (getGradientValue(Gradient.FIRST, gradient) as string) || '#67e0e3'],  
183 - [  
184 - secondGradient,  
185 - (getGradientValue(Gradient.SECOND, gradient) as string) || '#37a2da',  
186 - ],  
187 - [1, (getGradientValue(Gradient.THIRD, gradient) as string) || '#fd666d'], 183 + [firstGradient, firstRecord?.color || '#67e0e3'],
  184 + [secondGradient, secondRecord?.color || '#37a2da'],
  185 + [1, thirdRecord?.color || '#fd666d'],
188 ], 186 ],
189 }, 187 },
190 }, 188 },
@@ -231,11 +229,8 @@ export const instrumentComponent2 = (params?: { @@ -231,11 +229,8 @@ export const instrumentComponent2 = (params?: {
231 }; 229 };
232 }; 230 };
233 231
234 -export const getGradientValue = (key: Gradient, record: GradientInfo[]) => {  
235 - return record.find((item) => item.key === key)?.color;  
236 -};  
237 -  
238 -export const getGradient = (key: Gradient, record: GradientInfo[]) => { 232 +export const getGradient = (key: Gradient, record: GradientInfo[] = []) => {
  233 + if (!isArray(record)) return;
239 return record.find((item) => item.key === key); 234 return record.find((item) => item.key === key);
240 }; 235 };
241 236
@@ -51,16 +51,11 @@ @@ -51,16 +51,11 @@
51 51
52 const handleAddComponent = async (value: Recordable) => { 52 const handleAddComponent = async (value: Recordable) => {
53 try { 53 try {
54 - const data = await addDataComponent({ 54 + await addDataComponent({
55 boardId: unref(boardId), 55 boardId: unref(boardId),
56 record: { dataBoardId: unref(boardId), frontId: unref(frontId), ...value }, 56 record: { dataBoardId: unref(boardId), frontId: unref(frontId), ...value },
57 }); 57 });
58 createMessage.success('创建成功'); 58 createMessage.success('创建成功');
59 - const id = data.data.id;  
60 - await updateDataBoardLayout({  
61 - boardId: unref(boardId),  
62 - layout: [{ id, w: DEFAULT_WIDGET_WIDTH, h: DEFAULT_WIDGET_HEIGHT, x: 0, y: 0 }],  
63 - });  
64 closeModal(); 59 closeModal();
65 emit('submit'); 60 emit('submit');
66 } catch (error) { 61 } catch (error) {
@@ -214,7 +214,7 @@ @@ -214,7 +214,7 @@
214 const handleCopy = async (id: string) => { 214 const handleCopy = async (id: string) => {
215 const record = unref(dataBoardList).find((item) => item.i === id); 215 const record = unref(dataBoardList).find((item) => item.i === id);
216 try { 216 try {
217 - const data = await addDataComponent({ 217 + await addDataComponent({
218 boardId: unref(getBoardId), 218 boardId: unref(getBoardId),
219 record: { 219 record: {
220 dataBoardId: unref(getBoardId), 220 dataBoardId: unref(getBoardId),
@@ -223,11 +223,6 @@ @@ -223,11 +223,6 @@
223 }, 223 },
224 }); 224 });
225 createMessage.success('复制成功'); 225 createMessage.success('复制成功');
226 - const id = data.data.id;  
227 - await updateDataBoardLayout({  
228 - boardId: unref(getBoardId),  
229 - layout: [{ id, w: DEFAULT_WIDGET_WIDTH, h: DEFAULT_WIDGET_HEIGHT, x: 0, y: 0 }],  
230 - });  
231 getDataBoardComponent(); 226 getDataBoardComponent();
232 } catch (error) {} 227 } catch (error) {}
233 }; 228 };