ol-base-components 2.4.1 → 2.5.0

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ol-base-components",
3
- "version": "2.4.1",
3
+ "version": "2.5.0",
4
4
  "private": false,
5
5
  "main": "src/package/index.js",
6
6
  "bin": {
package/src/App.vue CHANGED
@@ -13,42 +13,26 @@
13
13
  :paginations="paginations"
14
14
  :empty-img="tableData.emptyImg"
15
15
  :btnlist="[]"
16
- url="/api/app/stock-out/send-pick-tray-back"
16
+ url="/api/app/bind-record/bind-record-detail-pages"
17
17
  :table-data="tableData"
18
18
  :multiple-selection="multipleSelection"
19
19
  @SelectionChange="SelectionChange"
20
20
  @handleSizeChange="handleSizeChange"
21
21
  @handleindexChange="handleindexChange"
22
22
  ></ol-table>
23
- <el-button @click="handlePrint">接口</el-button>
23
+ <!-- <el-button @click="handlePrint">接口</el-button>
24
24
 
25
- <div class="ellipsis-container">
26
- 如何处理文本溢出?如何实现单行文本溢出显示省略号?如何实现多行文本溢出显示省略号?
27
- </div>
25
+ <div
26
+ class="ellipsis-container"
27
+ id="ellipsis-container"
28
+ v-for="item in 5"
29
+ :key="item"
30
+ >如何处理文本溢出如何实现单行文本溢出显示省略号</div>
28
31
 
29
- <!-- 三角形 -->
30
32
  <div class="triangle-up"></div>
31
33
  <div class="grid-content">
32
34
  <div>11</div>
33
35
  <div>11</div>
34
- <!-- <div>11</div>
35
- <div>11</div>
36
- <div>11</div>
37
- <div>11</div>
38
- <div>11</div>
39
- <div>11</div>
40
- <div>11</div>
41
- <div>11</div>
42
- <div>11</div>
43
- <div>11</div>
44
- <div>11</div>
45
- <div>11</div>
46
- <div>11</div>
47
- <div>11</div>
48
- <div>11</div>
49
- <div>11</div>
50
- <div>11</div>
51
- <div>11</div> -->
52
36
  </div>
53
37
 
54
38
  <div class="container">
@@ -59,7 +43,7 @@
59
43
 
60
44
  <div class="square-container">
61
45
  <div class="square"></div>
62
- </div>
46
+ </div> -->
63
47
  </div>
64
48
  </template>
65
49
 
@@ -80,127 +64,13 @@ export default {
80
64
  headTool: true, // 开启头部工具栏
81
65
  refreshBtn: true, // 开启表格头部刷新按钮
82
66
  downloadBtn: true, // 开启表格头部下载按钮
67
+ useSlotHeader: false
83
68
  }, // 序号和复选框
84
- rows: [], // 表数据
85
- columns: [
86
- // {
87
- // label: "",
88
- // minWidth: "",
89
- // type: "selection",
90
- // show: true,
91
- // },
92
- {
93
- prop: "remark",
94
- label: "备注123",
95
- },
96
- {
97
- prop: "qualityEnumDesc123",
98
- label: "状态1111112222222",
99
- },
100
- // {
101
- // prop: "stockTypeDesc",
102
- // label: "类型",
103
- // },
104
- // {
105
- // prop: "productCode",
106
- // label: "零件编码",
107
- // minWidth: "200",
108
- // sortable: false,
109
- // show: true,
110
- // },
111
- // {
112
- // prop: "productName",
113
- // label: "零件名称",
114
- // minWidth: "180",
115
- // sortable: false,
116
- // show: true,
117
- // },
118
- // {
119
- // prop: "productBatch",
120
- // label: "批次",
121
- // minWidth: "",
122
- // sortable: false,
123
- // show: true,
124
- // },
125
- // {
126
- // prop: "receivingTime",
127
- // label: "收货日期",
128
- // minWidth: "160",
129
- // sortable: false,
130
- // show: true,
131
- // },
132
- // {
133
- // prop: "expireTime",
134
- // label: "到期时间",
135
- // },
136
- // {
137
- // prop: "projectCode",
138
- // label: "项目号",
139
- // },
140
- // {
141
- // prop: "boxCode",
142
- // label: "箱卡号",
143
- // },
144
- // {
145
- // prop: "region",
146
- // label: "区域",
147
- // },
148
- // {
149
- // prop: "area",
150
- // label: "库区",
151
- // },
152
- // {
153
- // prop: "carBodyTagNumber",
154
- // label: "标签号",
155
- // },
156
- // {
157
- // prop: "cargoLocationCode",
158
- // label: "库位编码",
159
- // minWidth: "",
160
- // sortable: false,
161
- // show: true,
162
- // },
163
- // {
164
- // prop: "containerCode",
165
- // label: "容器编码",
166
- // minWidth: "",
167
- // sortable: false,
168
- // show: true,
169
- // },
170
- // {
171
- // prop: "totalQty",
172
- // label: "库存数量",
173
- // minWidth: "120",
174
- // sortable: false,
175
- // show: true,
176
- // },
177
- // {
178
- // prop: "usableQty",
179
- // label: "可用数量",
180
- // minWidth: "120",
181
- // sortable: false,
182
- // show: true,
183
- // },
184
- // {
185
- // prop: "lockQty",
186
- // label: "占用数量",
187
- // minWidth: "120",
188
- // sortable: false,
189
- // show: true,
190
- // },
191
- // {
192
- // prop: "stockoutBillNo",
193
- // label: "出库单号",
194
- // },
195
- // {
196
- // prop: "loadPercent",
197
- // label: "容器承载百分比",
198
- // },
199
- // {
200
- // prop: "alv",
201
- // label: "客户件号",
202
- // },
203
- ], // 表头
69
+ rows: [{
70
+ bindStateEnum: '11',
71
+ tagNumber: '22'
72
+ }], // 表数据
73
+ columns: [],
204
74
  operates: [], // 表格里面的操作按钮
205
75
  tableHeightDiff: 300,
206
76
  },
