@ctzy-web-client/plugin-component-vue 1.0.54 → 1.0.55

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,4 +1,4 @@
1
- import { defineComponent, useAttrs, inject, openBlock, createBlock, unref, mergeProps, withCtx, renderSlot, createTextVNode, toDisplayString, createCommentVNode } from 'vue';
1
+ import { defineComponent, useAttrs, inject, openBlock, createBlock, unref, mergeProps, withCtx, renderSlot, createElementVNode, toDisplayString, createCommentVNode } from 'vue';
2
2
  import { ElTableColumn } from 'element-plus';
3
3
  import { dataTableKey } from '@ctzy-web-client/web-base-client-vue';
4
4
  import _export_sfc from '../_virtual/_plugin-vue_export-helper.mjs';
@@ -12,6 +12,7 @@ if (typeof __name === 'undefined') {
12
12
  });
13
13
  }
14
14
  }
15
+ const _hoisted_1 = { style: { "white-space": "nowrap", "display": "inline-block" } };
15
16
  const __default__ = defineComponent({ name: "BwaDataTableColumn" });
16
17
  const _sfc_main = /* @__PURE__ */ Object.assign(__default__, {
17
18
  props: {
@@ -44,7 +45,7 @@ const _sfc_main = /* @__PURE__ */ Object.assign(__default__, {
44
45
  column: column2,
45
46
  $index
46
47
  }, () => [
47
- createTextVNode(toDisplayString(column2.label), 1)
48
+ createElementVNode("span", _hoisted_1, toDisplayString(column2.label), 1)
48
49
  ])
49
50
  ]),
50
51
  default: withCtx(({ row, $index }) => [
@@ -1,4 +1,4 @@
1
- import { defineComponent, useAttrs, ref, computed, unref, watch, provide, reactive, nextTick, onUnmounted, openBlock, createElementBlock, normalizeClass, normalizeStyle, renderSlot, createVNode, mergeProps, withCtx, createBlock, createElementVNode, createCommentVNode, Fragment, renderList, createTextVNode, toDisplayString } from 'vue';
1
+ import { defineComponent, useAttrs, ref, computed, unref, watch, provide, reactive, nextTick, onUnmounted, openBlock, createElementBlock, normalizeClass, normalizeStyle, renderSlot, createVNode, mergeProps, withCtx, createBlock, createElementVNode, createCommentVNode, Fragment, renderList, toDisplayString } from 'vue';
2
2
  import { ElMessage, ElTable, ElTableColumn, ElPagination } from 'element-plus';
3
3
  import { useService, useGlobalConfig, dataTableKey, useNamespace, useEventDispatcher } from '@ctzy-web-client/web-base-client-vue';
4
4
  import DynamicComponent from './dynamic-component.mjs';
@@ -17,6 +17,7 @@ if (typeof __name === 'undefined') {
17
17
  });
18
18
  }
19
19
  }
20
+ const _hoisted_1 = { style: { "white-space": "nowrap", "display": "inline-block" } };
20
21
  const __default__ = defineComponent({ name: "BwaDataTable" });
