cnhis-design-vue 0.1.32 → 0.1.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,6 @@
1
1
  <template>
2
2
  <div class="text-group">
3
+ <MouseRightClick v-if="isRightVisible" :getContainer="getContainer" :nodeList="rightClickNode" :rightPos="rightPos" @nodeClick="handleRightClick" @closeRight="isRightVisible = false" />
3
4
  <DropPopup v-if="isDropVisible" :val="dropVal" :dropPos="dropPos" />
4
5
  </div>
5
6
  </template>
@@ -9,42 +10,52 @@ import fabricCommon from '../mixins/fabricCommon';
9
10
  import draw from '../mixins/draw';
10
11
  import defaultVaule from '../const/defaultVaule';
11
12
  import DropPopup from '../components/DropPopup';
13
+ import MouseRightClick from '../components/MouseRightClick';
14
+ import polylineCommon from '../mixins/polylineCommon';
12
15
 
16
+ const rightClickNode = [
17
+ { name: '修改', type: 'edit' },
18
+ { name: '删除', type: 'delete' }
19
+ ];
13
20
  export default {
14
21
  name: 'fabric-text-group',
15
22
  components: {
16
- DropPopup
23
+ DropPopup,
24
+ MouseRightClick
17
25
  },
18
- mixins: [fabricCommon, draw],
26
+ mixins: [fabricCommon, draw, polylineCommon],
19
27
  props: {
20
28
  templateData: {
21
29
  type: Object,
22
30
  required: true
23
31
  },
24
- // bottom: {
25
- // type: Object,
26
- // default: () => {}
27
- // }
32
+ other: {
33
+ type: Object,
34
+ default: () => {}
35
+ }
36
+ },
37
+ watch: {
38
+ other: {
39
+ handler(value) {
40
+ if (value) {
41
+ this.removeOther();
42
+ this.drawTextDataGroup(value);
43
+ this.canvas.renderAll();
44
+ }
45
+ },
46
+ deep: true
47
+ }
28
48
  },
29
- // watch: {
30
- // bottom: {
31
- // handler(value) {
32
- // if (value) {
33
- // if (value) {
34
- // this.removeMark();
35
- // this.drawBottomTextDataGroup(value);
36
- // }
37
- // }
38
- // },
39
- // deep: true
40
- // }
41
- // },
42
49
  data() {
43
50
  return {
44
51
  leftStartX: 0,
45
52
  isDropVisible: false,
46
53
  dropVal: {},
47
- dropPos: { clientX: 0, clientY: 0 }
54
+ dropPos: { clientX: 0, clientY: 0 },
55
+ isRightVisible: false,
56
+ rightPos: { clientX: 0, clientY: 0 },
57
+ rightClickNode: [],
58
+ activeEvent: null, // 当前可右键活动的对象
48
59
  };
49
60
  },
50
61
  mounted() {
@@ -69,13 +80,64 @@ export default {
69
80
  // 左侧边框线
70
81
  this.canvas.add(this.drawLine([0, 0, 0, this.propItems.canvasHeight], { ...this.girdLineStyle }));
71
82
 
72
- this.topTreeTextGroup(this.propItems.treeList);
73
- this.drawLeftScaleGroup(this.templateData);
74
- this.drawTextDataGroup(this.templateData.other);
75
- this.drawBottomTextDataGroup(this.templateData.bottom);
76
-
83
+ this.propItems.treeList.length > 0 && this.topTreeTextGroup(this.propItems.treeList);
84
+ this.templateData.left && this.drawLeftScaleGroup(this.templateData.left);
85
+ this.templateData.other && this.drawTextDataGroup(this.templateData.other);
86
+ this.templateData.bottom && this.drawBottomTextDataGroup(this.templateData.bottom);
87
+ this.createEvent();
77
88
  this.canvas.renderAll();
78
89
  },
90
+ createEvent() {
91
+ this.canvas.on('mouse:up', event => {
92
+ if (event.button === 3) {
93
+ const { x, y } = event.pointer;
94
+ const { originX, originY, endX, endY } = this.$propItems();
95
+ if (!(x < originX || x > endX || y < originY || y > endY)) {
96
+ this.activeEvent = event;
97
+ document.querySelector('.upper-canvas').addEventListener('contextmenu', this.addEventListenerContextmenu, true);
98
+ }
99
+ }
100
+ });
101
+ },
102
+ // 打开右键菜单
103
+ openRightModal(event) {
104
+ if (!this.propItems.eventStyle.evented) {
105
+ return;
106
+ }
107
+ this.rightPos = {
108
+ clientX: event.e.clientX || event.e.pageX,
109
+ clientY: event.e.clientY || event.e.pageY
110
+ };
111
+ this.isRightVisible = false;
112
+ const target = event.target;
113
+ const id = target ? target.id : '';
114
+ this.$nextTick(() => {
115
+ if (id && id.includes('_other')) {
116
+ this._currentPoint = target || '';
117
+ this.rightClickNode = Object.freeze(rightClickNode.slice());
118
+ this.isRightVisible = true;
119
+ }
120
+ });
121
+ },
122
+ // 关闭右键菜单,打开添加节点弹窗表单
123
+ handleRightClick({ type }) {
124
+ this.isRightVisible = false;
125
+ const text = this._currentPoint;
126
+ this._currentPoint = '';
127
+ const obj = {
128
+ type: text.type,
129
+ index: text.index,
130
+ dataIndex: text.dataIndex
131
+ }
132
+ this.$emit(`${type}Other`, obj);
133
+ },
134
+ removeOther() {
135
+ this.canvas.forEachObject(obj => {
136
+ if (obj.id && obj.id.includes('_other')) {
137
+ this.canvas.remove(obj);
138
+ }
139
+ });
140
+ },
79
141
  topTreeTextGroup(list) {
80
142
  list.forEach(item => {
81
143
  if (item.children && Array.isArray(item.children) && item.children.length > 0) {
@@ -106,21 +168,30 @@ export default {
106
168
  }
107
169
  },
108
170
  drawTextDataGroupColList(colList) {
171
+ const { originY, eventStyle } = this.propItems;
109
172
  let textList = [];
110
173
  colList.forEach((item, index) => {
111
- const baseTop = this.propItems.originY + (item.marginTop || 10);
174
+ const baseTop = originY + (item.marginTop || 10);
112
175
  if (this.isLimit(item.scalevalue)) {
113
176
  item.dataList.forEach((v, i) => {
114
177
  const top = baseTop + i * (item.lineHeight || 15);
115
- const text = new this.fabric.Text(String(v), {
178
+ const text = new this.fabric.Text(String(v.value), {
116
179
  ...defaultVaule.style,
117
180
  ...defaultVaule.textStyle,
118
181
  ...item.style,
119
182
  originX: 'left',
120
183
  originY: 'center',
121
184
  left: this.cumputedX(item.scalevalue),
122
- top
185
+ top,
186
+ lockMovementX: true,
187
+ lockMovementY: true,
188
+ dataIndex: index,
189
+ index: i,
190
+ type: 'colList',
191
+ id: `${index}_${i}_other_${Date.now()}`,
192
+ ...eventStyle
123
193
  });
194
+ text.hasControls = text.hasBorders = false;
124
195
  textList.push(text);
125
196
  });
126
197
  }
@@ -129,13 +200,13 @@ export default {
129
200
  },
130
201
  drawTextDataGroupList(list) {
131
202
  let textList = [];
132
- const { originX, originY } = this.propItems;
203
+ const { originX, originY, eventStyle } = this.propItems;
133
204
  let top = originY + 10;
134
- list.forEach((item, i) => {
205
+ list.forEach((item, index) => {
135
206
  const marginLeft = this.templateData.left.leftYScalevalue.spaceGridNumber || 3;
136
207
  const left = originX - marginLeft * 4; // 默认减去4倍的左边距,防止最左边的数据与名称显示重合了
137
208
 
138
- if (list[i - 1]) {
209
+ if (list[index - 1]) {
139
210
  top += item.lineHeight || 15;
140
211
  }
141
212
 
@@ -146,20 +217,29 @@ export default {
146
217
  originX: 'right',
147
218
  originY: 'center',
148
219
  left,
149
- top
220
+ top,
221
+ id: `${index}_other_${Date.now()}`,
150
222
  });
151
223
  textList.push(title);
152
- item.dataList.forEach(v => {
153
- if (this.isLimit(v[0])) {
154
- const text = new this.fabric.Text(String(v[1]), {
224
+ item.dataList.forEach((v, i) => {
225
+ if (this.isLimit(v.time)) {
226
+ const text = new this.fabric.Text(String(v.value), {
155
227
  ...defaultVaule.style,
156
228
  ...defaultVaule.textStyle,
157
229
  ...item.style,
158
230
  originX: 'center',
159
231
  originY: 'center',
160
- left: this.cumputedX(v[0]),
161
- top
232
+ left: this.cumputedX(v.time),
233
+ top,
234
+ lockMovementX: true,
235
+ lockMovementY: true,
236
+ dataIndex: index,
237
+ index: i,
238
+ type: 'list',
239
+ id: `${index}_${i}_other_${Date.now()}`,
240
+ ...eventStyle
162
241
  });
242
+ text.hasControls = text.hasBorders = false;
163
243
  textList.push(text);
164
244
  }
165
245
  });
@@ -187,7 +267,7 @@ export default {
187
267
  return;
188
268
  }
189
269
  const { originX, endY, canvasHeight, eventStyle } = this.propItems;
190
- let textList = [];
270
+ const textList = [];
191
271
  const marginLeft = this.templateData.left.leftYScalevalue.spaceGridNumber || 3;
192
272
  const left = originX - marginLeft * 4; // 默认减去4倍的左边距,防止最左边的数据与名称显示重合了
193
273
  const title = new this.fabric.Text(String(obj.title), {
@@ -195,38 +275,48 @@ export default {
195
275
  ...defaultVaule.textStyle,
196
276
  ...obj.style,
197
277
  originX: 'right',
198
- originY: 'bottom',
278
+ originY: 'center',
199
279
  left,
200
- top: canvasHeight - 20,
280
+ top: endY + (canvasHeight - endY) / 2,
201
281
  type: 'mark'
202
282
  });
203
283
  textList.push(title);
204
- const baseY = endY + 10; // 目前固定10像素的下边距
205
- const baseYLimit = endY - 10; // 目前固定10像素的上边距
284
+ const baseY = endY + 2; // 目前固定10像素的下边距
285
+ const baseYLimit = endY - 2; // 目前固定10像素的上边距
286
+ const lineHeight = (obj.iconStyle?.height && obj.iconStyle.height + 2) || 14; // 标志点的line-height值
206
287
  obj.list.forEach((item, index) => {
207
- let limitIndex = -1;
288
+ let limitIndex = -1; // 标志点是否往上排列的标志,大于-1则表示需要往上排列
289
+ let y = baseY;
208
290
  const x = this.cumputedX(item[0]);
209
291
  if (this.isLimit(item[0])) {
210
292
  item[1].forEach(async (v, i) => {
211
- let y = baseY + i * 14; // 目前固定14像素的line-height
212
- if (y + 7 > endY + obj.height) {
213
- limitIndex++;
214
- y = baseYLimit - limitIndex * 14;
293
+ if (!~limitIndex) {
294
+ y += i === 0 ? lineHeight / 2 : lineHeight;
295
+ if (y >= canvasHeight - lineHeight / 2) {
296
+ limitIndex++;
297
+ if (limitIndex === 0) {
298
+ y = baseYLimit;
299
+ y -= lineHeight / 2;
300
+ }
301
+ }
302
+ } else {
303
+ y -= lineHeight;
215
304
  }
305
+ const common = {
306
+ left: x,
307
+ top: y,
308
+ originX: 'center',
309
+ originY: 'center',
310
+ data: v.data || {},
311
+ other: v.other || {},
312
+ time: item[0],
313
+ name: v.name,
314
+ type: 'mark',
315
+ };
216
316
  if (this.isObject(v) && !v.value) {
217
317
  const option = Object.assign({}, obj.iconStyle || {}, v || {}, {
218
318
  ...defaultVaule.style,
219
- left: x,
220
- top: y,
221
- originX: 'center',
222
- // lockMovementY: true, // 锁定Y轴,即只能x轴方向移动
223
- data: v.data || {},
224
- other: v.other || {},
225
- time: item[0],
226
- name: v.name,
227
- // listIndex: index,
228
- // index: i,
229
- type: 'mark',
319
+ ...common,
230
320
  ...eventStyle
231
321
  });
232
322
  let ele;
@@ -245,17 +335,7 @@ export default {
245
335
  const text = new this.fabric.Text(String(v.value), {
246
336
  ...defaultVaule.textStyle,
247
337
  ...obj.style,
248
- originX: 'center',
249
- left: x,
250
- top: y,
251
- // lockMovementY: true, // 锁定Y轴,即只能x轴方向移动
252
- time: item[0],
253
- name: v.name,
254
- data: v.data || {},
255
- other: v.other || {},
256
- // listIndex: index,
257
- // index: i,
258
- type: 'mark',
338
+ ...common,
259
339
  ...eventStyle
260
340
  });
261
341
  text.hasControls = text.hasBorders = false;
@@ -286,8 +366,6 @@ export default {
286
366
  data: point.data,
287
367
  oldVal: point.time,
288
368
  newVal: this.getXValue(point.left),
289
- // listIndex: point.listIndex,
290
- // index: point.index
291
369
  };
292
370
  this.$emit('markChange', value);
293
371
  });
@@ -338,7 +416,6 @@ export default {
338
416
  if (point.top < originY) {
339
417
  point.set('top', originY);
340
418
  }
341
- point.setCoords();
342
419
  },
343
420
  showDrapPopup(point) {
344
421
  // 第二个参数表示需要展示提供的viewTime时间
@@ -354,13 +431,13 @@ export default {
354
431
  };
355
432
  },
356
433
 
357
- drawLeftScaleGroup(templateData) {
358
- this.drawLeftTitle(templateData);
359
- const { canvasHeight, originX, originY } = this.propItems;
434
+ drawLeftScaleGroup(dataLeft) {
435
+ this.drawLeftTitle(dataLeft);
436
+ const { canvasHeight, originX, originY, treeTableminCellWidth } = this.propItems;
360
437
  let rect = new this.fabric.Rect({
361
- left: templateData.top.treeTableminCellWidth,
438
+ left: treeTableminCellWidth,
362
439
  top: originY,
363
- width: originX - templateData.top.treeTableminCellWidth,
440
+ width: originX - treeTableminCellWidth,
364
441
  height: canvasHeight - originY,
365
442
  ...defaultVaule.rectStyle,
366
443
  ...defaultVaule.style,
@@ -370,12 +447,12 @@ export default {
370
447
  rect.sendToBack(); // 向下跳底层
371
448
  this.canvas.add(rect);
372
449
  },
373
- drawLeftTitle(templateData) {
374
- if (templateData.left.title) {
450
+ drawLeftTitle(dataLeft) {
451
+ if (dataLeft.title) {
375
452
  this.canvas.add(
376
453
  this.drawTextGroup(
377
- { width: templateData.top.treeTableminCellWidth, height: this.propItems.canvasHeight - this.propItems.originY },
378
- { text: String(templateData.left.title.split('').join('\n')), ...defaultVaule.textStyle, ...templateData.left.titleStyle },
454
+ { width: this.propItems.treeTableminCellWidth, height: this.propItems.canvasHeight - this.propItems.originY },
455
+ { text: String(dataLeft.title.split('').join('\n')), ...defaultVaule.textStyle, ...dataLeft.titleStyle },
379
456
  { left: 0, top: this.propItems.originY }
380
457
  )
381
458
  );
@@ -41,11 +41,10 @@ export default {
41
41
  } else if (left === originX) {
42
42
  time = xScaleList[0];
43
43
  } else {
44
- const index = xScaleCellList.findIndex(v => v.x >= left);
45
- if (index > -1) {
46
- const obj = xScaleCellList[index - 1];
47
- time = obj.time + (left - obj.x) * obj.xScaleTime;
48
- }
44
+ let index = xScaleCellList.findIndex(v => v.x >= left);
45
+ !~index && (index = xScaleCellList.length);
46
+ const obj = xScaleCellList[index - 1];
47
+ time = obj.time + (left - obj.x) * obj.xScaleTime;
49
48
  }
50
49
  let d = new Date(time);
51
50
  const month = `00${d.getMonth() + 1}`.slice(-2);
@@ -12,7 +12,7 @@ export default {
12
12
  methods: {
13
13
  // 折线点移动限制 目前仅限制不能移动出画布
14
14
  pointMoveLimit(point) {
15
- point.setCoords();
15
+ point.setCoords(); // 需调用setCoords()才能重新计算控制位置(改变Object状态)
16
16
  // const objBoundingBox = point.getBoundingRect(); // 此方式会导致结果不精准,应该用point的top值判断
17
17
  const leftLimit = point.prevPoint ? point.prevPoint.get('left') : this.propItems.originX;
18
18
  const rightLimit = point.nextPoint ? point.nextPoint.get('left') : this.propItems.endX;
@@ -28,7 +28,9 @@ export default {
28
28
  if (point.left > rightLimit) {
29
29
  point.set('left', rightLimit);
30
30
  }
31
- point.setCoords();
31
+ },
32
+ getContainer() {
33
+ return this.$el;
32
34
  },
33
35
  /**
34
36
  * 右键监听事件