@@ -343,7 +213,13 @@ export default {
343
213
  },
344
214
  };
345
215
  },
346
- onMounted() { },
216
+ // onMounted() {
217
+
218
+ // },
219
+ mounted() {
220
+ const el = document.getElementById("ellipsis-container");
221
+ this.truncateMiddleByWidth(el)
222
+ },
347
223
  methods: {
348
224
  SelectionChange(row) {
349
225
  this.multipleSelection = row;
@@ -382,6 +258,26 @@ export default {
382
258
  }
383
259
  this.paginations.page = 1;
384
260
  },
261
+ truncateMiddleByWidth(el) {
262
+ let text = el.textContent;
263
+ if (el.scrollWidth <= el.clientWidth) return;
264
+ const suffix = text.slice(-3);
265
+ let left = 0;
266
+ let right = text.length - 3;
267
+ let result = '';
268
+ while (left <= right) {
269
+ let mid = Math.floor((left + right) / 2);
270
+ const temp = text.slice(0, mid) + '...' + suffix;
271
+ el.textContent = temp;
272
+ if (el.scrollWidth <= el.clientWidth) {
273
+ result = temp;
274
+ left = mid + 1;
275
+ } else {
276
+ right = mid - 1;
277
+ }
278
+ }
279
+ el.textContent = result;
280
+ }
385
281
  },
386
282
  };
387
283
  </script>
@@ -445,13 +341,14 @@ export default {
445
341
  }
446
342
 
447
343
  .ellipsis-container {
448
- width: 100px;
344
+ width: 200px;
449
345
  // height: 100px;
450
346
  border: 1px solid #ccc;
451
347
  overflow: hidden;
452
- text-overflow: ellipsis;
453
- display: -webkit-box;
454
- -webkit-line-clamp: 4; /* 设置行数,例如3行 */
455
- -webkit-box-orient: vertical;
348
+ white-space: nowrap;
349
+ // text-overflow: ellipsis;
350
+ // display: -webkit-box;
351
+ // -webkit-line-clamp: 4; /* 设置行数,例如3行 */
352
+ // -webkit-box-orient: vertical;
456
353
  }
457
354
  </style>
package/src/api/api.js CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
  const fs = require("fs");
3
3
  const path = require("path");
4
4
  const SwaggerClient = require("swagger-client");
