yk-element-components
Version:
2 lines (1 loc) • 15.6 kB
JavaScript
(function(e,O){typeof exports=="object"&&typeof module<"u"?module.exports=O(require("vue")):typeof define=="function"&&define.amd?define(["vue"],O):(e=typeof globalThis<"u"?globalThis:e||self,e.index=O(e.Vue))})(this,function(e){"use strict";const O="",z={props:{scopedSlots:{type:Array,default:()=>[]},align:{type:String,default:"left"},more:{type:Array,default:()=>[]},trigger:{type:String,default:"hover"},editing:{type:Boolean,default:!1},orEdit:{type:Boolean,default:!1}},data(){return{}},render(i){const B=this.scopedSlots,f=B.slice(0,this.orEdit?this.editing?1:2:3),p=B.slice(this.orEdit?this.editing?1:2:3,B.length),y=()=>this.more.length===0?e.createVNode(e.resolveComponent("el-button"),{type:"text"},{default:()=>[e.createVNode("i",{class:"el-icon-more"},null),e.createTextVNode("\u66F4\u591A")]}):this.more;return e.createVNode("div",null,[e.createVNode("div",null,[f.map((x,k)=>x),p.length>0?e.createVNode(e.resolveComponent("el-dropdown"),{style:"margin-left: 10px","popper-class":"node_dropdown_box",trigger:this.trigger},{default:()=>[y()],dropdown:()=>e.createVNode(e.Fragment,null,[e.createVNode(e.resolveComponent("el-dropdown-menu"),null,{default:()=>[e.createVNode("div",{class:"dropdownBox"},[p.map(x=>e.createVNode("div",{class:["dropdownItem",this.align]},[x]))])]})])}):""])])}},A={key:1},W={key:1},U={key:1},R={key:1},J={key:1},j={class:"operation"},P=e.defineComponent({__name:"index",props:{page:{type:[Number,String],default:1},limit:{type:Number,default:20},options:{type:Array,required:!0},data:{type:Array,required:!0},isLoading:{type:Array,default:!1},elementLoadingText:{type:String},elementLoadingSpinner:{type:String},elementLoadingBackground:{type:String},elementLoadingSvg:{type:String},elementLoadingSvgViewBox:{type:String},orEdit:{type:Boolean,default:!1},editRowIndex:{type:String,default:""},pagination:{type:Boolean,default:!1},pageSizes:{type:Array,default:()=>[10,20,30,40]},total:{type:Number,default:0},paginationAlign:{type:String,default:"left"},operateDropAlign:{type:String,default:"left"},trigger:{type:String,default:"hover"},rowKey:{type:String,default:""},treeProps:{type:Object,default:()=>{}},lazy:{type:Boolean,default:!1},load:{type:Function,default:null},defaultEdit:{type:Boolean,default:!1},spanMethod:Function},emits:["edit","rowClick","cancel","confirm","selection-change","select-all","pagination","update:page","update:limit"],setup(i,{expose:B,emit:f}){const p=i;let y=e.ref(),x=e.computed(()=>(p.options.forEach(o=>{o.headerSlot&&(o.headerName="header")}),p.options.filter(o=>!o.action&&!o.selection))),k=e.computed(()=>p.options.find(o=>o.selection)),w=e.computed(()=>p.options.find(o=>o.action)),$=e.computed({get(){return Number(p.page)},set(o){f("update:page",o)}}),N=e.computed({get(){return p.limit},set(o){f("update:limit",o)}}),c=e.ref({});const F=o=>(o.forEach(a=>{a.headerSlot&&(a.headerName="header")}),o.filter(a=>!a.action&&!a.selection)),q=o=>{y.value.clearFilter(o)},C=(o,a,s)=>{if(s.sortable&&s.sortMethod)return s.sortMethod(o,a,s)},u=(o,a,s,g)=>{if(g.filterMethod&&g.filterMethod)return g.filterMethod(o,a,s)},K=(o,a)=>{let s=JSON.parse(JSON.stringify(o));c.value[a]=s,o.rowEdit=!0,f("edit",o,a)},G=(o,a)=>{for(let s in o)o[s]=c.value[a][s];o.rowEdit=!1,e.nextTick(()=>{c.value[a]={}}),f("confirm",o,a)};let H=(o,a)=>{f("rowClick",o,a)},Q=(o,a)=>{o.rowEdit=!1,e.nextTick(()=>{c.value[a]={},f("cancel",o,a)})},T=e.ref(JSON.parse(JSON.stringify(p.data)));e.watch(()=>p.data,o=>{o&&D()},{deep:!0}),e.onMounted(()=>{D()});const X=({row:o,column:a,rowIndex:s,columnIndex:g})=>{if(p.spanMethod)return p.spanMethod({row:o,column:a,rowIndex:s,columnIndex:g})},D=()=>{let o=JSON.parse(JSON.stringify(p.data));o.map((a,s)=>{a.rowEdit=a.rowEdit?a.rowEdit:p.defaultEdit;let g=JSON.parse(JSON.stringify(a));c.value[s]=g}),T.value=o},Y=(o,a)=>{y.value.toggleRowSelection(o,a)},Z=()=>{y.value.clearSelection()},_=o=>{f("selection-change",o)},v=o=>{f("select-all",o)},ee=(o,a)=>{f("pagination",o,a)};return B({clearFilter:q,toggleRowSelection:Y,clearSelection:Z}),(o,a)=>{const s=e.resolveComponent("el-table-column"),g=e.resolveComponent("el-input"),L=e.resolveComponent("el-button"),oe=e.resolveComponent("el-table"),te=e.resolveComponent("yk-pagination"),le=e.resolveDirective("loading");return e.openBlock(),e.createElementBlock(e.Fragment,null,[e.withDirectives((e.openBlock(),e.createBlock(oe,e.mergeProps({ref_key:"customTable",ref:y},o.$attrs,{data:e.unref(T),"element-loading-text":i.elementLoadingText,"element-loading-spinner":i.elementLoadingSpinner,"element-loading-background":i.elementLoadingBackground,"element-loading-svg":i.elementLoadingSvg,"element-loading-svg-view-box":i.elementLoadingSvgViewBox,onRowClick:e.unref(H),onSelectionChange:_,onSelectAll:v,"tree-props":i.treeProps,"row-key":i.rowKey,lazy:i.lazy,load:i.load,"span-method":X}),{default:e.withCtx(()=>[e.unref(k)&&e.unref(k).selection?(e.openBlock(),e.createBlock(s,{key:0,type:"selection",align:e.unref(k).align?e.unref(k).align:"left",width:e.unref(k).width?e.unref(k).width:"","min-width":e.unref(k).minWidth?e.unref(k).minWidth:"",fixed:e.unref(k).fixed,selectable:e.unref(k).selectable,"reserve-selection":e.unref(k).reserveSelection},null,8,["align","width","min-width","fixed","selectable","reserve-selection"])):e.createCommentVNode("",!0),(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(x),(t,M)=>(e.openBlock(),e.createBlock(s,{key:M,label:t.label,prop:t.prop,align:t.align?t.align:"left",width:t.width,fixed:t.fixed,sortable:t.sortable,"sort-method":t.sortMethod?(r,S)=>C(r,S,t):null,"min-width":t.minWidth?t.minWidth:"","show-overflow-tooltip":t.showOverflowTooltip,"column-key":t.prop,filters:t.filters,"filter-method":t.filterMethod?(r,S,l)=>u(r,S,l,t):null},e.createSlots({default:e.withCtx(()=>[t.childrenOptions&&t.childrenOptions.length>0?(e.openBlock(!0),e.createElementBlock(e.Fragment,{key:0},e.renderList(F(t.childrenOptions),(r,S)=>(e.openBlock(),e.createBlock(s,{key:S,label:r.label,prop:r.prop,align:r.align?r.align:"left",width:r.width,fixed:r.fixed,sortable:r.sortable,"sort-method":r.sortMethod?(l,E)=>C(l,E,r):null,"min-width":r.minWidth?r.minWidth:"","show-overflow-tooltip":r.showOverflowTooltip,"column-key":r.prop,filters:r.filters,"filter-method":r.filterMethod?(l,E,n)=>u(l,E,n,r):null},e.createSlots({default:e.withCtx(()=>[r.childrenOptions&&r.childrenOptions.length>0?(e.openBlock(!0),e.createElementBlock(e.Fragment,{key:0},e.renderList(F(r.childrenOptions),(l,E)=>(e.openBlock(),e.createBlock(s,{key:E,label:l.label,prop:l.prop,align:l.align?l.align:"left",width:l.width,fixed:l.fixed,sortable:l.sortable,"sort-method":l.sortMethod?(n,b)=>C(n,b,l):null,"min-width":l.minWidth?l.minWidth:"","show-overflow-tooltip":l.showOverflowTooltip,"column-key":l.prop,filters:l.filters,"filter-method":l.filterMethod?(n,b,d)=>u(n,b,d,l):null},e.createSlots({default:e.withCtx(()=>[l.childrenOptions&&l.childrenOptions.length>0?(e.openBlock(!0),e.createElementBlock(e.Fragment,{key:0},e.renderList(F(l.childrenOptions),(n,b)=>(e.openBlock(),e.createBlock(s,{key:b,label:n.label,prop:n.prop,align:n.align?n.align:"left",width:n.width,fixed:n.fixed,sortable:n.sortable,"sort-method":n.sortMethod?(d,m)=>C(d,m,n):null,"min-width":n.minWidth?n.minWidth:"","show-overflow-tooltip":n.showOverflowTooltip,"column-key":n.prop,filters:n.filters,"filter-method":n.filterMethod?(d,m,h)=>u(d,m,h,n):null},e.createSlots({default:e.withCtx(()=>[n.childrenOptions&&n.childrenOptions.length>0?(e.openBlock(!0),e.createElementBlock(e.Fragment,{key:0},e.renderList(F(n.childrenOptions),(d,m)=>(e.openBlock(),e.createBlock(s,{key:m,label:d.label,prop:d.prop,align:d.align?d.align:"left",width:d.width,fixed:d.fixed,sortable:d.sortable,"sort-method":d.sortMethod?(h,V)=>C(h,V,d):null,"min-width":d.minWidth?d.minWidth:"","show-overflow-tooltip":d.showOverflowTooltip,"column-key":d.prop,filters:d.filters,"filter-method":d.filterMethod?(h,V,ne)=>u(h,V,ne,d):null},e.createSlots({_:2},[d.headerSlot?{name:"header",fn:e.withCtx(h=>[e.renderSlot(o.$slots,d.headerSlot,{scope:h},void 0,!0)]),key:"0"}:void 0,!d.childrenOptions||d.childrenOptions.length==0?{name:"default",fn:e.withCtx(h=>[h.row.rowEdit&&d.editable&&i.orEdit?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[d.customEditSlot?e.renderSlot(o.$slots,d.customEditSlot,{key:0,scope:e.unref(c)[h.$index]},void 0,!0):(e.openBlock(),e.createBlock(g,{key:1,size:"small",modelValue:e.unref(c)[h.$index][d.prop?d.prop:""],"onUpdate:modelValue":V=>e.unref(c)[h.$index][d.prop?d.prop:""]=V},null,8,["modelValue","onUpdate:modelValue"]))],64)):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[d.slot?e.renderSlot(o.$slots,d.slot,{key:0,scope:h},void 0,!0):(e.openBlock(),e.createElementBlock("span",A,e.toDisplayString(h.row[d.prop?d.prop:""]),1))],64))]),key:"1"}:void 0]),1032,["label","prop","align","width","fixed","sortable","sort-method","min-width","show-overflow-tooltip","column-key","filters","filter-method"]))),128)):e.createCommentVNode("",!0)]),_:2},[n.headerSlot?{name:"header",fn:e.withCtx(d=>[e.renderSlot(o.$slots,n.headerSlot,{scope:d},void 0,!0)]),key:"0"}:void 0,!n.childrenOptions||n.childrenOptions.length==0?{name:"default",fn:e.withCtx(d=>[d.row.rowEdit&&n.editable&&i.orEdit?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[n.customEditSlot?e.renderSlot(o.$slots,n.customEditSlot,{key:0,scope:e.unref(c)[d.$index]},void 0,!0):(e.openBlock(),e.createBlock(g,{key:1,size:"small",modelValue:e.unref(c)[d.$index][n.prop?n.prop:""],"onUpdate:modelValue":m=>e.unref(c)[d.$index][n.prop?n.prop:""]=m},null,8,["modelValue","onUpdate:modelValue"]))],64)):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[n.slot?e.renderSlot(o.$slots,n.slot,{key:0,scope:d},void 0,!0):(e.openBlock(),e.createElementBlock("span",W,e.toDisplayString(d.row[n.prop?n.prop:""]),1))],64))]),key:"1"}:void 0]),1032,["label","prop","align","width","fixed","sortable","sort-method","min-width","show-overflow-tooltip","column-key","filters","filter-method"]))),128)):e.createCommentVNode("",!0)]),_:2},[l.headerSlot?{name:"header",fn:e.withCtx(n=>[e.renderSlot(o.$slots,l.headerSlot,{scope:n},void 0,!0)]),key:"0"}:void 0,!l.childrenOptions||l.childrenOptions.length==0?{name:"default",fn:e.withCtx(n=>[n.row.rowEdit&&l.editable&&i.orEdit?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[l.customEditSlot?e.renderSlot(o.$slots,l.customEditSlot,{key:0,scope:e.unref(c)[n.$index]},void 0,!0):(e.openBlock(),e.createBlock(g,{key:1,size:"small",modelValue:e.unref(c)[n.$index][l.prop?l.prop:""],"onUpdate:modelValue":b=>e.unref(c)[n.$index][l.prop?l.prop:""]=b},null,8,["modelValue","onUpdate:modelValue"]))],64)):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[l.slot?e.renderSlot(o.$slots,l.slot,{key:0,scope:n},void 0,!0):(e.openBlock(),e.createElementBlock("span",U,e.toDisplayString(n.row[l.prop?l.prop:""]),1))],64))]),key:"1"}:void 0]),1032,["label","prop","align","width","fixed","sortable","sort-method","min-width","show-overflow-tooltip","column-key","filters","filter-method"]))),128)):e.createCommentVNode("",!0)]),_:2},[r.headerSlot?{name:"header",fn:e.withCtx(l=>[e.renderSlot(o.$slots,r.headerSlot,{scope:l},void 0,!0)]),key:"0"}:void 0,!r.childrenOptions||r.childrenOptions.length==0?{name:"default",fn:e.withCtx(l=>[l.row.rowEdit&&r.editable&&i.orEdit?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[r.customEditSlot?e.renderSlot(o.$slots,r.customEditSlot,{key:0,scope:e.unref(c)[l.$index]},void 0,!0):(e.openBlock(),e.createBlock(g,{key:1,size:"small",modelValue:e.unref(c)[l.$index][r.prop?r.prop:""],"onUpdate:modelValue":E=>e.unref(c)[l.$index][r.prop?r.prop:""]=E},null,8,["modelValue","onUpdate:modelValue"]))],64)):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[r.slot?e.renderSlot(o.$slots,r.slot,{key:0,scope:l},void 0,!0):(e.openBlock(),e.createElementBlock("span",R,e.toDisplayString(l.row[r.prop?r.prop:""]),1))],64))]),key:"1"}:void 0]),1032,["label","prop","align","width","fixed","sortable","sort-method","min-width","show-overflow-tooltip","column-key","filters","filter-method"]))),128)):e.createCommentVNode("",!0)]),_:2},[t.headerSlot?{name:"header",fn:e.withCtx(r=>[e.renderSlot(o.$slots,t.headerSlot,{scope:r},void 0,!0)]),key:"0"}:void 0,!t.childrenOptions||t.childrenOptions.length==0?{name:"default",fn:e.withCtx(r=>[r.row.rowEdit&&t.editable&&i.orEdit?(e.openBlock(),e.createElementBlock(e.Fragment,{key:0},[t.customEditSlot?e.renderSlot(o.$slots,t.customEditSlot,{key:0,scope:e.unref(c)[r.$index]},void 0,!0):(e.openBlock(),e.createBlock(g,{key:1,size:"small",modelValue:e.unref(c)[r.$index][t.prop?t.prop:""],"onUpdate:modelValue":S=>e.unref(c)[r.$index][t.prop?t.prop:""]=S},null,8,["modelValue","onUpdate:modelValue"]))],64)):(e.openBlock(),e.createElementBlock(e.Fragment,{key:1},[t.slot?e.renderSlot(o.$slots,t.slot,{key:0,scope:r},void 0,!0):(e.openBlock(),e.createElementBlock("span",J,e.toDisplayString(r.row[t.prop?t.prop:""]),1))],64))]),key:"1"}:void 0]),1032,["label","prop","align","width","fixed","sortable","sort-method","min-width","show-overflow-tooltip","column-key","filters","filter-method"]))),128)),e.unref(w)?(e.openBlock(),e.createBlock(s,{key:1,label:e.unref(w).label?e.unref(w).label:"",align:e.unref(w).align?e.unref(w).align:"left",width:e.unref(w).width?e.unref(w).width:"","min-width":e.unref(w).minWidth?e.unref(w).minWidth:"",fixed:e.unref(w).fixed},{default:e.withCtx(t=>[e.createElementVNode("div",j,[i.orEdit&&!t.row.rowEdit?(e.openBlock(),e.createBlock(L,{key:0,type:"text",size:"mini",style:{"margin-right":"10px"},onClick:M=>K(t.row,t.$index)},{default:e.withCtx(()=>[e.createTextVNode("\u7F16\u8F91")]),_:2},1032,["onClick"])):e.createCommentVNode("",!0),i.orEdit&&t.row.rowEdit?(e.openBlock(),e.createBlock(L,{key:1,type:"text",size:"mini",onClick:M=>G(t.row,t.$index)},{default:e.withCtx(()=>[e.createTextVNode("\u786E\u8BA4")]),_:2},1032,["onClick"])):e.createCommentVNode("",!0),i.orEdit&&t.row.rowEdit?(e.openBlock(),e.createBlock(L,{key:2,type:"text",size:"mini",style:{"margin-right":"10px"},onClick:M=>e.unref(Q)(t.row,t.$index)},{default:e.withCtx(()=>[e.createTextVNode("\u53D6\u6D88")]),_:2},1032,["onClick"])):e.createCommentVNode("",!0),t.row.rowEdit?(e.openBlock(),e.createBlock(e.unref(z),{key:3,orEdit:i.orEdit,editing:t.row.rowEdit,align:i.operateDropAlign,"scoped-slots":o.$slots.editRow?o.$slots.editRow({scope:t}):{},more:o.$slots.moreEl,trigger:i.trigger},null,8,["orEdit","editing","align","scoped-slots","more","trigger"])):(e.openBlock(),e.createBlock(e.unref(z),{key:4,orEdit:i.orEdit,editing:t.row.rowEdit,align:i.operateDropAlign,"scoped-slots":o.$slots.action?o.$slots.action({scope:t}):{},more:o.$slots.moreEl,trigger:i.trigger},null,8,["orEdit","editing","align","scoped-slots","more","trigger"]))])]),_:1},8,["label","align","width","min-width","fixed"])):e.createCommentVNode("",!0)]),_:3},16,["data","element-loading-text","element-loading-spinner","element-loading-background","element-loading-svg","element-loading-svg-view-box","onRowClick","tree-props","row-key","lazy","load"])),[[le,i.isLoading]]),e.withDirectives(e.createVNode(te,{total:i.total,page:e.unref($),"onUpdate:page":a[0]||(a[0]=t=>e.isRef($)?$.value=t:$=t),limit:e.unref(N),"onUpdate:limit":a[1]||(a[1]=t=>e.isRef(N)?N.value=t:N=t),pageSizes:i.pageSizes,onPagination:ee},null,8,["total","page","limit","pageSizes"]),[[e.vShow,i.pagination]])],64)}}}),re="",I=((i,B)=>{const f=i.__vccOpts||i;for(const[p,y]of B)f[p]=y;return f})(P,[["__scopeId","data-v-12f74e4a"]]);return{install(i){i.component("yk-table",I)}}});