vue3-smart-table 0.0.4 → 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,12 @@ 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}` 或自定义 |
48
47
  | pagination | `{page: number, size: number}` | - | 序号列计算序号(可选),page:当前页,size:当前页显示条数,不填则默认序号 |
49
48
 
50
49
  > 其余属性将 **透传给 el-table**。
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue"),w=require("element-plus");function h(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 A=e.defineComponent({__name:"input",props:{row:{},col:{},onCellBlur:{type:Function},onCellEnter:{type:Function}},setup(n){const t=n,l=e.ref(h(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]=d=>l.value=d)},{placeholder:"",size:"small",clearable:!0,...n.col.renderProps},{onBlur:o,onKeyup:e.withKeys(s,["enter"])}),null,16,["modelValue"])}}}),I=e.defineComponent({__name:"inputNumber",props:{row:{},col:{},onCellChange:{type:Function},onCellBlur:{type:Function},onCellEnter:{type:Function}},setup(n){const t=n,l=e.ref(h(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]=d=>l.value=d)},{min:0,max:99999,controls:!1,size:"small",...n.col.renderProps},{onBlur:o,onKeyup:e.withKeys(s,["enter"])}),null,16,["modelValue"])}}}),L=e.defineComponent({__name:"select",props:{row:{},col:{},onCellChange:{type:Function},onCellBlur:{type:Function},onCellEnter:{type:Function}},setup(n){const t=n,l=e.ref(h(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 d=e.resolveComponent("el-option"),p=e.resolveComponent("el-select");return e.openBlock(),e.createBlock(p,e.mergeProps({modelValue:l.value,"onUpdate:modelValue":a[0]||(a[0]=g=>l.value=g)},{placeholder:"请选择",size:"small",clearable:!0,...n.col.renderProps},{onChange:o,onBlur:s,onKeyup:e.withKeys(r,["enter"])}),{default:e.withCtx(()=>{var g;return[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(((g=n.col.renderProps)==null?void 0:g.options)||[],u=>(e.openBlock(),e.createBlock(d,{key:u.value,label:u.label,value:u.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 M(n){return typeof n.formatter=="function"}function z(){return{input:S(A),"input-number":S(I),select:S(L),button:n=>{const t=n.col.renderProps||{},l=h(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=h(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=h(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=h(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(()=>{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=h(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:`
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:`共 ${s.length} 张图片`},`+${s.length-1}`)]))},dict:n=>{const t=h(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(p=>r.includes(String(p.value))),a=r.filter(p=>!o.some(g=>String(g.value)===p)),d=i.map((p,g)=>e.h(w.ElTag,{key:p.value,type:p.listClass,class:p.cssClass,disableTransitions:!0},{default:()=>p.label+" "}));return s&&a.length>0&&d.push(e.h("span",{},a.join(" "))),e.h("div",{},d)},map:n=>{var o;const t=h(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=h(n.row,n.col.key)??"";return M(t)?(s=t.formatter)==null?void 0:s.call(t,o,l):o??""},icon:n=>{const t=h(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 f=Array.isArray(c)?c:[c];return l.some(y=>y===s||f.includes(y))},i=e.computed(()=>n.some(c=>r(c.permission))),a=e.computed(()=>n.filter(f=>r(f.permission)).slice(0,t).reduce((f,y)=>f+(y.width??60),0)),d=(c,f)=>r(c.permission)&&(c.visible?c.visible(f):!0),p=c=>n.filter(y=>d(y,c)).slice(0,t).reduce((y,b)=>y+(b.width??60),0);return{hasAnyButton:i,optWidth:a,hasAnyVisibleButton:c=>c!=null&&c.length?c.some(f=>n.some(y=>d(y,f))):!1,getMaxOptWidth:c=>c!=null&&c.length?c.reduce((f,y)=>Math.max(f,p(y)),0):a.value,getVisibleButtons:c=>n.filter(f=>d(f,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=m=>{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+m+1:m+1},{col:r}=e.toRefs(l),i=(m,v)=>o("cellChange",m,v),a=(m,v)=>o("cellBlur",m,v),d=(m,v)=>o("cellEnter",m,v),p=(m,v)=>o("cellClick",m,v),g=z(),{hasAnyButton:u,hasAnyVisibleButton:k,optWidth:c,getMaxOptWidth:f,getVisibleButtons:y}=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||[]):u.value:!1),E=e.computed(()=>r.value.__rows?f(r.value.__rows):c.value);function $(m){return!(m.type==="selection"||m.type==="index"||m.type==="operation"&&!b.value||m.visible===!1)}return(m,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(y)(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"])):$(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,F;return[e.unref(r).render==="slot"&&m.$slots[((_=e.unref(r))==null?void 0:_.slot)||e.unref(r).key]?e.renderSlot(m.$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(g)[e.unref(r).render]?(e.openBlock(),e.createBlock(e.resolveDynamicComponent(e.unref(g)[e.unref(r).render]),{key:1,row:C.row,col:e.unref(r),onCellChange:i,onCellBlur:a,onCellEnter:d,onClick:p},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(((F=e.unref(r).renderProps)==null?void 0:F.class)||""),title:e.unref(h)(C.row,e.unref(r).key)},e.toDisplayString(e.unref(h)(C.row,e.unref(r).key)),15,W))]}),_:3},16,["label"])):e.createCommentVNode("",!0)}}}),N="table_columns_";function R(n,t){return`${N}${n}_${t}`}function K(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 j(n,t){const{pageKey:l,userId:o,storage:s=localStorage}=t||{},i=o?R(o,l||""):null,a=i?s.getItem(i):null,d=e.ref(K(n,a?JSON.parse(a):[]));return e.watch(d,p=>{if(!i)return;const g=p.map(u=>({key:u.key,visible:u.visible,columnOpts:u.columnOpts}));s.setItem(i,JSON.stringify(g))},{deep:!0}),{columns:d,setColumns(p){d.value=K(n,p),i&&s.setItem(i,JSON.stringify(p))},resetColumns(){d.value=n,i&&s.removeItem(i)}}}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:""},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}=j(o.columns,{pageKey:o.pageKey??"",userId:o.userId??""});e.watch(r,u=>s("update:columns",u),{deep:!0,immediate:!0});const i=(u,k)=>s("cellChange",u,k),a=(u,k)=>{s("cellBlur",u,k)},d=(u,k)=>{console.log("enter"),s("cellEnter",u,k)},p=(u,k)=>{k&&s("cell-click",u,k)},g=e.ref();return t({tableRef:g}),(u,k)=>{const c=e.resolveComponent("el-table"),f=e.resolveDirective("loading");return e.withDirectives((e.openBlock(),e.createBlock(c,e.mergeProps({ref_key:"tableRef",ref:g},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(r),y=>(e.openBlock(),e.createBlock(D,{key:y.key,col:y,permissions:n.permissions,pagination:n.pagination,onCellChange:i,onCellBlur:a,onCellEnter:d,onCellClick:p},e.createSlots({_:2},[e.renderList(e.unref(r),b=>({name:b.key,fn:e.withCtx(E=>[e.renderSlot(u.$slots,b.key,e.mergeProps({ref_for:!0},E),void 0,!0)])}))]),1032,["col","permissions","pagination"]))),128))]),_:3},16,["data","row-key"])),[[f,n.loading]])}}}),J=(n,t)=>{const l=n.__vccOpts||n;for(const[o,s]of t)l[o]=s;return l},U=J(q,[["__scopeId","data-v-7c94ec39"]]);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-7c94ec39]{width:100%}
1
+ .copy-wrapper:hover .copy-btn{display:inline-block!important}.smart-table[data-v-f4c8de68]{width:100%}
@@ -1,5 +1,5 @@
1
- import { defineComponent as O, ref as A, watch as F, resolveComponent as V, createBlock as _, openBlock as v, mergeProps as x, withKeys as R, withCtx as S, createElementBlock as I, Fragment as J, renderList as L, h as g, computed as z, toRefs as Q, createCommentVNode as Z, unref as s, createTextVNode as q, toDisplayString as T, renderSlot as Y, 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 $, ElButton as ae } 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
5
  return e.split(".").reduce((n, r) => n == null ? void 0 : n[r], t);
@@ -18,8 +18,8 @@ const ce = /* @__PURE__ */ O({
18
18
  onCellEnter: { type: Function }
19
19
  },
20
20
  setup(t) {
21
- const e = t, n = A(C(e.row, e.col.key));
22
- F(n, (l) => {
21
+ const e = t, n = F(C(e.row, e.col.key));
22
+ $(n, (l) => {
23
23
  U(e.row, e.col.key, l);
24
24
  });
25
25
  const r = () => {
@@ -31,9 +31,9 @@ const ce = /* @__PURE__ */ O({
31
31
  };
32
32
  return (l, i) => {
33
33
  const c = V("el-input");
34
- return v(), _(c, x({
34
+ return g(), _(c, x({
35
35
  modelValue: n.value,
36
- "onUpdate:modelValue": i[0] || (i[0] = (d) => n.value = d)
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
39
  onKeyup: R(o, ["enter"])
@@ -50,8 +50,8 @@ const ce = /* @__PURE__ */ O({
50
50
  onCellEnter: { type: Function }
51
51
  },
52
52
  setup(t) {
53
- const e = t, n = A(C(e.row, e.col.key));
54
- F(n, (l) => {
53
+ const e = t, n = F(C(e.row, e.col.key));
54
+ $(n, (l) => {
55
55
  var i;
56
56
  U(e.row, e.col.key, l), (i = e.onCellChange) == null || i.call(e, e.row, e.col);
57
57
  });
@@ -64,9 +64,9 @@ const ce = /* @__PURE__ */ O({
64
64
  };
65
65
  return (l, i) => {
66
66
  const c = V("el-input-number");
67
- return v(), _(c, x({
67
+ return g(), _(c, x({
68
68
  modelValue: n.value,
69
- "onUpdate:modelValue": i[0] || (i[0] = (d) => n.value = d)
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
72
  onKeyup: R(o, ["enter"])
@@ -83,8 +83,8 @@ const ce = /* @__PURE__ */ O({
83
83
  onCellEnter: { type: Function }
84
84
  },
85
85
  setup(t) {
86
- const e = t, n = A(C(e.row, e.col.key));
87
- F(n, (i) => {
86
+ const e = t, n = F(C(e.row, e.col.key));
87
+ $(n, (i) => {
88
88
  U(e.row, e.col.key, i);
89
89
  });
90
90
  const r = () => {
@@ -98,22 +98,22 @@ const ce = /* @__PURE__ */ O({
98
98
  return (i = e.onCellEnter) == null ? void 0 : i.call(e, e.row, e.col);
99
99
  };
100
100
  return (i, c) => {
101
- const d = V("el-option"), y = V("el-select");
102
- return v(), _(y, x({
101
+ const u = V("el-option"), h = V("el-select");
102
+ return g(), _(h, x({
103
103
  modelValue: n.value,
104
- "onUpdate:modelValue": c[0] || (c[0] = (h) => n.value = h)
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
107
  onBlur: o,
108
108
  onKeyup: R(l, ["enter"])
109
109
  }), {
110
- default: S(() => {
111
- var h;
110
+ default: P(() => {
111
+ var v;
112
112
  return [
113
- (v(!0), I(J, null, L(((h = t.col.renderProps) == null ? void 0 : h.options) || [], (u) => (v(), _(d, {
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
  }),
@@ -124,7 +124,7 @@ const ce = /* @__PURE__ */ O({
124
124
  }), N = (t) => O({
125
125
  props: ["row", "col", "onCellChange", "onCellBlur", "onCellEnter", "onClick"],
126
126
  setup(e) {
127
- return () => g(t, e);
127
+ return () => f(t, e);
128
128
  }
129
129
  });
130
130
  function ye(t) {
@@ -137,7 +137,7 @@ function me() {
137
137
  select: N(de),
138
138
  button: (t) => {
139
139
  const e = t.col.renderProps || {}, n = C(t.row, t.col.key);
140
- return g(ae, {
140
+ return f(ae, {
141
141
  type: e.type || "primary",
142
142
  ...e,
143
143
  onClick: () => {
@@ -148,7 +148,7 @@ function me() {
148
148
  },
149
149
  link: (t) => {
150
150
  const e = t.col.renderProps || {}, n = C(t.row, t.col.key);
151
- return g("a", {
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;",
@@ -161,7 +161,7 @@ function me() {
161
161
  html: (t) => {
162
162
  var n;
163
163
  const e = C(t.row, t.col.key);
164
- return g("div", {
164
+ return f("div", {
165
165
  class: "line-clamp-2",
166
166
  innerHTML: e ?? "",
167
167
  ...((n = t.col) == null ? void 0 : n.renderProps) || {}
@@ -169,18 +169,18 @@ function me() {
169
169
  },
170
170
  copy: (t) => {
171
171
  const e = C(t.row, t.col.key) ?? "";
172
- return g(
172
+ return f(
173
173
  "div",
174
174
  {
175
175
  class: "copy-wrapper",
176
176
  style: "position: relative; display: inline-block;"
177
177
  },
178
178
  [
179
- g("span", {
179
+ f("span", {
180
180
  class: "copy-text line-clamp-1",
181
181
  style: "padding-right: 20px;"
182
182
  }, e),
183
- g(
183
+ f(
184
184
  "span",
185
185
  {
186
186
  class: "copy-btn",
@@ -200,18 +200,18 @@ function me() {
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
208
  const n = document.createElement("textarea");
209
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(n), 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
  },
@@ -232,17 +232,17 @@ function me() {
232
232
  marginRight: o.length > 1 ? "4px" : "0",
233
233
  ...n.style || {}
234
234
  };
235
- return o.length === 1 ? g(D, {
235
+ return o.length === 1 ? f(D, {
236
236
  src: o[0],
237
237
  previewSrcList: n.previewSrcList || o,
238
238
  fit: n.fit || "contain",
239
239
  style: l,
240
240
  ...n
241
- }) : (console.log(n.previewSrcList), g("div", {
241
+ }) : (console.log(n.previewSrcList), f("div", {
242
242
  style: "display: flex; align-items: center; position: relative"
243
243
  }, [
244
244
  // 显示第一张图片,点击可预览所有
245
- g(D, {
245
+ f(D, {
246
246
  src: o[0],
247
247
  previewSrcList: n.previewSrcList || o,
248
248
  fit: n.fit || "contain",
@@ -250,7 +250,7 @@ function me() {
250
250
  ...n
251
251
  }),
252
252
  // 如果图片数量大于1,显示剩余图片数量
253
- o.length > 1 && g("span", {
253
+ o.length > 1 && f("span", {
254
254
  style: `
255
255
  margin-left: 8px;
256
256
  font-size: 12px;
@@ -269,12 +269,12 @@ function me() {
269
269
  dict: (t) => {
270
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 l = Array.isArray(e) ? e.map(String) : [String(e)], i = r.filter((y) => l.includes(String(y.value))), c = l.filter((y) => !r.some((h) => String(h.value) === y)), d = i.map((y, h) => g(
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: y.value, type: y.listClass, class: y.cssClass, disableTransitions: !0 },
275
- { default: () => y.label + " " }
274
+ { key: h.value, type: h.listClass, class: h.cssClass, disableTransitions: !0 },
275
+ { default: () => h.label + " " }
276
276
  ));
277
- return o && c.length > 0 && d.push(g("span", {}, c.join(" "))), g("div", {}, d);
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;
@@ -288,17 +288,17 @@ function me() {
288
288
  },
289
289
  icon: (t) => {
290
290
  const e = C(t.row, t.col.key) ?? "", n = t.col.renderProps || {};
291
- return e ? /^https?:\/\//.test(e) ? g(D, {
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
296
  ...n
297
- }) : /^\s*<svg[\s\S]*<\/svg>\s*$/.test(e) ? g("div", {
297
+ }) : /^\s*<svg[\s\S]*<\/svg>\s*$/.test(e) ? f("div", {
298
298
  innerHTML: e,
299
299
  style: `width:40px;height:40px;display:inline-block;${n.style || ""}`,
300
300
  ...n
301
- }) : g("i", {
301
+ }) : f("i", {
302
302
  class: e,
303
303
  // val 直接当 className
304
304
  style: `font-size:20px;${n.style || ""}`,
@@ -310,31 +310,31 @@ function me() {
310
310
  function pe(t, e = 10, n = []) {
311
311
  const o = "*:*:*", l = (a) => {
312
312
  if (!a) return !0;
313
- const p = Array.isArray(a) ? a : [a];
313
+ const m = Array.isArray(a) ? a : [a];
314
314
  return n.some(
315
- (f) => f === o || p.includes(f)
315
+ (p) => p === o || m.includes(p)
316
316
  );
317
- }, i = z(() => t.some((a) => l(a.permission))), c = z(() => t.filter((p) => l(p.permission)).slice(0, e).reduce(
318
- (p, f) => p + (f.width ?? 60),
317
+ }, i = W(() => t.some((a) => l(a.permission))), c = W(() => t.filter((m) => l(m.permission)).slice(0, e).reduce(
318
+ (m, p) => m + (p.width ?? 60),
319
319
  0
320
- )), d = (a, p) => l(a.permission) && (a.visible ? a.visible(p) : !0), y = (a) => t.filter((f) => d(f, a)).slice(0, e).reduce(
321
- (f, B) => f + (B.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
325
  hasAnyButton: i,
326
326
  optWidth: c,
327
327
  hasAnyVisibleButton: (a) => a != null && a.length ? a.some(
328
- (p) => t.some((f) => d(f, p))
328
+ (m) => t.some((p) => u(p, m))
329
329
  ) : !1,
330
330
  getMaxOptWidth: (a) => a != null && a.length ? a.reduce(
331
- (p, f) => Math.max(p, y(f)),
331
+ (m, p) => Math.max(m, h(p)),
332
332
  0
333
333
  ) : c.value,
334
- getVisibleButtons: (a) => t.filter((p) => d(p, a)).slice(0, e)
334
+ getVisibleButtons: (a) => t.filter((m) => u(m, a)).slice(0, e)
335
335
  };
336
336
  }
337
- const fe = ["title"], ge = /* @__PURE__ */ O({
337
+ const fe = ["title"], he = /* @__PURE__ */ O({
338
338
  __name: "index",
339
339
  props: {
340
340
  col: { type: Object, required: !0 },
@@ -343,78 +343,78 @@ const fe = ["title"], ge = /* @__PURE__ */ O({
343
343
  },
344
344
  emits: ["cellBlur", "cellEnter", "cellChange", "cellClick"],
345
345
  setup(t, { emit: e }) {
346
- const n = t, r = e, o = (m) => {
347
- var K, w;
348
- const k = (K = n.pagination) == null ? void 0 : K.page, E = (w = n.pagination) == null ? void 0 : w.size;
349
- return k && E ? (k - 1) * E + m + 1 : m + 1;
350
- }, { col: l } = Q(n), i = (m, k) => r("cellChange", m, k), c = (m, k) => r("cellBlur", m, k), d = (m, k) => r("cellEnter", m, k), y = (m, k) => r("cellClick", m, k), h = me(), {
351
- hasAnyButton: u,
352
- hasAnyVisibleButton: b,
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
353
  optWidth: a,
354
- getMaxOptWidth: p,
355
- getVisibleButtons: f
354
+ getMaxOptWidth: m,
355
+ getVisibleButtons: p
356
356
  } = pe(
357
357
  l.value.buttons || [],
358
358
  l.value.maxbtn ?? 10,
359
359
  n.permissions || []
360
- ), B = z(() => (l.value.buttons || []).length ? (l.value.__rows || []).length ? b(l.value.__rows || []) : u.value : !1), W = z(() => l.value.__rows ? p(l.value.__rows) : a.value);
361
- function G(m) {
362
- return !(m.type === "selection" || m.type === "index" || m.type === "operation" && !B.value || m.visible === !1);
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);
363
363
  }
364
- return (m, k) => {
365
- const E = V("el-table-column"), K = V("el-button");
366
- return s(l).type === "selection" ? (v(), _(E, x({
364
+ return (y, b) => {
365
+ const E = V("el-table-column"), L = V("el-button");
366
+ return s(l).type === "selection" ? (g(), _(E, x({
367
367
  key: 0,
368
368
  type: "selection"
369
- }, s(l).columnProps), null, 16)) : s(l).type === "index" ? (v(), _(E, x({
369
+ }, s(l).columnProps), null, 16)) : s(l).type === "index" ? (g(), _(E, x({
370
370
  key: 1,
371
371
  type: "index",
372
372
  label: s(l).label || "#",
373
373
  align: "center"
374
374
  }, s(l).columnProps), {
375
- default: S(({ $index: w }) => [
375
+ default: P(({ $index: w }) => [
376
376
  q(T(o(w)), 1)
377
377
  ]),
378
378
  _: 1
379
- }, 16, ["label"])) : s(l).type === "operation" && B.value ? (v(), _(E, x({
379
+ }, 16, ["label"])) : s(l).type === "operation" && B.value ? (g(), _(E, x({
380
380
  key: 2,
381
381
  label: s(l).label || "操作",
382
382
  align: "center"
383
383
  }, {
384
384
  ...s(l).columnProps,
385
- width: W.value
385
+ width: I.value
386
386
  }), {
387
- default: S(({ row: w }) => [
388
- (v(!0), I(J, null, L(s(f)(w), (P) => (v(), _(K, {
389
- key: P.label,
390
- type: P.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",
391
391
  link: "",
392
- onClick: (M) => P.action(w)
392
+ onClick: (M) => S.action(w)
393
393
  }, {
394
- default: S(() => [
395
- q(T(P.label), 1)
394
+ default: P(() => [
395
+ q(T(S.label), 1)
396
396
  ]),
397
397
  _: 2
398
398
  }, 1032, ["type", "onClick"]))), 128))
399
399
  ]),
400
400
  _: 1
401
- }, 16, ["label"])) : G(s(l)) ? (v(), _(E, x({
401
+ }, 16, ["label"])) : Q(s(l)) ? (g(), _(E, x({
402
402
  key: 3,
403
403
  label: s(l).label,
404
404
  align: "center"
405
405
  }, s(l).columnProps || {}), {
406
- default: S((w) => {
407
- var P, M, j, H;
406
+ default: P((w) => {
407
+ var S, M, j, H;
408
408
  return [
409
- s(l).render === "slot" && m.$slots[((P = s(l)) == null ? void 0 : P.slot) || s(l).key] ? Y(m.$slots, ((M = s(l)) == null ? void 0 : M.slot) || s(l).key, ee(x({ key: 0 }, w))) : s(l).render && s(h)[s(l).render] ? (v(), _(te(s(h)[s(l).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]), {
410
410
  key: 1,
411
411
  row: w.row,
412
412
  col: s(l),
413
413
  onCellChange: i,
414
414
  onCellBlur: c,
415
- onCellEnter: d,
416
- onClick: y
417
- }, null, 40, ["row", "col"])) : (v(), I("span", {
415
+ onCellEnter: u,
416
+ onClick: h
417
+ }, null, 40, ["row", "col"])) : (g(), z("span", {
418
418
  key: 2,
419
419
  style: le(((j = s(l).renderProps) == null ? void 0 : j.style) || ""),
420
420
  class: ne(((H = s(l).renderProps) == null ? void 0 : H.class) || ""),
@@ -426,11 +426,8 @@ const fe = ["title"], ge = /* @__PURE__ */ O({
426
426
  }, 16, ["label"])) : Z("", !0);
427
427
  };
428
428
  }
429
- }), he = "table_columns_";
430
- function ve(t, e) {
431
- return `${he}${t}_${e}`;
432
- }
433
- function X(t, e) {
429
+ });
430
+ function Y(t, e) {
434
431
  if (!(e != null && e.length)) return t;
435
432
  const n = new Map(
436
433
  e.map((r) => [r.key, r])
@@ -443,74 +440,64 @@ function X(t, e) {
443
440
  } : r;
444
441
  });
445
442
  }
446
- function Ce(t, e) {
447
- const {
448
- pageKey: n,
449
- userId: r,
450
- storage: o = localStorage
451
- } = e || {}, i = r ? ve(r, n || "") : null, c = i ? o.getItem(i) : null, d = A(
452
- X(
443
+ function ge(t, e) {
444
+ const { cacheKey: n, storage: r = localStorage } = e || {}, o = n ? r.getItem(n) : null, l = F(
445
+ Y(
453
446
  t,
454
- c ? JSON.parse(c) : []
447
+ o ? JSON.parse(o) : []
455
448
  )
456
449
  );
457
- return F(
458
- d,
459
- (y) => {
460
- if (!i) return;
461
- const h = y.map((u) => ({
450
+ return $(
451
+ l,
452
+ (i) => {
453
+ if (!n) return;
454
+ const c = i.map((u) => ({
462
455
  key: u.key,
463
456
  visible: u.visible,
464
457
  columnOpts: u.columnOpts
465
458
  }));
466
- o.setItem(
467
- i,
468
- JSON.stringify(h)
459
+ r.setItem(
460
+ n,
461
+ JSON.stringify(c)
469
462
  );
470
463
  },
471
464
  { deep: !0 }
472
465
  ), {
473
466
  /** 当前列配置(响应式) */
474
- columns: d,
467
+ columns: l,
475
468
  /**
476
469
  * 主动设置列配置
477
470
  * 常用于:列设置弹窗 / 拖拽排序完成
478
471
  */
479
- setColumns(y) {
480
- d.value = X(
472
+ setColumns(i) {
473
+ l.value = Y(
481
474
  t,
482
- y
483
- ), i && o.setItem(
484
- i,
485
- JSON.stringify(y)
475
+ i
476
+ ), n && r.setItem(
477
+ n,
478
+ JSON.stringify(i)
486
479
  );
487
480
  },
488
481
  /**
489
482
  * 重置为默认列配置
490
483
  */
491
484
  resetColumns() {
492
- d.value = t, i && o.removeItem(i);
485
+ l.value = t, n && r.removeItem(n);
493
486
  }
494
487
  };
495
488
  }
496
- const be = /* @__PURE__ */ O({
489
+ const ve = /* @__PURE__ */ O({
497
490
  __name: "index",
498
491
  props: {
499
492
  data: { type: Array, default: () => [] },
500
493
  columns: { type: Array, default: () => [] },
501
- // v-model:columns
502
- pageKey: String,
503
494
  rowKey: { type: String, default: "id" },
504
495
  loading: { type: Boolean, default: !1 },
505
496
  permissions: {
506
497
  type: Array,
507
498
  default: () => []
508
499
  },
509
- userId: {
510
- /** 当前用户标识(可选,用于列缓存) */
511
- type: [String, Number],
512
- default: ""
513
- },
500
+ cacheKey: String,
514
501
  pagination: { type: Object, default: () => ({}) }
515
502
  },
516
503
  emits: [
@@ -521,65 +508,64 @@ const be = /* @__PURE__ */ O({
521
508
  "cell-click"
522
509
  ],
523
510
  setup(t, { expose: e, emit: n }) {
524
- const r = t, o = n, { columns: l } = Ce(r.columns, {
525
- pageKey: r.pageKey ?? "",
526
- userId: r.userId ?? ""
511
+ const r = t, o = n, { columns: l } = ge(r.columns, {
512
+ cacheKey: r.cacheKey ?? ""
527
513
  });
528
- F(
514
+ $(
529
515
  l,
530
- (u) => o("update:columns", u),
516
+ (d) => o("update:columns", d),
531
517
  { deep: !0, immediate: !0 }
532
518
  );
533
- const i = (u, b) => o("cellChange", u, b), c = (u, b) => {
534
- o("cellBlur", u, b);
535
- }, d = (u, b) => {
536
- console.log("enter"), o("cellEnter", u, b);
537
- }, y = (u, b) => {
538
- b && o("cell-click", u, b);
539
- }, h = 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();
540
526
  return e({
541
- tableRef: h
542
- }), (u, b) => {
543
- const a = V("el-table"), p = re("loading");
544
- return oe((v(), _(a, x({
527
+ tableRef: v
528
+ }), (d, k) => {
529
+ const a = V("el-table"), m = re("loading");
530
+ return oe((g(), _(a, x({
545
531
  ref_key: "tableRef",
546
- ref: h
547
- }, u.$attrs, {
532
+ ref: v
533
+ }, d.$attrs, {
548
534
  data: t.data,
549
535
  "row-key": t.rowKey,
550
536
  class: "smart-table"
551
537
  }), {
552
- default: S(() => [
553
- (v(!0), I(J, null, L(s(l), (f) => (v(), _(ge, {
554
- key: f.key,
555
- col: f,
538
+ default: P(() => [
539
+ (g(!0), z(J, null, K(s(l), (p) => (g(), _(he, {
540
+ key: p.key,
541
+ col: p,
556
542
  permissions: t.permissions,
557
543
  pagination: t.pagination,
558
544
  onCellChange: i,
559
545
  onCellBlur: c,
560
- onCellEnter: d,
561
- onCellClick: y
546
+ onCellEnter: u,
547
+ onCellClick: h
562
548
  }, ie({ _: 2 }, [
563
- L(s(l), (B) => ({
549
+ K(s(l), (B) => ({
564
550
  name: B.key,
565
- fn: S((W) => [
566
- Y(u.$slots, B.key, x({ ref_for: !0 }, W), void 0, !0)
551
+ fn: P((I) => [
552
+ G(d.$slots, B.key, x({ ref_for: !0 }, I), void 0, !0)
567
553
  ])
568
554
  }))
569
555
  ]), 1032, ["col", "permissions", "pagination"]))), 128))
570
556
  ]),
571
557
  _: 3
572
558
  }, 16, ["data", "row-key"])), [
573
- [p, t.loading]
559
+ [m, t.loading]
574
560
  ]);
575
561
  };
576
562
  }
577
- }), ke = (t, e) => {
563
+ }), Ce = (t, e) => {
578
564
  const n = t.__vccOpts || t;
579
565
  for (const [r, o] of e)
580
566
  n[r] = o;
581
567
  return n;
582
- }, xe = /* @__PURE__ */ ke(be, [["__scopeId", "data-v-7c94ec39"]]);
568
+ }, we = /* @__PURE__ */ Ce(ve, [["__scopeId", "data-v-f4c8de68"]]);
583
569
  export {
584
- xe as SmartTable
570
+ we as SmartTable
585
571
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue3-smart-table",
3
- "version": "0.0.4",
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",