@@ -14,7 +14,6 @@ let defaultRemark = `/**
14
14
  * ⚠️ 警告:此文件由脚本自动生成,请勿手动编辑!
15
15
  * �� 如需修改,请重新运行生成脚本
16
16
  * 📅 生成时间: ${new Date().toLocaleString()}
17
- *
18
17
  */\n\n`;
19
18
  const spinnerChars = ["|", "/", "-", "\\"];
20
19
  let spinnerIndex = 0;
package/src/api/run.js CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
  const http = require("http");
3
3
  const fs = require("fs");
4
4
  const path = require("path");
@@ -10,6 +10,11 @@ const swaggerUrl = process.argv[2]
10
10
  : "";
11
11
  const outputPath = process.argv[3] || "src/api/swagger.js";
12
12
 
13
+ let defaultRemark = `/**
14
+ * ⚠️ 警告:此文件由脚本自动生成,请勿手动编辑!
15
+ * �� 如需修改,请重新运行生成脚本
16
+ * 📅 生成时间: ${new Date().toLocaleString()}
17
+ */\n\n`;
13
18
  const spinnerChars = ["|", "/", "-", "\\"];
14
19
  let spinnerIndex = 0;
15
20
  let dotCount = 0;
@@ -131,12 +136,7 @@ const generateApiModules = (swagger) => {
131
136
  }
132
137
 
133
138
  // 生成最终的输出字符串
134
- let output = `/**
135
- * ⚠️ 警告:此文件由脚本自动生成,请勿手动编辑!
136
- * �� 如需修改,请重新运行生成脚本
137
- * 📅 生成时间: ${new Date().toLocaleString()}
138
- *
139
- */\n\n`;
139
+ let output = defaultRemark;
140
140
  for (const [moduleName, methods] of Object.entries(apiModules)) {
141
141
  const description = tags.find((e) => e.name === moduleName).description;
142
142
  output += `// ${description}\n`;
@@ -101,6 +101,7 @@
101
101
  @select-all="selectAll"
102
102
  @row-click="rowClick"
103
103
  >
104
+
104
105
  <el-table-column
105
106
  v-if="tableData.options && tableData.options.index"
106
107
  width="60"
@@ -116,48 +117,65 @@
116
117
  type="selection"
117
118
  label=""
118
119
  />
119
- <template v-for="(item, index) in bindTableColumns">
120
- <el-table-column
121
- :key="index"
122
- :label="item.label"
123
- :prop="item.prop"
124
- :min-width="item.minWidth || '150px'"
125
- :show-overflow-tooltip="item.overHidden || true"
126
- :type="item.type || 'normal'"
127
- v-bind="{
120
+ <!-- 新增插槽,允许父组件自定义表头 -->
121
+ <template v-if="tableData.options && tableData.options.useSlotHeader">
122
+ <slot
123
+ name="table-columns"
124
+ :columns="bindTableColumns"
125
+ >
126
+ <template v-for="(item, index) in bindTableColumns">
127
+ <my-table-column
128
+ :column="item"
129
+ :key="index"
130
+ />
131
+ </template>
132
+ </slot>
133
+ </template>
134
+ <!-- 防止之前逻辑出现纰漏,故保留之前逻辑再扩展自定义插槽方式渲染 -->
135
+ <template v-else>
136
+ <template v-for="(item, index) in bindTableColumns">
137
+ <el-table-column
138
+ :key="index"
139
+ :label="item.label"
140
+ :prop="item.prop"
141
+ :min-width="item.minWidth || '150px'"
142
+ :show-overflow-tooltip="item.overHidden || true"
143
+ :type="item.type || 'normal'"
144
+ v-bind="{
128
145
  align: 'center',
129
146
  width: item.width,
130
147
  fixed: item.fixed || false,
131
148
  sortable: item.sortable || false,
132
149
  ...item.attrs,
133
150
  }"
134
- >
135
- <template v-slot:header>
136
- <el-tooltip
137
- :content="`${item.label} ${item.prop}`"
138
- placement="top"
139
- >
140
- <span>{{ item.label }}</span>
141
- </el-tooltip>
142
- </template>
143
- <template
144
- v-if="item.render"
145
- v-slot="scope"
146
- >
147
- <!-- 使用函数式组件进行dom渲染 -->
148
- <render-dom :render="() => item.render(scope.row)" />
149
- </template>
150
- <template
151
- v-else-if="item.renderSlot"
152
- v-slot="scope"
153
151
  >
