vue3-smart-table 0.0.3 → 0.0.5

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 CHANGED
@@ -38,13 +38,13 @@ SmartTable/
38
38
 
39
39
  | 属性 | 类型 | 默认值 | 说明 |
40
40
  | --- | --- | --- | --- |
41
- | data | `any[]` | `[]` | 表格数据 |
42
- | columns | `ColumnConfig[]` | `[]` | 列配置(支持 v-model:columns |
43
- | rowKey | `string` | `'id'` | 行唯一 key |
44
- | loading | `boolean` | `false` | loading 状态 |
45
- | permissions | `string[]` | `[]` | 当前用户权限列表 |
46
- | pageKey | `string` | - | 列缓存 pageKey(可选) |
47
- | userId | `string \| number` | - | 列缓存 userId(可选) |
41
+ | data | `any[]` | `[]` | 必需 - 表格数据 |
42
+ | columns | `ColumnConfig[]` | `[]` |必需 - 列配置数组,支持 v-model:columns 双向绑定|
43
+ | rowKey | `string` | `'id'` | 行数据的唯一标识字段 |
44
+ | loading | `boolean` | `false` | 加载状态,显示加载动画 |
45
+ | permissions | `string[]` | `[]` | 当前用户权限列表,用于操作列权限控制 |
46
+ | cacheKey | `string` | - | **列缓存键(推荐)**,如果提供则直接使用,格式:`table_columns_{userId}_{pageKey}` 或自定义 |
47
+ | pagination | `{page: number, size: number}` | - | 序号列计算序号(可选),page:当前页,size:当前页显示条数,不填则默认序号 |
48
48
 
49
49
  > 其余属性将 **透传给 el-table**。
50
50
 
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),v=require("element-plus");function g(n,t){if(!(!n||!t))return t.split(".").reduce((r,o)=>r==null?void 0:r[o],n)}function S(n,t,r){if(!n||!t)return;const o=t.split("."),l=o.pop(),c=o.reduce((s,a)=>(s[a]||(s[a]={}),s[a]),n);c[l]=r}const A=e.defineComponent({__name:"input",props:{row:{},col:{},onCellBlur:{type:Function},onCellEnter:{type:Function}},setup(n){const t=n,r=e.ref(g(t.row,t.col.key));e.watch(r,c=>{S(t.row,t.col.key,c)});const o=()=>{var c;return(c=t.onCellBlur)==null?void 0:c.call(t,t.row,t.col)},l=()=>{var c;return(c=t.onCellEnter)==null?void 0:c.call(t,t.row,t.col)};return(c,s)=>{const a=e.resolveComponent("el-input");return e.openBlock(),e.createBlock(a,e.mergeProps({modelValue:r.value,"onUpdate:modelValue":s[0]||(s[0]=m=>r.value=m)},{placeholder:"",size:"small",clearable:!0,...n.col.renderProps},{onBlur:o,onKeyup:e.withKeys(l,["enter"])}),null,16,["modelValue"])}}}),O=e.defineComponent({__name:"inputNumber",props:{row:{},col:{},onCellChange:{type:Function},onCellBlur:{type:Function},onCellEnter:{type:Function}},setup(n){const t=n,r=e.ref(g(t.row,t.col.key));e.watch(r,c=>{var s;S(t.row,t.col.key,c),(s=t.onCellChange)==null||s.call(t,t.row,t.col)});const o=()=>{var c;return(c=t.onCellBlur)==null?void 0:c.call(t,t.row,t.col)},l=()=>{var c;return(c=t.onCellEnter)==null?void 0:c.call(t,t.row,t.col)};return(c,s)=>{const a=e.resolveComponent("el-input-number");return e.openBlock(),e.createBlock(a,e.mergeProps({modelValue:r.value,"onUpdate:modelValue":s[0]||(s[0]=m=>r.value=m)},{min:0,max:99999,controls:!1,size:"small",...n.col.renderProps},{onBlur:o,onKeyup:e.withKeys(l,["enter"])}),null,16,["modelValue"])}}}),I=e.defineComponent({__name:"select",props:{row:{},col:{},onCellChange:{type:Function},onCellBlur:{type:Function},onCellEnter:{type:Function}},setup(n){const t=n,r=e.ref(g(t.row,t.col.key));e.watch(r,s=>{S(t.row,t.col.key,s)});const o=()=>{var s;return(s=t.onCellChange)==null?void 0:s.call(t,t.row,t.col)},l=()=>{var s;return(s=t.onCellBlur)==null?void 0:s.call(t,t.row,t.col)},c=()=>{var s;return(s=t.onCellEnter)==null?void 0:s.call(t,t.row,t.col)};return(s,a)=>{const m=e.resolveComponent("el-option"),d=e.resolveComponent("el-select");return e.openBlock(),e.createBlock(d,e.mergeProps({modelValue:r.value,"onUpdate:modelValue":a[0]||(a[0]=h=>r.value=h)},{placeholder:"请选择",size:"small",clearable:!0,...n.col.renderProps},{onChange:o,onBlur:l,onKeyup:e.withKeys(c,["enter"])}),{default:e.withCtx(()=>{var h;return[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(((h=n.col.renderProps)==null?void 0:h.options)||[],u=>(e.openBlock(),e.createBlock(m,{key:u.value,label:u.label,value:u.value},null,8,["label","value"]))),128))]}),_:1},16,["modelValue"])}}}),P=n=>e.defineComponent({props:["row","col","onCellChange","onCellBlur","onCellEnter","onClick"],setup(t){return()=>e.h(n,t)}});function L(n){return typeof n.formatter=="function"}function M(){return{input:P(A),"input-number":P(O),select:P(I),button:n=>{const t=n.col.renderProps||{},r=g(n.row,n.col.key);return e.h(v.ElButton,{type:t.type||"primary",...t,onClick:()=>{var o;return(o=n.onClick)==null?void 0:o.call(n,n.row,n.col)}},()=>t.label||r)},link:n=>{const t=n.col.renderProps||{},r=g(n.row,n.col.key);return e.h("a",{href:t.href||"#",target:t.blank?"_blank":"_self",style:t.style||"color:#409EFF;cursor:pointer;",onClick:o=>{var l;o.preventDefault(),(l=n.onClick)==null||l.call(n,n.row,n.col)}},t.label||r)},html:n=>{var r;const t=g(n.row,n.col.key);return e.h("div",{class:"line-clamp-2",innerHTML:t??"",...((r=n.col)==null?void 0:r.renderProps)||{}})},copy:n=>{const t=g(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:`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),w=require("element-plus");function g(n,t){if(!(!n||!t))return t.split(".").reduce((l,o)=>l==null?void 0:l[o],n)}function V(n,t,l){if(!n||!t)return;const o=t.split("."),s=o.pop(),r=o.reduce((i,a)=>(i[a]||(i[a]={}),i[a]),n);r[s]=l}const M=e.defineComponent({__name:"input",props:{row:{},col:{},onCellBlur:{type:Function},onCellEnter:{type:Function}},setup(n){const t=n,l=e.ref(g(t.row,t.col.key));e.watch(l,r=>{V(t.row,t.col.key,r)});const o=()=>{var r;return(r=t.onCellBlur)==null?void 0:r.call(t,t.row,t.col)},s=()=>{var r;return(r=t.onCellEnter)==null?void 0:r.call(t,t.row,t.col)};return(r,i)=>{const a=e.resolveComponent("el-input");return e.openBlock(),e.createBlock(a,e.mergeProps({modelValue:l.value,"onUpdate:modelValue":i[0]||(i[0]=u=>l.value=u)},{placeholder:"",size:"small",clearable:!0,...n.col.renderProps},{onBlur:o,onKeyup:e.withKeys(s,["enter"])}),null,16,["modelValue"])}}}),$=e.defineComponent({__name:"inputNumber",props:{row:{},col:{},onCellChange:{type:Function},onCellBlur:{type:Function},onCellEnter:{type:Function}},setup(n){const t=n,l=e.ref(g(t.row,t.col.key));e.watch(l,r=>{var i;V(t.row,t.col.key,r),(i=t.onCellChange)==null||i.call(t,t.row,t.col)});const o=()=>{var r;return(r=t.onCellBlur)==null?void 0:r.call(t,t.row,t.col)},s=()=>{var r;return(r=t.onCellEnter)==null?void 0:r.call(t,t.row,t.col)};return(r,i)=>{const a=e.resolveComponent("el-input-number");return e.openBlock(),e.createBlock(a,e.mergeProps({modelValue:l.value,"onUpdate:modelValue":i[0]||(i[0]=u=>l.value=u)},{min:0,max:99999,controls:!1,size:"small",...n.col.renderProps},{onBlur:o,onKeyup:e.withKeys(s,["enter"])}),null,16,["modelValue"])}}}),K=e.defineComponent({__name:"select",props:{row:{},col:{},onCellChange:{type:Function},onCellBlur:{type:Function},onCellEnter:{type:Function}},setup(n){const t=n,l=e.ref(g(t.row,t.col.key));e.watch(l,i=>{V(t.row,t.col.key,i)});const o=()=>{var i;return(i=t.onCellChange)==null?void 0:i.call(t,t.row,t.col)},s=()=>{var i;return(i=t.onCellBlur)==null?void 0:i.call(t,t.row,t.col)},r=()=>{var i;return(i=t.onCellEnter)==null?void 0:i.call(t,t.row,t.col)};return(i,a)=>{const u=e.resolveComponent("el-option"),y=e.resolveComponent("el-select");return e.openBlock(),e.createBlock(y,e.mergeProps({modelValue:l.value,"onUpdate:modelValue":a[0]||(a[0]=h=>l.value=h)},{placeholder:"请选择",size:"small",clearable:!0,...n.col.renderProps},{onChange:o,onBlur:s,onKeyup:e.withKeys(r,["enter"])}),{default:e.withCtx(()=>{var h;return[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(((h=n.col.renderProps)==null?void 0:h.options)||[],d=>(e.openBlock(),e.createBlock(u,{key:d.value,label:d.label,value:d.value},null,8,["label","value"]))),128))]}),_:1},16,["modelValue"])}}}),S=n=>e.defineComponent({props:["row","col","onCellChange","onCellBlur","onCellEnter","onClick"],setup(t){return()=>e.h(n,t)}});function z(n){return typeof n.formatter=="function"}function I(){return{input:S(M),"input-number":S($),select:S(K),button:n=>{const t=n.col.renderProps||{},l=g(n.row,n.col.key);return e.h(w.ElButton,{type:t.type||"primary",...t,onClick:()=>{var o;return(o=n.onClick)==null?void 0:o.call(n,n.row,n.col)}},()=>t.label||l)},link:n=>{const t=n.col.renderProps||{},l=g(n.row,n.col.key);return e.h("a",{href:t.href||"#",target:t.blank?"_blank":"_self",style:t.style||"color:#409EFF;cursor:pointer;",onClick:o=>{var s;o.preventDefault(),(s=n.onClick)==null||s.call(n,n.row,n.col)}},t.label||l)},html:n=>{var l;const t=g(n.row,n.col.key);return e.h("div",{class:"line-clamp-2",innerHTML:t??"",...((l=n.col)==null?void 0:l.renderProps)||{}})},copy:n=>{const t=g(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,7 +8,7 @@
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(()=>{v.ElMessage.success("复制成功")}).catch(()=>{v.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?v.ElMessage.success("复制成功"):v.ElMessage.error("复制失败")}}catch{v.ElMessage.error("复制失败")}}},"📋")])},img:n=>{var s;const t=g(n.row,n.col.key)??"",r=((s=n.col)==null?void 0:s.renderProps)||{},l=t?Array.isArray(t)?t.filter(a=>a&&typeof a=="string"):[t]:[];if(l.length===0)return r.placeholder||"";const c={width:r.width||"80px",height:r.height||"80px",marginRight:l.length>1?"4px":"0",...r.style||{}};return l.length===1?e.h(v.ElImage,{src:l[0],previewSrcList:r.previewSrcList||l,fit:r.fit||"contain",style:c,...r}):(console.log(r.previewSrcList),e.h("div",{style:"display: flex; align-items: center; position: relative"},[e.h(v.ElImage,{src:l[0],previewSrcList:r.previewSrcList||l,fit:r.fit||"contain",style:c,...r}),l.length>1&&e.h("span",{style:`
11
+ `,onClick:()=>{if(t)try{if(navigator.clipboard&&navigator.clipboard.writeText)navigator.clipboard.writeText(t).then(()=>{w.ElMessage.success("复制成功")}).catch(()=>{w.ElMessage.error("复制失败")});else{const l=document.createElement("textarea");l.value=t,l.style.position="fixed",l.style.opacity="0",document.body.appendChild(l),l.select();const o=document.execCommand("copy");document.body.removeChild(l),o?w.ElMessage.success("复制成功"):w.ElMessage.error("复制失败")}}catch{w.ElMessage.error("复制失败")}}},"📋")])},img:n=>{var i;const t=g(n.row,n.col.key)??"",l=((i=n.col)==null?void 0:i.renderProps)||{},s=t?Array.isArray(t)?t.filter(a=>a&&typeof a=="string"):[t]:[];if(s.length===0)return l.placeholder||"";const r={width:l.width||"80px",height:l.height||"80px",marginRight:s.length>1?"4px":"0",...l.style||{}};return s.length===1?e.h(w.ElImage,{src:s[0],previewSrcList:l.previewSrcList||s,fit:l.fit||"contain",style:r,...l}):(console.log(l.previewSrcList),e.h("div",{style:"display: flex; align-items: center; position: relative"},[e.h(w.ElImage,{src:s[0],previewSrcList:l.previewSrcList||s,fit:l.fit||"contain",style:r,...l}),s.length>1&&e.h("span",{style:`
12
12
  margin-left: 8px;
13
13
  font-size: 12px;
14
14
  color: #666;
@@ -18,4 +18,4 @@
18
18
  position: absolute;
19
19
  top: 0;
20
20
  right: 0;
21
- `,title:`共 ${l.length} 张图片`},`+${l.length-1}`)]))},dict:n=>{const t=g(n.row,n.col.key)??"",r=n.col.renderProps||{},o=r.options??[],l=r.showValue??!1;if(t==null||t==="")return"";const c=Array.isArray(t)?t.map(String):[String(t)],s=o.filter(d=>c.includes(String(d.value))),a=c.filter(d=>!o.some(h=>String(h.value)===d)),m=s.map((d,h)=>e.h(v.ElTag,{key:d.value,type:d.listClass,class:d.cssClass,disableTransitions:!0},{default:()=>d.label+" "}));return l&&a.length>0&&m.push(e.h("span",{},a.join(" "))),e.h("div",{},m)},map:n=>{var o;const t=g(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=g(n.row,n.col.key)??"";return L(t)?(l=t.formatter)==null?void 0:l.call(t,o,r):o??""},icon:n=>{const t=g(n.row,n.col.key)??"",r=n.col.renderProps||{};return t?/^https?:\/\//.test(t)?e.h(v.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 T(n,t=10,r=[]){const l="*:*:*",c=i=>{if(!i)return!0;const p=Array.isArray(i)?i:[i];return r.some(f=>f===l||p.includes(f))},s=e.computed(()=>n.some(i=>c(i.permission))),a=e.computed(()=>n.filter(p=>c(p.permission)).slice(0,t).reduce((p,f)=>p+(f.width??60),0)),m=(i,p)=>c(i.permission)&&(i.visible?i.visible(p):!0),d=i=>n.filter(f=>m(f,i)).slice(0,t).reduce((f,b)=>f+(b.width??60),0);return{hasAnyButton:s,optWidth:a,hasAnyVisibleButton:i=>i!=null&&i.length?i.some(p=>n.some(f=>m(f,p))):!1,getMaxOptWidth:i=>i!=null&&i.length?i.reduce((p,f)=>Math.max(p,d(f)),0):a.value,getVisibleButtons:i=>n.filter(p=>m(p,i)).slice(0,t)}}const W=["title"],z=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),c=(y,C)=>o("cellChange",y,C),s=(y,C)=>o("cellBlur",y,C),a=(y,C)=>o("cellEnter",y,C),m=(y,C)=>o("cellClick",y,C),d=M(),{hasAnyButton:h,hasAnyVisibleButton:u,optWidth:k,getMaxOptWidth:i,getVisibleButtons:p}=T(l.value.buttons||[],l.value.maxbtn??10,r.permissions||[]),f=e.computed(()=>(l.value.buttons||[]).length?(l.value.__rows||[]).length?u(l.value.__rows||[]):h.value:!1),b=e.computed(()=>l.value.__rows?i(l.value.__rows):k.value);function x(y){return!(y.type==="selection"||y.type==="index"||y.type==="operation"&&!f.value||y.visible===!1)}return(y,C)=>{const _=e.resolveComponent("el-table-column"),$=e.resolveComponent("el-button");return e.unref(l).type==="selection"?(e.openBlock(),e.createBlock(_,e.mergeProps({key:0,type:"selection"},e.unref(l).columnProps),null,16)):e.unref(l).type==="index"?(e.openBlock(),e.createBlock(_,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"&&f.value?(e.openBlock(),e.createBlock(_,e.mergeProps({key:2,label:e.unref(l).label||"操作",align:"center"},{...e.unref(l).columnProps,width:b.value}),{default:e.withCtx(({row:w})=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(p)(w),B=>(e.openBlock(),e.createBlock($,{key:B.label,type:B.type||"primary",link:"",onClick:E=>B.action(w)},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(B.label),1)]),_:2},1032,["type","onClick"]))),128))]),_:1},16,["label"])):x(e.unref(l))?(e.openBlock(),e.createBlock(_,e.mergeProps({key:3,label:e.unref(l).label,align:"center"},e.unref(l).columnProps||{}),{default:e.withCtx(w=>{var B,E,V,F;return[e.unref(l).render==="slot"&&y.$slots[((B=e.unref(l))==null?void 0:B.slot)||e.unref(l).key]?e.renderSlot(y.$slots,((E=e.unref(l))==null?void 0:E.slot)||e.unref(l).key,e.normalizeProps(e.mergeProps({key:0},w))):e.unref(l).render&&e.unref(d)[e.unref(l).render]?(e.openBlock(),e.createBlock(e.resolveDynamicComponent(e.unref(d)[e.unref(l).render]),{key:1,row:w.row,col:e.unref(l),onCellChange:c,onCellBlur:s,onCellEnter:a,onClick:m},null,40,["row","col"])):(e.openBlock(),e.createElementBlock("span",{key:2,style:e.normalizeStyle(((V=e.unref(l).renderProps)==null?void 0:V.style)||""),class:e.normalizeClass(((F=e.unref(l).renderProps)==null?void 0:F.class)||""),title:e.unref(g)(w.row,e.unref(l).key)},e.toDisplayString(e.unref(g)(w.row,e.unref(l).key)),15,W))]}),_:3},16,["label"])):e.createCommentVNode("",!0)}}}),D="table_columns_";function N(n,t){return`${D}${n}_${t}`}function K(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 R(n,t){const{pageKey:r,userId:o,storage:l=localStorage}=t||{},s=o?N(o,r||""):null,a=s?l.getItem(s):null,m=e.ref(K(n,a?JSON.parse(a):[]));return e.watch(m,d=>{if(!s)return;const h=d.map(u=>({key:u.key,visible:u.visible,columnOpts:u.columnOpts}));l.setItem(s,JSON.stringify(h))},{deep:!0}),{columns:m,setColumns(d){m.value=K(n,d),s&&l.setItem(s,JSON.stringify(d))},resetColumns(){m.value=n,s&&l.removeItem(s)}}}const q=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:c}=R(o.columns,{pageKey:o.pageKey??"",userId:o.userId??""});e.watch(c,u=>l("update:columns",u),{deep:!0,immediate:!0});const s=(u,k)=>l("cellChange",u,k),a=(u,k)=>{l("cellBlur",u,k)},m=(u,k)=>{console.log("enter"),l("cellEnter",u,k)},d=(u,k)=>{k&&l("cell-click",u,k)},h=e.ref();return t({tableRef:h}),(u,k)=>{const i=e.resolveComponent("el-table"),p=e.resolveDirective("loading");return e.withDirectives((e.openBlock(),e.createBlock(i,e.mergeProps({ref_key:"tableRef",ref:h},u.$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(c),f=>(e.openBlock(),e.createBlock(z,{key:f.key,col:f,permissions:n.permissions,onCellChange:s,onCellBlur:a,onCellEnter:m,onCellClick:d},e.createSlots({_:2},[e.renderList(e.unref(c),b=>({name:b.key,fn:e.withCtx(x=>[e.renderSlot(u.$slots,b.key,e.mergeProps({ref_for:!0},x),void 0,!0)])}))]),1032,["col","permissions"]))),128))]),_:3},16,["data","row-key"])),[[p,n.loading]])}}}),J=(n,t)=>{const r=n.__vccOpts||n;for(const[o,l]of t)r[o]=l;return r},U=J(q,[["__scopeId","data-v-25f299e7"]]);exports.SmartTable=U;
21
+ `,title:`共 ${s.length} 张图片`},`+${s.length-1}`)]))},dict:n=>{const t=g(n.row,n.col.key)??"",l=n.col.renderProps||{},o=l.options??[],s=l.showValue??!1;if(t==null||t==="")return"";const r=Array.isArray(t)?t.map(String):[String(t)],i=o.filter(y=>r.includes(String(y.value))),a=r.filter(y=>!o.some(h=>String(h.value)===y)),u=i.map((y,h)=>e.h(w.ElTag,{key:y.value,type:y.listClass,class:y.cssClass,disableTransitions:!0},{default:()=>y.label+" "}));return s&&a.length>0&&u.push(e.h("span",{},a.join(" "))),e.h("div",{},u)},map:n=>{var o;const t=g(n.row,n.col.key)??"",l=((o=n.col.renderProps)==null?void 0:o.options)??{};return t!=null?l[t]??"":""},formatter:n=>{var s;const{col:t,row:l}=n,o=g(n.row,n.col.key)??"";return z(t)?(s=t.formatter)==null?void 0:s.call(t,o,l):o??""},icon:n=>{const t=g(n.row,n.col.key)??"",l=n.col.renderProps||{};return t?/^https?:\/\//.test(t)?e.h(w.ElImage,{src:t,previewSrcList:[t],fit:"contain",style:"width:40px;height:40px",...l}):/^\s*<svg[\s\S]*<\/svg>\s*$/.test(t)?e.h("div",{innerHTML:t,style:`width:40px;height:40px;display:inline-block;${l.style||""}`,...l}):e.h("i",{class:t,style:`font-size:20px;${l.style||""}`,...l}):""}}}function T(n,t=10,l=[]){const s="*:*:*",r=c=>{if(!c)return!0;const m=Array.isArray(c)?c:[c];return l.some(f=>f===s||m.includes(f))},i=e.computed(()=>n.some(c=>r(c.permission))),a=e.computed(()=>n.filter(m=>r(m.permission)).slice(0,t).reduce((m,f)=>m+(f.width??60),0)),u=(c,m)=>r(c.permission)&&(c.visible?c.visible(m):!0),y=c=>n.filter(f=>u(f,c)).slice(0,t).reduce((f,B)=>f+(B.width??60),0);return{hasAnyButton:i,optWidth:a,hasAnyVisibleButton:c=>c!=null&&c.length?c.some(m=>n.some(f=>u(f,m))):!1,getMaxOptWidth:c=>c!=null&&c.length?c.reduce((m,f)=>Math.max(m,y(f)),0):a.value,getVisibleButtons:c=>n.filter(m=>u(m,c)).slice(0,t)}}const W=["title"],D=e.defineComponent({__name:"index",props:{col:{type:Object,required:!0},permissions:{type:Array,default:()=>[]},pagination:{type:Object,default:()=>({})}},emits:["cellBlur","cellEnter","cellChange","cellClick"],setup(n,{emit:t}){const l=n,o=t,s=p=>{var x,C;const v=(x=l.pagination)==null?void 0:x.page,b=(C=l.pagination)==null?void 0:C.size;return v&&b?(v-1)*b+p+1:p+1},{col:r}=e.toRefs(l),i=(p,v)=>o("cellChange",p,v),a=(p,v)=>o("cellBlur",p,v),u=(p,v)=>o("cellEnter",p,v),y=(p,v)=>o("cellClick",p,v),h=I(),{hasAnyButton:d,hasAnyVisibleButton:k,optWidth:c,getMaxOptWidth:m,getVisibleButtons:f}=T(r.value.buttons||[],r.value.maxbtn??10,l.permissions||[]),B=e.computed(()=>(r.value.buttons||[]).length?(r.value.__rows||[]).length?k(r.value.__rows||[]):d.value:!1),E=e.computed(()=>r.value.__rows?m(r.value.__rows):c.value);function L(p){return!(p.type==="selection"||p.type==="index"||p.type==="operation"&&!B.value||p.visible===!1)}return(p,v)=>{const b=e.resolveComponent("el-table-column"),x=e.resolveComponent("el-button");return e.unref(r).type==="selection"?(e.openBlock(),e.createBlock(b,e.mergeProps({key:0,type:"selection"},e.unref(r).columnProps),null,16)):e.unref(r).type==="index"?(e.openBlock(),e.createBlock(b,e.mergeProps({key:1,type:"index",label:e.unref(r).label||"#",align:"center"},e.unref(r).columnProps),{default:e.withCtx(({$index:C})=>[e.createTextVNode(e.toDisplayString(s(C)),1)]),_:1},16,["label"])):e.unref(r).type==="operation"&&B.value?(e.openBlock(),e.createBlock(b,e.mergeProps({key:2,label:e.unref(r).label||"操作",align:"center"},{...e.unref(r).columnProps,width:E.value}),{default:e.withCtx(({row:C})=>[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(f)(C),_=>(e.openBlock(),e.createBlock(x,{key:_.label,type:_.type||"primary",link:"",onClick:P=>_.action(C)},{default:e.withCtx(()=>[e.createTextVNode(e.toDisplayString(_.label),1)]),_:2},1032,["type","onClick"]))),128))]),_:1},16,["label"])):L(e.unref(r))?(e.openBlock(),e.createBlock(b,e.mergeProps({key:3,label:e.unref(r).label,align:"center"},e.unref(r).columnProps||{}),{default:e.withCtx(C=>{var _,P,O,A;return[e.unref(r).render==="slot"&&p.$slots[((_=e.unref(r))==null?void 0:_.slot)||e.unref(r).key]?e.renderSlot(p.$slots,((P=e.unref(r))==null?void 0:P.slot)||e.unref(r).key,e.normalizeProps(e.mergeProps({key:0},C))):e.unref(r).render&&e.unref(h)[e.unref(r).render]?(e.openBlock(),e.createBlock(e.resolveDynamicComponent(e.unref(h)[e.unref(r).render]),{key:1,row:C.row,col:e.unref(r),onCellChange:i,onCellBlur:a,onCellEnter:u,onClick:y},null,40,["row","col"])):(e.openBlock(),e.createElementBlock("span",{key:2,style:e.normalizeStyle(((O=e.unref(r).renderProps)==null?void 0:O.style)||""),class:e.normalizeClass(((A=e.unref(r).renderProps)==null?void 0:A.class)||""),title:e.unref(g)(C.row,e.unref(r).key)},e.toDisplayString(e.unref(g)(C.row,e.unref(r).key)),15,W))]}),_:3},16,["label"])):e.createCommentVNode("",!0)}}});function F(n,t){if(!(t!=null&&t.length))return n;const l=new Map(t.map(o=>[o.key,o]));return n.map(o=>{const s=l.get(o.key);return s?{...o,visible:typeof s.visible=="boolean"?s.visible:o.visible}:o})}function N(n,t){const{cacheKey:l,storage:o=localStorage}=t||{},s=l?o.getItem(l):null,r=e.ref(F(n,s?JSON.parse(s):[]));return e.watch(r,i=>{if(!l)return;const a=i.map(u=>({key:u.key,visible:u.visible,columnOpts:u.columnOpts}));o.setItem(l,JSON.stringify(a))},{deep:!0}),{columns:r,setColumns(i){r.value=F(n,i),l&&o.setItem(l,JSON.stringify(i))},resetColumns(){r.value=n,l&&o.removeItem(l)}}}const R=e.defineComponent({__name:"index",props:{data:{type:Array,default:()=>[]},columns:{type:Array,default:()=>[]},rowKey:{type:String,default:"id"},loading:{type:Boolean,default:!1},permissions:{type:Array,default:()=>[]},cacheKey:String,pagination:{type:Object,default:()=>({})}},emits:["update:columns","cellChange","cellBlur","cellEnter","cell-click"],setup(n,{expose:t,emit:l}){const o=n,s=l,{columns:r}=N(o.columns,{cacheKey:o.cacheKey??""});e.watch(r,d=>s("update:columns",d),{deep:!0,immediate:!0});const i=(d,k)=>s("cellChange",d,k),a=(d,k)=>{s("cellBlur",d,k)},u=(d,k)=>{console.log("enter"),s("cellEnter",d,k)},y=(d,k)=>{k&&s("cell-click",d,k)},h=e.ref();return t({tableRef:h}),(d,k)=>{const c=e.resolveComponent("el-table"),m=e.resolveDirective("loading");return e.withDirectives((e.openBlock(),e.createBlock(c,e.mergeProps({ref_key:"tableRef",ref:h},d.$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(r),f=>(e.openBlock(),e.createBlock(D,{key:f.key,col:f,permissions:n.permissions,pagination:n.pagination,onCellChange:i,onCellBlur:a,onCellEnter:u,onCellClick:y},e.createSlots({_:2},[e.renderList(e.unref(r),B=>({name:B.key,fn:e.withCtx(E=>[e.renderSlot(d.$slots,B.key,e.mergeProps({ref_for:!0},E),void 0,!0)])}))]),1032,["col","permissions","pagination"]))),128))]),_:3},16,["data","row-key"])),[[m,n.loading]])}}}),j=(n,t)=>{const l=n.__vccOpts||n;for(const[o,s]of t)l[o]=s;return l},q=j(R,[["__scopeId","data-v-f4c8de68"]]);exports.SmartTable=q;
@@ -1 +1 @@
1
- .copy-wrapper:hover .copy-btn{display:inline-block!important}.smart-table[data-v-25f299e7]{width:100%}
1
+ .copy-wrapper:hover .copy-btn{display:inline-block!important}.smart-table[data-v-f4c8de68]{width:100%}
@@ -1,15 +1,15 @@
1
- import { defineComponent as V, ref as A, watch as F, resolveComponent as E, createBlock as b, openBlock as g, mergeProps as _, withKeys as D, withCtx as S, createElementBlock as O, Fragment as N, renderList as I, h as f, computed as L, toRefs as j, createCommentVNode as G, unref as i, createTextVNode as Q, toDisplayString as H, renderSlot as X, normalizeProps as Z, resolveDynamicComponent as ee, normalizeClass as te, normalizeStyle as ne, resolveDirective as le, withDirectives as re, createSlots as oe } from "vue";
2
- import { ElImage as M, ElTag as se, ElMessage as $, ElButton as ie } from "element-plus";
1
+ import { defineComponent as O, ref as F, watch as $, resolveComponent as V, createBlock as _, openBlock as g, mergeProps as x, withKeys as R, withCtx as P, createElementBlock as z, Fragment as J, renderList as K, h as f, computed as W, toRefs as X, createCommentVNode as Z, unref as s, createTextVNode as q, toDisplayString as T, renderSlot as G, normalizeProps as ee, resolveDynamicComponent as te, normalizeClass as ne, normalizeStyle as le, resolveDirective as re, withDirectives as oe, createSlots as ie } from "vue";
2
+ import { ElImage as D, ElTag as se, ElMessage as A, ElButton as ae } from "element-plus";
3
3
  function C(t, e) {
4
4
  if (!(!t || !e))
5
- return e.split(".").reduce((l, r) => l == null ? void 0 : l[r], t);
5
+ return e.split(".").reduce((n, r) => n == null ? void 0 : n[r], t);
6
6
  }
7
- function R(t, e, l) {
7
+ function U(t, e, n) {
8
8
  if (!t || !e) return;
9
- const r = e.split("."), n = r.pop(), s = r.reduce((o, c) => (o[c] || (o[c] = {}), o[c]), t);
10
- s[n] = l;
9
+ const r = e.split("."), o = r.pop(), l = r.reduce((i, c) => (i[c] || (i[c] = {}), i[c]), t);
10
+ l[o] = n;
11
11
  }
12
- const ae = /* @__PURE__ */ V({
12
+ const ce = /* @__PURE__ */ O({
13
13
  __name: "input",
14
14
  props: {
15
15
  row: {},
@@ -18,29 +18,29 @@ const ae = /* @__PURE__ */ V({
18
18
  onCellEnter: { type: Function }
19
19
  },
20
20
  setup(t) {
21
- const e = t, l = A(C(e.row, e.col.key));
22
- F(l, (s) => {
23
- R(e.row, e.col.key, s);
21
+ const e = t, n = F(C(e.row, e.col.key));
22
+ $(n, (l) => {
23
+ U(e.row, e.col.key, l);
24
24
  });
25
25
  const r = () => {
26
- var s;
27
- return (s = e.onCellBlur) == null ? void 0 : s.call(e, e.row, e.col);
28
- }, n = () => {
29
- var s;
30
- return (s = e.onCellEnter) == null ? void 0 : s.call(e, e.row, e.col);
26
+ var l;
27
+ return (l = e.onCellBlur) == null ? void 0 : l.call(e, e.row, e.col);
28
+ }, o = () => {
29
+ var l;
30
+ return (l = e.onCellEnter) == null ? void 0 : l.call(e, e.row, e.col);
31
31
  };
32
- return (s, o) => {
33
- const c = E("el-input");
34
- return g(), b(c, _({
35
- modelValue: l.value,
36
- "onUpdate:modelValue": o[0] || (o[0] = (y) => l.value = y)
32
+ return (l, i) => {
33
+ const c = V("el-input");
34
+ return g(), _(c, x({
35
+ modelValue: n.value,
36
+ "onUpdate:modelValue": i[0] || (i[0] = (u) => n.value = u)
37
37
  }, { placeholder: "", size: "small", clearable: !0, ...t.col.renderProps }, {
38
38
  onBlur: r,
39
- onKeyup: D(n, ["enter"])
39
+ onKeyup: R(o, ["enter"])
40
40
  }), null, 16, ["modelValue"]);
41
41
  };
42
42
  }
43
- }), ce = /* @__PURE__ */ V({
43
+ }), ue = /* @__PURE__ */ O({
44
44
  __name: "inputNumber",
45
45
  props: {
46
46
  row: {},
@@ -50,30 +50,30 @@ const ae = /* @__PURE__ */ V({
50
50
  onCellEnter: { type: Function }
51
51
  },
52
52
  setup(t) {
53
- const e = t, l = A(C(e.row, e.col.key));
54
- F(l, (s) => {
55
- var o;
56
- R(e.row, e.col.key, s), (o = e.onCellChange) == null || o.call(e, e.row, e.col);
53
+ const e = t, n = F(C(e.row, e.col.key));
54
+ $(n, (l) => {
55
+ var i;
56
+ U(e.row, e.col.key, l), (i = e.onCellChange) == null || i.call(e, e.row, e.col);
57
57
  });
58
58
  const r = () => {
59
- var s;
60
- return (s = e.onCellBlur) == null ? void 0 : s.call(e, e.row, e.col);
61
- }, n = () => {
62
- var s;
63
- return (s = e.onCellEnter) == null ? void 0 : s.call(e, e.row, e.col);
59
+ var l;
60
+ return (l = e.onCellBlur) == null ? void 0 : l.call(e, e.row, e.col);
61
+ }, o = () => {
62
+ var l;
63
+ return (l = e.onCellEnter) == null ? void 0 : l.call(e, e.row, e.col);
64
64
  };
65
- return (s, o) => {
66
- const c = E("el-input-number");
67
- return g(), b(c, _({
68
- modelValue: l.value,
69
- "onUpdate:modelValue": o[0] || (o[0] = (y) => l.value = y)
65
+ return (l, i) => {
66
+ const c = V("el-input-number");
67
+ return g(), _(c, x({
68
+ modelValue: n.value,
69
+ "onUpdate:modelValue": i[0] || (i[0] = (u) => n.value = u)
70
70
  }, { min: 0, max: 99999, controls: !1, size: "small", ...t.col.renderProps }, {
71
71
  onBlur: r,
72
- onKeyup: D(n, ["enter"])
72
+ onKeyup: R(o, ["enter"])
73
73
  }), null, 16, ["modelValue"]);
74
74
  };
75
75
  }
76
- }), ue = /* @__PURE__ */ V({
76
+ }), de = /* @__PURE__ */ O({
77
77
  __name: "select",
78
78
  props: {
79
79
  row: {},
@@ -83,37 +83,37 @@ const ae = /* @__PURE__ */ V({
83
83
  onCellEnter: { type: Function }
84
84
  },
85
85
  setup(t) {
86
- const e = t, l = A(C(e.row, e.col.key));
87
- F(l, (o) => {
88
- R(e.row, e.col.key, o);
86
+ const e = t, n = F(C(e.row, e.col.key));
87
+ $(n, (i) => {
88
+ U(e.row, e.col.key, i);
89
89
  });
90
90
  const r = () => {
91
- var o;
92
- return (o = e.onCellChange) == null ? void 0 : o.call(e, e.row, e.col);
93
- }, n = () => {
94
- var o;
95
- return (o = e.onCellBlur) == null ? void 0 : o.call(e, e.row, e.col);
96
- }, s = () => {
97
- var o;
98
- return (o = e.onCellEnter) == null ? void 0 : o.call(e, e.row, e.col);
91
+ var i;
92
+ return (i = e.onCellChange) == null ? void 0 : i.call(e, e.row, e.col);
93
+ }, o = () => {
94
+ var i;
95
+ return (i = e.onCellBlur) == null ? void 0 : i.call(e, e.row, e.col);
96
+ }, l = () => {
97
+ var i;
98
+ return (i = e.onCellEnter) == null ? void 0 : i.call(e, e.row, e.col);
99
99
  };
100
- return (o, c) => {
101
- const y = E("el-option"), d = E("el-select");
102
- return g(), b(d, _({
103
- modelValue: l.value,
104
- "onUpdate:modelValue": c[0] || (c[0] = (v) => l.value = v)
100
+ return (i, c) => {
101
+ const u = V("el-option"), h = V("el-select");
102
+ return g(), _(h, x({
103
+ modelValue: n.value,
104
+ "onUpdate:modelValue": c[0] || (c[0] = (v) => n.value = v)
105
105
  }, { placeholder: "请选择", size: "small", clearable: !0, ...t.col.renderProps }, {
106
106
  onChange: r,
107
- onBlur: n,
108
- onKeyup: D(s, ["enter"])
107
+ onBlur: o,
108
+ onKeyup: R(l, ["enter"])
109
109
  }), {
110
- default: S(() => {
110
+ default: P(() => {
111
111
  var v;
112
112
  return [
113
- (g(!0), O(N, null, I(((v = t.col.renderProps) == null ? void 0 : v.options) || [], (u) => (g(), b(y, {
114
- key: u.value,
115
- label: u.label,
116
- value: u.value
113
+ (g(!0), z(J, null, K(((v = t.col.renderProps) == null ? void 0 : v.options) || [], (d) => (g(), _(u, {
114
+ key: d.value,
115
+ label: d.label,
116
+ value: d.value
117
117
  }, null, 8, ["label", "value"]))), 128))
118
118
  ];
119
119
  }),
@@ -121,50 +121,50 @@ const ae = /* @__PURE__ */ V({
121
121
  }, 16, ["modelValue"]);
122
122
  };
123
123
  }
124
- }), T = (t) => V({
124
+ }), N = (t) => O({
125
125
  props: ["row", "col", "onCellChange", "onCellBlur", "onCellEnter", "onClick"],
126
126
  setup(e) {
127
127
  return () => f(t, e);
128
128
  }
129
129
  });
130
- function de(t) {
130
+ function ye(t) {
131
131
  return typeof t.formatter == "function";
132
132
  }
133
- function ye() {
133
+ function me() {
134
134
  return {
135
- input: T(ae),
136
- "input-number": T(ce),
137
- select: T(ue),
135
+ input: N(ce),
136
+ "input-number": N(ue),
137
+ select: N(de),
138
138
  button: (t) => {
139
- const e = t.col.renderProps || {}, l = C(t.row, t.col.key);
140
- return f(ie, {
139
+ const e = t.col.renderProps || {}, n = C(t.row, t.col.key);
140
+ return f(ae, {
141
141
  type: e.type || "primary",
142
142
  ...e,
143
143
  onClick: () => {
144
144
  var r;
145
145
  return (r = t.onClick) == null ? void 0 : r.call(t, t.row, t.col);
146
146
  }
147
- }, () => e.label || l);
147
+ }, () => e.label || n);
148
148
  },
149
149
  link: (t) => {
150
- const e = t.col.renderProps || {}, l = C(t.row, t.col.key);
150
+ const e = t.col.renderProps || {}, n = C(t.row, t.col.key);
151
151
  return f("a", {
152
152
  href: e.href || "#",
153
153
  target: e.blank ? "_blank" : "_self",
154
154
  style: e.style || "color:#409EFF;cursor:pointer;",
155
155
  onClick: (r) => {
156
- var n;
157
- r.preventDefault(), (n = t.onClick) == null || n.call(t, t.row, t.col);
156
+ var o;
157
+ r.preventDefault(), (o = t.onClick) == null || o.call(t, t.row, t.col);
158
158
  }
159
- }, e.label || l);
159
+ }, e.label || n);
160
160
  },
161
161
  html: (t) => {
162
- var l;
162
+ var n;
163
163
  const e = C(t.row, t.col.key);
164
164
  return f("div", {
165
165
  class: "line-clamp-2",
166
166
  innerHTML: e ?? "",
167
- ...((l = t.col) == null ? void 0 : l.renderProps) || {}
167
+ ...((n = t.col) == null ? void 0 : n.renderProps) || {}
168
168
  });
169
169
  },
170
170
  copy: (t) => {
@@ -200,18 +200,18 @@ function ye() {
200
200
  try {
201
201
  if (navigator.clipboard && navigator.clipboard.writeText)
202
202
  navigator.clipboard.writeText(e).then(() => {
203
- $.success("复制成功");
203
+ A.success("复制成功");
204
204
  }).catch(() => {
205
- $.error("复制失败");
205
+ A.error("复制失败");
206
206
  });
207
207
  else {
208
- const l = document.createElement("textarea");
209
- l.value = e, l.style.position = "fixed", l.style.opacity = "0", document.body.appendChild(l), l.select();
208
+ const n = document.createElement("textarea");
209
+ n.value = e, n.style.position = "fixed", n.style.opacity = "0", document.body.appendChild(n), n.select();
210
210
  const r = document.execCommand("copy");
211
- document.body.removeChild(l), r ? $.success("复制成功") : $.error("复制失败");
211
+ document.body.removeChild(n), r ? A.success("复制成功") : A.error("复制失败");
212
212
  }
213
213
  } catch {
214
- $.error("复制失败");
214
+ A.error("复制失败");
215
215
  }
216
216
  }
217
217
  },
@@ -222,35 +222,35 @@ function ye() {
222
222
  );
223
223
  },
224
224
  img: (t) => {
225
- var o;
226
- const e = C(t.row, t.col.key) ?? "", l = ((o = t.col) == null ? void 0 : o.renderProps) || {}, n = e ? Array.isArray(e) ? e.filter((c) => c && typeof c == "string") : [e] : [];
227
- if (n.length === 0)
228
- return l.placeholder || "";
229
- const s = {
230
- width: l.width || "80px",
231
- height: l.height || "80px",
232
- marginRight: n.length > 1 ? "4px" : "0",
233
- ...l.style || {}
225
+ var i;
226
+ const e = C(t.row, t.col.key) ?? "", n = ((i = t.col) == null ? void 0 : i.renderProps) || {}, o = e ? Array.isArray(e) ? e.filter((c) => c && typeof c == "string") : [e] : [];
227
+ if (o.length === 0)
228
+ return n.placeholder || "";
229
+ const l = {
230
+ width: n.width || "80px",
231
+ height: n.height || "80px",
232
+ marginRight: o.length > 1 ? "4px" : "0",
233
+ ...n.style || {}
234
234
  };
235
- return n.length === 1 ? f(M, {
236
- src: n[0],
237
- previewSrcList: l.previewSrcList || n,
238
- fit: l.fit || "contain",
239
- style: s,
240
- ...l
241
- }) : (console.log(l.previewSrcList), f("div", {
235
+ return o.length === 1 ? f(D, {
236
+ src: o[0],
237
+ previewSrcList: n.previewSrcList || o,
238
+ fit: n.fit || "contain",
239
+ style: l,
240
+ ...n
241
+ }) : (console.log(n.previewSrcList), f("div", {
242
242
  style: "display: flex; align-items: center; position: relative"
243
243
  }, [
244
244
  // 显示第一张图片,点击可预览所有
245
- f(M, {
246
- src: n[0],
247
- previewSrcList: l.previewSrcList || n,
248
- fit: l.fit || "contain",
249
- style: s,
250
- ...l
245
+ f(D, {
246
+ src: o[0],
247
+ previewSrcList: n.previewSrcList || o,
248
+ fit: n.fit || "contain",
249
+ style: l,
250
+ ...n
251
251
  }),
252
252
  // 如果图片数量大于1,显示剩余图片数量
253
- n.length > 1 && f("span", {
253
+ o.length > 1 && f("span", {
254
254
  style: `
255
255
  margin-left: 8px;
256
256
  font-size: 12px;
@@ -262,245 +262,243 @@ function ye() {
262
262
  top: 0;
263
263
  right: 0;
264
264
  `,
265
- title: `共 ${n.length} 张图片`
266
- }, `+${n.length - 1}`)
265
+ title: `共 ${o.length} 张图片`
266
+ }, `+${o.length - 1}`)
267
267
  ]));
268
268
  },
269
269
  dict: (t) => {
270
- const e = C(t.row, t.col.key) ?? "", l = t.col.renderProps || {}, r = l.options ?? [], n = l.showValue ?? !1;
270
+ const e = C(t.row, t.col.key) ?? "", n = t.col.renderProps || {}, r = n.options ?? [], o = n.showValue ?? !1;
271
271
  if (e == null || e === "") return "";
272
- const s = Array.isArray(e) ? e.map(String) : [String(e)], o = r.filter((d) => s.includes(String(d.value))), c = s.filter((d) => !r.some((v) => String(v.value) === d)), y = o.map((d, v) => f(
272
+ const l = Array.isArray(e) ? e.map(String) : [String(e)], i = r.filter((h) => l.includes(String(h.value))), c = l.filter((h) => !r.some((v) => String(v.value) === h)), u = i.map((h, v) => f(
273
273
  se,
274
- { key: d.value, type: d.listClass, class: d.cssClass, disableTransitions: !0 },
275
- { default: () => d.label + " " }
274
+ { key: h.value, type: h.listClass, class: h.cssClass, disableTransitions: !0 },
275
+ { default: () => h.label + " " }
276
276
  ));
277
- return n && c.length > 0 && y.push(f("span", {}, c.join(" "))), f("div", {}, y);
277
+ return o && c.length > 0 && u.push(f("span", {}, c.join(" "))), f("div", {}, u);
278
278
  },
279
279
  map: (t) => {
280
280
  var r;
281
- const e = C(t.row, t.col.key) ?? "", l = ((r = t.col.renderProps) == null ? void 0 : r.options) ?? {};
282
- return e != null ? l[e] ?? "" : "";
281
+ const e = C(t.row, t.col.key) ?? "", n = ((r = t.col.renderProps) == null ? void 0 : r.options) ?? {};
282
+ return e != null ? n[e] ?? "" : "";
283
283
  },
284
284
  formatter: (t) => {
285
- var n;
286
- const { col: e, row: l } = t, r = C(t.row, t.col.key) ?? "";
287
- return de(e) ? (n = e.formatter) == null ? void 0 : n.call(e, r, l) : r ?? "";
285
+ var o;
286
+ const { col: e, row: n } = t, r = C(t.row, t.col.key) ?? "";
287
+ return ye(e) ? (o = e.formatter) == null ? void 0 : o.call(e, r, n) : r ?? "";
288
288
  },
289
289
  icon: (t) => {
290
- const e = C(t.row, t.col.key) ?? "", l = t.col.renderProps || {};
291
- return e ? /^https?:\/\//.test(e) ? f(M, {
290
+ const e = C(t.row, t.col.key) ?? "", n = t.col.renderProps || {};
291
+ return e ? /^https?:\/\//.test(e) ? f(D, {
292
292
  src: e,
293
293
  previewSrcList: [e],
294
294
  fit: "contain",
295
295
  style: "width:40px;height:40px",
296
- ...l
296
+ ...n
297
297
  }) : /^\s*<svg[\s\S]*<\/svg>\s*$/.test(e) ? f("div", {
298
298
  innerHTML: e,
299
- style: `width:40px;height:40px;display:inline-block;${l.style || ""}`,
300
- ...l
299
+ style: `width:40px;height:40px;display:inline-block;${n.style || ""}`,
300
+ ...n
301
301
  }) : f("i", {
302
302
  class: e,
303
303
  // val 直接当 className
304
- style: `font-size:20px;${l.style || ""}`,
305
- ...l
304
+ style: `font-size:20px;${n.style || ""}`,
305
+ ...n
306
306
  }) : "";
307
307
  }
308
308
  };
309
309
  }
310
- function me(t, e = 10, l = []) {
311
- const n = "*:*:*", s = (a) => {
310
+ function pe(t, e = 10, n = []) {
311
+ const o = "*:*:*", l = (a) => {
312
312
  if (!a) return !0;
313
313
  const m = Array.isArray(a) ? a : [a];
314
- return l.some(
315
- (p) => p === n || m.includes(p)
314
+ return n.some(
315
+ (p) => p === o || m.includes(p)
316
316
  );
317
- }, o = L(() => t.some((a) => s(a.permission))), c = L(() => t.filter((m) => s(m.permission)).slice(0, e).reduce(
317
+ }, i = W(() => t.some((a) => l(a.permission))), c = W(() => t.filter((m) => l(m.permission)).slice(0, e).reduce(
318
318
  (m, p) => m + (p.width ?? 60),
319
319
  0
320
- )), y = (a, m) => s(a.permission) && (a.visible ? a.visible(m) : !0), d = (a) => t.filter((p) => y(p, a)).slice(0, e).reduce(
321
- (p, P) => p + (P.width ?? 60),
320
+ )), u = (a, m) => l(a.permission) && (a.visible ? a.visible(m) : !0), h = (a) => t.filter((p) => u(p, a)).slice(0, e).reduce(
321
+ (p, B) => p + (B.width ?? 60),
322
322
  0
323
323
  );
324
324
  return {
325
- hasAnyButton: o,
325
+ hasAnyButton: i,
326
326
  optWidth: c,
327
327
  hasAnyVisibleButton: (a) => a != null && a.length ? a.some(
328
- (m) => t.some((p) => y(p, m))
328
+ (m) => t.some((p) => u(p, m))
329
329
  ) : !1,
330
330
  getMaxOptWidth: (a) => a != null && a.length ? a.reduce(
331
- (m, p) => Math.max(m, d(p)),
331
+ (m, p) => Math.max(m, h(p)),
332
332
  0
333
333
  ) : c.value,
334
- getVisibleButtons: (a) => t.filter((m) => y(m, a)).slice(0, e)
334
+ getVisibleButtons: (a) => t.filter((m) => u(m, a)).slice(0, e)
335
335
  };
336
336
  }
337
- const pe = ["title"], fe = /* @__PURE__ */ V({
337
+ const fe = ["title"], he = /* @__PURE__ */ O({
338
338
  __name: "index",
339
339
  props: {
340
340
  col: { type: Object, required: !0 },
341
- permissions: { type: Array, default: () => [] }
341
+ permissions: { type: Array, default: () => [] },
342
+ pagination: { type: Object, default: () => ({}) }
342
343
  },
343
344
  emits: ["cellBlur", "cellEnter", "cellChange", "cellClick"],
344
345
  setup(t, { emit: e }) {
345
- const l = t, r = e, { col: n } = j(l), s = (h, w) => r("cellChange", h, w), o = (h, w) => r("cellBlur", h, w), c = (h, w) => r("cellEnter", h, w), y = (h, w) => r("cellClick", h, w), d = ye(), {
346
- hasAnyButton: v,
347
- hasAnyVisibleButton: u,
348
- optWidth: k,
349
- getMaxOptWidth: a,
350
- getVisibleButtons: m
351
- } = me(
352
- n.value.buttons || [],
353
- n.value.maxbtn ?? 10,
354
- l.permissions || []
355
- ), p = L(() => (n.value.buttons || []).length ? (n.value.__rows || []).length ? u(n.value.__rows || []) : v.value : !1), P = L(() => n.value.__rows ? a(n.value.__rows) : k.value);
356
- function W(h) {
357
- return !(h.type === "selection" || h.type === "index" || h.type === "operation" && !p.value || h.visible === !1);
346
+ const n = t, r = e, o = (y) => {
347
+ var L, w;
348
+ const b = (L = n.pagination) == null ? void 0 : L.page, E = (w = n.pagination) == null ? void 0 : w.size;
349
+ return b && E ? (b - 1) * E + y + 1 : y + 1;
350
+ }, { col: l } = X(n), i = (y, b) => r("cellChange", y, b), c = (y, b) => r("cellBlur", y, b), u = (y, b) => r("cellEnter", y, b), h = (y, b) => r("cellClick", y, b), v = me(), {
351
+ hasAnyButton: d,
352
+ hasAnyVisibleButton: k,
353
+ optWidth: a,
354
+ getMaxOptWidth: m,
355
+ getVisibleButtons: p
356
+ } = pe(
357
+ l.value.buttons || [],
358
+ l.value.maxbtn ?? 10,
359
+ n.permissions || []
360
+ ), B = W(() => (l.value.buttons || []).length ? (l.value.__rows || []).length ? k(l.value.__rows || []) : d.value : !1), I = W(() => l.value.__rows ? m(l.value.__rows) : a.value);
361
+ function Q(y) {
362
+ return !(y.type === "selection" || y.type === "index" || y.type === "operation" && !B.value || y.visible === !1);
358
363
  }
359
- return (h, w) => {
360
- const K = E("el-table-column"), Y = E("el-button");
361
- return i(n).type === "selection" ? (g(), b(K, _({
364
+ return (y, b) => {
365
+ const E = V("el-table-column"), L = V("el-button");
366
+ return s(l).type === "selection" ? (g(), _(E, x({
362
367
  key: 0,
363
368
  type: "selection"
364
- }, i(n).columnProps), null, 16)) : i(n).type === "index" ? (g(), b(K, _({
369
+ }, s(l).columnProps), null, 16)) : s(l).type === "index" ? (g(), _(E, x({
365
370
  key: 1,
366
371
  type: "index",
367
- label: i(n).label || "#",
372
+ label: s(l).label || "#",
368
373
  align: "center"
369
- }, i(n).columnProps), null, 16, ["label"])) : i(n).type === "operation" && p.value ? (g(), b(K, _({
374
+ }, s(l).columnProps), {
375
+ default: P(({ $index: w }) => [
376
+ q(T(o(w)), 1)
377
+ ]),
378
+ _: 1
379
+ }, 16, ["label"])) : s(l).type === "operation" && B.value ? (g(), _(E, x({
370
380
  key: 2,
371
- label: i(n).label || "操作",
381
+ label: s(l).label || "操作",
372
382
  align: "center"
373
383
  }, {
374
- ...i(n).columnProps,
375
- width: P.value
384
+ ...s(l).columnProps,
385
+ width: I.value
376
386
  }), {
377
- default: S(({ row: x }) => [
378
- (g(!0), O(N, null, I(i(m)(x), (B) => (g(), b(Y, {
379
- key: B.label,
380
- type: B.type || "primary",
387
+ default: P(({ row: w }) => [
388
+ (g(!0), z(J, null, K(s(p)(w), (S) => (g(), _(L, {
389
+ key: S.label,
390
+ type: S.type || "primary",
381
391
  link: "",
382
- onClick: (z) => B.action(x)
392
+ onClick: (M) => S.action(w)
383
393
  }, {
384
- default: S(() => [
385
- Q(H(B.label), 1)
394
+ default: P(() => [
395
+ q(T(S.label), 1)
386
396
  ]),
387
397
  _: 2
388
398
  }, 1032, ["type", "onClick"]))), 128))
389
399
  ]),
390
400
  _: 1
391
- }, 16, ["label"])) : W(i(n)) ? (g(), b(K, _({
401
+ }, 16, ["label"])) : Q(s(l)) ? (g(), _(E, x({
392
402
  key: 3,
393
- label: i(n).label,
403
+ label: s(l).label,
394
404
  align: "center"
395
- }, i(n).columnProps || {}), {
396
- default: S((x) => {
397
- var B, z, J, U;
405
+ }, s(l).columnProps || {}), {
406
+ default: P((w) => {
407
+ var S, M, j, H;
398
408
  return [
399
- i(n).render === "slot" && h.$slots[((B = i(n)) == null ? void 0 : B.slot) || i(n).key] ? X(h.$slots, ((z = i(n)) == null ? void 0 : z.slot) || i(n).key, Z(_({ key: 0 }, x))) : i(n).render && i(d)[i(n).render] ? (g(), b(ee(i(d)[i(n).render]), {
409
+ s(l).render === "slot" && y.$slots[((S = s(l)) == null ? void 0 : S.slot) || s(l).key] ? G(y.$slots, ((M = s(l)) == null ? void 0 : M.slot) || s(l).key, ee(x({ key: 0 }, w))) : s(l).render && s(v)[s(l).render] ? (g(), _(te(s(v)[s(l).render]), {
400
410
  key: 1,
401
- row: x.row,
402
- col: i(n),
403
- onCellChange: s,
404
- onCellBlur: o,
405
- onCellEnter: c,
406
- onClick: y
407
- }, null, 40, ["row", "col"])) : (g(), O("span", {
411
+ row: w.row,
412
+ col: s(l),
413
+ onCellChange: i,
414
+ onCellBlur: c,
415
+ onCellEnter: u,
416
+ onClick: h
417
+ }, null, 40, ["row", "col"])) : (g(), z("span", {
408
418
  key: 2,
409
- style: ne(((J = i(n).renderProps) == null ? void 0 : J.style) || ""),
410
- class: te(((U = i(n).renderProps) == null ? void 0 : U.class) || ""),
411
- title: i(C)(x.row, i(n).key)
412
- }, H(i(C)(x.row, i(n).key)), 15, pe))
419
+ style: le(((j = s(l).renderProps) == null ? void 0 : j.style) || ""),
420
+ class: ne(((H = s(l).renderProps) == null ? void 0 : H.class) || ""),
421
+ title: s(C)(w.row, s(l).key)
422
+ }, T(s(C)(w.row, s(l).key)), 15, fe))
413
423
  ];
414
424
  }),
415
425
  _: 3
416
- }, 16, ["label"])) : G("", !0);
426
+ }, 16, ["label"])) : Z("", !0);
417
427
  };
418
428
  }
419
- }), he = "table_columns_";
420
- function ge(t, e) {
421
- return `${he}${t}_${e}`;
422
- }
423
- function q(t, e) {
429
+ });
430
+ function Y(t, e) {
424
431
  if (!(e != null && e.length)) return t;
425
- const l = new Map(
432
+ const n = new Map(
426
433
  e.map((r) => [r.key, r])
427
434
  );
428
435
  return t.map((r) => {
429
- const n = l.get(r.key);
430
- return n ? {
436
+ const o = n.get(r.key);
437
+ return o ? {
431
438
  ...r,
432
- visible: typeof n.visible == "boolean" ? n.visible : r.visible
439
+ visible: typeof o.visible == "boolean" ? o.visible : r.visible
433
440
  } : r;
434
441
  });
435
442
  }
436
- function ve(t, e) {
437
- const {
438
- pageKey: l,
439
- userId: r,
440
- storage: n = localStorage
441
- } = e || {}, o = r ? ge(r, l || "") : null, c = o ? n.getItem(o) : null, y = A(
442
- q(
443
+ function ge(t, e) {
444
+ const { cacheKey: n, storage: r = localStorage } = e || {}, o = n ? r.getItem(n) : null, l = F(
445
+ Y(
443
446
  t,
444
- c ? JSON.parse(c) : []
447
+ o ? JSON.parse(o) : []
445
448
  )
446
449
  );
447
- return F(
448
- y,
449
- (d) => {
450
- if (!o) return;
451
- const v = d.map((u) => ({
450
+ return $(
451
+ l,
452
+ (i) => {
453
+ if (!n) return;
454
+ const c = i.map((u) => ({
452
455
  key: u.key,
453
456
  visible: u.visible,
454
457
  columnOpts: u.columnOpts
455
458
  }));
456
- n.setItem(
457
- o,
458
- JSON.stringify(v)
459
+ r.setItem(
460
+ n,
461
+ JSON.stringify(c)
459
462
  );
460
463
  },
461
464
  { deep: !0 }
462
465
  ), {
463
466
  /** 当前列配置(响应式) */
464
- columns: y,
467
+ columns: l,
465
468
  /**
466
469
  * 主动设置列配置
467
470
  * 常用于:列设置弹窗 / 拖拽排序完成
468
471
  */
469
- setColumns(d) {
470
- y.value = q(
472
+ setColumns(i) {
473
+ l.value = Y(
471
474
  t,
472
- d
473
- ), o && n.setItem(
474
- o,
475
- JSON.stringify(d)
475
+ i
476
+ ), n && r.setItem(
477
+ n,
478
+ JSON.stringify(i)
476
479
  );
477
480
  },
478
481
  /**
479
482
  * 重置为默认列配置
480
483
  */
481
484
  resetColumns() {
482
- y.value = t, o && n.removeItem(o);
485
+ l.value = t, n && r.removeItem(n);
483
486
  }
484
487
  };
485
488
  }
486
- const Ce = /* @__PURE__ */ V({
489
+ const ve = /* @__PURE__ */ O({
487
490
  __name: "index",
488
491
  props: {
489
492
  data: { type: Array, default: () => [] },
490
493
  columns: { type: Array, default: () => [] },
491
- // v-model:columns
492
- pageKey: String,
493
494
  rowKey: { type: String, default: "id" },
494
495
  loading: { type: Boolean, default: !1 },
495
496
  permissions: {
496
497
  type: Array,
497
498
  default: () => []
498
499
  },
499
- userId: {
500
- /** 当前用户标识(可选,用于列缓存) */
501
- type: [String, Number],
502
- default: ""
503
- }
500
+ cacheKey: String,
501
+ pagination: { type: Object, default: () => ({}) }
504
502
  },
505
503
  emits: [
506
504
  "update:columns",
@@ -509,52 +507,52 @@ const Ce = /* @__PURE__ */ V({
509
507
  "cellEnter",
510
508
  "cell-click"
511
509
  ],
512
- setup(t, { expose: e, emit: l }) {
513
- const r = t, n = l, { columns: s } = ve(r.columns, {
514
- pageKey: r.pageKey ?? "",
515
- userId: r.userId ?? ""
510
+ setup(t, { expose: e, emit: n }) {
511
+ const r = t, o = n, { columns: l } = ge(r.columns, {
512
+ cacheKey: r.cacheKey ?? ""
516
513
  });
517
- F(
518
- s,
519
- (u) => n("update:columns", u),
514
+ $(
515
+ l,
516
+ (d) => o("update:columns", d),
520
517
  { deep: !0, immediate: !0 }
521
518
  );
522
- const o = (u, k) => n("cellChange", u, k), c = (u, k) => {
523
- n("cellBlur", u, k);
524
- }, y = (u, k) => {
525
- console.log("enter"), n("cellEnter", u, k);
526
- }, d = (u, k) => {
527
- k && n("cell-click", u, k);
528
- }, v = A();
519
+ const i = (d, k) => o("cellChange", d, k), c = (d, k) => {
520
+ o("cellBlur", d, k);
521
+ }, u = (d, k) => {
522
+ console.log("enter"), o("cellEnter", d, k);
523
+ }, h = (d, k) => {
524
+ k && o("cell-click", d, k);
525
+ }, v = F();
529
526
  return e({
530
527
  tableRef: v
531
- }), (u, k) => {
532
- const a = E("el-table"), m = le("loading");
533
- return re((g(), b(a, _({
528
+ }), (d, k) => {
529
+ const a = V("el-table"), m = re("loading");
530
+ return oe((g(), _(a, x({
534
531
  ref_key: "tableRef",
535
532
  ref: v
536
- }, u.$attrs, {
533
+ }, d.$attrs, {
537
534
  data: t.data,
538
535
  "row-key": t.rowKey,
539
536
  class: "smart-table"
540
537
  }), {
541
- default: S(() => [
542
- (g(!0), O(N, null, I(i(s), (p) => (g(), b(fe, {
538
+ default: P(() => [
539
+ (g(!0), z(J, null, K(s(l), (p) => (g(), _(he, {
543
540
  key: p.key,
544
541
  col: p,
545
542
  permissions: t.permissions,
546
- onCellChange: o,
543
+ pagination: t.pagination,
544
+ onCellChange: i,
547
545
  onCellBlur: c,
548
- onCellEnter: y,
549
- onCellClick: d
550
- }, oe({ _: 2 }, [
551
- I(i(s), (P) => ({
552
- name: P.key,
553
- fn: S((W) => [
554
- X(u.$slots, P.key, _({ ref_for: !0 }, W), void 0, !0)
546
+ onCellEnter: u,
547
+ onCellClick: h
548
+ }, ie({ _: 2 }, [
549
+ K(s(l), (B) => ({
550
+ name: B.key,
551
+ fn: P((I) => [
552
+ G(d.$slots, B.key, x({ ref_for: !0 }, I), void 0, !0)
555
553
  ])
556
554
  }))
557
- ]), 1032, ["col", "permissions"]))), 128))
555
+ ]), 1032, ["col", "permissions", "pagination"]))), 128))
558
556
  ]),
559
557
  _: 3
560
558
  }, 16, ["data", "row-key"])), [
@@ -562,12 +560,12 @@ const Ce = /* @__PURE__ */ V({
562
560
  ]);
563
561
  };
564
562
  }
565
- }), ke = (t, e) => {
566
- const l = t.__vccOpts || t;
567
- for (const [r, n] of e)
568
- l[r] = n;
569
- return l;
570
- }, we = /* @__PURE__ */ ke(Ce, [["__scopeId", "data-v-25f299e7"]]);
563
+ }), Ce = (t, e) => {
564
+ const n = t.__vccOpts || t;
565
+ for (const [r, o] of e)
566
+ n[r] = o;
567
+ return n;
568
+ }, we = /* @__PURE__ */ Ce(ve, [["__scopeId", "data-v-f4c8de68"]]);
571
569
  export {
572
570
  we as SmartTable
573
571
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue3-smart-table",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "基于 Vue 3 + Element Plus 的高可复用表格组件",
5
5
  "main": "dist/vue3-smart-table.cjs.js",
6
6
  "module": "dist/vue3-smart-table.es.js",