n20-common-lib 2.18.0 → 2.18.2
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/package.json
CHANGED
|
@@ -341,13 +341,19 @@ export default {
|
|
|
341
341
|
}
|
|
342
342
|
})
|
|
343
343
|
const wrapperEl = document.querySelector('div#app')
|
|
344
|
-
|
|
345
|
-
if (!wrapperEl || notHasWidth.length > 0) {
|
|
344
|
+
if (!wrapperEl) {
|
|
346
345
|
return columns
|
|
347
346
|
}
|
|
348
347
|
const { width: windowWidth } = wrapperEl.getBoundingClientRect()
|
|
348
|
+
|
|
349
|
+
// 定义每个字符的平均宽度(像素)
|
|
350
|
+
const CHAR_WIDTH = 20 // 根据实际字体大小调整
|
|
351
|
+
const PADDING = 20 // 左右padding
|
|
352
|
+
|
|
349
353
|
function calc(columns) {
|
|
350
354
|
let columnsWidth = 0
|
|
355
|
+
|
|
356
|
+
// 先计算每列的基础宽度
|
|
351
357
|
columns.forEach((column) => {
|
|
352
358
|
if (column.static && column.label === $lc('操作') && !column.width && !column.minWidth) {
|
|
353
359
|
column.width = 80
|
|
@@ -355,24 +361,35 @@ export default {
|
|
|
355
361
|
if (column.type === 'checkbox') {
|
|
356
362
|
column.width = 80
|
|
357
363
|
}
|
|
364
|
+
|
|
365
|
+
// 如果没有设置宽度,根据字符数计算最小宽度
|
|
366
|
+
if (!column.width && !column.minWidth) {
|
|
367
|
+
const textLength = column.label.length
|
|
368
|
+
column.minWidth = Math.ceil(textLength * CHAR_WIDTH + PADDING)
|
|
369
|
+
}
|
|
370
|
+
|
|
358
371
|
const width = column.minWidth || column.width
|
|
359
372
|
column['_width_'] = column['_width_'] || parseInt(width)
|
|
360
373
|
column['width'] = parseInt(width)
|
|
361
|
-
column['minWidth'] = undefined
|
|
362
374
|
columnsWidth += column.width
|
|
363
375
|
})
|
|
364
376
|
|
|
365
|
-
|
|
377
|
+
// 如果总宽度超过容器宽度,直接返回
|
|
378
|
+
if (columnsWidth >= windowWidth) {
|
|
379
|
+
return columns
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// 否则按比例分配剩余空间
|
|
366
383
|
return columns.map((column) => {
|
|
367
384
|
if (!column.type) {
|
|
368
385
|
const rate = column['_width_'] / columnsWidth
|
|
369
|
-
column['width'] = Math.
|
|
386
|
+
column['width'] = Math.max(windowWidth * rate, column.minWidth || column.width)
|
|
370
387
|
return column
|
|
371
388
|
}
|
|
372
|
-
|
|
373
389
|
return column
|
|
374
390
|
})
|
|
375
391
|
}
|
|
392
|
+
|
|
376
393
|
return calc(columns)
|
|
377
394
|
}
|
|
378
395
|
}
|
|
@@ -42,7 +42,7 @@ function tipShow(el, arg) {
|
|
|
42
42
|
if (el.$tooltipTitle) {
|
|
43
43
|
// 修改这里的判断逻辑
|
|
44
44
|
const shouldShowTooltip =
|
|
45
|
-
el.$tooltipTitleOverflow || el.clientWidth < el.scrollWidth || el.offsetWidth < el.scrollWidth
|
|
45
|
+
!el.$tooltipTitleOverflow || el.clientWidth < el.scrollWidth || el.offsetWidth < el.scrollWidth
|
|
46
46
|
|
|
47
47
|
if (shouldShowTooltip) {
|
|
48
48
|
text = el.$tooltipTitle
|