154
- <slot
155
- :row="scope.row"
156
- :name="item.prop"
157
- />
158
- </template>
159
- </el-table-column>
152
+ <template v-slot:header>
153
+ <el-tooltip
154
+ :content="`${item.label} ${item.prop}`"
155
+ placement="top"
156
+ >
157
+ <span>{{ item.label }}</span>
158
+ </el-tooltip>
159
+ </template>
160
+ <template
161
+ v-if="item.render"
162
+ v-slot="scope"
163
+ >
164
+ <render-dom :render="() => item.render(scope.row)" />
165
+ </template>
166
+ <template
167
+ v-else-if="item.renderSlot"
168
+ v-slot="scope"
169
+ >
170
+ <slot
171
+ :row="scope.row"
172
+ :name="item.prop"
173
+ />
174
+ </template>
175
+ </el-table-column>
176
+ </template>
160
177
  </template>
178
+
161
179
  <el-table-column
162
180
  v-if="tableData.operates && tableData.operates.length > 0"
163
181
  label="操作"
@@ -260,6 +278,77 @@ export default {
260
278
  return <div>{renDom.props.render()}</div>;
261
279
  },
262
280
  },
281
+ myTableColumn: {
282
+ functional: true,
283
+ props: {
284
+ column: { type: Object, required: true }
285
+ },
286
+ render(h, ctx) {
287
+ const col = ctx.props.column;
288
+
289
+ // 多级表头处理
290
+ if (col.children && col.children.length) {
291
+ return h(
292
+ 'el-table-column',
293
+ {
294
+ props: {
295
+ label: col.label,
296
+ ...col.attrs
297
+ }
298
+ },
299
+ col.children.map((child, idx) =>
300
+ h(ctx.parent.$options.components.myTableColumn, {
301
+ props: { column: child },
302
+ key: idx
303
+ })
304
+ )
305
+ );
306
+ }
307
+
308
+ // 单列表头处理
309
+ return h(
310
+ 'el-table-column',
311
+ {
312
+ props: {
313
+ label: col.label,
314
+ prop: col.prop,
315
+ minWidth: col.minWidth || '150px',
316
+ showOverflowTooltip: col.overHidden || true,
317
+ type: col.type || 'normal',
318
+ align: 'center',
319
+ width: col.width,
320
+ fixed: col.fixed || false,
321
+ sortable: col.sortable || false,
322
+ ...col.attrs
323
+ }
324
+ },
325
+ [
326
+ // 表头插槽 - 添加 el-tooltip
327
+ h('template', { slot: 'header' }, [
328
+ h('el-tooltip', {
329
+ props: {
330
+ content: `${col.label} ${col.prop}`,
331
+ placement: 'top'
332
+ }
333
+ }, [
334
+ h('span', col.label)
335
+ ])
336
+ ]),
337
+ // 内容插槽 - 支持自定义渲染
338
+ col.render ? h('template', { slot: 'default' }, {
339
+ render: (scope) => h(ctx.parent.$options.components.renderDom, {
340
+ props: { render: () => col.render(scope.row) }
341
+ })
342
+ }) : null,
343
+ // 插槽渲染
344
+ col.renderSlot ? h('template', { slot: 'default' }, {
345
+ render: (scope) => ctx.parent.$scopedSlots[col.prop] ?
346
+ ctx.parent.$scopedSlots[col.prop](scope) : null
347
+ }) : null
348
+ ].filter(Boolean)
349
+ );
350
+ }
351
+ }
263
352
  },
264
353
  model: {
265
354
  prop: "multipleSelection",
@@ -305,6 +394,7 @@ export default {
305
394
  headTool: true, // 开启头部工具栏
306
395
  refreshBtn: true, // 开启表格头部刷新按钮
307
396
  downloadBtn: true, // 开启表格头部下载按钮
397
+ useSlotHeader: false, // 使用插槽自定义表头
308
398
  }, // 序号和复选框
309
399
  rows: [], // 表数据
310
400
  columns: [], // 表头
@@ -402,30 +492,103 @@ export default {
402
492
  },
403
493
  },
