vue3-smart-table 0.0.2 → 1.0.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/README.md +285 -29
- package/dist/vue3-smart-table.cjs.js +12 -2
- package/dist/vue3-smart-table.es.js +258 -218
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# SmartTable 使用文档
|
|
2
2
|
|
|
3
3
|
## 概览
|
|
4
4
|
|
|
@@ -55,10 +55,7 @@ export interface ColumnConfig<R = any> {
|
|
|
55
55
|
|
|
56
56
|
visible?: boolean
|
|
57
57
|
inControl?: boolean
|
|
58
|
-
|
|
59
58
|
render?: string
|
|
60
|
-
editable?: boolean
|
|
61
|
-
editType?: 'input' | 'number' | 'select'
|
|
62
59
|
|
|
63
60
|
renderProps?: Record<string, any>
|
|
64
61
|
columnProps?: Record<string, any>
|
|
@@ -119,8 +116,12 @@ export interface ButtonConfig<R = any> {
|
|
|
119
116
|
| `dict` | 字典映射 |
|
|
120
117
|
| `map` | key-value 映射 |
|
|
121
118
|
| `formatter` | 自定义格式化 |
|
|
122
|
-
| `editable` | 可编辑单元格(input / number / select) |
|
|
123
119
|
| `icon` | iconfont / svg / url |
|
|
120
|
+
| `input` | 可编辑单元格 |
|
|
121
|
+
| `input-number` | 可编辑单元格 |
|
|
122
|
+
| `select` | 可编辑单元格 |
|
|
123
|
+
| `button` | 单行按钮 |
|
|
124
|
+
| `link` | 单行链接 |
|
|
124
125
|
|
|
125
126
|
### copy 示例
|
|
126
127
|
|
|
@@ -143,12 +144,39 @@ export interface ButtonConfig<R = any> {
|
|
|
143
144
|
key: 'avatar',
|
|
144
145
|
label: '头像',
|
|
145
146
|
render: 'img',
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
147
|
+
columnProps: { minWidth: 150},
|
|
148
|
+
renderProps: {
|
|
149
|
+
width: '60px',
|
|
150
|
+
height: '60px',
|
|
151
|
+
fit: 'cover',
|
|
152
|
+
placeholder: '--'
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
key: 'gallery',
|
|
157
|
+
label: '相册',
|
|
158
|
+
render: 'img',
|
|
159
|
+
columnProps: { minWidth: 150},
|
|
160
|
+
renderProps: {
|
|
161
|
+
width: '100px',
|
|
162
|
+
height: '100px'
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
const tableData = reactive([
|
|
166
|
+
{ id: 3, name: 'Charlie', code: '9525', status: 0, map: 1, regionCode:'海外', orderNum: 1, selectId: 2,
|
|
167
|
+
avatar: 'https://iconfont.alicdn.com/p/illus_3d/file/UMAqlm6KX5gw/8e357f00-9a4e-44c4-b0c5-bbed255cff24.png' ,
|
|
168
|
+
gallery: [
|
|
169
|
+
'https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png',
|
|
170
|
+
'https://iconfont.alicdn.com/p/illus_3d/file/UMAqlm6KX5gw/8e357f00-9a4e-44c4-b0c5-bbed255cff24.png',
|
|
171
|
+
],
|
|
172
|
+
},
|
|
173
|
+
])
|
|
149
174
|
```
|
|
150
|
-
-
|
|
151
|
-
-
|
|
175
|
+
- 单张图片:正常显示并支持预览
|
|
176
|
+
- 多张图片:显示第一张,右侧显示剩余数量(如:+2)
|
|
177
|
+
- 支持 previewSrcList 自定义预览列表
|
|
178
|
+
- 支持图片大小(width/height)、填充模式(fit)配置
|
|
179
|
+
- 无图片时显示占位符或空内容
|
|
152
180
|
|
|
153
181
|
### map 示例
|
|
154
182
|
|
|
@@ -208,23 +236,21 @@ const Enables = [
|
|
|
208
236
|
```
|
|
209
237
|
- 使用自定义函数格式化显示内容
|
|
210
238
|
|
|
211
|
-
###
|
|
239
|
+
### 编辑型 渲染器
|
|
212
240
|
|
|
213
241
|
```ts
|
|
214
242
|
{
|
|
215
243
|
key: 'age',
|
|
216
244
|
label: '年龄',
|
|
217
|
-
render: '
|
|
218
|
-
editable: true,
|
|
219
|
-
editType: 'number',
|
|
245
|
+
render: 'input-number',
|
|
220
246
|
renderProps: { min: 0, max: 120 }
|
|
221
247
|
}
|
|
222
248
|
```
|
|
223
249
|
- 支持类型:input / number / select
|
|
224
250
|
- 支持事件:
|
|
225
|
-
- cellChange(row,
|
|
226
|
-
- cellBlur(row,
|
|
227
|
-
- cellEnter(row,
|
|
251
|
+
- cellChange(row, col) 值变化
|
|
252
|
+
- cellBlur(row, col) 失去焦点
|
|
253
|
+
- cellEnter(row, col) 回车事件(input)
|
|
228
254
|
### icon 示例
|
|
229
255
|
```ts
|
|
230
256
|
{
|
|
@@ -237,7 +263,21 @@ const Enables = [
|
|
|
237
263
|
- 支持网络图片 URL
|
|
238
264
|
- 支持 svg 字符串
|
|
239
265
|
- 支持 iconfont class
|
|
266
|
+
|
|
267
|
+
### button / link
|
|
268
|
+
```ts
|
|
269
|
+
{ key: 'action', label: '操作', render: 'button', renderProps: { label: '编辑', type: 'text' } }
|
|
270
|
+
{ key: 'url', label: '查看', render: 'link', renderProps: { label: '详情', href: 'https://example.com', blank: true } }
|
|
271
|
+
|
|
272
|
+
```
|
|
273
|
+
- 支持事件:
|
|
274
|
+
- cellClick(row, col) 点击事件
|
|
275
|
+
|
|
276
|
+
|
|
240
277
|
## 5. useTableColumns(列显隐缓存)
|
|
278
|
+
```ts
|
|
279
|
+
const { columns } = useTableColumns(defaultColumns, { pageKey: 'user-list', userId: currentUserId })
|
|
280
|
+
```
|
|
241
281
|
|
|
242
282
|
### 设计原则
|
|
243
283
|
|
|
@@ -257,26 +297,242 @@ const { columns } = useTableColumns(defaultColumns, {
|
|
|
257
297
|
- 不传则不启用缓存
|
|
258
298
|
|
|
259
299
|
---
|
|
300
|
+
## 6. 事件
|
|
301
|
+
- 支持类型:input / number / select
|
|
302
|
+
- 支持事件:
|
|
303
|
+
- cellChange(row, col) 值变化
|
|
304
|
+
- cellBlur(row, col) 失去焦点
|
|
305
|
+
- cellEnter(row, col) 回车事件(input)
|
|
306
|
+
- cellClick(row, col) 点击事件
|
|
307
|
+
|
|
260
308
|
|
|
261
|
-
##
|
|
309
|
+
## 7. 使用示例
|
|
262
310
|
|
|
263
311
|
```vue
|
|
312
|
+
<!-- 全局注册 -->
|
|
313
|
+
import { createApp } from 'vue'
|
|
314
|
+
import App from './App.vue'
|
|
315
|
+
import { SmartTable } from 'vue3-smart-table'
|
|
316
|
+
|
|
317
|
+
const app = createApp(App)
|
|
318
|
+
app.component('SmartTable', SmartTable)
|
|
319
|
+
app.mount('#app')
|
|
320
|
+
|
|
321
|
+
<!-- 或者局部注册 -->
|
|
322
|
+
<script setup>
|
|
323
|
+
import { SmartTable } from 'vue3-smart-table'
|
|
324
|
+
</script>
|
|
325
|
+
|
|
264
326
|
<SmartTable
|
|
265
|
-
:data="tableData"
|
|
266
327
|
v-model:columns="columns"
|
|
267
|
-
:
|
|
268
|
-
:
|
|
269
|
-
|
|
328
|
+
:border="true"
|
|
329
|
+
:loading="loading"
|
|
330
|
+
:pageKey="route.name"
|
|
331
|
+
:rowKey="'appId'"
|
|
332
|
+
:data="tabList"
|
|
333
|
+
:userId="userInfo?.userId"
|
|
334
|
+
:permissions="userStore.permissions"
|
|
270
335
|
@cellChange="onCellChange"
|
|
271
|
-
|
|
336
|
+
@cellBlur="onCellBlur"
|
|
337
|
+
@cellEnter="onCellEnter"
|
|
338
|
+
@cellClick="onCellClick" >
|
|
339
|
+
</SmartTable>
|
|
340
|
+
```
|
|
341
|
+
## 完整示例代码
|
|
342
|
+

|
|
343
|
+
```vue
|
|
344
|
+
<template>
|
|
345
|
+
<div class="demo-container" style="padding: 20px;">
|
|
346
|
+
<h2>Demo</h2>
|
|
347
|
+
<SmartTable
|
|
348
|
+
class="h-400px"
|
|
349
|
+
class-name="table-flex"
|
|
350
|
+
:border="true"
|
|
351
|
+
:loading="loading"
|
|
352
|
+
:pageKey="'route.name'"
|
|
353
|
+
:rowKey="'id'"
|
|
354
|
+
:data="tableData"
|
|
355
|
+
v-model:columns="columns"
|
|
356
|
+
:userId="'userId'"
|
|
357
|
+
:permissions="permissions"
|
|
358
|
+
@cell-blur="onCellBlur"
|
|
359
|
+
@cell-enter="onCellEnter"
|
|
360
|
+
@cell-change="onCellChange"
|
|
361
|
+
@cell-click="onCellClick"
|
|
362
|
+
/>
|
|
363
|
+
</div>
|
|
364
|
+
</template>
|
|
365
|
+
|
|
366
|
+
<script setup lang="ts" name="APP">
|
|
367
|
+
import { reactive, ref } from 'vue'
|
|
368
|
+
import { SmartTable } from 'vue3-smart-table'
|
|
369
|
+
const loading = ref(false)
|
|
370
|
+
const Enables = [
|
|
371
|
+
{ label: '启用', value: 1, listClass: 'primary' },
|
|
372
|
+
{ label: '禁用', value: 0, listClass: 'warning' }
|
|
373
|
+
]
|
|
374
|
+
const buttonConfigs = [
|
|
375
|
+
{ permission: 'edit', label: '编辑', type: 'primary', action: (row: any) => console.log(row)},
|
|
376
|
+
{ permission: 'view', label:'删除', type: 'danger', action: (row: any) => console.log(row)},
|
|
377
|
+
{ permission: 'copy', label: '复制', type: 'success', action: (row: any) => console.log(row)},
|
|
378
|
+
]
|
|
379
|
+
const permissions = ['edit', 'view']
|
|
380
|
+
const columns = ref([
|
|
381
|
+
{
|
|
382
|
+
type: 'selection',
|
|
383
|
+
key: 'index',
|
|
384
|
+
inControl: false,
|
|
385
|
+
},
|
|
386
|
+
{
|
|
387
|
+
type: 'index',
|
|
388
|
+
key: 'index',
|
|
389
|
+
label: '序号',
|
|
390
|
+
inControl: false,
|
|
391
|
+
columnProps: { width: 60}
|
|
392
|
+
},
|
|
393
|
+
{
|
|
394
|
+
type: 'operation',
|
|
395
|
+
key: 'opt',
|
|
396
|
+
label: '操作',
|
|
397
|
+
inControl: false,
|
|
398
|
+
buttons: buttonConfigs,
|
|
399
|
+
columnProps: {
|
|
400
|
+
fixed: "right",
|
|
401
|
+
align: "left"
|
|
402
|
+
}
|
|
403
|
+
},
|
|
404
|
+
{
|
|
405
|
+
key: 'action',
|
|
406
|
+
label: '按钮',
|
|
407
|
+
render: 'button',
|
|
408
|
+
renderProps: {
|
|
409
|
+
label: '编辑',
|
|
410
|
+
type: 'text'
|
|
411
|
+
}
|
|
412
|
+
},
|
|
413
|
+
{
|
|
414
|
+
key: 'url',
|
|
415
|
+
label: 'li单元格',
|
|
416
|
+
render: 'link',
|
|
417
|
+
renderProps: {
|
|
418
|
+
label: '查看详情',
|
|
419
|
+
href: 'https://example.com',
|
|
420
|
+
blank: true
|
|
421
|
+
}
|
|
422
|
+
},
|
|
423
|
+
{
|
|
424
|
+
key: "selectId",
|
|
425
|
+
label: "可选单元格",
|
|
426
|
+
visible: true,
|
|
427
|
+
render: 'select',
|
|
428
|
+
columnProps: { minWidth: 150},
|
|
429
|
+
renderProps:{
|
|
430
|
+
options: [
|
|
431
|
+
{label: '选中-1', value: 1},
|
|
432
|
+
{label: '选中-2', value: 2},
|
|
433
|
+
]
|
|
434
|
+
}
|
|
435
|
+
},
|
|
436
|
+
{
|
|
437
|
+
key: "orderNum",
|
|
438
|
+
label: "输入单元格",
|
|
439
|
+
visible: true,
|
|
440
|
+
render: 'input-number',
|
|
441
|
+
columnProps: { minWidth: 150, sortable: true}
|
|
442
|
+
},
|
|
443
|
+
{
|
|
444
|
+
key: 'avatar',
|
|
445
|
+
label: '头像',
|
|
446
|
+
render: 'img',
|
|
447
|
+
columnProps: { minWidth: 150, sortable: true},
|
|
448
|
+
renderProps: {
|
|
449
|
+
width: '60px',
|
|
450
|
+
height: '60px',
|
|
451
|
+
fit: 'cover',
|
|
452
|
+
placeholder: '--'
|
|
453
|
+
}
|
|
454
|
+
},
|
|
455
|
+
{
|
|
456
|
+
key: 'gallery',
|
|
457
|
+
label: '相册',
|
|
458
|
+
render: 'img',
|
|
459
|
+
columnProps: { minWidth: 150, sortable: true},
|
|
460
|
+
renderProps: {
|
|
461
|
+
width: '100px',
|
|
462
|
+
height: '100px'
|
|
463
|
+
}
|
|
464
|
+
},
|
|
465
|
+
{
|
|
466
|
+
key: 'name',
|
|
467
|
+
label: 'Name',
|
|
468
|
+
visible: true,
|
|
469
|
+
render: 'html'
|
|
470
|
+
},
|
|
471
|
+
{
|
|
472
|
+
key: "code",
|
|
473
|
+
label: "系统标识",
|
|
474
|
+
visible: true,
|
|
475
|
+
render: "copy",
|
|
476
|
+
columnProps: { minWidth: 160, sortable: true}
|
|
477
|
+
},
|
|
478
|
+
{
|
|
479
|
+
key: "status",
|
|
480
|
+
label: "状态",
|
|
481
|
+
visible: true,
|
|
482
|
+
render: "dict",
|
|
483
|
+
renderProps: {
|
|
484
|
+
options: Enables,
|
|
485
|
+
},
|
|
486
|
+
columnProps: { minWidth: 80, sortable: true}
|
|
487
|
+
},
|
|
488
|
+
{
|
|
489
|
+
key: 'map',
|
|
490
|
+
label: 'Map',
|
|
491
|
+
visible: true,
|
|
492
|
+
render: 'map',
|
|
493
|
+
renderProps: { options: { 1: 'Active', 0: 'Inactive' } }
|
|
494
|
+
},
|
|
495
|
+
{
|
|
496
|
+
key: "regionCode",
|
|
497
|
+
label: "区域",
|
|
498
|
+
visible: true,
|
|
499
|
+
render: "formatter",
|
|
500
|
+
columnProps: { minWidth: 100, sortable: true, align: 'left'},
|
|
501
|
+
formatter: (val: string) => `${val}-123`,
|
|
502
|
+
},
|
|
503
|
+
])
|
|
504
|
+
|
|
505
|
+
const tableData = reactive([
|
|
506
|
+
{ id: 1, name: 'Alice', code: '9527', status: 1, map: 1, regionCode:'海外', orderNum: 1, selectId: 1 },
|
|
507
|
+
{ id: 2, name: 'Bob', code: '9526', status: 1, map: 1, regionCode:'海外', orderNum: 1, selectId: 1 },
|
|
508
|
+
{ id: 3, name: 'Charlie', code: '9525', status: 0, map: 1, regionCode:'海外', orderNum: 1, selectId: 2 },
|
|
509
|
+
{ id: 3, name: 'Charlie', code: '9525', status: 0, map: 1, regionCode:'海外', orderNum: 1, selectId: 2,
|
|
510
|
+
avatar: 'https://iconfont.alicdn.com/p/illus_3d/file/UMAqlm6KX5gw/8e357f00-9a4e-44c4-b0c5-bbed255cff24.png' ,
|
|
511
|
+
gallery: [
|
|
512
|
+
'https://www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png',
|
|
513
|
+
'https://iconfont.alicdn.com/p/illus_3d/file/UMAqlm6KX5gw/8e357f00-9a4e-44c4-b0c5-bbed255cff24.png',
|
|
514
|
+
],
|
|
515
|
+
},
|
|
516
|
+
])
|
|
517
|
+
|
|
518
|
+
// 编辑单元格回调
|
|
519
|
+
const onCellBlur = (row: any, col: any) => {
|
|
520
|
+
console.log('cell blur:', row, col)
|
|
521
|
+
}
|
|
522
|
+
const onCellEnter = (row: any, col: any) => {
|
|
523
|
+
console.log('cell enter:', row, col)
|
|
524
|
+
}
|
|
525
|
+
const onCellChange = (row: any, col: any) => {
|
|
526
|
+
console.log('cell Change:', row, col)
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
const onCellClick = (row: any, col: any) => {
|
|
530
|
+
console.log('cell button click:', row, col)
|
|
531
|
+
}
|
|
532
|
+
</script>
|
|
533
|
+
|
|
272
534
|
```
|
|
273
535
|
|
|
274
|
-
## 7. 设计边界说明
|
|
275
|
-
|
|
276
|
-
- SmartTable **不关心权限系统如何实现**
|
|
277
|
-
- permission 只是 string 比对
|
|
278
|
-
- renderer 只负责 UI,不处理权限
|
|
279
|
-
- 操作列是否显示由 SmartTable 统一决策
|
|
280
536
|
|
|
281
537
|
|
|
282
538
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),k=require("element-plus"),V=e.defineComponent({__name:"input",props:{row:{},col:{},onCellBlur:{type:Function},onCellEnter:{type:Function}},setup(n){const t=n,r=e.ref(t.row[t.col.key]);e.watch(r,s=>{t.row[t.col.key]=s});const o=()=>{var s;return(s=t.onCellBlur)==null?void 0:s.call(t,t.row,t.col)},l=()=>{var s;return(s=t.onCellEnter)==null?void 0:s.call(t,t.row,t.col)};return(s,c)=>{const a=e.resolveComponent("el-input");return e.openBlock(),e.createBlock(a,e.mergeProps({modelValue:r.value,"onUpdate:modelValue":c[0]||(c[0]=d=>r.value=d)},{placeholder:"",size:"small",clearable:!0,...n.col.renderProps},{onBlur:o,onKeyup:e.withKeys(l,["enter"])}),null,16,["modelValue"])}}}),F=e.defineComponent({__name:"inputNumber",props:{row:{},col:{},onCellChange:{type:Function},onCellBlur:{type:Function},onCellEnter:{type:Function}},setup(n){const t=n,r=e.ref(t.row[t.col.key]);e.watch(r,s=>{var c;t.row[t.col.key]=s,(c=t.onCellChange)==null||c.call(t,t.row,t.col)});const o=()=>{var s;return(s=t.onCellBlur)==null?void 0:s.call(t,t.row,t.col)},l=()=>{var s;return(s=t.onCellEnter)==null?void 0:s.call(t,t.row,t.col)};return(s,c)=>{const a=e.resolveComponent("el-input-number");return e.openBlock(),e.createBlock(a,e.mergeProps({modelValue:r.value,"onUpdate:modelValue":c[0]||(c[0]=d=>r.value=d)},{min:0,max:99999,controls:!1,size:"small",...n.col.renderProps},{onBlur:o,onKeyup:e.withKeys(l,["enter"])}),null,16,["modelValue"])}}}),A=e.defineComponent({__name:"select",props:{row:{},col:{},onCellChange:{type:Function},onCellBlur:{type:Function},onCellEnter:{type:Function}},setup(n){const t=n,r=e.ref(t.row[t.col.key]);e.watch(r,c=>{t.row[t.col.key]=c});const o=()=>{var c;return(c=t.onCellChange)==null?void 0:c.call(t,t.row,t.col)},l=()=>{var c;return(c=t.onCellBlur)==null?void 0:c.call(t,t.row,t.col)},s=()=>{var c;return(c=t.onCellEnter)==null?void 0:c.call(t,t.row,t.col)};return(c,a)=>{const d=e.resolveComponent("el-option"),u=e.resolveComponent("el-select");return e.openBlock(),e.createBlock(u,e.mergeProps({modelValue:r.value,"onUpdate:modelValue":a[0]||(a[0]=f=>r.value=f)},{placeholder:"请选择",size:"small",clearable:!0,...n.col.renderProps},{onChange:o,onBlur:l,onKeyup:e.withKeys(s,["enter"])}),{default:e.withCtx(()=>{var f;return[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(((f=n.col.renderProps)==null?void 0:f.options)||[],p=>(e.openBlock(),e.createBlock(d,{key:p.value,label:p.label,value:p.value},null,8,["label","value"]))),128))]}),_:1},16,["modelValue"])}}}),x=n=>e.defineComponent({props:["row","col","onCellChange","onCellBlur","onCellEnter","onClick"],setup(t){return()=>e.h(n,t)}});function K(n){return typeof n.formatter=="function"}function O(){return{input:x(V),"input-number":x(F),select:x(A),button:n=>{const t=n.col.renderProps||{};return e.h(k.ElButton,{type:t.type||"primary",...t,onClick:()=>{var r;return(r=n.onClick)==null?void 0:r.call(n,n.row,n.col)}},()=>t.label||n.row[n.col.key])},link:n=>{const t=n.col.renderProps||{};return e.h("a",{href:t.href||"#",target:t.blank?"_blank":"_self",style:t.style||"color:#409EFF;cursor:pointer;",onClick:r=>{var o;r.preventDefault(),(o=n.onClick)==null||o.call(n,n.row,n.col)}},t.label||n.row[n.col.key])},html:n=>{var t;return e.h("div",{class:"line-clamp-2",innerHTML:n.row[n.col.key]??"",...((t=n.col)==null?void 0:t.renderProps)||{}})},copy:n=>{const t=n.row[n.col.key]??"";return e.h("div",{class:"copy-wrapper",style:"position: relative; display: inline-block;"},[e.h("span",{class:"copy-text line-clamp-1",style:"padding-right: 20px;"},t),e.h("span",{class:"copy-btn",style:`
|
|
2
2
|
position: absolute;
|
|
3
3
|
right: 0;
|
|
4
4
|
top: 50%;
|
|
@@ -8,4 +8,14 @@
|
|
|
8
8
|
font-size: 12px;
|
|
9
9
|
color: #409EFF;
|
|
10
10
|
user-select: none;
|
|
11
|
-
`,onClick:()=>{if(t)try{if(navigator.clipboard&&navigator.clipboard.writeText)navigator.clipboard.writeText(t).then(()=>{
|
|
11
|
+
`,onClick:()=>{if(t)try{if(navigator.clipboard&&navigator.clipboard.writeText)navigator.clipboard.writeText(t).then(()=>{k.ElMessage.success("复制成功")}).catch(()=>{k.ElMessage.error("复制失败")});else{const r=document.createElement("textarea");r.value=t,r.style.position="fixed",r.style.opacity="0",document.body.appendChild(r),r.select();const o=document.execCommand("copy");document.body.removeChild(r),o?k.ElMessage.success("复制成功"):k.ElMessage.error("复制失败")}}catch{k.ElMessage.error("复制失败")}}},"📋")])},img:n=>{var c;const t=n.row[n.col.key],r=((c=n.col)==null?void 0:c.renderProps)||{},l=t?Array.isArray(t)?t.filter(a=>a&&typeof a=="string"):[t]:[];if(l.length===0)return r.placeholder||"";const s={width:r.width||"80px",height:r.height||"80px",marginRight:l.length>1?"4px":"0",...r.style||{}};return l.length===1?e.h(k.ElImage,{src:l[0],previewSrcList:r.previewSrcList||l,fit:r.fit||"contain",style:s,...r}):(console.log(r.previewSrcList),e.h("div",{style:"display: flex; align-items: center; position: relative"},[e.h(k.ElImage,{src:l[0],previewSrcList:r.previewSrcList||l,fit:r.fit||"contain",style:s,...r}),l.length>1&&e.h("span",{style:`
|
|
12
|
+
margin-left: 8px;
|
|
13
|
+
font-size: 12px;
|
|
14
|
+
color: #666;
|
|
15
|
+
background: #f0f0f0;
|
|
16
|
+
padding: 2px 6px;
|
|
17
|
+
border-radius: 2px;
|
|
18
|
+
position: absolute;
|
|
19
|
+
top: 0;
|
|
20
|
+
right: 0;
|
|
21
|
+
`,title:`共 ${l.length} 张图片`},`+${l.length-1}`)]))},dict:n=>{const t=n.row[n.col.key],r=n.col.renderProps||{},o=r.options??[],l=r.showValue??!1;if(t==null||t==="")return"";const s=Array.isArray(t)?t.map(String):[String(t)],c=o.filter(u=>s.includes(String(u.value))),a=s.filter(u=>!o.some(f=>String(f.value)===u)),d=c.map((u,f)=>e.h(k.ElTag,{key:u.value,type:u.listClass,class:u.cssClass,disableTransitions:!0},{default:()=>u.label+" "}));return l&&a.length>0&&d.push(e.h("span",{},a.join(" "))),e.h("div",{},d)},map:n=>{var o;const t=n.row[n.col.key],r=((o=n.col.renderProps)==null?void 0:o.options)??{};return t!=null?r[t]??"":""},formatter:n=>{var l;const{col:t,row:r}=n,o=r[t.key];return K(t)?(l=t.formatter)==null?void 0:l.call(t,o,r):o??""},icon:n=>{const t=n.row[n.col.key]??"",r=n.col.renderProps||{};return t?/^https?:\/\//.test(t)?e.h(k.ElImage,{src:t,previewSrcList:[t],fit:"contain",style:"width:40px;height:40px",...r}):/^\s*<svg[\s\S]*<\/svg>\s*$/.test(t)?e.h("div",{innerHTML:t,style:`width:40px;height:40px;display:inline-block;${r.style||""}`,...r}):e.h("i",{class:t,style:`font-size:20px;${r.style||""}`,...r}):""}}}function I(n,t=10,r=[]){const l="*:*:*",s=i=>{if(!i)return!0;const m=Array.isArray(i)?i:[i];return r.some(y=>y===l||m.includes(y))},c=e.computed(()=>n.some(i=>s(i.permission))),a=e.computed(()=>n.filter(m=>s(m.permission)).slice(0,t).reduce((m,y)=>m+(y.width??55),0)),d=(i,m)=>s(i.permission)&&(i.visible?i.visible(m):!0),u=i=>n.filter(y=>d(y,i)).slice(0,t).reduce((y,w)=>y+(w.width??55),0);return{hasAnyButton:c,optWidth:a,hasAnyVisibleButton:i=>i!=null&&i.length?i.some(m=>n.some(y=>d(y,m))):!1,getMaxOptWidth:i=>i!=null&&i.length?i.reduce((m,y)=>Math.max(m,u(y)),0):a.value,getVisibleButtons:i=>n.filter(m=>d(m,i)).slice(0,t)}}const L=["title"],M=e.defineComponent({__name:"index",props:{col:{type:Object,required:!0},permissions:{type:Array,default:()=>[]}},emits:["cellBlur","cellEnter","cellChange","cellClick"],setup(n,{emit:t}){const r=n,o=t,{col:l}=e.toRefs(r),s=(h,C)=>o("cellChange",h,C),c=(h,C)=>o("cellBlur",h,C),a=(h,C)=>o("cellEnter",h,C),d=(h,C)=>o("cellClick",h,C),u=O(),{hasAnyButton:f,hasAnyVisibleButton:p,optWidth:g,getMaxOptWidth:i,getVisibleButtons:m}=I(l.value.buttons||[],l.value.maxbtn??10,r.permissions||[]),y=e.computed(()=>(l.value.buttons||[]).length?(l.value.__rows||[]).length?p(l.value.__rows||[]):f.value:!1),w=e.computed(()=>l.value.__rows?i(l.value.__rows):g.value);function P(h){return!(h.type==="selection"||h.type==="index"||h.type==="operation"&&!y.value||h.visible===!1)}return(h,C)=>{const B=e.resolveComponent("el-table-column"),S=e.resolveComponent("el-button");return e.unref(l).type==="selection"?(e.openBlock(),e.createBlock(B,e.mergeProps({key:0,type:"selection"},e.unref(l).columnProps),null,16)):e.unref(l).type==="index"?(e.openBlock(),e.createBlock(B,e.mergeProps({key:1,type:"index",label:e.unref(l).label||"#",align:"center"},e.unref(l).columnProps),null,16,["label"])):e.unref(l).type==="operation"&&y.value?(e.openBlock(),e.createBlock(B,e.mergeProps({key:2,label:e.unref(l).label||"操作",align:"center"},{...e.unref(l).columnProps,width:w.value}),{default:e.withCtx(({row:b})=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(m)(b),v=>(e.openBlock(),e.createBlock(S,{key:v.label,type:v.type||"primary",link:"",onClick:_=>v.action(b)},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(v.label),1)]),_:2},1032,["type","onClick"]))),128))]),_:1},16,["label"])):P(e.unref(l))?(e.openBlock(),e.createBlock(B,e.mergeProps({key:3,prop:e.unref(l).key,label:e.unref(l).label,align:"center"},e.unref(l).columnProps||{}),{default:e.withCtx(({row:b})=>{var v,_;return[e.unref(l).render&&e.unref(u)[e.unref(l).render]?(e.openBlock(),e.createBlock(e.resolveDynamicComponent(e.unref(u)[e.unref(l).render]),{key:0,row:b,col:e.unref(l),onCellChange:s,onCellBlur:c,onCellEnter:a,onClick:d},null,40,["row","col"])):(e.openBlock(),e.createElementBlock("span",{key:1,style:e.normalizeStyle(((v=e.unref(l).renderProps)==null?void 0:v.style)||""),class:e.normalizeClass(((_=e.unref(l).renderProps)==null?void 0:_.class)||""),title:b[e.unref(l).key]},e.toDisplayString(b[e.unref(l).key]),15,L))]}),_:1},16,["prop","label"])):e.createCommentVNode("",!0)}}}),$="table_columns_";function T(n,t){return`${$}${n}_${t}`}function E(n,t){if(!(t!=null&&t.length))return n;const r=new Map(t.map(o=>[o.key,o]));return n.map(o=>{const l=r.get(o.key);return l?{...o,visible:typeof l.visible=="boolean"?l.visible:o.visible}:o})}function W(n,t){const{pageKey:r,userId:o,storage:l=localStorage}=t||{},c=o?T(o,r||""):null,a=c?l.getItem(c):null,d=e.ref(E(n,a?JSON.parse(a):[]));return e.watch(d,u=>{if(!c)return;const f=u.map(p=>({key:p.key,visible:p.visible,columnOpts:p.columnOpts}));l.setItem(c,JSON.stringify(f))},{deep:!0}),{columns:d,setColumns(u){d.value=E(n,u),c&&l.setItem(c,JSON.stringify(u))},resetColumns(){d.value=n,c&&l.removeItem(c)}}}const z=e.defineComponent({__name:"index",props:{data:{type:Array,default:()=>[]},columns:{type:Array,default:()=>[]},pageKey:String,rowKey:{type:String,default:"id"},loading:{type:Boolean,default:!1},permissions:{type:Array,default:()=>[]},userId:{type:[String,Number],default:""}},emits:["update:columns","cellChange","cellBlur","cellEnter","cell-click"],setup(n,{expose:t,emit:r}){const o=n,l=r,{columns:s}=W(o.columns,{pageKey:o.pageKey??"",userId:o.userId??""});e.watch(s,p=>l("update:columns",p),{deep:!0,immediate:!0});const c=(p,g)=>l("cellChange",p,g),a=(p,g)=>{l("cellBlur",p,g)},d=(p,g)=>{console.log("enter"),l("cellEnter",p,g)},u=(p,g)=>{g&&l("cell-click",p,g)},f=e.ref();return t({tableRef:f}),(p,g)=>{const i=e.resolveComponent("el-table"),m=e.resolveDirective("loading");return e.withDirectives((e.openBlock(),e.createBlock(i,e.mergeProps({ref_key:"tableRef",ref:f},p.$attrs,{data:n.data,"row-key":n.rowKey,class:"smart-table"}),{default:e.withCtx(()=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(s),y=>(e.openBlock(),e.createBlock(M,{key:y.key,col:y,permissions:n.permissions,onCellChange:c,onCellBlur:a,onCellEnter:d,onCellClick:u},null,8,["col","permissions"]))),128))]),_:1},16,["data","row-key"])),[[m,n.loading]])}}}),D=(n,t)=>{const r=n.__vccOpts||n;for(const[o,l]of t)r[o]=l;return r},N=D(z,[["__scopeId","data-v-338b77db"]]);exports.SmartTable=N;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { defineComponent as
|
|
2
|
-
import { ElImage as L, ElTag as
|
|
3
|
-
const
|
|
1
|
+
import { defineComponent as E, ref as V, watch as A, resolveComponent as x, createBlock as b, openBlock as h, mergeProps as _, withKeys as M, withCtx as P, createElementBlock as O, Fragment as T, renderList as z, h as f, computed as K, toRefs as U, createCommentVNode as j, unref as c, createTextVNode as H, toDisplayString as D, resolveDynamicComponent as q, normalizeClass as X, normalizeStyle as Y, resolveDirective as G, withDirectives as Q } from "vue";
|
|
2
|
+
import { ElImage as L, ElTag as Z, ElMessage as S, ElButton as ee } from "element-plus";
|
|
3
|
+
const te = /* @__PURE__ */ E({
|
|
4
4
|
__name: "input",
|
|
5
5
|
props: {
|
|
6
6
|
row: {},
|
|
@@ -9,29 +9,29 @@ const Q = /* @__PURE__ */ x({
|
|
|
9
9
|
onCellEnter: { type: Function }
|
|
10
10
|
},
|
|
11
11
|
setup(t) {
|
|
12
|
-
const e = t,
|
|
13
|
-
|
|
14
|
-
e.row[e.col.key] =
|
|
12
|
+
const e = t, l = V(e.row[e.col.key]);
|
|
13
|
+
A(l, (s) => {
|
|
14
|
+
e.row[e.col.key] = s;
|
|
15
15
|
});
|
|
16
16
|
const r = () => {
|
|
17
|
-
var
|
|
18
|
-
return (
|
|
19
|
-
},
|
|
20
|
-
var
|
|
21
|
-
return (
|
|
17
|
+
var s;
|
|
18
|
+
return (s = e.onCellBlur) == null ? void 0 : s.call(e, e.row, e.col);
|
|
19
|
+
}, n = () => {
|
|
20
|
+
var s;
|
|
21
|
+
return (s = e.onCellEnter) == null ? void 0 : s.call(e, e.row, e.col);
|
|
22
22
|
};
|
|
23
|
-
return (
|
|
24
|
-
const
|
|
25
|
-
return
|
|
26
|
-
modelValue:
|
|
27
|
-
"onUpdate:modelValue": o[0] || (o[0] = (
|
|
23
|
+
return (s, o) => {
|
|
24
|
+
const a = x("el-input");
|
|
25
|
+
return h(), b(a, _({
|
|
26
|
+
modelValue: l.value,
|
|
27
|
+
"onUpdate:modelValue": o[0] || (o[0] = (y) => l.value = y)
|
|
28
28
|
}, { placeholder: "", size: "small", clearable: !0, ...t.col.renderProps }, {
|
|
29
29
|
onBlur: r,
|
|
30
|
-
onKeyup: M(
|
|
30
|
+
onKeyup: M(n, ["enter"])
|
|
31
31
|
}), null, 16, ["modelValue"]);
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
|
-
}),
|
|
34
|
+
}), ne = /* @__PURE__ */ E({
|
|
35
35
|
__name: "inputNumber",
|
|
36
36
|
props: {
|
|
37
37
|
row: {},
|
|
@@ -41,30 +41,30 @@ const Q = /* @__PURE__ */ x({
|
|
|
41
41
|
onCellEnter: { type: Function }
|
|
42
42
|
},
|
|
43
43
|
setup(t) {
|
|
44
|
-
const e = t,
|
|
45
|
-
|
|
44
|
+
const e = t, l = V(e.row[e.col.key]);
|
|
45
|
+
A(l, (s) => {
|
|
46
46
|
var o;
|
|
47
|
-
e.row[e.col.key] =
|
|
47
|
+
e.row[e.col.key] = s, (o = e.onCellChange) == null || o.call(e, e.row, e.col);
|
|
48
48
|
});
|
|
49
49
|
const r = () => {
|
|
50
|
-
var
|
|
51
|
-
return (
|
|
52
|
-
},
|
|
53
|
-
var
|
|
54
|
-
return (
|
|
50
|
+
var s;
|
|
51
|
+
return (s = e.onCellBlur) == null ? void 0 : s.call(e, e.row, e.col);
|
|
52
|
+
}, n = () => {
|
|
53
|
+
var s;
|
|
54
|
+
return (s = e.onCellEnter) == null ? void 0 : s.call(e, e.row, e.col);
|
|
55
55
|
};
|
|
56
|
-
return (
|
|
57
|
-
const
|
|
58
|
-
return
|
|
59
|
-
modelValue:
|
|
60
|
-
"onUpdate:modelValue": o[0] || (o[0] = (
|
|
56
|
+
return (s, o) => {
|
|
57
|
+
const a = x("el-input-number");
|
|
58
|
+
return h(), b(a, _({
|
|
59
|
+
modelValue: l.value,
|
|
60
|
+
"onUpdate:modelValue": o[0] || (o[0] = (y) => l.value = y)
|
|
61
61
|
}, { min: 0, max: 99999, controls: !1, size: "small", ...t.col.renderProps }, {
|
|
62
62
|
onBlur: r,
|
|
63
|
-
onKeyup: M(
|
|
63
|
+
onKeyup: M(n, ["enter"])
|
|
64
64
|
}), null, 16, ["modelValue"]);
|
|
65
65
|
};
|
|
66
66
|
}
|
|
67
|
-
}),
|
|
67
|
+
}), le = /* @__PURE__ */ E({
|
|
68
68
|
__name: "select",
|
|
69
69
|
props: {
|
|
70
70
|
row: {},
|
|
@@ -74,37 +74,37 @@ const Q = /* @__PURE__ */ x({
|
|
|
74
74
|
onCellEnter: { type: Function }
|
|
75
75
|
},
|
|
76
76
|
setup(t) {
|
|
77
|
-
const e = t,
|
|
78
|
-
|
|
77
|
+
const e = t, l = V(e.row[e.col.key]);
|
|
78
|
+
A(l, (o) => {
|
|
79
79
|
e.row[e.col.key] = o;
|
|
80
80
|
});
|
|
81
81
|
const r = () => {
|
|
82
82
|
var o;
|
|
83
83
|
return (o = e.onCellChange) == null ? void 0 : o.call(e, e.row, e.col);
|
|
84
|
-
},
|
|
84
|
+
}, n = () => {
|
|
85
85
|
var o;
|
|
86
86
|
return (o = e.onCellBlur) == null ? void 0 : o.call(e, e.row, e.col);
|
|
87
|
-
},
|
|
87
|
+
}, s = () => {
|
|
88
88
|
var o;
|
|
89
89
|
return (o = e.onCellEnter) == null ? void 0 : o.call(e, e.row, e.col);
|
|
90
90
|
};
|
|
91
|
-
return (o,
|
|
92
|
-
const
|
|
93
|
-
return
|
|
94
|
-
modelValue:
|
|
95
|
-
"onUpdate:modelValue":
|
|
91
|
+
return (o, a) => {
|
|
92
|
+
const y = x("el-option"), u = x("el-select");
|
|
93
|
+
return h(), b(u, _({
|
|
94
|
+
modelValue: l.value,
|
|
95
|
+
"onUpdate:modelValue": a[0] || (a[0] = (g) => l.value = g)
|
|
96
96
|
}, { placeholder: "请选择", size: "small", clearable: !0, ...t.col.renderProps }, {
|
|
97
97
|
onChange: r,
|
|
98
|
-
onBlur:
|
|
99
|
-
onKeyup: M(
|
|
98
|
+
onBlur: n,
|
|
99
|
+
onKeyup: M(s, ["enter"])
|
|
100
100
|
}), {
|
|
101
101
|
default: P(() => {
|
|
102
|
-
var
|
|
102
|
+
var g;
|
|
103
103
|
return [
|
|
104
|
-
(
|
|
105
|
-
key:
|
|
106
|
-
label:
|
|
107
|
-
value:
|
|
104
|
+
(h(!0), O(T, null, z(((g = t.col.renderProps) == null ? void 0 : g.options) || [], (d) => (h(), b(y, {
|
|
105
|
+
key: d.value,
|
|
106
|
+
label: d.label,
|
|
107
|
+
value: d.value
|
|
108
108
|
}, null, 8, ["label", "value"]))), 128))
|
|
109
109
|
];
|
|
110
110
|
}),
|
|
@@ -112,46 +112,46 @@ const Q = /* @__PURE__ */ x({
|
|
|
112
112
|
}, 16, ["modelValue"]);
|
|
113
113
|
};
|
|
114
114
|
}
|
|
115
|
-
}), W = (t) =>
|
|
115
|
+
}), W = (t) => E({
|
|
116
116
|
props: ["row", "col", "onCellChange", "onCellBlur", "onCellEnter", "onClick"],
|
|
117
117
|
setup(e) {
|
|
118
|
-
return () =>
|
|
118
|
+
return () => f(t, e);
|
|
119
119
|
}
|
|
120
120
|
});
|
|
121
|
-
function
|
|
121
|
+
function re(t) {
|
|
122
122
|
return typeof t.formatter == "function";
|
|
123
123
|
}
|
|
124
|
-
function
|
|
124
|
+
function oe() {
|
|
125
125
|
return {
|
|
126
|
-
input: W(
|
|
127
|
-
"input-number": W(
|
|
128
|
-
select: W(
|
|
126
|
+
input: W(te),
|
|
127
|
+
"input-number": W(ne),
|
|
128
|
+
select: W(le),
|
|
129
129
|
button: (t) => {
|
|
130
130
|
const e = t.col.renderProps || {};
|
|
131
|
-
return
|
|
131
|
+
return f(ee, {
|
|
132
132
|
type: e.type || "primary",
|
|
133
133
|
...e,
|
|
134
134
|
onClick: () => {
|
|
135
|
-
var
|
|
136
|
-
return (
|
|
135
|
+
var l;
|
|
136
|
+
return (l = t.onClick) == null ? void 0 : l.call(t, t.row, t.col);
|
|
137
137
|
}
|
|
138
138
|
}, () => e.label || t.row[t.col.key]);
|
|
139
139
|
},
|
|
140
140
|
link: (t) => {
|
|
141
141
|
const e = t.col.renderProps || {};
|
|
142
|
-
return
|
|
142
|
+
return f("a", {
|
|
143
143
|
href: e.href || "#",
|
|
144
144
|
target: e.blank ? "_blank" : "_self",
|
|
145
145
|
style: e.style || "color:#409EFF;cursor:pointer;",
|
|
146
|
-
onClick: (
|
|
146
|
+
onClick: (l) => {
|
|
147
147
|
var r;
|
|
148
|
-
|
|
148
|
+
l.preventDefault(), (r = t.onClick) == null || r.call(t, t.row, t.col);
|
|
149
149
|
}
|
|
150
150
|
}, e.label || t.row[t.col.key]);
|
|
151
151
|
},
|
|
152
152
|
html: (t) => {
|
|
153
153
|
var e;
|
|
154
|
-
return
|
|
154
|
+
return f("div", {
|
|
155
155
|
class: "line-clamp-2",
|
|
156
156
|
innerHTML: t.row[t.col.key] ?? "",
|
|
157
157
|
...((e = t.col) == null ? void 0 : e.renderProps) || {}
|
|
@@ -159,18 +159,18 @@ function ne() {
|
|
|
159
159
|
},
|
|
160
160
|
copy: (t) => {
|
|
161
161
|
const e = t.row[t.col.key] ?? "";
|
|
162
|
-
return
|
|
162
|
+
return f(
|
|
163
163
|
"div",
|
|
164
164
|
{
|
|
165
165
|
class: "copy-wrapper",
|
|
166
166
|
style: "position: relative; display: inline-block;"
|
|
167
167
|
},
|
|
168
168
|
[
|
|
169
|
-
|
|
169
|
+
f("span", {
|
|
170
170
|
class: "copy-text line-clamp-1",
|
|
171
171
|
style: "padding-right: 20px;"
|
|
172
172
|
}, e),
|
|
173
|
-
|
|
173
|
+
f(
|
|
174
174
|
"span",
|
|
175
175
|
{
|
|
176
176
|
class: "copy-btn",
|
|
@@ -190,18 +190,18 @@ function ne() {
|
|
|
190
190
|
try {
|
|
191
191
|
if (navigator.clipboard && navigator.clipboard.writeText)
|
|
192
192
|
navigator.clipboard.writeText(e).then(() => {
|
|
193
|
-
|
|
193
|
+
S.success("复制成功");
|
|
194
194
|
}).catch(() => {
|
|
195
|
-
|
|
195
|
+
S.error("复制失败");
|
|
196
196
|
});
|
|
197
197
|
else {
|
|
198
|
-
const
|
|
199
|
-
|
|
198
|
+
const l = document.createElement("textarea");
|
|
199
|
+
l.value = e, l.style.position = "fixed", l.style.opacity = "0", document.body.appendChild(l), l.select();
|
|
200
200
|
const r = document.execCommand("copy");
|
|
201
|
-
document.body.removeChild(
|
|
201
|
+
document.body.removeChild(l), r ? S.success("复制成功") : S.error("复制失败");
|
|
202
202
|
}
|
|
203
203
|
} catch {
|
|
204
|
-
|
|
204
|
+
S.error("复制失败");
|
|
205
205
|
}
|
|
206
206
|
}
|
|
207
207
|
},
|
|
@@ -212,85 +212,119 @@ function ne() {
|
|
|
212
212
|
);
|
|
213
213
|
},
|
|
214
214
|
img: (t) => {
|
|
215
|
-
var
|
|
216
|
-
const e = t.row[t.col.key]
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
215
|
+
var o;
|
|
216
|
+
const e = t.row[t.col.key], l = ((o = t.col) == null ? void 0 : o.renderProps) || {}, n = e ? Array.isArray(e) ? e.filter((a) => a && typeof a == "string") : [e] : [];
|
|
217
|
+
if (n.length === 0)
|
|
218
|
+
return l.placeholder || "";
|
|
219
|
+
const s = {
|
|
220
|
+
width: l.width || "80px",
|
|
221
|
+
height: l.height || "80px",
|
|
222
|
+
marginRight: n.length > 1 ? "4px" : "0",
|
|
223
|
+
...l.style || {}
|
|
224
|
+
};
|
|
225
|
+
return n.length === 1 ? f(L, {
|
|
226
|
+
src: n[0],
|
|
227
|
+
previewSrcList: l.previewSrcList || n,
|
|
228
|
+
fit: l.fit || "contain",
|
|
229
|
+
style: s,
|
|
230
|
+
...l
|
|
231
|
+
}) : (console.log(l.previewSrcList), f("div", {
|
|
232
|
+
style: "display: flex; align-items: center; position: relative"
|
|
233
|
+
}, [
|
|
234
|
+
// 显示第一张图片,点击可预览所有
|
|
235
|
+
f(L, {
|
|
236
|
+
src: n[0],
|
|
237
|
+
previewSrcList: l.previewSrcList || n,
|
|
238
|
+
fit: l.fit || "contain",
|
|
239
|
+
style: s,
|
|
240
|
+
...l
|
|
241
|
+
}),
|
|
242
|
+
// 如果图片数量大于1,显示剩余图片数量
|
|
243
|
+
n.length > 1 && f("span", {
|
|
244
|
+
style: `
|
|
245
|
+
margin-left: 8px;
|
|
246
|
+
font-size: 12px;
|
|
247
|
+
color: #666;
|
|
248
|
+
background: #f0f0f0;
|
|
249
|
+
padding: 2px 6px;
|
|
250
|
+
border-radius: 2px;
|
|
251
|
+
position: absolute;
|
|
252
|
+
top: 0;
|
|
253
|
+
right: 0;
|
|
254
|
+
`,
|
|
255
|
+
title: `共 ${n.length} 张图片`
|
|
256
|
+
}, `+${n.length - 1}`)
|
|
257
|
+
]));
|
|
224
258
|
},
|
|
225
259
|
dict: (t) => {
|
|
226
|
-
const e = t.row[t.col.key],
|
|
260
|
+
const e = t.row[t.col.key], l = t.col.renderProps || {}, r = l.options ?? [], n = l.showValue ?? !1;
|
|
227
261
|
if (e == null || e === "") return "";
|
|
228
|
-
const
|
|
229
|
-
|
|
230
|
-
{ key:
|
|
231
|
-
{ default: () =>
|
|
262
|
+
const s = Array.isArray(e) ? e.map(String) : [String(e)], o = r.filter((u) => s.includes(String(u.value))), a = s.filter((u) => !r.some((g) => String(g.value) === u)), y = o.map((u, g) => f(
|
|
263
|
+
Z,
|
|
264
|
+
{ key: u.value, type: u.listClass, class: u.cssClass, disableTransitions: !0 },
|
|
265
|
+
{ default: () => u.label + " " }
|
|
232
266
|
));
|
|
233
|
-
return
|
|
267
|
+
return n && a.length > 0 && y.push(f("span", {}, a.join(" "))), f("div", {}, y);
|
|
234
268
|
},
|
|
235
269
|
map: (t) => {
|
|
236
270
|
var r;
|
|
237
|
-
const e = t.row[t.col.key],
|
|
238
|
-
return e != null ?
|
|
271
|
+
const e = t.row[t.col.key], l = ((r = t.col.renderProps) == null ? void 0 : r.options) ?? {};
|
|
272
|
+
return e != null ? l[e] ?? "" : "";
|
|
239
273
|
},
|
|
240
274
|
formatter: (t) => {
|
|
241
|
-
var
|
|
242
|
-
const { col: e, row:
|
|
243
|
-
return
|
|
275
|
+
var n;
|
|
276
|
+
const { col: e, row: l } = t, r = l[e.key];
|
|
277
|
+
return re(e) ? (n = e.formatter) == null ? void 0 : n.call(e, r, l) : r ?? "";
|
|
244
278
|
},
|
|
245
279
|
icon: (t) => {
|
|
246
|
-
const e = t.row[t.col.key] ?? "",
|
|
247
|
-
return e ? /^https?:\/\//.test(e) ?
|
|
280
|
+
const e = t.row[t.col.key] ?? "", l = t.col.renderProps || {};
|
|
281
|
+
return e ? /^https?:\/\//.test(e) ? f(L, {
|
|
248
282
|
src: e,
|
|
249
283
|
previewSrcList: [e],
|
|
250
284
|
fit: "contain",
|
|
251
285
|
style: "width:40px;height:40px",
|
|
252
|
-
...
|
|
253
|
-
}) : /^\s*<svg[\s\S]*<\/svg>\s*$/.test(e) ?
|
|
286
|
+
...l
|
|
287
|
+
}) : /^\s*<svg[\s\S]*<\/svg>\s*$/.test(e) ? f("div", {
|
|
254
288
|
innerHTML: e,
|
|
255
|
-
style: `width:40px;height:40px;display:inline-block;${
|
|
256
|
-
...
|
|
257
|
-
}) :
|
|
289
|
+
style: `width:40px;height:40px;display:inline-block;${l.style || ""}`,
|
|
290
|
+
...l
|
|
291
|
+
}) : f("i", {
|
|
258
292
|
class: e,
|
|
259
293
|
// val 直接当 className
|
|
260
|
-
style: `font-size:20px;${
|
|
261
|
-
...
|
|
294
|
+
style: `font-size:20px;${l.style || ""}`,
|
|
295
|
+
...l
|
|
262
296
|
}) : "";
|
|
263
297
|
}
|
|
264
298
|
};
|
|
265
299
|
}
|
|
266
|
-
function
|
|
267
|
-
const
|
|
268
|
-
if (!
|
|
269
|
-
const m = Array.isArray(
|
|
270
|
-
return
|
|
271
|
-
(p) => p ===
|
|
300
|
+
function se(t, e = 10, l = []) {
|
|
301
|
+
const n = "*:*:*", s = (i) => {
|
|
302
|
+
if (!i) return !0;
|
|
303
|
+
const m = Array.isArray(i) ? i : [i];
|
|
304
|
+
return l.some(
|
|
305
|
+
(p) => p === n || m.includes(p)
|
|
272
306
|
);
|
|
273
|
-
}, o =
|
|
307
|
+
}, o = K(() => t.some((i) => s(i.permission))), a = K(() => t.filter((m) => s(m.permission)).slice(0, e).reduce(
|
|
274
308
|
(m, p) => m + (p.width ?? 55),
|
|
275
309
|
0
|
|
276
|
-
)),
|
|
277
|
-
(p,
|
|
310
|
+
)), y = (i, m) => s(i.permission) && (i.visible ? i.visible(m) : !0), u = (i) => t.filter((p) => y(p, i)).slice(0, e).reduce(
|
|
311
|
+
(p, $) => p + ($.width ?? 55),
|
|
278
312
|
0
|
|
279
313
|
);
|
|
280
314
|
return {
|
|
281
315
|
hasAnyButton: o,
|
|
282
|
-
optWidth:
|
|
283
|
-
hasAnyVisibleButton: (
|
|
284
|
-
(m) => t.some((p) =>
|
|
316
|
+
optWidth: a,
|
|
317
|
+
hasAnyVisibleButton: (i) => i != null && i.length ? i.some(
|
|
318
|
+
(m) => t.some((p) => y(p, m))
|
|
285
319
|
) : !1,
|
|
286
|
-
getMaxOptWidth: (
|
|
287
|
-
(m, p) => Math.max(m,
|
|
320
|
+
getMaxOptWidth: (i) => i != null && i.length ? i.reduce(
|
|
321
|
+
(m, p) => Math.max(m, u(p)),
|
|
288
322
|
0
|
|
289
|
-
) :
|
|
290
|
-
getVisibleButtons: (
|
|
323
|
+
) : a.value,
|
|
324
|
+
getVisibleButtons: (i) => t.filter((m) => y(m, i)).slice(0, e)
|
|
291
325
|
};
|
|
292
326
|
}
|
|
293
|
-
const
|
|
327
|
+
const ie = ["title"], ce = /* @__PURE__ */ E({
|
|
294
328
|
__name: "index",
|
|
295
329
|
props: {
|
|
296
330
|
col: { type: Object, required: !0 },
|
|
@@ -298,143 +332,149 @@ const re = /* @__PURE__ */ x({
|
|
|
298
332
|
},
|
|
299
333
|
emits: ["cellBlur", "cellEnter", "cellChange", "cellClick"],
|
|
300
334
|
setup(t, { emit: e }) {
|
|
301
|
-
const
|
|
302
|
-
hasAnyButton:
|
|
303
|
-
hasAnyVisibleButton:
|
|
335
|
+
const l = t, r = e, { col: n } = U(l), s = (v, k) => r("cellChange", v, k), o = (v, k) => r("cellBlur", v, k), a = (v, k) => r("cellEnter", v, k), y = (v, k) => r("cellClick", v, k), u = oe(), {
|
|
336
|
+
hasAnyButton: g,
|
|
337
|
+
hasAnyVisibleButton: d,
|
|
304
338
|
optWidth: C,
|
|
305
|
-
getMaxOptWidth:
|
|
339
|
+
getMaxOptWidth: i,
|
|
306
340
|
getVisibleButtons: m
|
|
307
|
-
} =
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
), p =
|
|
312
|
-
function
|
|
341
|
+
} = se(
|
|
342
|
+
n.value.buttons || [],
|
|
343
|
+
n.value.maxbtn ?? 10,
|
|
344
|
+
l.permissions || []
|
|
345
|
+
), p = K(() => (n.value.buttons || []).length ? (n.value.__rows || []).length ? d(n.value.__rows || []) : g.value : !1), $ = K(() => n.value.__rows ? i(n.value.__rows) : C.value);
|
|
346
|
+
function R(v) {
|
|
313
347
|
return !(v.type === "selection" || v.type === "index" || v.type === "operation" && !p.value || v.visible === !1);
|
|
314
348
|
}
|
|
315
349
|
return (v, k) => {
|
|
316
|
-
const
|
|
317
|
-
return
|
|
350
|
+
const F = x("el-table-column"), J = x("el-button");
|
|
351
|
+
return c(n).type === "selection" ? (h(), b(F, _({
|
|
318
352
|
key: 0,
|
|
319
353
|
type: "selection"
|
|
320
|
-
},
|
|
354
|
+
}, c(n).columnProps), null, 16)) : c(n).type === "index" ? (h(), b(F, _({
|
|
321
355
|
key: 1,
|
|
322
356
|
type: "index",
|
|
323
|
-
label:
|
|
357
|
+
label: c(n).label || "#",
|
|
324
358
|
align: "center"
|
|
325
|
-
},
|
|
359
|
+
}, c(n).columnProps), null, 16, ["label"])) : c(n).type === "operation" && p.value ? (h(), b(F, _({
|
|
326
360
|
key: 2,
|
|
327
|
-
label:
|
|
361
|
+
label: c(n).label || "操作",
|
|
328
362
|
align: "center"
|
|
329
363
|
}, {
|
|
330
|
-
...
|
|
331
|
-
width:
|
|
364
|
+
...c(n).columnProps,
|
|
365
|
+
width: $.value
|
|
332
366
|
}), {
|
|
333
367
|
default: P(({ row: B }) => [
|
|
334
|
-
(
|
|
335
|
-
key:
|
|
336
|
-
type:
|
|
368
|
+
(h(!0), O(T, null, z(c(m)(B), (w) => (h(), b(J, {
|
|
369
|
+
key: w.label,
|
|
370
|
+
type: w.type || "primary",
|
|
337
371
|
link: "",
|
|
338
|
-
onClick: (
|
|
372
|
+
onClick: (I) => w.action(B)
|
|
339
373
|
}, {
|
|
340
374
|
default: P(() => [
|
|
341
|
-
D(
|
|
375
|
+
H(D(w.label), 1)
|
|
342
376
|
]),
|
|
343
377
|
_: 2
|
|
344
378
|
}, 1032, ["type", "onClick"]))), 128))
|
|
345
379
|
]),
|
|
346
380
|
_: 1
|
|
347
|
-
}, 16, ["label"])) :
|
|
381
|
+
}, 16, ["label"])) : R(c(n)) ? (h(), b(F, _({
|
|
348
382
|
key: 3,
|
|
349
|
-
prop:
|
|
350
|
-
label:
|
|
383
|
+
prop: c(n).key,
|
|
384
|
+
label: c(n).label,
|
|
351
385
|
align: "center"
|
|
352
|
-
},
|
|
353
|
-
default: P(({ row: B }) =>
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
386
|
+
}, c(n).columnProps || {}), {
|
|
387
|
+
default: P(({ row: B }) => {
|
|
388
|
+
var w, I;
|
|
389
|
+
return [
|
|
390
|
+
c(n).render && c(u)[c(n).render] ? (h(), b(q(c(u)[c(n).render]), {
|
|
391
|
+
key: 0,
|
|
392
|
+
row: B,
|
|
393
|
+
col: c(n),
|
|
394
|
+
onCellChange: s,
|
|
395
|
+
onCellBlur: o,
|
|
396
|
+
onCellEnter: a,
|
|
397
|
+
onClick: y
|
|
398
|
+
}, null, 40, ["row", "col"])) : (h(), O("span", {
|
|
399
|
+
key: 1,
|
|
400
|
+
style: Y(((w = c(n).renderProps) == null ? void 0 : w.style) || ""),
|
|
401
|
+
class: X(((I = c(n).renderProps) == null ? void 0 : I.class) || ""),
|
|
402
|
+
title: B[c(n).key]
|
|
403
|
+
}, D(B[c(n).key]), 15, ie))
|
|
404
|
+
];
|
|
405
|
+
}),
|
|
366
406
|
_: 1
|
|
367
407
|
}, 16, ["prop", "label"])) : j("", !0);
|
|
368
408
|
};
|
|
369
409
|
}
|
|
370
|
-
}),
|
|
371
|
-
function
|
|
372
|
-
return `${
|
|
410
|
+
}), ae = "table_columns_";
|
|
411
|
+
function ue(t, e) {
|
|
412
|
+
return `${ae}${t}_${e}`;
|
|
373
413
|
}
|
|
374
|
-
function
|
|
414
|
+
function N(t, e) {
|
|
375
415
|
if (!(e != null && e.length)) return t;
|
|
376
|
-
const
|
|
416
|
+
const l = new Map(
|
|
377
417
|
e.map((r) => [r.key, r])
|
|
378
418
|
);
|
|
379
419
|
return t.map((r) => {
|
|
380
|
-
const
|
|
381
|
-
return
|
|
420
|
+
const n = l.get(r.key);
|
|
421
|
+
return n ? {
|
|
382
422
|
...r,
|
|
383
|
-
visible: typeof
|
|
423
|
+
visible: typeof n.visible == "boolean" ? n.visible : r.visible
|
|
384
424
|
} : r;
|
|
385
425
|
});
|
|
386
426
|
}
|
|
387
|
-
function
|
|
427
|
+
function de(t, e) {
|
|
388
428
|
const {
|
|
389
|
-
pageKey:
|
|
429
|
+
pageKey: l,
|
|
390
430
|
userId: r,
|
|
391
|
-
storage:
|
|
392
|
-
} = e || {}, o = r ?
|
|
393
|
-
|
|
431
|
+
storage: n = localStorage
|
|
432
|
+
} = e || {}, o = r ? ue(r, l || "") : null, a = o ? n.getItem(o) : null, y = V(
|
|
433
|
+
N(
|
|
394
434
|
t,
|
|
395
|
-
|
|
435
|
+
a ? JSON.parse(a) : []
|
|
396
436
|
)
|
|
397
437
|
);
|
|
398
|
-
return
|
|
399
|
-
|
|
400
|
-
(
|
|
438
|
+
return A(
|
|
439
|
+
y,
|
|
440
|
+
(u) => {
|
|
401
441
|
if (!o) return;
|
|
402
|
-
const
|
|
403
|
-
key:
|
|
404
|
-
visible:
|
|
405
|
-
columnOpts:
|
|
442
|
+
const g = u.map((d) => ({
|
|
443
|
+
key: d.key,
|
|
444
|
+
visible: d.visible,
|
|
445
|
+
columnOpts: d.columnOpts
|
|
406
446
|
}));
|
|
407
|
-
|
|
447
|
+
n.setItem(
|
|
408
448
|
o,
|
|
409
|
-
JSON.stringify(
|
|
449
|
+
JSON.stringify(g)
|
|
410
450
|
);
|
|
411
451
|
},
|
|
412
452
|
{ deep: !0 }
|
|
413
453
|
), {
|
|
414
454
|
/** 当前列配置(响应式) */
|
|
415
|
-
columns:
|
|
455
|
+
columns: y,
|
|
416
456
|
/**
|
|
417
457
|
* 主动设置列配置
|
|
418
458
|
* 常用于:列设置弹窗 / 拖拽排序完成
|
|
419
459
|
*/
|
|
420
|
-
setColumns(
|
|
421
|
-
|
|
460
|
+
setColumns(u) {
|
|
461
|
+
y.value = N(
|
|
422
462
|
t,
|
|
423
|
-
|
|
424
|
-
), o &&
|
|
463
|
+
u
|
|
464
|
+
), o && n.setItem(
|
|
425
465
|
o,
|
|
426
|
-
JSON.stringify(
|
|
466
|
+
JSON.stringify(u)
|
|
427
467
|
);
|
|
428
468
|
},
|
|
429
469
|
/**
|
|
430
470
|
* 重置为默认列配置
|
|
431
471
|
*/
|
|
432
472
|
resetColumns() {
|
|
433
|
-
|
|
473
|
+
y.value = t, o && n.removeItem(o);
|
|
434
474
|
}
|
|
435
475
|
};
|
|
436
476
|
}
|
|
437
|
-
const
|
|
477
|
+
const ye = /* @__PURE__ */ E({
|
|
438
478
|
__name: "index",
|
|
439
479
|
props: {
|
|
440
480
|
data: { type: Array, default: () => [] },
|
|
@@ -460,44 +500,44 @@ const ie = /* @__PURE__ */ x({
|
|
|
460
500
|
"cellEnter",
|
|
461
501
|
"cell-click"
|
|
462
502
|
],
|
|
463
|
-
setup(t, { expose: e, emit:
|
|
464
|
-
const r = t,
|
|
503
|
+
setup(t, { expose: e, emit: l }) {
|
|
504
|
+
const r = t, n = l, { columns: s } = de(r.columns, {
|
|
465
505
|
pageKey: r.pageKey ?? "",
|
|
466
506
|
userId: r.userId ?? ""
|
|
467
507
|
});
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
(
|
|
508
|
+
A(
|
|
509
|
+
s,
|
|
510
|
+
(d) => n("update:columns", d),
|
|
471
511
|
{ deep: !0, immediate: !0 }
|
|
472
512
|
);
|
|
473
|
-
const o = (
|
|
474
|
-
|
|
475
|
-
},
|
|
476
|
-
console.log("enter"),
|
|
477
|
-
},
|
|
478
|
-
C &&
|
|
479
|
-
},
|
|
513
|
+
const o = (d, C) => n("cellChange", d, C), a = (d, C) => {
|
|
514
|
+
n("cellBlur", d, C);
|
|
515
|
+
}, y = (d, C) => {
|
|
516
|
+
console.log("enter"), n("cellEnter", d, C);
|
|
517
|
+
}, u = (d, C) => {
|
|
518
|
+
C && n("cell-click", d, C);
|
|
519
|
+
}, g = V();
|
|
480
520
|
return e({
|
|
481
|
-
tableRef:
|
|
482
|
-
}), (
|
|
483
|
-
const
|
|
484
|
-
return
|
|
521
|
+
tableRef: g
|
|
522
|
+
}), (d, C) => {
|
|
523
|
+
const i = x("el-table"), m = G("loading");
|
|
524
|
+
return Q((h(), b(i, _({
|
|
485
525
|
ref_key: "tableRef",
|
|
486
|
-
ref:
|
|
487
|
-
},
|
|
526
|
+
ref: g
|
|
527
|
+
}, d.$attrs, {
|
|
488
528
|
data: t.data,
|
|
489
529
|
"row-key": t.rowKey,
|
|
490
530
|
class: "smart-table"
|
|
491
531
|
}), {
|
|
492
532
|
default: P(() => [
|
|
493
|
-
(
|
|
533
|
+
(h(!0), O(T, null, z(c(s), (p) => (h(), b(ce, {
|
|
494
534
|
key: p.key,
|
|
495
535
|
col: p,
|
|
496
536
|
permissions: t.permissions,
|
|
497
537
|
onCellChange: o,
|
|
498
|
-
onCellBlur:
|
|
499
|
-
onCellEnter:
|
|
500
|
-
onCellClick:
|
|
538
|
+
onCellBlur: a,
|
|
539
|
+
onCellEnter: y,
|
|
540
|
+
onCellClick: u
|
|
501
541
|
}, null, 8, ["col", "permissions"]))), 128))
|
|
502
542
|
]),
|
|
503
543
|
_: 1
|
|
@@ -506,12 +546,12 @@ const ie = /* @__PURE__ */ x({
|
|
|
506
546
|
]);
|
|
507
547
|
};
|
|
508
548
|
}
|
|
509
|
-
}),
|
|
510
|
-
const
|
|
511
|
-
for (const [r,
|
|
512
|
-
|
|
513
|
-
return
|
|
514
|
-
},
|
|
549
|
+
}), me = (t, e) => {
|
|
550
|
+
const l = t.__vccOpts || t;
|
|
551
|
+
for (const [r, n] of e)
|
|
552
|
+
l[r] = n;
|
|
553
|
+
return l;
|
|
554
|
+
}, he = /* @__PURE__ */ me(ye, [["__scopeId", "data-v-338b77db"]]);
|
|
515
555
|
export {
|
|
516
|
-
|
|
556
|
+
he as SmartTable
|
|
517
557
|
};
|