21
22
  const _sfc_main = /* @__PURE__ */ Object.assign(__default__, {
22
23
  props: {
@@ -95,24 +96,43 @@ const _sfc_main = /* @__PURE__ */ Object.assign(__default__, {
95
96
  const searchParams = computed(() => props.searchParams);
96
97
  const emit = __emit;
97
98
  const debounceDelay = useGlobalConfig("debounceDelay", 500);
98
- const calculateNameLengthPx = (name, cnCharSize = 20, enCharSize = 6, padding = 15) => {
99
+ const calculateNameLengthPx = (name, hasSort = false, cnCharSize = 20, enCharSize = 6, padding = 30) => {
99
100
  const str = String(name != null ? name : "").trim();
100
101
  if (!str)
101
- return 60;
102
+ return 80;
102
103
  let cnCount = 0;
103
104
  let enCount = 0;
104
105
  for (const char of str) {
105
106
  const isCn = /[\u4e00-\u9fa5\uff00-\uffff]/.test(char);
106
- if (isCn) {
107
- cnCount++;
108
- } else {
109
- enCount++;
110
- }
107
+ isCn ? cnCount++ : enCount++;
111
108
  }
112
- const textWidth = cnCount * cnCharSize + enCount * enCharSize;
113
- const totalPx = Math.max(60, textWidth + padding);
109
+ let textWidth = cnCount * cnCharSize + enCount * enCharSize;
110
+ if (hasSort)
111
+ textWidth += 32;
112
+ const totalPx = Math.max(90, textWidth + padding);
114
113
  return totalPx;
115
114
  };
115
+ const parseWidthNum = (width) => {
116
+ if (width === void 0 || width === null || width === "" || width === "auto")
117
+ return null;
118
+ let num;
119
+ if (typeof width === "string") {
120
+ const pureStr = width.replace(/px$/gi, "");
121
+ num = Number(pureStr);
122
+ } else {
123
+ num = Number(width);
124
+ }
125
+ if (isNaN(num) || num <= 0)
126
+ return null;
127
+ return num;
128
+ };
129
+ const getColumnWidth = (item) => {
130
+ const minW = calculateNameLengthPx(item.title, item.sortable === "custom");
131
+ const customW = parseWidthNum(item.width);
132
+ if (customW === null)
133
+ return minW;
134
+ return Math.max(customW, minW);
135
+ };
116
136
  provide(
117
137
  dataTableKey,
118
138
  reactive({
@@ -299,7 +319,8 @@ const _sfc_main = /* @__PURE__ */ Object.assign(__default__, {
299
319
  data: data.value,
300
320
  "row-key": unref(dataTable).primaryKey,
301
321
  "show-header": "",
302
- stripe: ""
322
+ stripe: "",
323
+ fit: ""
303
324
  }, unref(attrs), {
304
325
  onHeaderDragend: headerDragend,
305
326
  onSelectionChange: unref(selectionChange),
@@ -349,8 +370,7 @@ const _sfc_main = /* @__PURE__ */ Object.assign(__default__, {
349
370
  key: item.attrName,
350
371
  label: item.title,
351
372
  prop: item.fullAttrName,
352
- "min-width": calculateNameLengthPx(item.title),
353
- width: item.width,
373
+ width: getColumnWidth(item),
354
374
  fixed: item.fixed,
355
375
  align: item.align
356
376
  }, { ref_for: true }, item.componentProps, {
@@ -358,7 +378,7 @@ const _sfc_main = /* @__PURE__ */ Object.assign(__default__, {
358
378
  }), {
359
379
  header: withCtx(() => [
360
380
  renderSlot(_ctx.$slots, `table-header-col-${item.attrName}`, {}, () => [
361
- createTextVNode(toDisplayString(item.title), 1)
381
+ createElementVNode("span", _hoisted_1, toDisplayString(item.title), 1)
362
382
  ])
363
383
  ]),
364
384
  default: withCtx(({ row, $index }) => [
@@ -376,7 +396,7 @@ const _sfc_main = /* @__PURE__ */ Object.assign(__default__, {
376
396
  ]) : createCommentVNode("v-if", true)
377
397
  ]),
378
398
  _: 2
379
- }, 1040, ["column-key", "label", "prop", "min-width", "width", "fixed", "align", "sortable"]);
399
+ }, 1040, ["column-key", "label", "prop", "width", "fixed", "align", "sortable"]);
380
400
  }), 128))
381
401
  ]),
382
402
  renderSlot(_ctx.$slots, "column-append")
@@ -16,6 +16,7 @@ if (typeof __name === 'undefined') {
16
16
  });
17
17
  }
18
18
  }
19
+ const _hoisted_1 = { style: { "white-space": "nowrap", "display": "inline-block" } };
19
20
  const __default__ = vue.defineComponent({ name: "BwaDataTableColumn" });
20
21
  const _sfc_main = /* @__PURE__ */ Object.assign(__default__, {
21
22
  props: {
@@ -48,7 +49,7 @@ const _sfc_main = /* @__PURE__ */ Object.assign(__default__, {
48
49
  column: column2,
49
50
  $index
50
51
  }, () => [
51
- vue.createTextVNode(vue.toDisplayString(column2.label), 1)
52
+ vue.createElementVNode("span", _hoisted_1, vue.toDisplayString(column2.label), 1)
52
53
  ])
53
54
  ]),
54
55
  default: vue.withCtx(({ row, $index }) => [
@@ -21,6 +21,7 @@ if (typeof __name === 'undefined') {
21
21
  });
22
22
  }
23
23
  }
24
+ const _hoisted_1 = { style: { "white-space": "nowrap", "display": "inline-block" } };
24
25
  const __default__ = vue.defineComponent({ name: "BwaDataTable" });
25
26
  const _sfc_main = /* @__PURE__ */ Object.assign(__default__, {
26
27
  props: {
@@ -99,24 +100,43 @@ const _sfc_main = /* @__PURE__ */ Object.assign(__default__, {
99
100
  const searchParams = vue.computed(() => props.searchParams);
100
101
  const emit = __emit;
101
102
  const debounceDelay = webBaseClientVue.useGlobalConfig("debounceDelay", 500);
102
- const calculateNameLengthPx = (name, cnCharSize = 20, enCharSize = 6, padding = 15) => {
103
+ const calculateNameLengthPx = (name, hasSort = false, cnCharSize = 20, enCharSize = 6, padding = 30) => {
103
104
  const str = String(name != null ? name : "").trim();
104
105
  if (!str)
105
- return 60;
106
+ return 80;
106
107
  let cnCount = 0;
107
108
  let enCount = 0;
108
109
  for (const char of str) {
109
110
  const isCn = /[\u4e00-\u9fa5\uff00-\uffff]/.test(char);
110
- if (isCn) {
111
- cnCount++;
112
- } else {
113
- enCount++;
114
- }
111
+ isCn ? cnCount++ : enCount++;
115
112
  }
116
- const textWidth = cnCount * cnCharSize + enCount * enCharSize;
117
- const totalPx = Math.max(60, textWidth + padding);
113
+ let textWidth = cnCount * cnCharSize + enCount * enCharSize;
114
+ if (hasSort)
115
+ textWidth += 32;
116
+ const totalPx = Math.max(90, textWidth + padding);
118
117
  return totalPx;
119
118
  };
119
+ const parseWidthNum = (width) => {
120
+ if (width === void 0 || width === null || width === "" || width === "auto")
121
+ return null;
122
+ let num;
123
+ if (typeof width === "string") {
124
+ const pureStr = width.replace(/px$/gi, "");
125
+ num = Number(pureStr);
126
+ } else {
127
+ num = Number(width);
128
+ }
129
+ if (isNaN(num) || num <= 0)
130
+ return null;
131
+ return num;
132
+ };
133
+ const getColumnWidth = (item) => {
134
+ const minW = calculateNameLengthPx(item.title, item.sortable === "custom");
135
+ const customW = parseWidthNum(item.width);
136
+ if (customW === null)
137
+ return minW;
138
+ return Math.max(customW, minW);
139
+ };
120
140
  vue.provide(
121
141
  webBaseClientVue.dataTableKey,
122
142
  vue.reactive({
@@ -303,7 +323,8 @@ const _sfc_main = /* @__PURE__ */ Object.assign(__default__, {
303
323
  data: data.value,
304
324
  "row-key": vue.unref(dataTable).primaryKey,
305
325
  "show-header": "",
306
- stripe: ""
326
+ stripe: "",
327
+ fit: ""
307
328
  }, vue.unref(attrs), {
308
329
  onHeaderDragend: headerDragend,
309
330
  onSelectionChange: vue.unref(selectionChange),
@@ -353,8 +374,7 @@ const _sfc_main = /* @__PURE__ */ Object.assign(__default__, {
353
374
  key: item.attrName,
354
375
  label: item.title,
355
376
  prop: item.fullAttrName,
356
- "min-width": calculateNameLengthPx(item.title),
357
- width: item.width,
377
+ width: getColumnWidth(item),
358
378
  fixed: item.fixed,
359
379
  align: item.align
360
380
  }, { ref_for: true }, item.componentProps, {
@@ -362,7 +382,7 @@ const _sfc_main = /* @__PURE__ */ Object.assign(__default__, {
362
382
  }), {
363
383
  header: vue.withCtx(() => [
364
384
  vue.renderSlot(_ctx.$slots, `table-header-col-${item.attrName}`, {}, () => [
365
- vue.createTextVNode(vue.toDisplayString(item.title), 1)
385
+ vue.createElementVNode("span", _hoisted_1, vue.toDisplayString(item.title), 1)
366
386
  ])
367
387
  ]),
368
388
  default: vue.withCtx(({ row, $index }) => [
@@ -380,7 +400,7 @@ const _sfc_main = /* @__PURE__ */ Object.assign(__default__, {
380
400
  ]) : vue.createCommentVNode("v-if", true)
381
401
  ]),
382
402
  _: 2
383
- }, 1040, ["column-key", "label", "prop", "min-width", "width", "fixed", "align", "sortable"]);
403
+ }, 1040, ["column-key", "label", "prop", "width", "fixed", "align", "sortable"]);
384
404
  }), 128))
385
405
  ]),
386
406
  vue.renderSlot(_ctx.$slots, "column-append")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ctzy-web-client/plugin-component-vue",
3
- "version": "1.0.54",
3
+ "version": "1.0.55",
4
4
  "main": "lib/index.js",
5
5
  "module": "es/index.mjs",
6
6
  "exports": {
@@ -5,7 +5,11 @@
5
5
  v-bind="attrs"
6
6
  >
7
7
  <template #header="{ column, $index }">
8
- <slot name="header" :column="column" :$index="$index">{{ column.label }}</slot>
8
+ <slot name="header" :column="column" :$index="$index">
9
+ <span style="white-space: nowrap; display: inline-block;">
10
+ {{ column.label }}
11
+ </span>
12
+ </slot>
9
13
  </template>
10
14
 
11
15
  <template #default="{ row, $index }">
@@ -10,6 +10,7 @@
10
10
  :row-key="dataTable.primaryKey"
11
11
  show-header
12
12
  stripe
13
+ fit
13
14
  v-bind="attrs"
14
15
  @header-dragend='headerDragend'
15
16
  @selection-change="selectionChange"
@@ -42,8 +43,7 @@
42
43
  :key="item.attrName"
43
44
  :label="item.title"
44
45
  :prop="item.fullAttrName"
45
- :min-width="calculateNameLengthPx(item.title)"
46
- :width="item.width"
46
+ :width="getColumnWidth(item)"
47
47
  :fixed="item.fixed"
48
48
  :align="item.align"
49
49
  v-bind="item.componentProps"
@@ -51,7 +51,7 @@
51
51
  >
52
52
  <template #header>
53
53
  <slot :name="`table-header-col-${item.attrName}`">
54
- {{ item.title }}
54
+ <span style="white-space: nowrap; display: inline-block;"> {{ item.title }}</span>
55
55
  </slot>
56
56
  </template>
57
57
  <template #default="{ row, $index }">
@@ -223,27 +223,58 @@ const searchParams = computed(() => props.searchParams);
223
223
 
224
224
  const emit = defineEmits(['drag','headerWidthChange']);
225
225
 
226
- const debounceDelay = useGlobalConfig('debounceDelay', 500);
227
- const calculateNameLengthPx = (name, cnCharSize = 20, enCharSize = 6, padding = 15) => {
226
+ const debounceDelay = useGlobalConfig('debounceDelay', 500);const calculateNameLengthPx = (
227
+ name,
228
+ hasSort = false,
229
+ cnCharSize = 20,
230
+ enCharSize = 6,
231
+ padding = 30
232
+ ) => {
228
233
  const str = String(name ?? '').trim();
229
- if (!str) return 60;
230
- let cnCount = 0; // 中文字符、全角符号计数
231
- let enCount = 0; // 英文、数字、半角符号计数
232
- // 正则匹配区分字符
234
+ if (!str) return 80;
235
+ let cnCount = 0;
236
+ let enCount = 0;
237
+
233
238
  for (const char of str) {
234
- // 判断是否为中文/全角字符
235
239
  const isCn = /[\u4e00-\u9fa5\uff00-\uffff]/.test(char);
236
- if (isCn) {
237
- cnCount++;
238
- } else {
239
- enCount++;
240
- }
240
+ isCn ? cnCount++ : enCount++;
241
241
  }
242
- // 分别计算字符总宽度,再加两边内边距
243
- const textWidth = cnCount * cnCharSize + enCount * enCharSize;
244
- const totalPx = Math.max(60, textWidth + padding);
242
+
243
+ let textWidth = cnCount * cnCharSize + enCount * enCharSize;
244
+ if (hasSort) textWidth += 32;
245
+ const totalPx = Math.max(90, textWidth + padding);
245
246
  return totalPx;
246
- }
247
+ };
248
+ const parseWidthNum = (width) => {
249
+ // 空值、auto 标记为无自定义宽度
250
+ if (width === undefined || width === null || width === '' || width === 'auto') return null;
251
+ let num;
252
+ if (typeof width === 'string') {
253
+ // 统一去掉末尾px,忽略大小写 PX/Px
254
+ const pureStr = width.replace(/px$/gi, '');
255
+ num = Number(pureStr);
256
+ } else {
257
+ num = Number(width);
258
+ }
259
+ // 非法数字、负数直接返回null,走最小宽度兜底
260
+ if (isNaN(num) || num <= 0) return null;
261
+ return num;
262
+ };
263
+ /**
264
+ * 获取最终列宽度
265
+ * @param item 列配置项
266
+ * @returns 最终生效宽度
267
+ */
268
+ const getColumnWidth = (item) => {
269
+ const minW = calculateNameLengthPx(item.title, item.sortable === 'custom');
270
+ // 无自定义宽度直接返回计算最小值
271
+
272
+ const customW = parseWidthNum(item.width);
273
+
274
+ // 无合法自定义宽度,直接用自适应最小宽度
275
+ if (customW === null) return minW;
276
+ return Math.max(customW, minW);
277
+ };
247
278
  //当前data table 上下文对象
248
279
  provide(
249
280
  dataTableKey,
File without changes
File without changes