404
494
  methods: {
495
+ // init() {
496
+ // // 从 IndexedDB 中获取 Swagger 数据
497
+ // getData().then((swaggerData) => {
498
+ // const swaggerColumns = swaggerData.paths[this.url].get.responses["200"].content['application/json'].schema.properties.items.items.properties;
499
+
500
+ // Object.keys(swaggerColumns).forEach(key => {
501
+ // const item = swaggerColumns[key];
502
+ // let tempItem = this.tableData.columns.find((e) => e.prop == key);
503
+ // if (tempItem) {
504
+ // tempItem = { ...item, ...tempItem };
505
+ // } else if (item.description) {
506
+ // this.tableData.columns.push({
507
+ // prop: key,
508
+ // label: item.description,
509
+ // show: true,
510
+ // sortable: false,
511
+ // attrs: {}
512
+ // });
513
+ // }
514
+ // });
515
+ // console.log(`\x1b[36m\x1b[4mol插件-表格`, this.tableData.columns)
516
+ // }).catch((error) => {
517
+ // console.error("获取 Swagger 数据失败:", error);
518
+ // });
519
+ // },
520
+ // 支持多级表头 useSlotHeader: true,且支持排序,通过columns中的顺序实现
521
+ // columns: [
522
+ // {
523
+ // label: '一级表头',
524
+ // children: [{ prop: 'bindStateEnum', label: '112' }, { prop: 'tagNumber' }]
525
+ // },
526
+ // {
527
+ // prop: "remark",
528
+ // label: "备注123",
529
+ // },
530
+ // ],
405
531
  init() {
406
532
  // 从 IndexedDB 中获取 Swagger 数据
407
533
  getData().then((swaggerData) => {
408
534
  const swaggerColumns = swaggerData.paths[this.url].get.responses["200"].content['application/json'].schema.properties.items.items.properties;
409
535
 
536
+ // 递归映射函数
537
+ const mapSwaggerToColumns = (columns) => {
538
+ columns.forEach(column => {
539
+ if (column.children && column.children.length) {
540
+ mapSwaggerToColumns(column.children);
541
+ } else {
542
+ if (column.prop && swaggerColumns[column.prop]) {
543
+ const swaggerItem = swaggerColumns[column.prop];
544
+ Object.assign(column, {
545
+ label: swaggerItem.description,
546
+ show: true,
547
+ sortable: false,
548
+ ...column
549
+ });
550
+ }
551
+ }
552
+ });
553
+ };
554
+
555
+ mapSwaggerToColumns(this.tableData.columns);
556
+
410
557
  Object.keys(swaggerColumns).forEach(key => {
411
558
  const item = swaggerColumns[key];
412
- let tempItem = this.tableData.columns.find((e) => e.prop == key);
413
- if (tempItem) {
414
- tempItem = { ...item, ...tempItem };
415
- } else if (item.description) {
559
+ const existingColumn = this.findColumnByProp(this.tableData.columns, key);
560
+ if (!existingColumn && item.description) {
416
561
  this.tableData.columns.push({
417
562
  prop: key,
418
563
  label: item.description,
419
564
  show: true,
420
565
  sortable: false,
421
- attrs: {}
566
+ attrs: {},
567
+ ...item
422
568
  });
423
569
  }
424
570
  });
571
+
425
572
  console.log(`\x1b[36m\x1b[4mol插件-表格`, this.tableData.columns)
426
573
  }).catch((error) => {
427
574
  console.error("获取 Swagger 数据失败:", error);
428
575
  });
576
+ },
577
+ // 递归查找列配置的辅助方法
578
+ findColumnByProp(columns, prop) {
579
+ for (const column of columns) {
580
+ if (column.children && column.children.length) {
581
+ const found = this.findColumnByProp(column.children, prop);
582
+ if (found) return found;
583
+ } else if (column.prop === prop) {
584
+ return column;
585
+ }
586
+ }
587
+ return null;
588
+ },
589
+ // 多级表头转换
590
+ multilevelHeader() {
591
+
429
592
  },
430
593
  radioChange() {
431
594
  this.$emit("radioChange", this.twinPage);