lambo-design-bi 0.0.229 → 0.0.230
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.
- package/bi/widget/table/paging-table.vue +238 -1
- package/package.json +1 -1
|
@@ -241,6 +241,238 @@ export default {
|
|
|
241
241
|
}
|
|
242
242
|
return children
|
|
243
243
|
},
|
|
244
|
+
isTrendChartsColumn(column) {
|
|
245
|
+
const isTrendCharts = column && (column.isTrendCharts === true || column.isTrendCharts === '1')
|
|
246
|
+
if (isTrendCharts) {
|
|
247
|
+
console.log("BiPagingTable -- isTrendChartsColumn -- 命中趋势图列:", column)
|
|
248
|
+
}
|
|
249
|
+
return isTrendCharts
|
|
250
|
+
},
|
|
251
|
+
stringifyTrendChartsValue(value) {
|
|
252
|
+
if (value === null || value === undefined) {
|
|
253
|
+
return ''
|
|
254
|
+
}
|
|
255
|
+
if (typeof value === 'object') {
|
|
256
|
+
try {
|
|
257
|
+
return JSON.stringify(value)
|
|
258
|
+
} catch (e) {
|
|
259
|
+
return String(value)
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return String(value)
|
|
263
|
+
},
|
|
264
|
+
parseTrendChartsValue(value) {
|
|
265
|
+
if (Array.isArray(value)) {
|
|
266
|
+
return value
|
|
267
|
+
}
|
|
268
|
+
if (typeof value === 'string') {
|
|
269
|
+
const trimValue = value.trim()
|
|
270
|
+
if (trimValue.indexOf('[') === 0 && trimValue.lastIndexOf(']') === trimValue.length - 1) {
|
|
271
|
+
try {
|
|
272
|
+
const parseValue = JSON.parse(trimValue)
|
|
273
|
+
if (Array.isArray(parseValue)) {
|
|
274
|
+
console.log("BiPagingTable -- parseTrendChartsValue -- 字符串数组解析成功:", {
|
|
275
|
+
value,
|
|
276
|
+
parseValue
|
|
277
|
+
})
|
|
278
|
+
return parseValue
|
|
279
|
+
}
|
|
280
|
+
} catch (e) {
|
|
281
|
+
console.log("BiPagingTable -- parseTrendChartsValue -- 字符串数组解析失败:", {
|
|
282
|
+
value,
|
|
283
|
+
error: e
|
|
284
|
+
})
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
return value
|
|
289
|
+
},
|
|
290
|
+
renderTrendChartsCell(h, params) {
|
|
291
|
+
const key = params.column.key
|
|
292
|
+
const value = params.row[key]
|
|
293
|
+
const chartValue = this.parseTrendChartsValue(value)
|
|
294
|
+
console.log("BiPagingTable -- renderTrendChartsCell -- 渲染趋势图单元格:", {
|
|
295
|
+
key,
|
|
296
|
+
title: params.column.title,
|
|
297
|
+
rowIndex: params.index,
|
|
298
|
+
value,
|
|
299
|
+
chartValue,
|
|
300
|
+
isArray: Array.isArray(chartValue)
|
|
301
|
+
})
|
|
302
|
+
if (!Array.isArray(chartValue)) {
|
|
303
|
+
console.log("BiPagingTable -- renderTrendChartsCell -- 当前值不是数组,按字符串展示:", {
|
|
304
|
+
key,
|
|
305
|
+
value,
|
|
306
|
+
stringValue: this.stringifyTrendChartsValue(value)
|
|
307
|
+
})
|
|
308
|
+
return h('span', this.stringifyTrendChartsValue(value))
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
const width = Number(params.column.trendChartWidth) || 240
|
|
312
|
+
const height = Number(params.column.trendChartHeight) || 48
|
|
313
|
+
return h('canvas', {
|
|
314
|
+
class: 'bi-trend-canvas',
|
|
315
|
+
attrs: {
|
|
316
|
+
width,
|
|
317
|
+
height
|
|
318
|
+
},
|
|
319
|
+
style: {
|
|
320
|
+
display: 'block',
|
|
321
|
+
margin: '0',
|
|
322
|
+
width: width + 'px',
|
|
323
|
+
height: height + 'px'
|
|
324
|
+
},
|
|
325
|
+
hook: {
|
|
326
|
+
insert: vnode => {
|
|
327
|
+
console.log("BiPagingTable -- renderTrendChartsCell -- canvas 已插入DOM,准备绘制:", {
|
|
328
|
+
key: params.column.key,
|
|
329
|
+
rowIndex: params.index,
|
|
330
|
+
width,
|
|
331
|
+
height,
|
|
332
|
+
dataLength: chartValue.length
|
|
333
|
+
})
|
|
334
|
+
this.drawTrendCharts(vnode.elm, chartValue, width, height, params.column)
|
|
335
|
+
},
|
|
336
|
+
postpatch: (...args) => {
|
|
337
|
+
const vnode = args[1]
|
|
338
|
+
console.log("BiPagingTable -- renderTrendChartsCell -- canvas 更新,重新绘制:", {
|
|
339
|
+
key: params.column.key,
|
|
340
|
+
rowIndex: params.index,
|
|
341
|
+
width,
|
|
342
|
+
height,
|
|
343
|
+
dataLength: chartValue.length
|
|
344
|
+
})
|
|
345
|
+
this.drawTrendCharts(vnode.elm, chartValue, width, height, params.column)
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
})
|
|
349
|
+
},
|
|
350
|
+
getTrendChartsSmooth() {
|
|
351
|
+
return true
|
|
352
|
+
},
|
|
353
|
+
drawTrendChartsLine(ctx, points, smooth) {
|
|
354
|
+
ctx.beginPath()
|
|
355
|
+
points.forEach((point, index) => {
|
|
356
|
+
if (index === 0) {
|
|
357
|
+
ctx.moveTo(point.x, point.y)
|
|
358
|
+
} else if (smooth) {
|
|
359
|
+
const prevPoint = points[index - 1]
|
|
360
|
+
const midX = (prevPoint.x + point.x) / 2
|
|
361
|
+
ctx.bezierCurveTo(midX, prevPoint.y, midX, point.y, point.x, point.y)
|
|
362
|
+
} else {
|
|
363
|
+
ctx.lineTo(point.x, point.y)
|
|
364
|
+
}
|
|
365
|
+
})
|
|
366
|
+
},
|
|
367
|
+
drawTrendChartsArea(ctx, points, smooth, bottomY) {
|
|
368
|
+
ctx.beginPath()
|
|
369
|
+
ctx.moveTo(points[0].x, bottomY)
|
|
370
|
+
points.forEach((point, index) => {
|
|
371
|
+
if (index === 0) {
|
|
372
|
+
ctx.lineTo(point.x, point.y)
|
|
373
|
+
} else if (smooth) {
|
|
374
|
+
const prevPoint = points[index - 1]
|
|
375
|
+
const midX = (prevPoint.x + point.x) / 2
|
|
376
|
+
ctx.bezierCurveTo(midX, prevPoint.y, midX, point.y, point.x, point.y)
|
|
377
|
+
} else {
|
|
378
|
+
ctx.lineTo(point.x, point.y)
|
|
379
|
+
}
|
|
380
|
+
})
|
|
381
|
+
ctx.lineTo(points[points.length - 1].x, bottomY)
|
|
382
|
+
ctx.closePath()
|
|
383
|
+
},
|
|
384
|
+
drawTrendCharts(canvas, data, width, height, column) {
|
|
385
|
+
if (!canvas) {
|
|
386
|
+
console.log("BiPagingTable -- drawTrendCharts -- canvas 不存在,无法绘制", { data, width, height })
|
|
387
|
+
return
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
const chartData = data.map(item => Number(item))
|
|
391
|
+
if (!chartData.length || chartData.some(item => isNaN(item))) {
|
|
392
|
+
console.log("BiPagingTable -- drawTrendCharts -- 数据为空或存在非数字,无法绘制:", {
|
|
393
|
+
data,
|
|
394
|
+
chartData,
|
|
395
|
+
hasNaN: chartData.some(item => isNaN(item))
|
|
396
|
+
})
|
|
397
|
+
return
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
const ctx = canvas.getContext('2d')
|
|
401
|
+
console.log("BiPagingTable -- drawTrendCharts -- 开始绘制趋势图:", {
|
|
402
|
+
data,
|
|
403
|
+
chartData,
|
|
404
|
+
width,
|
|
405
|
+
height,
|
|
406
|
+
canvasClientWidth: canvas.clientWidth,
|
|
407
|
+
canvasClientHeight: canvas.clientHeight
|
|
408
|
+
})
|
|
409
|
+
const ratio = window.devicePixelRatio || 1
|
|
410
|
+
canvas.width = width * ratio
|
|
411
|
+
canvas.height = height * ratio
|
|
412
|
+
canvas.style.width = width + 'px'
|
|
413
|
+
canvas.style.height = height + 'px'
|
|
414
|
+
ctx.setTransform(ratio, 0, 0, ratio, 0, 0)
|
|
415
|
+
ctx.clearRect(0, 0, width, height)
|
|
416
|
+
|
|
417
|
+
const padding = { top: 6, right: 6, bottom: 6, left: 6 }
|
|
418
|
+
const chartW = width - padding.left - padding.right
|
|
419
|
+
const chartH = height - padding.top - padding.bottom
|
|
420
|
+
const max = Math.max(...chartData)
|
|
421
|
+
const min = Math.min(...chartData)
|
|
422
|
+
const range = max - min || 1
|
|
423
|
+
const points = chartData.map((val, index) => ({
|
|
424
|
+
x: chartData.length === 1 ? width / 2 : padding.left + (index / (chartData.length - 1)) * chartW,
|
|
425
|
+
y: padding.top + chartH - ((val - min) / range) * chartH
|
|
426
|
+
}))
|
|
427
|
+
const smooth = this.getTrendChartsSmooth()
|
|
428
|
+
console.log("BiPagingTable -- drawTrendCharts -- 趋势图线条类型:", {
|
|
429
|
+
key: column && column.key,
|
|
430
|
+
pointCount: points.length,
|
|
431
|
+
smooth
|
|
432
|
+
})
|
|
433
|
+
|
|
434
|
+
const gradient = ctx.createLinearGradient(0, padding.top, 0, height)
|
|
435
|
+
gradient.addColorStop(0, 'rgba(45, 140, 240, 0.25)')
|
|
436
|
+
gradient.addColorStop(0.5, 'rgba(45, 140, 240, 0.1)')
|
|
437
|
+
gradient.addColorStop(1, 'rgba(45, 140, 240, 0.02)')
|
|
438
|
+
|
|
439
|
+
this.drawTrendChartsArea(ctx, points, smooth, height - padding.bottom)
|
|
440
|
+
ctx.fillStyle = gradient
|
|
441
|
+
ctx.fill()
|
|
442
|
+
|
|
443
|
+
this.drawTrendChartsLine(ctx, points, smooth)
|
|
444
|
+
ctx.strokeStyle = '#2d8cf0'
|
|
445
|
+
ctx.lineWidth = 1.8
|
|
446
|
+
ctx.lineJoin = 'round'
|
|
447
|
+
ctx.lineCap = 'round'
|
|
448
|
+
ctx.stroke()
|
|
449
|
+
|
|
450
|
+
points.forEach((point, index) => {
|
|
451
|
+
if (index === 0 || index === points.length - 1 || index % 3 === 0) {
|
|
452
|
+
ctx.beginPath()
|
|
453
|
+
ctx.arc(point.x, point.y, 2.5, 0, Math.PI * 2)
|
|
454
|
+
ctx.fillStyle = '#fff'
|
|
455
|
+
ctx.fill()
|
|
456
|
+
ctx.strokeStyle = '#2d8cf0'
|
|
457
|
+
ctx.lineWidth = 1.5
|
|
458
|
+
ctx.stroke()
|
|
459
|
+
}
|
|
460
|
+
})
|
|
461
|
+
|
|
462
|
+
const lastPoint = points[points.length - 1]
|
|
463
|
+
ctx.beginPath()
|
|
464
|
+
ctx.arc(lastPoint.x, lastPoint.y, 4, 0, Math.PI * 2)
|
|
465
|
+
ctx.fillStyle = 'rgba(45, 140, 240, 0.2)'
|
|
466
|
+
ctx.fill()
|
|
467
|
+
ctx.strokeStyle = '#2d8cf0'
|
|
468
|
+
ctx.lineWidth = 2
|
|
469
|
+
ctx.stroke()
|
|
470
|
+
console.log("BiPagingTable -- drawTrendCharts -- 趋势图绘制完成", {
|
|
471
|
+
pointCount: points.length,
|
|
472
|
+
min,
|
|
473
|
+
max
|
|
474
|
+
})
|
|
475
|
+
},
|
|
244
476
|
onClose() {
|
|
245
477
|
this.boxShow = false
|
|
246
478
|
},
|
|
@@ -285,7 +517,12 @@ export default {
|
|
|
285
517
|
column.type = 'index'
|
|
286
518
|
column.indexMethod = (row, index) => this.getRankIcon(this.getRankTableIndex(index, row))
|
|
287
519
|
}
|
|
288
|
-
if (column
|
|
520
|
+
if (this.isTrendChartsColumn(column)) {
|
|
521
|
+
let self = this
|
|
522
|
+
column.render = function (h, params) {
|
|
523
|
+
return self.renderTrendChartsCell(h, params)
|
|
524
|
+
}
|
|
525
|
+
} else if (column.detailName) {
|
|
289
526
|
let self = this
|
|
290
527
|
column.render = function (h, params) {
|
|
291
528
|
return h(
|