znyg-frontend-common 1.1.12 → 1.1.14
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/es/components/znTable/src/index.vue2.mjs +16 -16
- package/es/components/znTable/src/index.vue2.mjs.map +1 -1
- package/es/components/znTreeFilter/src/index.vue2.mjs +4 -4
- package/es/components/znTreeFilter/src/index.vue2.mjs.map +1 -1
- package/es/index.mjs +1 -1
- package/es/index.mjs.map +1 -1
- package/lib/components/znTable/src/index.vue2.js +2 -2
- package/lib/components/znTable/src/index.vue2.js.map +1 -1
- package/lib/components/znTreeFilter/src/index.vue2.js +2 -2
- package/lib/components/znTreeFilter/src/index.vue2.js.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{defineComponent as e,getCurrentInstance as t,ref as
|
|
1
|
+
import{defineComponent as e,getCurrentInstance as t,ref as a,computed as l,onMounted as r,onUnmounted as o,toRaw as n,reactive as i,watch as s,nextTick as u,unref as c,provide as p,resolveComponent as d,resolveDirective as h,createElementBlock as m,openBlock as f,createCommentVNode as v,withDirectives as g,createElementVNode as y,createBlock as S,createVNode as b,vShow as C,normalizeClass as w,renderSlot as _,mergeProps as q,withCtx as k,Fragment as T,renderList as x,resolveDynamicComponent as A,createSlots as B}from"vue";import E from"./assets/notData.png.mjs";import"./components/ColSetting.vue.mjs";import"./components/Pagination.vue.mjs";import"./components/TableColumn.vue.mjs";import"./components/SearchForm/index.vue.mjs";import"./components/OperationBtns/index.vue.mjs";import{useSelection as P}from"./hooks/useSelection.mjs";import{useTable as N}from"./hooks/useTable.mjs";import{generateUUID as O,handleProp as L}from"./utils.mjs";import{Refresh as F,Operation as M,Search as j,DCaret as z,Loading as $}from"@element-plus/icons-vue";import{ElTable as I}from"element-plus";import{useLocalStorage as U,useResizeObserver as H}from"@vueuse/core";import V from"./components/SearchForm/index.vue2.mjs";import R from"./components/OperationBtns/index.vue2.mjs";import D from"./components/TableColumn.vue2.mjs";import K from"./components/Pagination.vue2.mjs";import G from"./components/ColSetting.vue2.mjs";var X=Object.defineProperty,J=(e,t)=>X(e,"name",{value:t,configurable:!0});const Z={class:"table-box"},Q={class:"table-header"},W={class:"header-button-lf"},Y={key:0,class:"header-button-ri"},ee={key:0,style:{display:"flex","align-items":"center","justify-content":"center",padding:"20px 0",color:"#909399","font-size":"14px"}},te={key:0,style:{display:"flex","align-items":"center",gap:"8px"}},ae={key:1,style:{color:"#909399"}},le={class:"table-empty"};var re=e({name:"ZnTable",__name:"index",props:{columns:{type:Array,required:!0,default:J((()=>[]),"default")},data:{type:Array,required:!1},requestApi:{type:Function,required:!1},requestAuto:{type:Boolean,required:!1,default:!0},requestError:{type:Function,required:!1},dataCallback:{type:Function,required:!1},title:{type:String,required:!1},pagination:{type:Boolean,required:!1,default:!0},pageSizeOptions:{type:Array,required:!1,default:J((()=>[10,25,50,100]),"default")},pageSize:{type:Number,required:!1,default:15},initParam:{required:!1,default:{}},border:{type:Boolean,required:!1,default:!0},toolButton:{type:[Array,Boolean],required:!1,default:!0},rowKey:{type:String,required:!1,default:"id"},searchCol:{type:[Number,Object],required:!1,default:J((()=>({xs:1,sm:2,md:2,lg:3,xl:4})),"default")},height:{type:[String,Number],required:!1},heightOffset:{type:Number,required:!1,default:0},minHeight:{type:[String,Number],required:!1,default:200},onlyTable:{type:Boolean,required:!1,default:!1},isView:{type:Boolean,required:!1,default:!1},searchFormShow:{type:Boolean,required:!1,default:!0},enableScrollPagination:{type:Boolean,required:!1,default:!1},scrollPaginationThreshold:{type:Number,required:!1,default:100}},emits:["search","reset","dragSort","handleOperateBtnsClick"],setup(e,{expose:X,emit:re}){const oe=e,ne=t(),ie=U("znyg",{dictMap:{}}),se=a(0);H(document.body,(e=>{const t=e[0],{height:a}=t.contentRect;se.value=a}));const ue=l((()=>{if(oe.height){if("auto"===oe.height){if(!(Ve.value&&Ve.value.length>0)){const e="number"==typeof oe.minHeight?oe.minHeight:parseInt(oe.minHeight.toString());return Math.max(e,200)}}return oe.height}const e=se.value-100-(ge.value?120:40)-(oe.pagination?150:0)-oe.heightOffset,t="number"==typeof oe.minHeight?oe.minHeight:parseInt(oe.minHeight.toString());return e>t?e:t})),ce=a(),pe=a("id-"+O()),de={
|
|
2
2
|
// 前置特殊列(显示在表格最前面)
|
|
3
3
|
FRONT_COLUMNS:["selection","radio","index","expand","sort"],
|
|
4
4
|
// 后置特殊列(显示在表格最后面)
|
|
@@ -8,23 +8,23 @@ EXCLUDE_FROM_SETTING:{props:["operation"],
|
|
|
8
8
|
// 按 prop 排除
|
|
9
9
|
types:[],
|
|
10
10
|
// 按 type 排除(会自动包含所有特殊列类型)
|
|
11
|
-
fixed:!0}},
|
|
12
|
-
/* STABLE */}),
|
|
13
|
-
/* HOISTED */))])):ze.value?
|
|
14
|
-
/* HOISTED */)])))]))])),empty:k((()=>[y("div",
|
|
15
|
-
/* HOISTED */)),
|
|
16
|
-
/* HOISTED */))]))])])),default:k((()=>[_(t.$slots,"default"),(
|
|
17
|
-
/* FULL_PROPS */)):_(t.$slots,
|
|
18
|
-
/* STABLE_FRAGMENT */)):
|
|
11
|
+
fixed:!0}},he=[...de.FRONT_COLUMNS,...de.BACK_COLUMNS],me=J((e=>e&&de.FRONT_COLUMNS.includes(e)),"isFrontSpecialColumn"),fe=J((e=>e&&de.BACK_COLUMNS.includes(e)),"isBackSpecialColumn"),ve=J((e=>{const{type:t,prop:a,fixed:l}=e;return!(!t||!he.includes(t))||(!(!a||!de.EXCLUDE_FROM_SETTING.props.includes(a))||!(!de.EXCLUDE_FROM_SETTING.fixed||!l))}),"shouldExcludeFromSetting"),ge=a(oe.searchFormShow),ye=J((e=>Array.isArray(oe.toolButton)?oe.toolButton.includes(e):oe.toolButton),"showToolButton"),Se=a(""),{selectionChange:be,selectedList:Ce,selectedListIds:we,isSelected:_e}=P(oe.rowKey),qe=J((()=>{const e=ce.value?.$el;if(e){const t=e.querySelector(".el-scrollbar__wrap");t&&(t.scrollTop=0)}}),"scrollToTop"),ke=J((()=>{ze.value=!0,je.value=!1,$e.value=!1}),"resetScrollPagination"),{tableData:Te,pageable:xe,searchParam:Ae,searchInitParam:Be,getTableList:Ee,search:Pe,reset:Ne,handleSizeChange:Oe,handleCurrentChange:Le,loading:Fe}=N(oe.requestApi,oe.initParam,oe.pagination||oe.enableScrollPagination,oe.dataCallback,oe.requestError,oe.pageSize,qe,ke,oe.enableScrollPagination),Me=J((async()=>{oe.enableScrollPagination&&ke(),await Ee()}),"getTableList"),je=a(!1),ze=a(!0),$e=a(!1),Ie=J((async()=>{if(je.value||!ze.value||$e.value||!oe.enableScrollPagination)return;if(0===xe.value.total)return;const e=Math.ceil(xe.value.total/xe.value.pageSize);if(xe.value.pageNum>=e)ze.value=!1;else try{je.value=!0,$e.value=!0;const e=xe.value.pageNum+1,t={...Be.value,...Ae.value,currPage:e,pageSize:xe.value.pageSize,params:{...Be.value,...Ae.value}};if(oe.requestApi){const{result:e}=await oe.requestApi(t),a=oe.dataCallback?oe.dataCallback(e):e;if(a&&a.list&&Array.isArray(a.list)&&a.list.length>0){Array.isArray(Te.value)||(Te.value=[]),Te.value.push(...a.list);const{currPage:e,limit:t,total:l}=a;xe.value.pageNum=e,xe.value.pageSize=t,xe.value.total=l;const r=Math.ceil(l/t);ze.value=e<r}else ze.value=!1,console.log("❌ 滚动翻页没有更多数据")}}catch(e){oe.requestError&&oe.requestError(e)}finally{je.value=!1,setTimeout((()=>{$e.value=!1}),1e3)}}),"handleScrollPagination"),Ue=J((e=>{if(!oe.enableScrollPagination||!oe.requestApi)return;if(je.value||!ze.value)return;const t=ce.value?.$el;if(!t)return;const a=t.querySelector(".el-scrollbar__wrap");if(!a)return;const l=a.scrollTop;a.scrollHeight-l-a.clientHeight<=oe.scrollPaginationThreshold&&Ie()}),"handleScroll"),He=J((()=>{ce.value&&ce.value.clearSelection()}),"clearSelection");r((()=>{oe.requestAuto&&Me(),oe.data&&(xe.value.total=oe.data.length),oe.enableScrollPagination&&setTimeout((()=>{const e=ce.value?.$el;if(e){const t=e.querySelector(".el-scrollbar__wrap");t&&(t.removeEventListener("scroll",Ue),t.addEventListener("scroll",Ue,{passive:!0}))}}),500)})),o((()=>{if(oe.enableScrollPagination){const e=ce.value?.$el;if(e){const t=e.querySelector(".el-scrollbar__wrap");t&&t.removeEventListener("scroll",Ue)}}}));const Ve=l((()=>{if(Array.isArray(Te.value)||(Te.value=[]),oe.data){if(!Array.isArray(oe.data))return console.warn("props.data 不是数组:",oe.data),[];if(!oe.pagination)return oe.data;const e=n(oe.data).slice((xe.value.pageNum-1)*xe.value.pageSize,xe.value.pageSize*xe.value.pageNum);return i(e)}return Te.value}));s((()=>oe.initParam),(()=>{Me()}),{deep:!0}),s((()=>Te.value),(()=>{oe.enableScrollPagination&&ze.value&&u((()=>{setTimeout((()=>{const e=ce.value?.$el;if(e){e.querySelector(".el-scrollbar__wrap")&&Ue({})}}),100)}))}),{deep:!0});let Re=i(oe.columns);const De=l((()=>Xe(Re))),Ke=a(new Map),Ge=J((async({prop:e,enum:t,dictCode:a})=>{if(a&&ie&&ie.value?.dictMap)return void Ke.value.set(e,ie.value.dictMap[a?.toString()]??[]);if(!t)return;if(Ke.value.has(e)&&("function"==typeof t||Ke.value.get(e)===t))return;if("function"!=typeof t)return Ke.value.set(e,c(t));Ke.value.set(e,[]);let l=await t();l=l?.result||l,Ke.value.set(e,l)}),"setEnumMap");p("enumMap",Ke);const Xe=J(((e,t=[])=>(e.forEach((async e=>{e._children?.length&&t.push(...Xe(e._children)),t.push(e),e.isShow=e.isShow??!0,e.isShowInView=e.isShowInView??!0,e.isFilterEnum=e.isFilterEnum??!0,await Ge(e)})),t.filter((e=>!e._children?.length)))),"flatColumnsFunc"),Je=l((()=>De.value?.filter((e=>e.search?.el||e.search?.render)).sort(((e,t)=>e.search.order-t.search.order))));Je.value?.forEach(((e,t)=>{e.search.order=e.search?.order??t+2;const a=e.search?.key??L(e.prop),l=e.search?.defaultValue;null!=l&&(Be.value[a]=l,Ae.value[a]=l)}));const Ze=a(),Qe=a([]),We=a(!1),Ye=J((()=>{Qe.value=Re.filter((e=>!ve(e)))}),"initColSetting");Ye(),s((()=>Re),(()=>{We.value||(console.log("检测到 tableColumns 变化,同步更新 colSetting"),Ye())}),{deep:!0});const et=J((e=>{if(!We.value)if(ne&&!ne.isUnmounted)try{if(We.value=!0,!e||!Array.isArray(e)||0===e.length)return void console.warn("updateTableColumns: 无效的列设置数据",{hasNewColSetting:!!e,isArray:Array.isArray(e),length:e?.length});let t;try{t=JSON.parse(JSON.stringify(e))}catch(a){console.warn("深拷贝列设置数据失败,使用浅拷贝"),t=[...e]}const a=new Map,l=[...Re];l.forEach((e=>{e&&e.prop&&a.set(e.prop,e)}));const r=[],o=new Set;l.forEach((e=>{e&&(me(e.type)||"left"===e.fixed)&&(r.push(e),e.prop&&o.add(e.prop))})),t.forEach((e=>{if(e&&e.prop&&a.has(e.prop)&&!o.has(e.prop)){const t=a.get(e.prop);if(t)try{const a={...t};a.isShow=e.isShow,a.sortable=e.sortable,r.push(a),o.add(e.prop)}catch(a){console.warn("更新列配置时出错:",a),r.push(t),o.add(e.prop)}}})),l.forEach((e=>{!e||e.prop&&o.has(e.prop)||!fe(e.type)&&(he.includes(e.type)||"left"===e.fixed)||r.push(e)})),setTimeout((()=>{if(ne&&!ne.isUnmounted)try{Re.length=0,r.forEach((e=>{e&&Re.push(e)})),Qe.value=t}catch(e){console.warn("更新表格列时出错:",e)}finally{We.value=!1}else console.warn("延迟更新时组件已销毁")}),50)}catch(e){console.warn("updateTableColumns执行时出错:",e),We.value=!1}else console.warn("组件已销毁,跳过列更新")}),"updateTableColumns"),tt=J((()=>{Ze.value.openColSetting()}),"openColSetting"),at=J((()=>{Ze.value.closeColSetting()}),"closeColSetting"),lt=re,rt=J((()=>{Pe(),lt("search")}),"_search"),ot=J((()=>{Ne(),lt("reset")}),"_reset"),nt=J(((e,t,a,l)=>{lt("handleOperateBtnsClick",e,t,a,l)}),"handleOperateBtnsClick"),it=J((()=>{Me()}),"refreshTable");return X({element:ce,tableData:Ve,radio:Se,pageable:xe,searchParam:Ae,searchInitParam:Be,getTableList:Me,search:Pe,reset:Ne,handleSizeChange:Oe,handleCurrentChange:Le,clearSelection:He,enumMap:Ke,isSelected:_e,selectedList:Ce,selectedListIds:we,refreshTable:it,setSearchFormShow:J((e=>{ge.value=e}),"setSearchFormShow"),getColumns:J((()=>Re),"getColumns"),getColSetting:J((()=>Qe.value),"getColSetting"),openColSetting:tt,closeColSetting:at}),(t,a)=>{const l=d("el-button"),r=d("el-radio"),o=d("el-icon"),n=d("el-tag"),i=d("el-table-column"),s=h("loading");return f(),m("div",Z,[v(" 查询表单 "),g(b(V,{search:rt,reset:ot,columns:Je.value,"search-param":c(Ae),"search-col":e.searchCol},null,8,["columns","search-param","search-col"]),[[C,ge.value]]),v(" 表格主体 "),y("div",{class:w([e.onlyTable?"only-table":"card table-main"])},[v(" 表格头部 操作按钮 "),y("div",Q,[y("div",W,[_(t.$slots,"tableHeader",{selectedList:c(Ce),selectedListIds:c(we),isSelected:c(_e)})]),e.toolButton?(f(),m("div",Y,[_(t.$slots,"toolButton",{},(()=>[ye("refresh")?(f(),S(l,{key:0,icon:c(F),circle:"",onClick:Me},null,8,["icon"])):v("v-if",!0),ye("setting")&&e.columns.length?(f(),S(l,{key:1,icon:c(M),circle:"",onClick:tt},null,8,["icon"])):v("v-if",!0),ye("search")&&Je.value?.length?(f(),S(l,{key:2,icon:c(j),circle:"",onClick:a[0]||(a[0]=e=>ge.value=!ge.value)},null,8,["icon"])):v("v-if",!0)]))])):v("v-if",!0)]),v(" 表格主体 "),g((f(),S(c(I),q({ref_key:"tableRef",ref:ce},t.$attrs,{data:Ve.value,border:e.border,id:pe.value,"row-key":e.rowKey,height:ue.value,onSelectionChange:c(be),onScroll:Ue}),{append:k((()=>[_(t.$slots,"append"),v(" 滚动翻页加载状态 "),!oe.enableScrollPagination||!je.value&&ze.value?v("v-if",!0):(f(),m("div",ee,[je.value?(f(),m("div",te,[b(o,{class:"is-loading"},{default:k((()=>[b(c($))])),_:1
|
|
12
|
+
/* STABLE */}),a[3]||(a[3]=y("span",null,"正在加载更多数据...",-1
|
|
13
|
+
/* HOISTED */))])):ze.value?v("v-if",!0):(f(),m("div",ae,a[4]||(a[4]=[y("span",null,"没有更多数据了",-1
|
|
14
|
+
/* HOISTED */)])))]))])),empty:k((()=>[y("div",le,[_(t.$slots,"empty",{},(()=>[a[5]||(a[5]=y("img",{src:E,alt:"notData"},null,-1
|
|
15
|
+
/* HOISTED */)),a[6]||(a[6]=y("div",null,"暂无数据",-1
|
|
16
|
+
/* HOISTED */))]))])])),default:k((()=>[_(t.$slots,"default"),(f(!0),m(T,null,x(c(Re),(l=>(f(),m(T,{key:l},[v(" selection || radio || index || expand || sort "),l.type&&he.includes(l.type)?(f(),S(i,q({key:0,ref_for:!0},l,{selectable:J((e=>null==e.selectable||null==e.selectable||e.selectable),"selectable"),align:l.align??"center","reserve-selection":"selection"==l.type}),{default:k((i=>[v(" expand "),"expand"==l.type?(f(),m(T,{key:0},[l.render?(f(),S(A(l.render),q({key:0,ref_for:!0},i),null,16
|
|
17
|
+
/* FULL_PROPS */)):_(t.$slots,l.type,q({key:1,ref_for:!0},i))],64
|
|
18
|
+
/* STABLE_FRAGMENT */)):v("v-if",!0),v(" radio "),"radio"==l.type?(f(),S(r,{key:1,modelValue:Se.value,"onUpdate:modelValue":a[1]||(a[1]=e=>Se.value=e),label:i.row[e.rowKey]},{default:k((()=>a[2]||(a[2]=[y("i",null,null,-1
|
|
19
19
|
/* HOISTED */)]))),_:2
|
|
20
|
-
/* DYNAMIC */},1032,["modelValue","label"])):
|
|
20
|
+
/* DYNAMIC */},1032,["modelValue","label"])):v("v-if",!0),v(" sort "),"sort"==l.type?(f(),S(n,{key:2,class:"move"},{default:k((()=>[b(o,null,{default:k((()=>[b(c(z))])),_:1
|
|
21
21
|
/* STABLE */})])),_:1
|
|
22
|
-
/* STABLE */})):
|
|
23
|
-
/* DYNAMIC */},1040,["selectable","align","reserve-selection"])):
|
|
24
|
-
/* DYNAMIC */},[x(Object.keys(t.$slots),(e=>({name:e,fn:k((
|
|
22
|
+
/* STABLE */})):v("v-if",!0),v(" operationBtns "),"operationBtns"==l.type?(f(),S(R,q({key:3,ref_for:!0},l.props,{row:i.row,index:i.$index,onBtnClick:nt}),null,16,["row","index"])):v("v-if",!0)])),_:2
|
|
23
|
+
/* DYNAMIC */},1040,["selectable","align","reserve-selection"])):v("v-if",!0),v(" other "),!l.type&&l.prop&&l.isShow&&(!c(e.isView)||c(e.isView)&&l.isShowInView)?(f(),S(D,{key:1,column:l,"is-view":e.isView},B({_:2
|
|
24
|
+
/* DYNAMIC */},[x(Object.keys(t.$slots),(e=>({name:e,fn:k((a=>[_(t.$slots,e,q({ref_for:!0},a))]))})))]),1032,["column","is-view"])):v("v-if",!0)],64
|
|
25
25
|
/* STABLE_FRAGMENT */)))),128
|
|
26
26
|
/* KEYED_FRAGMENT */))])),_:3
|
|
27
|
-
/* FORWARDED */},16,["data","border","id","row-key","height","onSelectionChange"])),[[s,c(Fe)]]),
|
|
28
|
-
/* CLASS */),
|
|
29
|
-
/* FORWARDED */},8,["col-setting"])):
|
|
27
|
+
/* FORWARDED */},16,["data","border","id","row-key","height","onSelectionChange"])),[[s,c(Fe)]]),v(" 分页组件 "),_(t.$slots,"pagination",{},(()=>[e.pagination&&!e.enableScrollPagination?(f(),S(K,{key:0,pageable:c(xe),"handle-size-change":c(Oe),"handle-current-change":c(Le),"page-size-options":e.pageSizeOptions},null,8,["pageable","handle-size-change","handle-current-change","page-size-options"])):v("v-if",!0)]))],2
|
|
28
|
+
/* CLASS */),v(" 列设置 "),e.toolButton?(f(),S(G,{key:0,ref_key:"colRef",ref:Ze,"col-setting":Qe.value,onUpdateColumns:et},{colSettingHeader:k((()=>[_(t.$slots,"colSettingHeader")])),_:3
|
|
29
|
+
/* FORWARDED */},8,["col-setting"])):v("v-if",!0)])}}});export{re as default};
|
|
30
30
|
//# sourceMappingURL=index.vue2.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.vue2.mjs","sources":["../../../../../../packages/components/znTable/src/index.vue"],"sourcesContent":["<!-- 📚📚📚 Pro-Table 文档: https://juejin.cn/post/7166068828202336263 -->\n\n<template>\n <div class=\"table-box\">\n <!-- 查询表单 -->\n <SearchForm v-show=\"isShowSearch\" :search=\"_search\" :reset=\"_reset\" :columns=\"searchColumns\" :search-param=\"searchParam\" :search-col=\"searchCol\" />\n\n <!-- 表格主体 -->\n <div :class=\"[onlyTable ? 'only-table' : 'card table-main']\">\n <!-- 表格头部 操作按钮 -->\n <div class=\"table-header\">\n <div class=\"header-button-lf\">\n <slot name=\"tableHeader\" :selected-list=\"selectedList\" :selected-list-ids=\"selectedListIds\" :is-selected=\"isSelected\"></slot>\n </div>\n <div v-if=\"toolButton\" class=\"header-button-ri\">\n <slot name=\"toolButton\">\n <el-button v-if=\"showToolButton('refresh')\" :icon=\"Refresh\" circle @click=\"getTableList\" />\n <el-button v-if=\"showToolButton('setting') && columns.length\" :icon=\"Operation\" circle @click=\"openColSetting\" />\n <el-button v-if=\"showToolButton('search') && searchColumns?.length\" :icon=\"Search\" circle @click=\"isShowSearch = !isShowSearch\" />\n </slot>\n </div>\n </div>\n <!-- 表格主体 -->\n <el-table\n ref=\"tableRef\"\n v-bind=\"$attrs\"\n :data=\"processTableData\"\n :border=\"border\"\n :id=\"uuid\"\n :row-key=\"rowKey\"\n :height=\"tableHeight\"\n v-loading=\"loading\"\n @selection-change=\"selectionChange\"\n @scroll.enter=\"handleScroll\">\n <!-- 默认插槽 -->\n <slot></slot>\n <template v-for=\"item in tableColumns\" :key=\"item\">\n <!-- selection || radio || index || expand || sort -->\n <el-table-column\n v-if=\"item.type && columnTypes.includes(item.type)\"\n v-bind=\"item\"\n :selectable=\"(row: any) => (row.selectable != null && row.selectable != undefined ? row.selectable : true)\"\n :align=\"item.align ?? 'center'\"\n :reserve-selection=\"item.type == 'selection'\">\n <template #default=\"scope\">\n <!-- expand -->\n <template v-if=\"item.type == 'expand'\">\n <component :is=\"item.render\" v-bind=\"scope\" v-if=\"item.render\" />\n <slot v-else :name=\"item.type\" v-bind=\"scope\"></slot>\n </template>\n <!-- radio -->\n <el-radio v-if=\"item.type == 'radio'\" v-model=\"radio\" :label=\"scope.row[rowKey]\">\n <i></i>\n </el-radio>\n <!-- sort -->\n <el-tag v-if=\"item.type == 'sort'\" class=\"move\">\n <el-icon><DCaret /></el-icon>\n </el-tag>\n <!-- operationBtns -->\n <OperationBtns v-if=\"item.type == 'operationBtns'\" v-bind=\"item.props\" :row=\"scope.row\" :index=\"scope.$index\" @btn-click=\"handleOperateBtnsClick\" />\n </template>\n </el-table-column>\n <!-- other -->\n <TableColumn\n v-if=\"!item.type && item.prop && item.isShow && (!unref(isView) || (unref(isView) && item.isShowInView))\"\n :column=\"item\"\n :is-view=\"isView\">\n <template v-for=\"slot in Object.keys($slots)\" #[slot]=\"scope\">\n <slot :name=\"slot\" v-bind=\"scope\"></slot>\n </template>\n </TableColumn>\n </template>\n <!-- 插入表格最后一行之后的插槽 -->\n <template #append>\n <slot name=\"append\"></slot>\n <!-- 滚动翻页加载状态 -->\n <div\n v-if=\"props.enableScrollPagination && (isScrollLoading || !hasMoreData)\"\n style=\"display: flex; align-items: center; justify-content: center; padding: 20px 0; color: #909399; font-size: 14px\">\n <div v-if=\"isScrollLoading\" style=\"display: flex; align-items: center; gap: 8px\">\n <el-icon class=\"is-loading\"><Loading /></el-icon>\n <span>正在加载更多数据...</span>\n </div>\n <div v-else-if=\"!hasMoreData\" style=\"color: #909399\">\n <span>没有更多数据了</span>\n </div>\n </div>\n </template>\n <!-- 无数据 -->\n <template #empty>\n <div class=\"table-empty\">\n <slot name=\"empty\">\n <img src=\"./assets/notData.png\" alt=\"notData\" />\n <div>暂无数据</div>\n </slot>\n </div>\n </template>\n </el-table>\n <!-- 分页组件 -->\n <slot name=\"pagination\">\n <Pagination\n v-if=\"pagination && !enableScrollPagination\"\n :pageable=\"pageable\"\n :handle-size-change=\"handleSizeChange\"\n :handle-current-change=\"handleCurrentChange\"\n :page-size-options=\"pageSizeOptions\" />\n </slot>\n </div>\n <!-- 列设置 -->\n <ColSetting v-if=\"toolButton\" ref=\"colRef\" :col-setting=\"colSetting\" @update-columns=\"updateTableColumns\">\n <!-- 列设置头部插槽 -->\n <template #colSettingHeader>\n <slot name=\"colSettingHeader\"></slot>\n </template>\n </ColSetting>\n </div>\n</template>\n\n<script setup lang=\"ts\" name=\"ZnTable\">\n import { computed, onMounted, provide, reactive, ref, toRaw, unref, watch, nextTick, getCurrentInstance, onUnmounted } from 'vue'\n\n import ColSetting from './components/ColSetting.vue'\n import Pagination from './components/Pagination.vue'\n import TableColumn from './components/TableColumn.vue'\n import SearchForm from './components/SearchForm/index.vue'\n import OperationBtns from './components/OperationBtns/index.vue'\n\n import { BreakPoint } from './components/Grid/interface'\n import { ColumnProps, TypeProps, OperationBtnProps } from './interface'\n import { useSelection } from './hooks/useSelection'\n import { useTable } from './hooks/useTable'\n import { generateUUID, handleProp } from './utils'\n import { Operation, Refresh, Search, DCaret, Loading } from '@element-plus/icons-vue'\n import { ElTable } from 'element-plus'\n // import Sortable from 'sortablejs'\n import { useResizeObserver, useLocalStorage } from '@vueuse/core'\n defineOptions({\n name: 'ZnTable'\n })\n\n export interface ZnTableProps {\n columns: ColumnProps[] // 列配置项 ==> 必传\n data?: any[] // 静态 table data 数据,若存在则不会使用 requestApi 返回的 data ==> 非必传\n requestApi?: (params: any) => Promise<any> // 请求表格数据的 api ==> 非必传\n requestAuto?: boolean // 是否自动执行请求 api ==> 非必传(默认为true)\n requestError?: (params: any) => void // 表格 api 请求错误监听 ==> 非必传\n dataCallback?: (data: any) => any // 返回数据的回调函数,可以对数据进行处理 ==> 非必传\n title?: string // 表格标题 ==> 非必传\n pagination?: boolean // 是否需要分页组件 ==> 非必传(默认为true)\n pageSizeOptions?: number[] // 分页每页条数选项 ==> 非必传(默认为[10, 25, 50, 100])\n pageSize?: number // 默认每页显示条数 ==> 非必传(默认为15)\n initParam?: any // 初始化请求参数 ==> 非必传(默认为{})\n border?: boolean // 是否带有纵向边框 ==> 非必传(默认为true)\n toolButton?: ('refresh' | 'setting' | 'search')[] | boolean // 是否显示表格功能按钮 ==> 非必传(默认为true)\n rowKey?: string // 行数据的 Key,用来优化 Table 的渲染,当表格数据多选时,所指定的 id ==> 非必传(默认为 id)\n searchCol?: number | Record<BreakPoint, number> // 表格搜索项 每列占比配置 ==> 非必传 { xs: 1, sm: 2, md: 2, lg: 3, xl: 4 }\n height?: string | number // 表格高度,如果传了,则直接使用这个高度 未传则自动计算\n heightOffset?: number // 如果没传height,自动计算时,去除的高度\n minHeight?: string | number // 表格最小高度 ==> 非必传(默认为200)\n // hiddenTableHeader?: boolean // 隐藏表格头部\n onlyTable?: boolean // 只展示el-table部分\n isView?: boolean // 是否查看,默认为否\n searchFormShow?: boolean // 是否显示筛选行,默认为true\n enableScrollPagination?: boolean // 是否启用滚动翻页(无限滚动)==> 非必传(默认为false)\n scrollPaginationThreshold?: number // 滚动翻页触发阈值(距离底部多少像素时触发)==> 非必传(默认为100)\n }\n\n // 接受父组件参数,配置默认值\n const props = defineProps({\n columns: { type: Array, required: true, default: () => [] },\n data: { type: Array, required: false },\n requestApi: { type: Function, required: false },\n requestAuto: { type: Boolean, required: false, default: true },\n requestError: { type: Function, required: false },\n dataCallback: { type: Function, required: false },\n title: { type: String, required: false },\n pagination: { type: Boolean, required: false, default: true },\n pageSizeOptions: { type: Array, required: false, default: () => [10, 25, 50, 100] },\n pageSize: { type: Number, required: false, default: 15 },\n initParam: { required: false, default: {} },\n border: { type: Boolean, required: false, default: true },\n toolButton: { type: [Array, Boolean], required: false, default: true },\n rowKey: { type: String, required: false, default: 'id' },\n searchCol: { type: [Number, Object], required: false, default: () => ({ xs: 1, sm: 2, md: 2, lg: 3, xl: 4 }) },\n height: { type: [String, Number], required: false },\n heightOffset: { type: Number, required: false, default: 0 },\n minHeight: { type: [String, Number], required: false, default: 200 },\n onlyTable: { type: Boolean, required: false, default: false },\n isView: { type: Boolean, required: false, default: false },\n searchFormShow: { type: Boolean, required: false, default: true },\n enableScrollPagination: { type: Boolean, required: false, default: false },\n scrollPaginationThreshold: { type: Number, required: false, default: 100 }\n})\n\n // 在 setup 顶层获取组件实例,确保能正确获取\n const componentInstance = getCurrentInstance()\n\n const znygStore = useLocalStorage('znyg', { dictMap: {} })\n\n const bodyHeight = ref(0)\n useResizeObserver(document.body, (entries) => {\n const entry = entries[0]\n const { height } = entry.contentRect\n bodyHeight.value = height\n })\n // 计算表格高度\n const tableHeight = computed(() => {\n if (props.height) {\n return props.height\n }\n const ret = bodyHeight.value - 100 - (isShowSearch.value ? 120 : 40) - (props.pagination ? 150 : 0) - props.heightOffset\n // console.log(bodyHeight.value + '-' + 100 + '-' + (isShowSearch.value ? 120 : 0) + '-' + (props.pagination ? 70 : 0))\n // console.log('bodyHeight:' + bodyHeight.value, 'isShowSearch:' + (isShowSearch.value ? 80 : 0), 'ret:' + ret)\n\n // 确保返回的高度不小于最小高度\n const minHeightValue = typeof props.minHeight === 'number' ? props.minHeight : parseInt(props.minHeight.toString())\n return ret > minHeightValue ? ret : minHeightValue\n })\n\n // table 实例\n const tableRef = ref<InstanceType<typeof ElTable>>()\n\n // 生成组件唯一id\n const uuid = ref('id-' + generateUUID())\n\n /**\n * 特殊列配置管理\n *\n * 如何添加新的特殊列类型:\n * 1. 在 interface/index.ts 中的 TypeProps 类型中添加新的列类型\n * 2. 根据列的显示位置,将新类型添加到 FRONT_COLUMNS 或 BACK_COLUMNS 数组中\n * 3. 如果需要从列设置中排除特定的 prop,添加到 EXCLUDE_FROM_SETTING.props 中\n * 4. 在模板中添加对应的渲染逻辑\n *\n * 就这样!不需要在其他地方修改代码了。\n */\n const SPECIAL_COLUMN_CONFIG = {\n // 前置特殊列(显示在表格最前面)\n FRONT_COLUMNS: ['selection', 'radio', 'index', 'expand', 'sort'] as TypeProps[],\n // 后置特殊列(显示在表格最后面)\n BACK_COLUMNS: ['operationBtns'] as TypeProps[],\n // 需要从列设置中排除的列(除了特殊列类型,还可以包括特定的 prop)\n EXCLUDE_FROM_SETTING: {\n props: ['operation'], // 按 prop 排除\n types: [] as TypeProps[], // 按 type 排除(会自动包含所有特殊列类型)\n fixed: true // 排除固定列\n }\n }\n\n // 所有特殊列类型(合并前置和后置)\n const columnTypes: TypeProps[] = [...SPECIAL_COLUMN_CONFIG.FRONT_COLUMNS, ...SPECIAL_COLUMN_CONFIG.BACK_COLUMNS]\n\n // 判断是否为前置特殊列\n const isFrontSpecialColumn = (type?: TypeProps) => {\n return type && SPECIAL_COLUMN_CONFIG.FRONT_COLUMNS.includes(type)\n }\n\n // 判断是否为后置特殊列\n const isBackSpecialColumn = (type?: TypeProps) => {\n return type && SPECIAL_COLUMN_CONFIG.BACK_COLUMNS.includes(type)\n }\n\n // 判断是否应该从列设置中排除\n const shouldExcludeFromSetting = (column: ColumnProps) => {\n const { type, prop, fixed } = column\n\n // 排除所有特殊列类型\n if (type && columnTypes.includes(type)) return true\n\n // 排除指定的 prop\n if (prop && SPECIAL_COLUMN_CONFIG.EXCLUDE_FROM_SETTING.props.includes(prop)) return true\n\n // 排除固定列\n if (SPECIAL_COLUMN_CONFIG.EXCLUDE_FROM_SETTING.fixed && fixed) return true\n\n return false\n }\n\n // 是否显示搜索模块\n const isShowSearch = ref(props.searchFormShow)\n\n // 控制 ToolButton 显示\n const showToolButton = (key: 'refresh' | 'setting' | 'search') => {\n return Array.isArray(props.toolButton) ? props.toolButton.includes(key) : props.toolButton\n }\n\n // 单选值\n const radio = ref('')\n\n // 表格多选 Hooks\n const { selectionChange, selectedList, selectedListIds, isSelected } = useSelection(props.rowKey)\n // 滚动到顶部\n const scrollToTop = () => {\n const tableEl = tableRef.value?.$el\n if (tableEl) {\n const scrollWrap = tableEl.querySelector('.el-scrollbar__wrap')\n if (scrollWrap) {\n scrollWrap.scrollTop = 0\n }\n }\n }\n // 重置滚动翻页状态\n const resetScrollPagination = () => {\n hasMoreData.value = true\n isScrollLoading.value = false\n scrollPaginationDisabled.value = false\n }\n // 表格操作 Hooks\n const {\n tableData,\n pageable,\n searchParam,\n searchInitParam,\n getTableList: originalGetTableList,\n search,\n reset,\n handleSizeChange,\n handleCurrentChange,\n loading\n } = useTable(\n props.requestApi,\n props.initParam,\n props.pagination || props.enableScrollPagination,\n props.dataCallback,\n props.requestError,\n props.pageSize,\n scrollToTop,\n resetScrollPagination,\n props.enableScrollPagination\n )\n\n // 包装 getTableList,确保重置滚动翻页状态\n const getTableList = async () => {\n // 重置滚动翻页状态\n if (props.enableScrollPagination) {\n resetScrollPagination()\n }\n await originalGetTableList()\n }\n\n // 滚动翻页相关状态\n const isScrollLoading = ref(false) // 滚动翻页加载状态\n const hasMoreData = ref(true) // 是否还有更多数据\n const scrollPaginationDisabled = ref(false) // 是否禁用滚动翻页\n\n // 滚动翻页处理函数\n const handleScrollPagination = async () => {\n // 如果正在加载、没有更多数据、或已禁用滚动翻页,则直接返回\n if (isScrollLoading.value || !hasMoreData.value || scrollPaginationDisabled.value || !props.enableScrollPagination) {\n return\n }\n\n // 如果总数为0,说明还没有初始数据,不应该触发滚动翻页\n if (pageable.value.total === 0) {\n return\n }\n\n // 检查是否还有下一页数据\n const totalPages = Math.ceil(pageable.value.total / pageable.value.pageSize)\n if (pageable.value.pageNum >= totalPages) {\n hasMoreData.value = false\n return\n }\n\n try {\n isScrollLoading.value = true\n scrollPaginationDisabled.value = true // 防止重复触发\n\n // 获取下一页数据\n const nextPage = pageable.value.pageNum + 1\n const nextPageParams = {\n ...searchInitParam.value,\n ...searchParam.value,\n currPage: nextPage,\n pageSize: pageable.value.pageSize,\n params: {\n ...searchInitParam.value,\n ...searchParam.value\n }\n }\n if (props.requestApi) {\n const { result } = await props.requestApi(nextPageParams)\n const processedResult = props.dataCallback ? props.dataCallback(result) : result\n if (processedResult && processedResult.list && Array.isArray(processedResult.list) && processedResult.list.length > 0) {\n // 确保 tableData.value 是数组\n if (!Array.isArray(tableData.value)) {\n tableData.value = []\n }\n // 将新数据追加到现有数据中\n tableData.value.push(...processedResult.list)\n\n // 更新分页信息\n const { currPage, limit, total } = processedResult\n pageable.value.pageNum = currPage\n pageable.value.pageSize = limit\n pageable.value.total = total\n\n // 检查是否还有更多数据\n const totalPages = Math.ceil(total / limit)\n hasMoreData.value = currPage < totalPages\n } else {\n hasMoreData.value = false\n console.log('❌ 滚动翻页没有更多数据')\n }\n }\n } catch (error) {\n props.requestError && props.requestError(error)\n } finally {\n isScrollLoading.value = false\n // 延迟重新启用滚动翻页,防止频繁触发\n setTimeout(() => {\n scrollPaginationDisabled.value = false\n }, 1000)\n }\n }\n\n // 滚动事件处理函数\n const handleScroll = (event: any) => {\n if (!props.enableScrollPagination || !props.requestApi) return\n\n // 如果正在加载或没有更多数据,直接返回\n if (isScrollLoading.value || !hasMoreData.value) return\n\n // 直接从表格元素获取滚动容器\n const tableEl = tableRef.value?.$el\n if (!tableEl) return\n\n // Element Plus 使用自定义滚动条,实际的滚动容器是 .el-scrollbar__wrap\n const scrollWrap = tableEl.querySelector('.el-scrollbar__wrap')\n if (!scrollWrap) return\n\n // 从滚动容器获取滚动信息\n const scrollTop = scrollWrap.scrollTop\n const scrollHeight = scrollWrap.scrollHeight\n const clientHeight = scrollWrap.clientHeight\n const threshold = props.scrollPaginationThreshold\n\n // 计算距离底部的距离\n const distanceToBottom = scrollHeight - scrollTop - clientHeight\n if (distanceToBottom <= threshold) {\n handleScrollPagination()\n }\n }\n\n // 清空选中数据列表\n const clearSelection = () => {\n if (!tableRef.value) return\n tableRef.value!.clearSelection()\n }\n // 初始化表格数据 && 拖拽排序\n onMounted(() => {\n // dragSort()\n props.requestAuto && getTableList()\n props.data && (pageable.value.total = props.data.length)\n\n // 如果启用滚动翻页,设置滚动监听\n if (props.enableScrollPagination) {\n // 延迟设置滚动监听,确保表格完全渲染\n setTimeout(() => {\n const tableEl = tableRef.value?.$el\n if (tableEl) {\n const scrollWrap = tableEl.querySelector('.el-scrollbar__wrap')\n if (scrollWrap) {\n // 移除可能存在的旧监听器\n scrollWrap.removeEventListener('scroll', handleScroll)\n // 添加新的滚动监听器\n scrollWrap.addEventListener('scroll', handleScroll, { passive: true })\n }\n }\n }, 500)\n }\n })\n\n // 组件卸载时清理事件监听\n onUnmounted(() => {\n if (props.enableScrollPagination) {\n const tableEl = tableRef.value?.$el\n if (tableEl) {\n const scrollWrap = tableEl.querySelector('.el-scrollbar__wrap')\n if (scrollWrap) {\n scrollWrap.removeEventListener('scroll', handleScroll)\n }\n }\n }\n })\n\n // 处理表格数据\n const processTableData = computed(() => {\n // 确保 tableData.value 是数组\n if (!Array.isArray(tableData.value)) {\n tableData.value = []\n }\n\n // 如果使用静态数据\n if (props.data) {\n // 确保 props.data 是数组\n if (!Array.isArray(props.data)) {\n console.warn('props.data 不是数组:', props.data)\n return []\n }\n\n if (!props.pagination) {\n return props.data\n }\n\n // 分页处理\n const rawData = toRaw(props.data)\n const slicedData = rawData.slice((pageable.value.pageNum - 1) * pageable.value.pageSize, pageable.value.pageSize * pageable.value.pageNum)\n return reactive(slicedData)\n }\n return tableData.value\n })\n\n // 监听页面 initParam 改化,重新获取表格数据\n watch(\n () => props.initParam,\n () => {\n getTableList()\n },\n { deep: true }\n )\n\n // 监听表格数据变化,检查是否需要重新启用滚动翻页\n watch(\n () => tableData.value,\n () => {\n if (props.enableScrollPagination && hasMoreData.value) {\n // 数据更新后,延迟检查滚动状态\n nextTick(() => {\n setTimeout(() => {\n const tableEl = tableRef.value?.$el\n if (tableEl) {\n const scrollWrap = tableEl.querySelector('.el-scrollbar__wrap')\n if (scrollWrap) {\n // 手动触发一次滚动检查\n handleScroll({})\n }\n }\n }, 100)\n })\n }\n },\n { deep: true }\n )\n\n // 接收 columns 并设置为响应式\n let tableColumns = reactive<ColumnProps[]>(props.columns)\n\n // 扁平化 columns\n const flatColumns = computed(() => flatColumnsFunc(tableColumns))\n\n // 定义 enumMap 存储 enum 值(避免异步请求无法格式化单元格内容 || 无法填充搜索下拉选择)\n const enumMap = ref(new Map<string, { [key: string]: any }[]>())\n const setEnumMap = async ({ prop, enum: enumValue, dictCode }: ColumnProps) => {\n if (dictCode) {\n // let znygStore = globalThis.localStorage.getItem('znyg')\n // if (znygStore) znygStore = JSON.parse(znygStore)\n if (znygStore && znygStore.value?.dictMap) {\n enumMap.value.set(prop!, znygStore.value.dictMap[dictCode?.toString()] ?? [])\n return\n }\n }\n if (!enumValue) return\n\n // 如果当前 enumMap 存在相同的值 return\n if (enumMap.value.has(prop!) && (typeof enumValue === 'function' || enumMap.value.get(prop!) === enumValue)) return\n\n // 当前 enum 为静态数据,则直接存储到 enumMap\n if (typeof enumValue !== 'function') return enumMap.value.set(prop!, unref(enumValue!))\n\n // 为了防止接口执行慢,而存储慢,导致重复请求,所以预先存储为[],接口返回后再二次存储\n enumMap.value.set(prop!, [])\n\n // 当前 enum 为后台数据需要请求数据,则调用该请求接口,并存储到 enumMap\n // const { data } = await enumValue()\n // 如果当前 enum 为后台数据需要请求数据,则调用该请求接口,并存储到 enumMap\n let data = await enumValue()\n // 适配 enum 接口返回 data 以及自定义函数返回数组\n data = data?.result || data\n enumMap.value.set(prop!, data)\n }\n // 注入 enumMap\n provide('enumMap', enumMap)\n\n // 扁平化 columns 的方法\n const flatColumnsFunc = (columns: ColumnProps[], flatArr: ColumnProps[] = []) => {\n columns.forEach(async (col) => {\n if (col._children?.length) flatArr.push(...flatColumnsFunc(col._children))\n flatArr.push(col)\n\n // column 添加默认 isShow && isFilterEnum 属性值\n col.isShow = col.isShow ?? true\n col.isShowInView = col.isShowInView ?? true\n col.isFilterEnum = col.isFilterEnum ?? true\n\n // 设置 enumMap\n await setEnumMap(col)\n })\n return flatArr.filter((item) => !item._children?.length)\n }\n\n // 过滤需要搜索的配置项 && 排序\n const searchColumns = computed(() => {\n return flatColumns.value?.filter((item) => item.search?.el || item.search?.render).sort((a, b) => a.search!.order! - b.search!.order!)\n })\n\n // 设置 搜索表单默认排序 && 搜索表单项的默认值\n searchColumns.value?.forEach((column, index) => {\n column.search!.order = column.search?.order ?? index + 2\n const key = column.search?.key ?? handleProp(column.prop!)\n const defaultValue = column.search?.defaultValue\n if (defaultValue !== undefined && defaultValue !== null) {\n searchInitParam.value[key] = defaultValue\n searchParam.value[key] = defaultValue\n }\n })\n\n // 列设置\n const colRef = ref()\n const colSetting = ref<ColumnProps[]>([])\n // 添加更新标志,避免循环更新\n const isUpdatingColumns = ref(false)\n\n // const colSetting = computed(() => {\n // return tableColumns.filter((item) => !shouldExcludeFromSetting(item))\n // })\n\n // 初始化列设置数据\n const initColSetting = () => {\n colSetting.value = tableColumns.filter((item) => !shouldExcludeFromSetting(item))\n }\n\n // 初始化时设置列配置\n initColSetting()\n\n // 监听 tableColumns 变化,同步更新 colSetting\n watch(\n () => tableColumns,\n () => {\n // 如果正在更新中,跳过同步\n if (isUpdatingColumns.value) {\n return\n }\n\n console.log('检测到 tableColumns 变化,同步更新 colSetting')\n initColSetting()\n },\n { deep: true }\n )\n\n // 手动更新表格列顺序的函数\n const updateTableColumns = (newColSetting: ColumnProps[]) => {\n // 如果正在更新中,避免循环调用\n if (isUpdatingColumns.value) {\n return\n }\n\n // console.log('updateTableColumns调用:', {\n // hasNewColSetting: !!newColSetting,\n // newColSettingLength: Array.isArray(newColSetting) ? newColSetting.length : 'not array',\n // currentTableColumnsLength: tableColumns.length\n // })\n\n // console.log('组件实例状态:', {\n // hasInstance: !!componentInstance,\n // isUnmounted: componentInstance?.isUnmounted\n // })\n\n if (!componentInstance || componentInstance.isUnmounted) {\n console.warn('组件已销毁,跳过列更新')\n return\n }\n\n try {\n // 设置更新标志\n isUpdatingColumns.value = true\n\n // 安全检查\n if (!newColSetting || !Array.isArray(newColSetting) || newColSetting.length === 0) {\n console.warn('updateTableColumns: 无效的列设置数据', {\n hasNewColSetting: !!newColSetting,\n isArray: Array.isArray(newColSetting),\n length: newColSetting?.length\n })\n return\n }\n\n // console.log('开始处理列设置数据')\n\n // 深拷贝输入数据,避免响应式问题\n let clonedColSetting: ColumnProps[]\n try {\n clonedColSetting = JSON.parse(JSON.stringify(newColSetting))\n // console.log('深拷贝成功')\n } catch (error) {\n console.warn('深拷贝列设置数据失败,使用浅拷贝')\n clonedColSetting = [...newColSetting]\n }\n\n // 创建一个映射,用于快速查找列配置\n const colMap = new Map()\n const currentColumns = [...tableColumns] // 创建当前列的副本\n\n currentColumns.forEach((col) => {\n if (col && col.prop) {\n colMap.set(col.prop, col)\n }\n })\n\n // console.log('创建列映射完成:', {\n // colMapSize: colMap.size,\n // currentColumnsLength: currentColumns.length\n // })\n\n // 根据新的列设置顺序重新排列列\n const reorderedColumns: ColumnProps[] = []\n const processedProps = new Set()\n\n // 首先添加前置特殊列(selection, radio, index 等)\n currentColumns.forEach((col) => {\n if (col && (isFrontSpecialColumn(col.type) || col.fixed === 'left')) {\n // console.log('添加前置特殊列:', { type: col.type, prop: col.prop, label: col.label })\n reorderedColumns.push(col)\n if (col.prop) {\n processedProps.add(col.prop)\n }\n }\n })\n\n // console.log('前置特殊列添加完成,当前列数:', reorderedColumns.length)\n\n // 然后添加按新顺序排列的普通列\n clonedColSetting.forEach((colSetting) => {\n if (colSetting && colSetting.prop && colMap.has(colSetting.prop) && !processedProps.has(colSetting.prop)) {\n const originalCol = colMap.get(colSetting.prop)\n if (originalCol) {\n // console.log('添加普通列:', { prop: colSetting.prop, label: colSetting.label, isShow: colSetting.isShow })\n try {\n // 创建列的副本并更新属性\n const updatedCol = { ...originalCol }\n updatedCol.isShow = colSetting.isShow\n updatedCol.sortable = colSetting.sortable\n reorderedColumns.push(updatedCol)\n processedProps.add(colSetting.prop)\n } catch (error) {\n console.warn('更新列配置时出错:', error)\n // 如果更新失败,使用原始列\n reorderedColumns.push(originalCol)\n processedProps.add(colSetting.prop)\n }\n }\n }\n })\n\n // console.log('普通列添加完成,当前列数:', reorderedColumns.length)\n\n // 最后添加后置特殊列(如操作列、operationBtns、右侧固定列等)\n currentColumns.forEach((col) => {\n if (\n col &&\n (!col.prop || !processedProps.has(col.prop)) &&\n (isBackSpecialColumn(col.type) || (!columnTypes.includes(col.type!) && col.fixed !== 'left'))\n ) {\n // console.log('添加后置特殊列:', { type: col.type, prop: col.prop, label: col.label })\n reorderedColumns.push(col)\n }\n })\n\n // console.log('列重排完成:', {\n // reorderedColumnsLength: reorderedColumns.length,\n // processedPropsSize: processedProps.size\n // })\n\n // 使用setTimeout而不是nextTick,确保在下一个事件循环中更新\n setTimeout(() => {\n // console.log('开始更新表格列,检查组件状态:', {\n // hasInstance: !!componentInstance,\n // isUnmounted: componentInstance?.isUnmounted\n // })\n\n if (!componentInstance || componentInstance.isUnmounted) {\n console.warn('延迟更新时组件已销毁')\n return\n }\n\n try {\n // console.log('执行表格列更新')\n // 简单直接的数组替换方法\n tableColumns.length = 0\n reorderedColumns.forEach((col) => {\n if (col) {\n tableColumns.push(col as any)\n }\n })\n\n // 同步更新 colSetting,但不触发新的更新\n colSetting.value = clonedColSetting\n\n // console.log('表格列更新完成:', {\n // newLength: tableColumns.length\n // })\n } catch (error) {\n console.warn('更新表格列时出错:', error)\n } finally {\n // 重置更新标志\n isUpdatingColumns.value = false\n }\n }, 50) // 50ms延迟\n } catch (error) {\n console.warn('updateTableColumns执行时出错:', error)\n // 确保在出错时也重置标志\n isUpdatingColumns.value = false\n }\n }\n\n const openColSetting = () => {\n // 直接打开列设置,不重新初始化以避免递归更新\n colRef.value.openColSetting()\n }\n\n const closeColSetting = () => {\n // 关闭列设置\n colRef.value.closeColSetting()\n }\n\n // 定义 emit 事件\n const emit = defineEmits([\"search\", \"reset\", \"dragSort\", \"handleOperateBtnsClick\"])\n\n const _search = () => {\n search()\n emit('search')\n }\n\n const _reset = () => {\n reset()\n emit('reset')\n }\n\n // 处理操作按钮点击事件\n const handleOperateBtnsClick = (btnName: string, row: any, btn: OperationBtnProps, index: number) => {\n emit('handleOperateBtnsClick', btnName, row, btn, index)\n }\n\n // 拖拽排序 // ! 列表数据需要有id\n const dragSort = () => {\n // const tbody = document.querySelector(`#${uuid.value} tbody`) as HTMLElement\n // Sortable.create(tbody, {\n // handle: '.move',\n // animation: 300,\n // onEnd({ newIndex, oldIndex }) {\n // const [removedItem] = processTableData.value.splice(oldIndex!, 1)\n // processTableData.value.splice(newIndex!, 0, removedItem)\n // console.log('newIndex', newIndex, 'oldIndex', oldIndex)\n // emit('dragSort', { newIndex, oldIndex })\n // }\n // })\n }\n\n const refreshTable = () => {\n getTableList()\n }\n\n const setSearchFormShow = (show: boolean) => {\n isShowSearch.value = show\n }\n\n // 获取当前列配置\n const getColumns = () => {\n return tableColumns\n }\n\n // 获取当前列设置配置\n const getColSetting = () => {\n return colSetting.value\n }\n\n // 暴露给父组件的参数和方法 (外部需要什么,都可以从这里暴露出去)\n defineExpose({\n element: tableRef,\n tableData: processTableData,\n radio,\n pageable,\n searchParam,\n searchInitParam,\n getTableList,\n search,\n reset,\n handleSizeChange,\n handleCurrentChange,\n clearSelection,\n enumMap,\n isSelected,\n selectedList,\n selectedListIds,\n refreshTable,\n setSearchFormShow,\n getColumns,\n getColSetting,\n openColSetting,\n closeColSetting\n })\n</script>\n"],"names":["props","__props","componentInstance","getCurrentInstance","znygStore","useLocalStorage","dictMap","bodyHeight","ref","useResizeObserver","document","body","entries","entry","height","contentRect","value","tableHeight","computed","ret","isShowSearch","pagination","heightOffset","minHeightValue","minHeight","parseInt","toString","tableRef","uuid","generateUUID","SPECIAL_COLUMN_CONFIG","FRONT_COLUMNS","BACK_COLUMNS","EXCLUDE_FROM_SETTING","types","fixed","columnTypes","isFrontSpecialColumn","type","includes","isBackSpecialColumn","shouldExcludeFromSetting","column","prop","searchFormShow","showToolButton","key","Array","isArray","toolButton","radio","selectionChange","selectedList","selectedListIds","isSelected","useSelection","rowKey","scrollToTop","__name","tableEl","$el","scrollWrap","querySelector","scrollTop","resetScrollPagination","hasMoreData","isScrollLoading","scrollPaginationDisabled","tableData","pageable","searchParam","searchInitParam","getTableList","originalGetTableList","search","reset","handleSizeChange","handleCurrentChange","loading","useTable","requestApi","initParam","enableScrollPagination","dataCallback","requestError","pageSize","async","handleScrollPagination","total","totalPages","Math","ceil","pageNum","nextPage","nextPageParams","currPage","params","result","processedResult","list","length","push","limit","console","log","error","setTimeout","handleScroll","event","scrollHeight","clientHeight","scrollPaginationThreshold","clearSelection","onMounted","requestAuto","data","removeEventListener","addEventListener","passive","onUnmounted","processTableData","warn","slicedData","toRaw","slice","reactive","watch","deep","nextTick","tableColumns","columns","flatColumns","flatColumnsFunc","enumMap","Map","setEnumMap","enum","enumValue","dictCode","set","has","get","unref","provide","flatArr","forEach","col","_children","isShow","isShowInView","isFilterEnum","filter","item","searchColumns","el","render","sort","a","b","order","index","handleProp","defaultValue","colRef","colSetting","isUpdatingColumns","initColSetting","updateTableColumns","newColSetting","isUnmounted","hasNewColSetting","clonedColSetting","JSON","parse","stringify","colMap","currentColumns","reorderedColumns","processedProps","Set","add","originalCol","updatedCol","sortable","openColSetting","closeColSetting","emit","__emit","_search","_reset","handleOperateBtnsClick","btnName","row","btn","refreshTable","__expose","element","setSearchFormShow","show","getColumns","getColSetting"],"mappings":"+mGAwKE,MAAMA,GAAQC,EA2BRC,GAAoBC,IAEpBC,GAAYC,EAAgB,OAAQ,CAAEC,QAAS,KAE/CC,GAAaC,EAAI,GACLC,EAAAC,SAASC,MAAOC,IAC1B,MAAAC,EAAQD,EAAQ,IAChBE,OAAEA,GAAWD,EAAME,YACzBR,GAAWS,MAAQF,CAAA,IAGf,MAAAG,GAAcC,GAAS,KAC3B,GAAIlB,GAAMc,OACR,OAAOd,GAAMc,OAEf,MAAMK,EAAMZ,GAAWS,MAAQ,KAAOI,GAAaJ,MAAQ,IAAM,KAAOhB,GAAMqB,WAAa,IAAM,GAAKrB,GAAMsB,aAKtGC,EAA4C,iBAApBvB,GAAMwB,UAAyBxB,GAAMwB,UAAYC,SAASzB,GAAM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AC,SACAC,oBACAC,uBACAmC,kBACAqB,WACA/E,cACAF,gBACAC,mBACA6I,gBACAG,qBAjCyBC,IACzBlL,GAAaJ,MAAQsL,CAAA,GADG,qBAkCxBC,WA7BuB7I,GAAA,IAChBuE,IADU,cA8BjBuE,cAzB0B9I,GAAA,IACnB0G,GAAWpJ,OADE,iBA0BpBwK,kBACAC;;;;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.vue2.mjs","sources":["../../../../../../packages/components/znTable/src/index.vue"],"sourcesContent":["<!-- 📚📚📚 Pro-Table 文档: https://juejin.cn/post/7166068828202336263 -->\n\n<template>\n <div class=\"table-box\">\n <!-- 查询表单 -->\n <SearchForm v-show=\"isShowSearch\" :search=\"_search\" :reset=\"_reset\" :columns=\"searchColumns\" :search-param=\"searchParam\" :search-col=\"searchCol\" />\n\n <!-- 表格主体 -->\n <div :class=\"[onlyTable ? 'only-table' : 'card table-main']\">\n <!-- 表格头部 操作按钮 -->\n <div class=\"table-header\">\n <div class=\"header-button-lf\">\n <slot name=\"tableHeader\" :selected-list=\"selectedList\" :selected-list-ids=\"selectedListIds\" :is-selected=\"isSelected\"></slot>\n </div>\n <div v-if=\"toolButton\" class=\"header-button-ri\">\n <slot name=\"toolButton\">\n <el-button v-if=\"showToolButton('refresh')\" :icon=\"Refresh\" circle @click=\"getTableList\" />\n <el-button v-if=\"showToolButton('setting') && columns.length\" :icon=\"Operation\" circle @click=\"openColSetting\" />\n <el-button v-if=\"showToolButton('search') && searchColumns?.length\" :icon=\"Search\" circle @click=\"isShowSearch = !isShowSearch\" />\n </slot>\n </div>\n </div>\n <!-- 表格主体 -->\n <el-table\n ref=\"tableRef\"\n v-bind=\"$attrs\"\n :data=\"processTableData\"\n :border=\"border\"\n :id=\"uuid\"\n :row-key=\"rowKey\"\n :height=\"tableHeight\"\n v-loading=\"loading\"\n @selection-change=\"selectionChange\"\n @scroll.enter=\"handleScroll\">\n <!-- 默认插槽 -->\n <slot></slot>\n <template v-for=\"item in tableColumns\" :key=\"item\">\n <!-- selection || radio || index || expand || sort -->\n <el-table-column\n v-if=\"item.type && columnTypes.includes(item.type)\"\n v-bind=\"item\"\n :selectable=\"(row: any) => (row.selectable != null && row.selectable != undefined ? row.selectable : true)\"\n :align=\"item.align ?? 'center'\"\n :reserve-selection=\"item.type == 'selection'\">\n <template #default=\"scope\">\n <!-- expand -->\n <template v-if=\"item.type == 'expand'\">\n <component :is=\"item.render\" v-bind=\"scope\" v-if=\"item.render\" />\n <slot v-else :name=\"item.type\" v-bind=\"scope\"></slot>\n </template>\n <!-- radio -->\n <el-radio v-if=\"item.type == 'radio'\" v-model=\"radio\" :label=\"scope.row[rowKey]\">\n <i></i>\n </el-radio>\n <!-- sort -->\n <el-tag v-if=\"item.type == 'sort'\" class=\"move\">\n <el-icon><DCaret /></el-icon>\n </el-tag>\n <!-- operationBtns -->\n <OperationBtns v-if=\"item.type == 'operationBtns'\" v-bind=\"item.props\" :row=\"scope.row\" :index=\"scope.$index\" @btn-click=\"handleOperateBtnsClick\" />\n </template>\n </el-table-column>\n <!-- other -->\n <TableColumn\n v-if=\"!item.type && item.prop && item.isShow && (!unref(isView) || (unref(isView) && item.isShowInView))\"\n :column=\"item\"\n :is-view=\"isView\">\n <template v-for=\"slot in Object.keys($slots)\" #[slot]=\"scope\">\n <slot :name=\"slot\" v-bind=\"scope\"></slot>\n </template>\n </TableColumn>\n </template>\n <!-- 插入表格最后一行之后的插槽 -->\n <template #append>\n <slot name=\"append\"></slot>\n <!-- 滚动翻页加载状态 -->\n <div\n v-if=\"props.enableScrollPagination && (isScrollLoading || !hasMoreData)\"\n style=\"display: flex; align-items: center; justify-content: center; padding: 20px 0; color: #909399; font-size: 14px\">\n <div v-if=\"isScrollLoading\" style=\"display: flex; align-items: center; gap: 8px\">\n <el-icon class=\"is-loading\"><Loading /></el-icon>\n <span>正在加载更多数据...</span>\n </div>\n <div v-else-if=\"!hasMoreData\" style=\"color: #909399\">\n <span>没有更多数据了</span>\n </div>\n </div>\n </template>\n <!-- 无数据 -->\n <template #empty>\n <div class=\"table-empty\">\n <slot name=\"empty\">\n <img src=\"./assets/notData.png\" alt=\"notData\" />\n <div>暂无数据</div>\n </slot>\n </div>\n </template>\n </el-table>\n <!-- 分页组件 -->\n <slot name=\"pagination\">\n <Pagination\n v-if=\"pagination && !enableScrollPagination\"\n :pageable=\"pageable\"\n :handle-size-change=\"handleSizeChange\"\n :handle-current-change=\"handleCurrentChange\"\n :page-size-options=\"pageSizeOptions\" />\n </slot>\n </div>\n <!-- 列设置 -->\n <ColSetting v-if=\"toolButton\" ref=\"colRef\" :col-setting=\"colSetting\" @update-columns=\"updateTableColumns\">\n <!-- 列设置头部插槽 -->\n <template #colSettingHeader>\n <slot name=\"colSettingHeader\"></slot>\n </template>\n </ColSetting>\n </div>\n</template>\n\n<script setup lang=\"ts\" name=\"ZnTable\">\n import { computed, onMounted, provide, reactive, ref, toRaw, unref, watch, nextTick, getCurrentInstance, onUnmounted } from 'vue'\n\n import ColSetting from './components/ColSetting.vue'\n import Pagination from './components/Pagination.vue'\n import TableColumn from './components/TableColumn.vue'\n import SearchForm from './components/SearchForm/index.vue'\n import OperationBtns from './components/OperationBtns/index.vue'\n\n import { BreakPoint } from './components/Grid/interface'\n import { ColumnProps, TypeProps, OperationBtnProps } from './interface'\n import { useSelection } from './hooks/useSelection'\n import { useTable } from './hooks/useTable'\n import { generateUUID, handleProp } from './utils'\n import { Operation, Refresh, Search, DCaret, Loading } from '@element-plus/icons-vue'\n import { ElTable } from 'element-plus'\n // import Sortable from 'sortablejs'\n import { useResizeObserver, useLocalStorage } from '@vueuse/core'\n defineOptions({\n name: 'ZnTable'\n })\n\n export interface ZnTableProps {\n columns: ColumnProps[] // 列配置项 ==> 必传\n data?: any[] // 静态 table data 数据,若存在则不会使用 requestApi 返回的 data ==> 非必传\n requestApi?: (params: any) => Promise<any> // 请求表格数据的 api ==> 非必传\n requestAuto?: boolean // 是否自动执行请求 api ==> 非必传(默认为true)\n requestError?: (params: any) => void // 表格 api 请求错误监听 ==> 非必传\n dataCallback?: (data: any) => any // 返回数据的回调函数,可以对数据进行处理 ==> 非必传\n title?: string // 表格标题 ==> 非必传\n pagination?: boolean // 是否需要分页组件 ==> 非必传(默认为true)\n pageSizeOptions?: number[] // 分页每页条数选项 ==> 非必传(默认为[10, 25, 50, 100])\n pageSize?: number // 默认每页显示条数 ==> 非必传(默认为15)\n initParam?: any // 初始化请求参数 ==> 非必传(默认为{})\n border?: boolean // 是否带有纵向边框 ==> 非必传(默认为true)\n toolButton?: ('refresh' | 'setting' | 'search')[] | boolean // 是否显示表格功能按钮 ==> 非必传(默认为true)\n rowKey?: string // 行数据的 Key,用来优化 Table 的渲染,当表格数据多选时,所指定的 id ==> 非必传(默认为 id)\n searchCol?: number | Record<BreakPoint, number> // 表格搜索项 每列占比配置 ==> 非必传 { xs: 1, sm: 2, md: 2, lg: 3, xl: 4 }\n height?: string | number // 表格高度,如果传了,则直接使用这个高度 未传则自动计算\n heightOffset?: number // 如果没传height,自动计算时,去除的高度\n minHeight?: string | number // 表格最小高度 ==> 非必传(默认为200)\n // hiddenTableHeader?: boolean // 隐藏表格头部\n onlyTable?: boolean // 只展示el-table部分\n isView?: boolean // 是否查看,默认为否\n searchFormShow?: boolean // 是否显示筛选行,默认为true\n enableScrollPagination?: boolean // 是否启用滚动翻页(无限滚动)==> 非必传(默认为false)\n scrollPaginationThreshold?: number // 滚动翻页触发阈值(距离底部多少像素时触发)==> 非必传(默认为100)\n }\n\n // 接受父组件参数,配置默认值\n const props = defineProps({\n columns: { type: Array, required: true, default: () => [] },\n data: { type: Array, required: false },\n requestApi: { type: Function, required: false },\n requestAuto: { type: Boolean, required: false, default: true },\n requestError: { type: Function, required: false },\n dataCallback: { type: Function, required: false },\n title: { type: String, required: false },\n pagination: { type: Boolean, required: false, default: true },\n pageSizeOptions: { type: Array, required: false, default: () => [10, 25, 50, 100] },\n pageSize: { type: Number, required: false, default: 15 },\n initParam: { required: false, default: {} },\n border: { type: Boolean, required: false, default: true },\n toolButton: { type: [Array, Boolean], required: false, default: true },\n rowKey: { type: String, required: false, default: 'id' },\n searchCol: { type: [Number, Object], required: false, default: () => ({ xs: 1, sm: 2, md: 2, lg: 3, xl: 4 }) },\n height: { type: [String, Number], required: false },\n heightOffset: { type: Number, required: false, default: 0 },\n minHeight: { type: [String, Number], required: false, default: 200 },\n onlyTable: { type: Boolean, required: false, default: false },\n isView: { type: Boolean, required: false, default: false },\n searchFormShow: { type: Boolean, required: false, default: true },\n enableScrollPagination: { type: Boolean, required: false, default: false },\n scrollPaginationThreshold: { type: Number, required: false, default: 100 }\n})\n\n // 在 setup 顶层获取组件实例,确保能正确获取\n const componentInstance = getCurrentInstance()\n\n const znygStore = useLocalStorage('znyg', { dictMap: {} })\n\n const bodyHeight = ref(0)\n useResizeObserver(document.body, (entries) => {\n const entry = entries[0]\n const { height } = entry.contentRect\n bodyHeight.value = height\n })\n // 计算表格高度\n const tableHeight = computed(() => {\n if (props.height) {\n // 如果 height 设置为 'auto',需要特殊处理空数据状态\n if (props.height === 'auto') {\n // 当没有数据时,确保有足够的高度显示空数据提示\n const hasData = processTableData.value && processTableData.value.length > 0\n if (!hasData) {\n // 没有数据时,使用最小高度确保空数据提示能正常显示\n const minHeightValue = typeof props.minHeight === 'number' ? props.minHeight : parseInt(props.minHeight.toString())\n return Math.max(minHeightValue, 200) // 至少200px高度\n }\n }\n return props.height\n }\n const ret = bodyHeight.value - 100 - (isShowSearch.value ? 120 : 40) - (props.pagination ? 150 : 0) - props.heightOffset\n // console.log(bodyHeight.value + '-' + 100 + '-' + (isShowSearch.value ? 120 : 0) + '-' + (props.pagination ? 70 : 0))\n // console.log('bodyHeight:' + bodyHeight.value, 'isShowSearch:' + (isShowSearch.value ? 80 : 0), 'ret:' + ret)\n\n // 确保返回的高度不小于最小高度\n const minHeightValue = typeof props.minHeight === 'number' ? props.minHeight : parseInt(props.minHeight.toString())\n return ret > minHeightValue ? ret : minHeightValue\n })\n\n // table 实例\n const tableRef = ref<InstanceType<typeof ElTable>>()\n\n // 生成组件唯一id\n const uuid = ref('id-' + generateUUID())\n\n /**\n * 特殊列配置管理\n *\n * 如何添加新的特殊列类型:\n * 1. 在 interface/index.ts 中的 TypeProps 类型中添加新的列类型\n * 2. 根据列的显示位置,将新类型添加到 FRONT_COLUMNS 或 BACK_COLUMNS 数组中\n * 3. 如果需要从列设置中排除特定的 prop,添加到 EXCLUDE_FROM_SETTING.props 中\n * 4. 在模板中添加对应的渲染逻辑\n *\n * 就这样!不需要在其他地方修改代码了。\n */\n const SPECIAL_COLUMN_CONFIG = {\n // 前置特殊列(显示在表格最前面)\n FRONT_COLUMNS: ['selection', 'radio', 'index', 'expand', 'sort'] as TypeProps[],\n // 后置特殊列(显示在表格最后面)\n BACK_COLUMNS: ['operationBtns'] as TypeProps[],\n // 需要从列设置中排除的列(除了特殊列类型,还可以包括特定的 prop)\n EXCLUDE_FROM_SETTING: {\n props: ['operation'], // 按 prop 排除\n types: [] as TypeProps[], // 按 type 排除(会自动包含所有特殊列类型)\n fixed: true // 排除固定列\n }\n }\n\n // 所有特殊列类型(合并前置和后置)\n const columnTypes: TypeProps[] = [...SPECIAL_COLUMN_CONFIG.FRONT_COLUMNS, ...SPECIAL_COLUMN_CONFIG.BACK_COLUMNS]\n\n // 判断是否为前置特殊列\n const isFrontSpecialColumn = (type?: TypeProps) => {\n return type && SPECIAL_COLUMN_CONFIG.FRONT_COLUMNS.includes(type)\n }\n\n // 判断是否为后置特殊列\n const isBackSpecialColumn = (type?: TypeProps) => {\n return type && SPECIAL_COLUMN_CONFIG.BACK_COLUMNS.includes(type)\n }\n\n // 判断是否应该从列设置中排除\n const shouldExcludeFromSetting = (column: ColumnProps) => {\n const { type, prop, fixed } = column\n\n // 排除所有特殊列类型\n if (type && columnTypes.includes(type)) return true\n\n // 排除指定的 prop\n if (prop && SPECIAL_COLUMN_CONFIG.EXCLUDE_FROM_SETTING.props.includes(prop)) return true\n\n // 排除固定列\n if (SPECIAL_COLUMN_CONFIG.EXCLUDE_FROM_SETTING.fixed && fixed) return true\n\n return false\n }\n\n // 是否显示搜索模块\n const isShowSearch = ref(props.searchFormShow)\n\n // 控制 ToolButton 显示\n const showToolButton = (key: 'refresh' | 'setting' | 'search') => {\n return Array.isArray(props.toolButton) ? props.toolButton.includes(key) : props.toolButton\n }\n\n // 单选值\n const radio = ref('')\n\n // 表格多选 Hooks\n const { selectionChange, selectedList, selectedListIds, isSelected } = useSelection(props.rowKey)\n // 滚动到顶部\n const scrollToTop = () => {\n const tableEl = tableRef.value?.$el\n if (tableEl) {\n const scrollWrap = tableEl.querySelector('.el-scrollbar__wrap')\n if (scrollWrap) {\n scrollWrap.scrollTop = 0\n }\n }\n }\n // 重置滚动翻页状态\n const resetScrollPagination = () => {\n hasMoreData.value = true\n isScrollLoading.value = false\n scrollPaginationDisabled.value = false\n }\n // 表格操作 Hooks\n const {\n tableData,\n pageable,\n searchParam,\n searchInitParam,\n getTableList: originalGetTableList,\n search,\n reset,\n handleSizeChange,\n handleCurrentChange,\n loading\n } = useTable(\n props.requestApi,\n props.initParam,\n props.pagination || props.enableScrollPagination,\n props.dataCallback,\n props.requestError,\n props.pageSize,\n scrollToTop,\n resetScrollPagination,\n props.enableScrollPagination\n )\n\n // 包装 getTableList,确保重置滚动翻页状态\n const getTableList = async () => {\n // 重置滚动翻页状态\n if (props.enableScrollPagination) {\n resetScrollPagination()\n }\n await originalGetTableList()\n }\n\n // 滚动翻页相关状态\n const isScrollLoading = ref(false) // 滚动翻页加载状态\n const hasMoreData = ref(true) // 是否还有更多数据\n const scrollPaginationDisabled = ref(false) // 是否禁用滚动翻页\n\n // 滚动翻页处理函数\n const handleScrollPagination = async () => {\n // 如果正在加载、没有更多数据、或已禁用滚动翻页,则直接返回\n if (isScrollLoading.value || !hasMoreData.value || scrollPaginationDisabled.value || !props.enableScrollPagination) {\n return\n }\n\n // 如果总数为0,说明还没有初始数据,不应该触发滚动翻页\n if (pageable.value.total === 0) {\n return\n }\n\n // 检查是否还有下一页数据\n const totalPages = Math.ceil(pageable.value.total / pageable.value.pageSize)\n if (pageable.value.pageNum >= totalPages) {\n hasMoreData.value = false\n return\n }\n\n try {\n isScrollLoading.value = true\n scrollPaginationDisabled.value = true // 防止重复触发\n\n // 获取下一页数据\n const nextPage = pageable.value.pageNum + 1\n const nextPageParams = {\n ...searchInitParam.value,\n ...searchParam.value,\n currPage: nextPage,\n pageSize: pageable.value.pageSize,\n params: {\n ...searchInitParam.value,\n ...searchParam.value\n }\n }\n if (props.requestApi) {\n const { result } = await props.requestApi(nextPageParams)\n const processedResult = props.dataCallback ? props.dataCallback(result) : result\n if (processedResult && processedResult.list && Array.isArray(processedResult.list) && processedResult.list.length > 0) {\n // 确保 tableData.value 是数组\n if (!Array.isArray(tableData.value)) {\n tableData.value = []\n }\n // 将新数据追加到现有数据中\n tableData.value.push(...processedResult.list)\n\n // 更新分页信息\n const { currPage, limit, total } = processedResult\n pageable.value.pageNum = currPage\n pageable.value.pageSize = limit\n pageable.value.total = total\n\n // 检查是否还有更多数据\n const totalPages = Math.ceil(total / limit)\n hasMoreData.value = currPage < totalPages\n } else {\n hasMoreData.value = false\n console.log('❌ 滚动翻页没有更多数据')\n }\n }\n } catch (error) {\n props.requestError && props.requestError(error)\n } finally {\n isScrollLoading.value = false\n // 延迟重新启用滚动翻页,防止频繁触发\n setTimeout(() => {\n scrollPaginationDisabled.value = false\n }, 1000)\n }\n }\n\n // 滚动事件处理函数\n const handleScroll = (event: any) => {\n if (!props.enableScrollPagination || !props.requestApi) return\n\n // 如果正在加载或没有更多数据,直接返回\n if (isScrollLoading.value || !hasMoreData.value) return\n\n // 直接从表格元素获取滚动容器\n const tableEl = tableRef.value?.$el\n if (!tableEl) return\n\n // Element Plus 使用自定义滚动条,实际的滚动容器是 .el-scrollbar__wrap\n const scrollWrap = tableEl.querySelector('.el-scrollbar__wrap')\n if (!scrollWrap) return\n\n // 从滚动容器获取滚动信息\n const scrollTop = scrollWrap.scrollTop\n const scrollHeight = scrollWrap.scrollHeight\n const clientHeight = scrollWrap.clientHeight\n const threshold = props.scrollPaginationThreshold\n\n // 计算距离底部的距离\n const distanceToBottom = scrollHeight - scrollTop - clientHeight\n if (distanceToBottom <= threshold) {\n handleScrollPagination()\n }\n }\n\n // 清空选中数据列表\n const clearSelection = () => {\n if (!tableRef.value) return\n tableRef.value!.clearSelection()\n }\n // 初始化表格数据 && 拖拽排序\n onMounted(() => {\n // dragSort()\n props.requestAuto && getTableList()\n props.data && (pageable.value.total = props.data.length)\n\n // 如果启用滚动翻页,设置滚动监听\n if (props.enableScrollPagination) {\n // 延迟设置滚动监听,确保表格完全渲染\n setTimeout(() => {\n const tableEl = tableRef.value?.$el\n if (tableEl) {\n const scrollWrap = tableEl.querySelector('.el-scrollbar__wrap')\n if (scrollWrap) {\n // 移除可能存在的旧监听器\n scrollWrap.removeEventListener('scroll', handleScroll)\n // 添加新的滚动监听器\n scrollWrap.addEventListener('scroll', handleScroll, { passive: true })\n }\n }\n }, 500)\n }\n })\n\n // 组件卸载时清理事件监听\n onUnmounted(() => {\n if (props.enableScrollPagination) {\n const tableEl = tableRef.value?.$el\n if (tableEl) {\n const scrollWrap = tableEl.querySelector('.el-scrollbar__wrap')\n if (scrollWrap) {\n scrollWrap.removeEventListener('scroll', handleScroll)\n }\n }\n }\n })\n\n // 处理表格数据\n const processTableData = computed(() => {\n // 确保 tableData.value 是数组\n if (!Array.isArray(tableData.value)) {\n tableData.value = []\n }\n\n // 如果使用静态数据\n if (props.data) {\n // 确保 props.data 是数组\n if (!Array.isArray(props.data)) {\n console.warn('props.data 不是数组:', props.data)\n return []\n }\n\n if (!props.pagination) {\n return props.data\n }\n\n // 分页处理\n const rawData = toRaw(props.data)\n const slicedData = rawData.slice((pageable.value.pageNum - 1) * pageable.value.pageSize, pageable.value.pageSize * pageable.value.pageNum)\n return reactive(slicedData)\n }\n return tableData.value\n })\n\n // 监听页面 initParam 改化,重新获取表格数据\n watch(\n () => props.initParam,\n () => {\n getTableList()\n },\n { deep: true }\n )\n\n // 监听表格数据变化,检查是否需要重新启用滚动翻页\n watch(\n () => tableData.value,\n () => {\n if (props.enableScrollPagination && hasMoreData.value) {\n // 数据更新后,延迟检查滚动状态\n nextTick(() => {\n setTimeout(() => {\n const tableEl = tableRef.value?.$el\n if (tableEl) {\n const scrollWrap = tableEl.querySelector('.el-scrollbar__wrap')\n if (scrollWrap) {\n // 手动触发一次滚动检查\n handleScroll({})\n }\n }\n }, 100)\n })\n }\n },\n { deep: true }\n )\n\n // 接收 columns 并设置为响应式\n let tableColumns = reactive<ColumnProps[]>(props.columns)\n\n // 扁平化 columns\n const flatColumns = computed(() => flatColumnsFunc(tableColumns))\n\n // 定义 enumMap 存储 enum 值(避免异步请求无法格式化单元格内容 || 无法填充搜索下拉选择)\n const enumMap = ref(new Map<string, { [key: string]: any }[]>())\n const setEnumMap = async ({ prop, enum: enumValue, dictCode }: ColumnProps) => {\n if (dictCode) {\n // let znygStore = globalThis.localStorage.getItem('znyg')\n // if (znygStore) znygStore = JSON.parse(znygStore)\n if (znygStore && znygStore.value?.dictMap) {\n enumMap.value.set(prop!, znygStore.value.dictMap[dictCode?.toString()] ?? [])\n return\n }\n }\n if (!enumValue) return\n\n // 如果当前 enumMap 存在相同的值 return\n if (enumMap.value.has(prop!) && (typeof enumValue === 'function' || enumMap.value.get(prop!) === enumValue)) return\n\n // 当前 enum 为静态数据,则直接存储到 enumMap\n if (typeof enumValue !== 'function') return enumMap.value.set(prop!, unref(enumValue!))\n\n // 为了防止接口执行慢,而存储慢,导致重复请求,所以预先存储为[],接口返回后再二次存储\n enumMap.value.set(prop!, [])\n\n // 当前 enum 为后台数据需要请求数据,则调用该请求接口,并存储到 enumMap\n // const { data } = await enumValue()\n // 如果当前 enum 为后台数据需要请求数据,则调用该请求接口,并存储到 enumMap\n let data = await enumValue()\n // 适配 enum 接口返回 data 以及自定义函数返回数组\n data = data?.result || data\n enumMap.value.set(prop!, data)\n }\n // 注入 enumMap\n provide('enumMap', enumMap)\n\n // 扁平化 columns 的方法\n const flatColumnsFunc = (columns: ColumnProps[], flatArr: ColumnProps[] = []) => {\n columns.forEach(async (col) => {\n if (col._children?.length) flatArr.push(...flatColumnsFunc(col._children))\n flatArr.push(col)\n\n // column 添加默认 isShow && isFilterEnum 属性值\n col.isShow = col.isShow ?? true\n col.isShowInView = col.isShowInView ?? true\n col.isFilterEnum = col.isFilterEnum ?? true\n\n // 设置 enumMap\n await setEnumMap(col)\n })\n return flatArr.filter((item) => !item._children?.length)\n }\n\n // 过滤需要搜索的配置项 && 排序\n const searchColumns = computed(() => {\n return flatColumns.value?.filter((item) => item.search?.el || item.search?.render).sort((a, b) => a.search!.order! - b.search!.order!)\n })\n\n // 设置 搜索表单默认排序 && 搜索表单项的默认值\n searchColumns.value?.forEach((column, index) => {\n column.search!.order = column.search?.order ?? index + 2\n const key = column.search?.key ?? handleProp(column.prop!)\n const defaultValue = column.search?.defaultValue\n if (defaultValue !== undefined && defaultValue !== null) {\n searchInitParam.value[key] = defaultValue\n searchParam.value[key] = defaultValue\n }\n })\n\n // 列设置\n const colRef = ref()\n const colSetting = ref<ColumnProps[]>([])\n // 添加更新标志,避免循环更新\n const isUpdatingColumns = ref(false)\n\n // const colSetting = computed(() => {\n // return tableColumns.filter((item) => !shouldExcludeFromSetting(item))\n // })\n\n // 初始化列设置数据\n const initColSetting = () => {\n colSetting.value = tableColumns.filter((item) => !shouldExcludeFromSetting(item))\n }\n\n // 初始化时设置列配置\n initColSetting()\n\n // 监听 tableColumns 变化,同步更新 colSetting\n watch(\n () => tableColumns,\n () => {\n // 如果正在更新中,跳过同步\n if (isUpdatingColumns.value) {\n return\n }\n\n console.log('检测到 tableColumns 变化,同步更新 colSetting')\n initColSetting()\n },\n { deep: true }\n )\n\n // 手动更新表格列顺序的函数\n const updateTableColumns = (newColSetting: ColumnProps[]) => {\n // 如果正在更新中,避免循环调用\n if (isUpdatingColumns.value) {\n return\n }\n\n // console.log('updateTableColumns调用:', {\n // hasNewColSetting: !!newColSetting,\n // newColSettingLength: Array.isArray(newColSetting) ? newColSetting.length : 'not array',\n // currentTableColumnsLength: tableColumns.length\n // })\n\n // console.log('组件实例状态:', {\n // hasInstance: !!componentInstance,\n // isUnmounted: componentInstance?.isUnmounted\n // })\n\n if (!componentInstance || componentInstance.isUnmounted) {\n console.warn('组件已销毁,跳过列更新')\n return\n }\n\n try {\n // 设置更新标志\n isUpdatingColumns.value = true\n\n // 安全检查\n if (!newColSetting || !Array.isArray(newColSetting) || newColSetting.length === 0) {\n console.warn('updateTableColumns: 无效的列设置数据', {\n hasNewColSetting: !!newColSetting,\n isArray: Array.isArray(newColSetting),\n length: newColSetting?.length\n })\n return\n }\n\n // console.log('开始处理列设置数据')\n\n // 深拷贝输入数据,避免响应式问题\n let clonedColSetting: ColumnProps[]\n try {\n clonedColSetting = JSON.parse(JSON.stringify(newColSetting))\n // console.log('深拷贝成功')\n } catch (error) {\n console.warn('深拷贝列设置数据失败,使用浅拷贝')\n clonedColSetting = [...newColSetting]\n }\n\n // 创建一个映射,用于快速查找列配置\n const colMap = new Map()\n const currentColumns = [...tableColumns] // 创建当前列的副本\n\n currentColumns.forEach((col) => {\n if (col && col.prop) {\n colMap.set(col.prop, col)\n }\n })\n\n // console.log('创建列映射完成:', {\n // colMapSize: colMap.size,\n // currentColumnsLength: currentColumns.length\n // })\n\n // 根据新的列设置顺序重新排列列\n const reorderedColumns: ColumnProps[] = []\n const processedProps = new Set()\n\n // 首先添加前置特殊列(selection, radio, index 等)\n currentColumns.forEach((col) => {\n if (col && (isFrontSpecialColumn(col.type) || col.fixed === 'left')) {\n // console.log('添加前置特殊列:', { type: col.type, prop: col.prop, label: col.label })\n reorderedColumns.push(col)\n if (col.prop) {\n processedProps.add(col.prop)\n }\n }\n })\n\n // console.log('前置特殊列添加完成,当前列数:', reorderedColumns.length)\n\n // 然后添加按新顺序排列的普通列\n clonedColSetting.forEach((colSetting) => {\n if (colSetting && colSetting.prop && colMap.has(colSetting.prop) && !processedProps.has(colSetting.prop)) {\n const originalCol = colMap.get(colSetting.prop)\n if (originalCol) {\n // console.log('添加普通列:', { prop: colSetting.prop, label: colSetting.label, isShow: colSetting.isShow })\n try {\n // 创建列的副本并更新属性\n const updatedCol = { ...originalCol }\n updatedCol.isShow = colSetting.isShow\n updatedCol.sortable = colSetting.sortable\n reorderedColumns.push(updatedCol)\n processedProps.add(colSetting.prop)\n } catch (error) {\n console.warn('更新列配置时出错:', error)\n // 如果更新失败,使用原始列\n reorderedColumns.push(originalCol)\n processedProps.add(colSetting.prop)\n }\n }\n }\n })\n\n // console.log('普通列添加完成,当前列数:', reorderedColumns.length)\n\n // 最后添加后置特殊列(如操作列、operationBtns、右侧固定列等)\n currentColumns.forEach((col) => {\n if (\n col &&\n (!col.prop || !processedProps.has(col.prop)) &&\n (isBackSpecialColumn(col.type) || (!columnTypes.includes(col.type!) && col.fixed !== 'left'))\n ) {\n // console.log('添加后置特殊列:', { type: col.type, prop: col.prop, label: col.label })\n reorderedColumns.push(col)\n }\n })\n\n // console.log('列重排完成:', {\n // reorderedColumnsLength: reorderedColumns.length,\n // processedPropsSize: processedProps.size\n // })\n\n // 使用setTimeout而不是nextTick,确保在下一个事件循环中更新\n setTimeout(() => {\n // console.log('开始更新表格列,检查组件状态:', {\n // hasInstance: !!componentInstance,\n // isUnmounted: componentInstance?.isUnmounted\n // })\n\n if (!componentInstance || componentInstance.isUnmounted) {\n console.warn('延迟更新时组件已销毁')\n return\n }\n\n try {\n // console.log('执行表格列更新')\n // 简单直接的数组替换方法\n tableColumns.length = 0\n reorderedColumns.forEach((col) => {\n if (col) {\n tableColumns.push(col as any)\n }\n })\n\n // 同步更新 colSetting,但不触发新的更新\n colSetting.value = clonedColSetting\n\n // console.log('表格列更新完成:', {\n // newLength: tableColumns.length\n // })\n } catch (error) {\n console.warn('更新表格列时出错:', error)\n } finally {\n // 重置更新标志\n isUpdatingColumns.value = false\n }\n }, 50) // 50ms延迟\n } catch (error) {\n console.warn('updateTableColumns执行时出错:', error)\n // 确保在出错时也重置标志\n isUpdatingColumns.value = false\n }\n }\n\n const openColSetting = () => {\n // 直接打开列设置,不重新初始化以避免递归更新\n colRef.value.openColSetting()\n }\n\n const closeColSetting = () => {\n // 关闭列设置\n colRef.value.closeColSetting()\n }\n\n // 定义 emit 事件\n const emit = defineEmits([\"search\", \"reset\", \"dragSort\", \"handleOperateBtnsClick\"])\n\n const _search = () => {\n search()\n emit('search')\n }\n\n const _reset = () => {\n reset()\n emit('reset')\n }\n\n // 处理操作按钮点击事件\n const handleOperateBtnsClick = (btnName: string, row: any, btn: OperationBtnProps, index: number) => {\n emit('handleOperateBtnsClick', btnName, row, btn, index)\n }\n\n // 拖拽排序 // ! 列表数据需要有id\n const dragSort = () => {\n // const tbody = document.querySelector(`#${uuid.value} tbody`) as HTMLElement\n // Sortable.create(tbody, {\n // handle: '.move',\n // animation: 300,\n // onEnd({ newIndex, oldIndex }) {\n // const [removedItem] = processTableData.value.splice(oldIndex!, 1)\n // processTableData.value.splice(newIndex!, 0, removedItem)\n // console.log('newIndex', newIndex, 'oldIndex', oldIndex)\n // emit('dragSort', { newIndex, oldIndex })\n // }\n // })\n }\n\n const refreshTable = () => {\n getTableList()\n }\n\n const setSearchFormShow = (show: boolean) => {\n isShowSearch.value = show\n }\n\n // 获取当前列配置\n const getColumns = () => {\n return tableColumns\n }\n\n // 获取当前列设置配置\n const getColSetting = () => {\n return colSetting.value\n }\n\n // 暴露给父组件的参数和方法 (外部需要什么,都可以从这里暴露出去)\n defineExpose({\n element: tableRef,\n tableData: processTableData,\n radio,\n pageable,\n searchParam,\n searchInitParam,\n getTableList,\n search,\n reset,\n handleSizeChange,\n handleCurrentChange,\n clearSelection,\n enumMap,\n isSelected,\n selectedList,\n selectedListIds,\n refreshTable,\n setSearchFormShow,\n getColumns,\n getColSetting,\n openColSetting,\n closeColSetting\n })\n</script>\n"],"names":["props","__props","componentInstance","getCurrentInstance","znygStore","useLocalStorage","dictMap","bodyHeight","ref","useResizeObserver","document","body","entries","entry","height","contentRect","value","tableHeight","computed","processTableData","length","minHeightValue","minHeight","parseInt","toString","Math","max","ret","isShowSearch","pagination","heightOffset","tableRef","uuid","generateUUID","SPECIAL_COLUMN_CONFIG","FRONT_COLUMNS","BACK_COLUMNS","EXCLUDE_FROM_SETTING","types","fixed","columnTypes","isFrontSpecialColumn","type","includes","isBackSpecialColumn","shouldExcludeFromSetting","column","prop","searchFormShow","showToolButton","key","Array","isArray","toolButton","radio","selectionChange","selectedList","selectedListIds","isSelected","useSelection","rowKey","scrollToTop","__name","tableEl","$el","scrollWrap","querySelector","scrollTop","resetScrollPagination","hasMoreData","isScrollLoading","scrollPaginationDisabled","tableData","pageable","searchParam","searchInitParam","getTableList","originalGetTableList","search","reset","handleSizeChange","handleCurrentChange","loading","useTable","requestApi","initParam","enableScrollPagination","dataCallback","requestError","pageSize","async","handleScrollPagination","total","totalPages","ceil","pageNum","nextPage","nextPageParams","currPage","params","result","processedResult","list","push","limit","console","log","error","setTimeout","handleScroll","event","scrollHeight","clientHeight","scrollPaginationThreshold","clearSelection","onMounted","requestAuto","data","removeEventListener","addEventListener","passive","onUnmounted","warn","slicedData","toRaw","slice","reactive","watch","deep","nextTick","tableColumns","columns","flatColumns","flatColumnsFunc","enumMap","Map","setEnumMap","enum","enumValue","dictCode","set","has","get","unref","provide","flatArr","forEach","col","_children","isShow","isShowInView","isFilterEnum","filter","item","searchColumns","el","render","sort","a","b","order","index","handleProp","defaultValue","colRef","colSetting","isUpdatingColumns","initColSetting","updateTableColumns","newColSetting","isUnmounted","hasNewColSetting","clonedColSetting","JSON","parse","stringify","colMap","currentColumns","reorderedColumns","processedProps","Set","add","originalCol","updatedCol","sortable","openColSetting","closeColSetting","emit","__emit","_search","_reset","handleOperateBtnsClick","btnName","row","btn","refreshTable","__expose","element","setSearchFormShow","show","getColumns","getColSetting"],"mappings":"+mGAwKE,MAAMA,GAAQC,EA2BRC,GAAoBC,IAEpB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AQ,CAAA,MAxB1ByF,QAAQiB,KAAK,aAwBa,GAE3B,UACIf,GACCF,QAAAiB,KAAK,2BAA4Bf,GAEzC2D,GAAkBtJ,OAAQ,CAAA,MA9I1ByF,QAAQiB,KAAK,cA8Ia,GAhKH,sBAoKrB+D,GAAuB3H,GAAA,KAE3BsG,GAAOpJ,MAAMyK,gBAAe,GAFP,kBAKjBC,GAAwB5H,GAAA,KAE5BsG,GAAOpJ,MAAM0K,iBAAgB,GAFP,mBAMlBC,GAAOC,GAEPC,GAAgB/H,GAAA,KACbgB,KACP6G,GAAK,SAAQ,GAFC,WAKVG,GAAehI,GAAA,KACbiB,KACN4G,GAAK,QAAO,GAFC,UAMTI,GAAyBjI,GAAA,CAACkI,EAAiBC,EAAUC,EAAwBjC,KACjF0B,GAAK,yBAA0BK,EAASC,EAAKC,EAAKjC,EAAK,GAD1B,0BAmBzBkC,GAAqBrI,GAAA,KACZc,IAAA,GADM,uBAmBRwH,EAAA,CACXC,QAAStK,GACTyC,UAAWrD,GACXmC,SACAmB,YACAC,eACAC,mBACAC,gBACAE,UACAC,SACAC,oBACAC,uBACAiC,kBACAoB,WACA5E,cACAF,gBACAC,mBACA0I,gBACAG,qBAjCyBC,IACzB3K,GAAaZ,MAAQuL,CAAA,GADG,qBAkCxBC,WA7BuB1I,GAAA,IAChBoE,IADU,cA8BjBuE,cAzB0B3I,GAAA,IACnBuG,GAAWrJ,OADE,iBA0BpByK,kBACAC;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import{defineComponent as e,ref as t,onBeforeMount as l,nextTick as a,watch as r,resolveComponent as d,createElementBlock as u,openBlock as i,normalizeStyle as n,createCommentVNode as s,createElementVNode as o,
|
|
2
|
-
/* TEXT */)):s("v-if",!0),o("div",K,[
|
|
3
|
-
/* FULL_PROPS */)):(i(),u("span",S,[
|
|
1
|
+
import{defineComponent as e,ref as t,onBeforeMount as l,nextTick as a,watch as r,resolveComponent as d,createElementBlock as u,openBlock as i,normalizeStyle as n,createCommentVNode as s,createElementVNode as o,renderSlot as c,createVNode as p,toDisplayString as f,createBlock as y,withCtx as h,unref as m,resolveDynamicComponent as k,normalizeProps as v,mergeProps as x,guardReactiveProps as g,createTextVNode as q}from"vue";import{ElTree as C}from"element-plus";import"../../../functions/index.mjs";import b from"../../../functions/modules/uitls.mjs";var V=Object.defineProperty,w=(e,t)=>V(e,"name",{value:t,configurable:!0});const A={key:0,class:"title sle"},K={class:"flex gap-10"},S={key:1,class:"el-tree-node__label"};var T=e({name:"ZnTreeFilter",__name:"index",props:{requestApi:{type:Function,required:!1},requestParams:{required:!1,default:w((()=>({})),"default")},data:{type:Array,required:!1},title:{type:String,required:!1},id:{type:String,required:!1,default:"id"},label:{type:String,required:!1,default:"label"},multiple:{type:Boolean,required:!1,default:!1},defaultValue:{required:!1},transformDataToTree:{type:Boolean,required:!1,default:!0},width:{type:String,required:!1,default:"460px"},height:{type:String,required:!1,default:"calc(100vh - 200px)"},defaultExpandAll:{type:Boolean,required:!1,default:!0},defaultExpandKeys:{type:Array,required:!1,default:w((()=>[]),"default")},expandOnClickNode:{type:Boolean,required:!1,default:!1},render:{type:Function,required:!1},showFilterText:{type:Boolean,required:!1,default:!0}},emits:["dataReady","change"],setup(e,{expose:V,emit:T}){const _=e,B={children:"children",label:_.label},N=t(),$=t([]),F=t([]),D=T,E=t(),L=w((()=>{_.multiple?E.value=Array.isArray(_.defaultValue)?_.defaultValue:[_.defaultValue]:E.value="string"==typeof _.defaultValue?_.defaultValue:""}),"setSelected"),O=w((async()=>{if(_.requestApi){const e=await _.requestApi(_.requestParams);let t=e.result.list??e.result;t.map(((e,t)=>{e.id||(e.id=`${e.treeLevel}-${t}`)})),_.transformDataToTree?$.value=b.treeListUtil(t):$.value=t,F.value=[...$.value],D("dataReady",t)}}),"getList");l((async()=>{await O(),!_.multiple&&_.defaultValue&&(H(_.defaultValue),await a(),N.value?.$el.querySelector(".is-current").firstChild.click())})),r((()=>_.requestParams),(e=>{e&&O()}),{deep:!0}),r((()=>_.defaultValue),(()=>a((()=>L()))),{deep:!0,immediate:!0}),r((()=>_.data),(()=>{_.data?.length&&($.value=_.data,F.value=[..._.data])}),{deep:!0,immediate:!0});const P=t("");r(P,(e=>{N.value.filter(e)}));const R=w(((e,t,l)=>{if(!e)return!0;let a=l.parent,r=[l.label],d=1;for(;d<l.level;)r=[...r,a.label],a=a.parent,d++;return r.some((t=>-1!==t.indexOf(e)))}),"filterNode"),j=w((e=>{_.multiple||D("change",e[_.id],e)}),"handleNodeClick"),U=w((()=>{D("change",N.value?.getCheckedNodes())}),"handleCheckChange"),z=w((e=>{N.value?.setCheckedKeys(e)}),"setCheckedKeys"),H=w((e=>{N.value?.setCurrentKey(e)}),"setCurrentKey");return V({treeData:$,treeAllData:F,treeRef:N,setCheckedKeys:z,getList:O,setCurrentKey:H}),(t,l)=>{const a=d("el-input"),r=d("el-scrollbar");return i(),u("div",{class:"zn-tree-filter",style:n({width:e.width,height:e.height})},[e.title?(i(),u("h4",A,f(e.title),1
|
|
2
|
+
/* TEXT */)):s("v-if",!0),o("div",K,[e.showFilterText?(i(),y(a,{key:0,modelValue:P.value,"onUpdate:modelValue":l[0]||(l[0]=e=>P.value=e),placeholder:"输入关键字进行过滤",clearable:""},null,8,["modelValue"])):s("v-if",!0),c(t.$slots,"toolButton")]),c(t.$slots,"treeHeader"),p(r,{style:n({height:e.title?"calc(100% - 95px)":"calc(100% - 56px)"})},{default:h((()=>[p(m(C),{ref_key:"treeRef",ref:N,"default-expand-all":e.defaultExpandAll,"node-key":e.id,data:e.multiple?$.value:F.value,"show-checkbox":e.multiple,"check-strictly":!1,"current-node-key":e.multiple?"":E.value,"highlight-current":!e.multiple,"expand-on-click-node":e.expandOnClickNode,"check-on-click-node":e.multiple,props:B,"filter-node-method":R,"default-checked-keys":e.multiple?E.value:[],"default-expanded-keys":e.defaultExpandKeys,onNodeClick:j,onCheck:U},{default:h((e=>[_.render?(i(),y(k(_.render),v(x({key:0},e)),null,16
|
|
3
|
+
/* FULL_PROPS */)):(i(),u("span",S,[c(t.$slots,"default",v(g(e)),(()=>[q(f(e.node.label),1
|
|
4
4
|
/* TEXT */)]))]))])),_:3
|
|
5
5
|
/* FORWARDED */},8,["default-expand-all","node-key","data","show-checkbox","current-node-key","highlight-current","expand-on-click-node","check-on-click-node","default-checked-keys","default-expanded-keys"])])),_:3
|
|
6
6
|
/* FORWARDED */},8,["style"])],4
|
|
7
|
-
/* STYLE */)}}});export{
|
|
7
|
+
/* STYLE */)}}});export{T as default};
|
|
8
8
|
//# sourceMappingURL=index.vue2.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.vue2.mjs","sources":["../../../../../../packages/components/znTreeFilter/src/index.vue"],"sourcesContent":["<template>\n <div class=\"zn-tree-filter\" :style=\"{ width, height }\">\n <h4 v-if=\"title\" class=\"title sle\">\n {{ title }}\n </h4>\n <div class=\"flex gap-10\">\n <el-input v-model=\"filterText\" placeholder=\"输入关键字进行过滤\" clearable />\n <slot name=\"toolButton\"></slot>\n </div>\n <el-scrollbar :style=\"{ height: title ? `calc(100% - 95px)` : `calc(100% - 56px)` }\">\n <el-tree\n ref=\"treeRef\"\n :default-expand-all=\"defaultExpandAll\"\n :node-key=\"id\"\n :data=\"multiple ? treeData : treeAllData\"\n :show-checkbox=\"multiple\"\n :check-strictly=\"false\"\n :current-node-key=\"!multiple ? selected : ''\"\n :highlight-current=\"!multiple\"\n :expand-on-click-node=\"expandOnClickNode\"\n :check-on-click-node=\"multiple\"\n :props=\"defaultProps\"\n :filter-node-method=\"filterNode\"\n :default-checked-keys=\"multiple ? selected : []\"\n :default-expanded-keys=\"defaultExpandKeys\"\n @node-click=\"handleNodeClick\"\n @check=\"handleCheckChange\">\n <template #default=\"scope\">\n <component v-if=\"props.render\" :is=\"props.render\" v-bind=\"scope\" />\n <span v-else class=\"el-tree-node__label\">\n <slot v-bind=\"scope\">\n {{ scope.node.label }}\n </slot>\n </span>\n </template>\n </el-tree>\n </el-scrollbar>\n </div>\n</template>\n\n<script setup lang=\"ts\" name=\"ZnTreeFilter\">\n import { nextTick, onBeforeMount, ref, watch, VNode } from 'vue'\n\n import { ElTree } from 'element-plus'\n import { utils } from '../../../functions'\n defineOptions({ name: 'ZnTreeFilter' })\n // 接收父组件参数并设置默认值\n interface TreeFilterProps {\n requestApi?: (data?: any) => Promise<any> /** 请求分类数据的 api ==> 非必传 */\n requestParams?: any /** 请求分类数据的参数 ==> 非必传 */\n data?: { [key: string]: any }[] /** 分类数据,如果有分类数据,则不会执行 api 请求 ==> 非必传 */\n title?: string /** treeFilter 标题 ==> 非必传 */\n id?: string /** 选择的id ==> 非必传,默认为 “id” */\n label?: string /** 显示的label ==> 非必传,默认为 “label” */\n multiple?: boolean /** 是否为多选 ==> 非必传,默认为 false */\n defaultValue?: any /** 默认选中的值 ==> 非必传 */\n transformDataToTree?: boolean /** 是否将数据转换为树形结构 ==> 非必传,默认为 true */\n width?: string /** 默认460px */\n height?: string /** 默认calc(100vh - 200px) */\n defaultExpandAll?: boolean /** 默认全部展开 */\n defaultExpandKeys?: any[]\n expandOnClickNode?: boolean\n render?: (scope: any) => VNode\n }\n const props = defineProps({\n requestApi: { type: Function, required: false },\n requestParams: { required: false, default: () => ({}) },\n data: { type: Array, required: false },\n title: { type: String, required: false },\n id: { type: String, required: false, default: 'id' },\n label: { type: String, required: false, default: 'label' },\n multiple: { type: Boolean, required: false, default: false },\n defaultValue: { required: false },\n transformDataToTree: { type: Boolean, required: false, default: true },\n width: { type: String, required: false, default: '460px' },\n height: { type: String, required: false, default: 'calc(100vh - 200px)' },\n defaultExpandAll: { type: Boolean, required: false, default: true },\n defaultExpandKeys: { type: Array, required: false, default: () => [] },\n expandOnClickNode: { type: Boolean, required: false, default: false },\n render: { type: Function, required: false }\n})\n\n const defaultProps = {\n children: 'children',\n label: props.label\n }\n\n const treeRef = ref<InstanceType<typeof ElTree>>()\n const treeData = ref<{ [key: string]: any }[]>([])\n const treeAllData = ref<{ [key: string]: any }[]>([])\n\n const emits = defineEmits(['dataReady', 'change'])\n\n const selected = ref()\n const setSelected = () => {\n if (props.multiple) selected.value = Array.isArray(props.defaultValue) ? props.defaultValue : [props.defaultValue]\n else selected.value = typeof props.defaultValue === 'string' ? props.defaultValue : ''\n }\n\n const getList = async () => {\n if (props.requestApi) {\n const res = await props.requestApi!(props.requestParams)\n let list = res.result.list ?? res.result\n // 后端说第六层没有id,所以补上 转树形的时候要用到\n list.map((item: any, index: number) => {\n if (!item.id) {\n item.id = `${item.treeLevel}-${index}`\n }\n })\n if (props.transformDataToTree) {\n treeData.value = utils.treeListUtil(list)\n } else {\n treeData.value = list\n }\n // treeAllData.value = [{ id: '', [props.label]: '全部' }, ...treeData.value]\n treeAllData.value = [...treeData.value]\n emits('dataReady', list)\n }\n }\n\n onBeforeMount(async () => {\n await getList()\n if (!props.multiple && props.defaultValue) {\n setCurrentKey(props.defaultValue)\n await nextTick()\n treeRef.value?.$el.querySelector('.is-current').firstChild.click()\n }\n })\n\n watch(\n () => props.requestParams,\n (val) => {\n if (val) {\n getList()\n }\n },\n {\n deep: true\n }\n )\n\n // 使用 nextTick 防止打包后赋值不生效,开发环境是正常的\n watch(\n () => props.defaultValue,\n () => nextTick(() => setSelected()),\n { deep: true, immediate: true }\n )\n\n watch(\n () => props.data,\n () => {\n if (props.data?.length) {\n treeData.value = props.data\n // treeAllData.value = [{ id: '', [props.label]: '全部' }, ...props.data]\n treeAllData.value = [...props.data]\n }\n },\n { deep: true, immediate: true }\n )\n\n const filterText = ref('')\n watch(filterText, (val) => {\n treeRef.value!.filter(val)\n })\n\n // 过滤\n const filterNode = (value: string, data: { [key: string]: any }, node: any) => {\n if (!value) return true\n let parentNode = node.parent\n let labels = [node.label]\n let level = 1\n while (level < node.level) {\n labels = [...labels, parentNode.label]\n parentNode = parentNode.parent\n level++\n }\n return labels.some((label) => label.indexOf(value) !== -1)\n }\n\n // emit\n // const emit = defineEmits<{\n // change: [value: any],\n // }>()\n\n // 单选\n const handleNodeClick = (data: { [key: string]: any }) => {\n if (props.multiple) return\n emits('change', data[props.id], data)\n }\n\n // 多选\n const handleCheckChange = () => {\n emits('change', treeRef.value?.getCheckedNodes())\n }\n\n const setCheckedKeys = (keys) => {\n treeRef.value?.setCheckedKeys(keys)\n }\n\n const setCurrentKey = (key) => {\n treeRef.value?.setCurrentKey(key)\n }\n\n // 暴露给父组件使用\n defineExpose({ treeData, treeAllData, treeRef, setCheckedKeys, getList, setCurrentKey })\n</script>\n"],"names":["props","__props","defaultProps","children","label","treeRef","ref","treeData","treeAllData","emits","__emit","selected","setSelected","__name","multiple","value","Array","isArray","defaultValue","getList","async","requestApi","res","requestParams","list","result","map","item","index","id","treeLevel","transformDataToTree","utils","treeListUtil","onBeforeMount","setCurrentKey","nextTick","$el","querySelector","firstChild","click","watch","val","deep","immediate","data","length","filterText","filter","filterNode","node","parentNode","parent","labels","level","some","indexOf","handleNodeClick","handleCheckChange","getCheckedNodes","setCheckedKeys","keys","key","__expose"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.vue2.mjs","sources":["../../../../../../packages/components/znTreeFilter/src/index.vue"],"sourcesContent":["<template>\n <div class=\"zn-tree-filter\" :style=\"{ width, height }\">\n <h4 v-if=\"title\" class=\"title sle\">\n {{ title }}\n </h4>\n <div class=\"flex gap-10\">\n <el-input v-if=\"showFilterText\" v-model=\"filterText\" placeholder=\"输入关键字进行过滤\" clearable />\n <slot name=\"toolButton\"></slot>\n </div>\n <slot name=\"treeHeader\"></slot>\n <el-scrollbar :style=\"{ height: title ? `calc(100% - 95px)` : `calc(100% - 56px)` }\">\n <el-tree\n ref=\"treeRef\"\n :default-expand-all=\"defaultExpandAll\"\n :node-key=\"id\"\n :data=\"multiple ? treeData : treeAllData\"\n :show-checkbox=\"multiple\"\n :check-strictly=\"false\"\n :current-node-key=\"!multiple ? selected : ''\"\n :highlight-current=\"!multiple\"\n :expand-on-click-node=\"expandOnClickNode\"\n :check-on-click-node=\"multiple\"\n :props=\"defaultProps\"\n :filter-node-method=\"filterNode\"\n :default-checked-keys=\"multiple ? selected : []\"\n :default-expanded-keys=\"defaultExpandKeys\"\n @node-click=\"handleNodeClick\"\n @check=\"handleCheckChange\">\n <template #default=\"scope\">\n <component v-if=\"props.render\" :is=\"props.render\" v-bind=\"scope\" />\n <span v-else class=\"el-tree-node__label\">\n <slot v-bind=\"scope\">\n {{ scope.node.label }}\n </slot>\n </span>\n </template>\n </el-tree>\n </el-scrollbar>\n </div>\n</template>\n\n<script setup lang=\"ts\" name=\"ZnTreeFilter\">\n import { nextTick, onBeforeMount, ref, watch, VNode } from 'vue'\n\n import { ElTree } from 'element-plus'\n import { utils } from '../../../functions'\n defineOptions({ name: 'ZnTreeFilter' })\n // 接收父组件参数并设置默认值\n interface TreeFilterProps {\n requestApi?: (data?: any) => Promise<any> /** 请求分类数据的 api ==> 非必传 */\n requestParams?: any /** 请求分类数据的参数 ==> 非必传 */\n data?: { [key: string]: any }[] /** 分类数据,如果有分类数据,则不会执行 api 请求 ==> 非必传 */\n title?: string /** treeFilter 标题 ==> 非必传 */\n id?: string /** 选择的id ==> 非必传,默认为 “id” */\n label?: string /** 显示的label ==> 非必传,默认为 “label” */\n multiple?: boolean /** 是否为多选 ==> 非必传,默认为 false */\n defaultValue?: any /** 默认选中的值 ==> 非必传 */\n transformDataToTree?: boolean /** 是否将数据转换为树形结构 ==> 非必传,默认为 true */\n width?: string /** 默认460px */\n height?: string /** 默认calc(100vh - 200px) */\n defaultExpandAll?: boolean /** 默认全部展开 */\n defaultExpandKeys?: any[]\n expandOnClickNode?: boolean\n render?: (scope: any) => VNode\n showFilterText?: boolean /** 是否显示过滤文本框 ==> 非必传,默认为 true */\n }\n const props = defineProps({\n requestApi: { type: Function, required: false },\n requestParams: { required: false, default: () => ({}) },\n data: { type: Array, required: false },\n title: { type: String, required: false },\n id: { type: String, required: false, default: 'id' },\n label: { type: String, required: false, default: 'label' },\n multiple: { type: Boolean, required: false, default: false },\n defaultValue: { required: false },\n transformDataToTree: { type: Boolean, required: false, default: true },\n width: { type: String, required: false, default: '460px' },\n height: { type: String, required: false, default: 'calc(100vh - 200px)' },\n defaultExpandAll: { type: Boolean, required: false, default: true },\n defaultExpandKeys: { type: Array, required: false, default: () => [] },\n expandOnClickNode: { type: Boolean, required: false, default: false },\n render: { type: Function, required: false },\n showFilterText: { type: Boolean, required: false, default: true }\n})\n\n const defaultProps = {\n children: 'children',\n label: props.label\n }\n\n const treeRef = ref<InstanceType<typeof ElTree>>()\n const treeData = ref<{ [key: string]: any }[]>([])\n const treeAllData = ref<{ [key: string]: any }[]>([])\n\n const emits = defineEmits(['dataReady', 'change'])\n\n const selected = ref()\n const setSelected = () => {\n if (props.multiple) selected.value = Array.isArray(props.defaultValue) ? props.defaultValue : [props.defaultValue]\n else selected.value = typeof props.defaultValue === 'string' ? props.defaultValue : ''\n }\n\n const getList = async () => {\n if (props.requestApi) {\n const res = await props.requestApi!(props.requestParams)\n let list = res.result.list ?? res.result\n // 后端说第六层没有id,所以补上 转树形的时候要用到\n list.map((item: any, index: number) => {\n if (!item.id) {\n item.id = `${item.treeLevel}-${index}`\n }\n })\n if (props.transformDataToTree) {\n treeData.value = utils.treeListUtil(list)\n } else {\n treeData.value = list\n }\n // treeAllData.value = [{ id: '', [props.label]: '全部' }, ...treeData.value]\n treeAllData.value = [...treeData.value]\n emits('dataReady', list)\n }\n }\n\n onBeforeMount(async () => {\n await getList()\n if (!props.multiple && props.defaultValue) {\n setCurrentKey(props.defaultValue)\n await nextTick()\n treeRef.value?.$el.querySelector('.is-current').firstChild.click()\n }\n })\n\n watch(\n () => props.requestParams,\n (val) => {\n if (val) {\n getList()\n }\n },\n {\n deep: true\n }\n )\n\n // 使用 nextTick 防止打包后赋值不生效,开发环境是正常的\n watch(\n () => props.defaultValue,\n () => nextTick(() => setSelected()),\n { deep: true, immediate: true }\n )\n\n watch(\n () => props.data,\n () => {\n if (props.data?.length) {\n treeData.value = props.data\n // treeAllData.value = [{ id: '', [props.label]: '全部' }, ...props.data]\n treeAllData.value = [...props.data]\n }\n },\n { deep: true, immediate: true }\n )\n\n const filterText = ref('')\n watch(filterText, (val) => {\n treeRef.value!.filter(val)\n })\n\n // 过滤\n const filterNode = (value: string, data: { [key: string]: any }, node: any) => {\n if (!value) return true\n let parentNode = node.parent\n let labels = [node.label]\n let level = 1\n while (level < node.level) {\n labels = [...labels, parentNode.label]\n parentNode = parentNode.parent\n level++\n }\n return labels.some((label) => label.indexOf(value) !== -1)\n }\n\n // emit\n // const emit = defineEmits<{\n // change: [value: any],\n // }>()\n\n // 单选\n const handleNodeClick = (data: { [key: string]: any }) => {\n if (props.multiple) return\n emits('change', data[props.id], data)\n }\n\n // 多选\n const handleCheckChange = () => {\n emits('change', treeRef.value?.getCheckedNodes())\n }\n\n const setCheckedKeys = (keys) => {\n treeRef.value?.setCheckedKeys(keys)\n }\n\n const setCurrentKey = (key) => {\n treeRef.value?.setCurrentKey(key)\n }\n\n // 暴露给父组件使用\n defineExpose({ treeData, treeAllData, treeRef, setCheckedKeys, getList, setCurrentKey })\n</script>\n"],"names":["props","__props","defaultProps","children","label","treeRef","ref","treeData","treeAllData","emits","__emit","selected","setSelected","__name","multiple","value","Array","isArray","defaultValue","getList","async","requestApi","res","requestParams","list","result","map","item","index","id","treeLevel","transformDataToTree","utils","treeListUtil","onBeforeMount","setCurrentKey","nextTick","$el","querySelector","firstChild","click","watch","val","deep","immediate","data","length","filterText","filter","filterNode","node","parentNode","parent","labels","level","some","indexOf","handleNodeClick","handleCheckChange","getCheckedNodes","setCheckedKeys","keys","key","__expose"],"mappings":"6jDAkEE,MAAMA,EAAQC,EAmBRC,EAAe,CACnBC,SAAU,WACVC,MAAOJ,EAAMI,OAGTC,EAAUC,IACVC,EAAWD,EAA8B,IACzCE,EAAcF,EAA8B,IAE5CG,EAAQC,EAERC,EAAWL,IACXM,EAAoBC,GAAA,KACpBb,EAAMc,SAAmBH,EAAAI,MAAQC,MAAMC,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D,EAAQ,EACL,KAAAA,EAAQJ,EAAKI,OAClBD,EAAS,IAAIA,EAAQF,EAAW/C,OAChC+C,EAAaA,EAAWC,OACxBE,IAEK,OAAAD,EAAOE,MAAMnD,IAAqC,IAA3BA,EAAMoD,QAAQzC,IAAa,GAVxC,cAmBb0C,KAAmBZ,IACnB7C,EAAMc,UACVL,EAAM,SAAUoC,EAAK7C,EAAM6B,IAAKgB,EAAI,GAFd,mBAMlBa,EAA0B7C,GAAA,KAC9BJ,EAAM,SAAUJ,EAAQU,OAAO4C,kBAAiB,GADxB,qBAIpBC,KAAkBC,IACdxD,EAAAU,OAAO6C,eAAeC,EAAI,GADb,kBAIjB1B,KAAiB2B,IACbzD,EAAAU,OAAOoB,cAAc2B,EAAG,GADZ,wBAKtBC,EAAa,CAAExD,WAAUC,cAAaH,UAASuD,iBAAgBzC,UAASgB;;;;;;"}
|
package/es/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import o from"./installer.mjs";export{install}from"./installer.mjs";import"./functions/index.mjs";import"./hooks/index.mjs";export{copyText,formatValue,treeListUtil,treeToList}from"./utils/index.mjs";import"./directives/index.mjs";import"./components/index.mjs";import e from"./functions/modules/log.mjs";export{useDialogV2}from"./hooks/useDialogV2/index.mjs";export{useDrawerV2}from"./hooks/useDrawerV2/index.mjs";export{closeAllDrawers}from"./hooks/useDrawerV2/src/index.mjs";export{closePopWindowById,closePopWindowByTag,getAllPopWindows,showPopWindow}from"./hooks/usePopWindow/src/index.mjs";export{usePopWindow}from"./hooks/usePopWindow/index.mjs";export{closePopWindowByIdV2,closePopWindowByTagV2,getAllPopWindowsV2,showPopWindowV2}from"./hooks/usePopWindowV2/src/index.mjs";export{usePopWindowV2}from"./hooks/usePopWindowV2/index.mjs";export{useDialog}from"./hooks/useDialog/index.mjs";export{default as ImageViewer}from"./hooks/useImageViewer/src/index.vue2.mjs";export{useImageViewer}from"./hooks/useImageViewer/index.mjs";export{useDrawer}from"./hooks/useDrawer/index.mjs";export{withInstall,withInstallDirectives}from"./utils/install.mjs";export{default as vCopy}from"./directives/modules/copy.mjs";export{default as vDrag}from"./directives/modules/drag.mjs";export{default as vAutoScroll}from"./directives/modules/autoScroll.mjs";export{default as vTooltip}from"./directives/modules/tooltip.mjs";export{default as vConfirm}from"./directives/modules/confirm.mjs";export{default as vCountTo}from"./directives/modules/countTo.mjs";export{default as utils}from"./functions/modules/uitls.mjs";import*as s from"./functions/modules/is.mjs";export{s as is};export{useZnForm}from"./components/znForm/src/hooks/useZnForm.mjs";export{useZnFormV2}from"./components/znFormV2/src/hooks/useZnFormV2.mjs";export{useZnSearch}from"./components/znSearch/src/hooks/useProSearch.mjs";export{ZnChart}from"./components/znChart/index.mjs";export{ZnCountTo}from"./components/znCountTo/index.mjs";export{default as ZnFormItem}from"./components/znForm/src/components/ZnFormItem.vue2.mjs";export{ZnForm}from"./components/znForm/index.mjs";export{batchExecute,camelCaseToHyphen,checkFeatureSupport,createUniqueId,debounce,delay,executeInIdle,getElementOffsetTop,getMemoryUsage,getObjectHash,isDeepEqual,isElementInViewport,isShallowEqual,throttle}from"./components/znFormV2/src/helper/index.mjs";export{default as ZnFormV2Item}from"./components/znFormV2/src/components/ZnFormV2Item.vue2.mjs";export{ZnFormV2}from"./components/znFormV2/index.mjs";export{ZnGrid,ZnGridItem}from"./components/znGrid/index.mjs";export{ZnNumberScroll}from"./components/znNumberScroll/index.mjs";export{ZnSearch}from"./components/znSearch/index.mjs";export{ZnTable}from"./components/znTable/index.mjs";export{ZnTest}from"./components/znTest/index.mjs";export{ZnTimeline}from"./components/znTimeLine/index.mjs";export{ZnTreeFilter}from"./components/znTreeFilter/index.mjs";export{ZnTreeSelect}from"./components/znTreeSelect/index.mjs";export{initVXETable,isVXETableInitialized}from"./components/znVirtualTable/src/utils/vxe-setup.mjs";export{ZnWorkGrid}from"./components/znWorkGrid/index.mjs";export{default as ZnVirtualTable}from"./components/znVirtualTable/src/index.vue2.mjs";globalThis.log=e;"function"==typeof globalThis?.log?.success&&globalThis.log.primary("1.1.
|
|
1
|
+
import o from"./installer.mjs";export{install}from"./installer.mjs";import"./functions/index.mjs";import"./hooks/index.mjs";export{copyText,formatValue,treeListUtil,treeToList}from"./utils/index.mjs";import"./directives/index.mjs";import"./components/index.mjs";import e from"./functions/modules/log.mjs";export{useDialogV2}from"./hooks/useDialogV2/index.mjs";export{useDrawerV2}from"./hooks/useDrawerV2/index.mjs";export{closeAllDrawers}from"./hooks/useDrawerV2/src/index.mjs";export{closePopWindowById,closePopWindowByTag,getAllPopWindows,showPopWindow}from"./hooks/usePopWindow/src/index.mjs";export{usePopWindow}from"./hooks/usePopWindow/index.mjs";export{closePopWindowByIdV2,closePopWindowByTagV2,getAllPopWindowsV2,showPopWindowV2}from"./hooks/usePopWindowV2/src/index.mjs";export{usePopWindowV2}from"./hooks/usePopWindowV2/index.mjs";export{useDialog}from"./hooks/useDialog/index.mjs";export{default as ImageViewer}from"./hooks/useImageViewer/src/index.vue2.mjs";export{useImageViewer}from"./hooks/useImageViewer/index.mjs";export{useDrawer}from"./hooks/useDrawer/index.mjs";export{withInstall,withInstallDirectives}from"./utils/install.mjs";export{default as vCopy}from"./directives/modules/copy.mjs";export{default as vDrag}from"./directives/modules/drag.mjs";export{default as vAutoScroll}from"./directives/modules/autoScroll.mjs";export{default as vTooltip}from"./directives/modules/tooltip.mjs";export{default as vConfirm}from"./directives/modules/confirm.mjs";export{default as vCountTo}from"./directives/modules/countTo.mjs";export{default as utils}from"./functions/modules/uitls.mjs";import*as s from"./functions/modules/is.mjs";export{s as is};export{useZnForm}from"./components/znForm/src/hooks/useZnForm.mjs";export{useZnFormV2}from"./components/znFormV2/src/hooks/useZnFormV2.mjs";export{useZnSearch}from"./components/znSearch/src/hooks/useProSearch.mjs";export{ZnChart}from"./components/znChart/index.mjs";export{ZnCountTo}from"./components/znCountTo/index.mjs";export{default as ZnFormItem}from"./components/znForm/src/components/ZnFormItem.vue2.mjs";export{ZnForm}from"./components/znForm/index.mjs";export{batchExecute,camelCaseToHyphen,checkFeatureSupport,createUniqueId,debounce,delay,executeInIdle,getElementOffsetTop,getMemoryUsage,getObjectHash,isDeepEqual,isElementInViewport,isShallowEqual,throttle}from"./components/znFormV2/src/helper/index.mjs";export{default as ZnFormV2Item}from"./components/znFormV2/src/components/ZnFormV2Item.vue2.mjs";export{ZnFormV2}from"./components/znFormV2/index.mjs";export{ZnGrid,ZnGridItem}from"./components/znGrid/index.mjs";export{ZnNumberScroll}from"./components/znNumberScroll/index.mjs";export{ZnSearch}from"./components/znSearch/index.mjs";export{ZnTable}from"./components/znTable/index.mjs";export{ZnTest}from"./components/znTest/index.mjs";export{ZnTimeline}from"./components/znTimeLine/index.mjs";export{ZnTreeFilter}from"./components/znTreeFilter/index.mjs";export{ZnTreeSelect}from"./components/znTreeSelect/index.mjs";export{initVXETable,isVXETableInitialized}from"./components/znVirtualTable/src/utils/vxe-setup.mjs";export{ZnWorkGrid}from"./components/znWorkGrid/index.mjs";export{default as ZnVirtualTable}from"./components/znVirtualTable/src/index.vue2.mjs";globalThis.log=e;"function"==typeof globalThis?.log?.success&&globalThis.log.primary("1.1.14","欢迎使用znyg-frontend-common,在线文档:http://192.168.99.34:10000/znyg-frontend-common-docs/");export{o as default,e as log};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
package/es/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../../packages/index.ts"],"sourcesContent":["import installer from './installer'\nimport { log } from './functions'\nexport * from './hooks'\nexport * from './utils'\nexport * from './installer'\nexport * from './directives'\nexport * from './functions'\nexport * from './components'\n\nexport default installer\nglobalThis.log = log\nconst version = '1.1.
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../../packages/index.ts"],"sourcesContent":["import installer from './installer'\nimport { log } from './functions'\nexport * from './hooks'\nexport * from './utils'\nexport * from './installer'\nexport * from './directives'\nexport * from './functions'\nexport * from './components'\n\nexport default installer\nglobalThis.log = log\nconst version = '1.1.14'\nif (typeof globalThis?.log?.success === 'function') {\n globalThis.log.primary(version, '欢迎使用znyg-frontend-common,在线文档:http://192.168.99.34:10000/znyg-frontend-common-docs/')\n}\n"],"names":["globalThis","log","success","primary"],"mappings":"sqGAUAA,WAAWC,IAAMA,EAEuB,mBAA7BD,YAAYC,KAAKC,SACfF,WAAAC,IAAIE,QAFD,SAEkB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("vue"),t=require("./assets/notData.png.js");require("./components/ColSetting.vue.js"),require("./components/Pagination.vue.js"),require("./components/TableColumn.vue.js"),require("./components/SearchForm/index.vue.js"),require("./components/OperationBtns/index.vue.js");var r=require("./hooks/useSelection.js"),a=require("./hooks/useTable.js"),l=require("./utils.js"),o=require("@element-plus/icons-vue"),n=require("element-plus"),i=require("@vueuse/core"),s=require("./components/SearchForm/index.vue2.js"),c=require("./components/OperationBtns/index.vue2.js"),u=require("./components/TableColumn.vue2.js"),d=require("./components/Pagination.vue2.js"),p=require("./components/ColSetting.vue2.js"),m=Object.defineProperty,f=(e,t)=>m(e,"name",{value:t,configurable:!0});const h={class:"table-box"},v={class:"table-header"},g={class:"header-button-lf"},y={key:0,class:"header-button-ri"},S={key:0,style:{display:"flex","align-items":"center","justify-content":"center",padding:"20px 0",color:"#909399","font-size":"14px"}},C={key:0,style:{display:"flex","align-items":"center",gap:"8px"}},b={key:1,style:{color:"#909399"}},k={class:"table-empty"};var w=e.defineComponent({name:"ZnTable",__name:"index",props:{columns:{type:Array,required:!0,default:f((()=>[]),"default")},data:{type:Array,required:!1},requestApi:{type:Function,required:!1},requestAuto:{type:Boolean,required:!1,default:!0},requestError:{type:Function,required:!1},dataCallback:{type:Function,required:!1},title:{type:String,required:!1},pagination:{type:Boolean,required:!1,default:!0},pageSizeOptions:{type:Array,required:!1,default:f((()=>[10,25,50,100]),"default")},pageSize:{type:Number,required:!1,default:15},initParam:{required:!1,default:{}},border:{type:Boolean,required:!1,default:!0},toolButton:{type:[Array,Boolean],required:!1,default:!0},rowKey:{type:String,required:!1,default:"id"},searchCol:{type:[Number,Object],required:!1,default:f((()=>({xs:1,sm:2,md:2,lg:3,xl:4})),"default")},height:{type:[String,Number],required:!1},heightOffset:{type:Number,required:!1,default:0},minHeight:{type:[String,Number],required:!1,default:200},onlyTable:{type:Boolean,required:!1,default:!1},isView:{type:Boolean,required:!1,default:!1},searchFormShow:{type:Boolean,required:!1,default:!0},enableScrollPagination:{type:Boolean,required:!1,default:!1},scrollPaginationThreshold:{type:Number,required:!1,default:100}},emits:["search","reset","dragSort","handleOperateBtnsClick"],setup(m,{expose:w,emit:B}){const N=m,q=e.getCurrentInstance(),V=i.useLocalStorage("znyg",{dictMap:{}}),_=e.ref(0);i.useResizeObserver(document.body,(e=>{const t=e[0],{height:r}=t.contentRect;_.value=r}));const E=e.computed((()=>{if(N.height)return N.height
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("vue"),t=require("./assets/notData.png.js");require("./components/ColSetting.vue.js"),require("./components/Pagination.vue.js"),require("./components/TableColumn.vue.js"),require("./components/SearchForm/index.vue.js"),require("./components/OperationBtns/index.vue.js");var r=require("./hooks/useSelection.js"),a=require("./hooks/useTable.js"),l=require("./utils.js"),o=require("@element-plus/icons-vue"),n=require("element-plus"),i=require("@vueuse/core"),s=require("./components/SearchForm/index.vue2.js"),c=require("./components/OperationBtns/index.vue2.js"),u=require("./components/TableColumn.vue2.js"),d=require("./components/Pagination.vue2.js"),p=require("./components/ColSetting.vue2.js"),m=Object.defineProperty,f=(e,t)=>m(e,"name",{value:t,configurable:!0});const h={class:"table-box"},v={class:"table-header"},g={class:"header-button-lf"},y={key:0,class:"header-button-ri"},S={key:0,style:{display:"flex","align-items":"center","justify-content":"center",padding:"20px 0",color:"#909399","font-size":"14px"}},C={key:0,style:{display:"flex","align-items":"center",gap:"8px"}},b={key:1,style:{color:"#909399"}},k={class:"table-empty"};var w=e.defineComponent({name:"ZnTable",__name:"index",props:{columns:{type:Array,required:!0,default:f((()=>[]),"default")},data:{type:Array,required:!1},requestApi:{type:Function,required:!1},requestAuto:{type:Boolean,required:!1,default:!0},requestError:{type:Function,required:!1},dataCallback:{type:Function,required:!1},title:{type:String,required:!1},pagination:{type:Boolean,required:!1,default:!0},pageSizeOptions:{type:Array,required:!1,default:f((()=>[10,25,50,100]),"default")},pageSize:{type:Number,required:!1,default:15},initParam:{required:!1,default:{}},border:{type:Boolean,required:!1,default:!0},toolButton:{type:[Array,Boolean],required:!1,default:!0},rowKey:{type:String,required:!1,default:"id"},searchCol:{type:[Number,Object],required:!1,default:f((()=>({xs:1,sm:2,md:2,lg:3,xl:4})),"default")},height:{type:[String,Number],required:!1},heightOffset:{type:Number,required:!1,default:0},minHeight:{type:[String,Number],required:!1,default:200},onlyTable:{type:Boolean,required:!1,default:!1},isView:{type:Boolean,required:!1,default:!1},searchFormShow:{type:Boolean,required:!1,default:!0},enableScrollPagination:{type:Boolean,required:!1,default:!1},scrollPaginationThreshold:{type:Number,required:!1,default:100}},emits:["search","reset","dragSort","handleOperateBtnsClick"],setup(m,{expose:w,emit:B}){const N=m,q=e.getCurrentInstance(),V=i.useLocalStorage("znyg",{dictMap:{}}),_=e.ref(0);i.useResizeObserver(document.body,(e=>{const t=e[0],{height:r}=t.contentRect;_.value=r}));const E=e.computed((()=>{if(N.height){if("auto"===N.height){if(!(ce.value&&ce.value.length>0)){const e="number"==typeof N.minHeight?N.minHeight:parseInt(N.minHeight.toString());return Math.max(e,200)}}return N.height}const e=_.value-100-(M.value?120:40)-(N.pagination?150:0)-N.heightOffset,t="number"==typeof N.minHeight?N.minHeight:parseInt(N.minHeight.toString());return e>t?e:t})),x=e.ref(),T=e.ref("id-"+l.generateUUID()),P={
|
|
2
2
|
// 前置特殊列(显示在表格最前面)
|
|
3
3
|
FRONT_COLUMNS:["selection","radio","index","expand","sort"],
|
|
4
4
|
// 后置特殊列(显示在表格最后面)
|
|
@@ -8,7 +8,7 @@ EXCLUDE_FROM_SETTING:{props:["operation"],
|
|
|
8
8
|
// 按 prop 排除
|
|
9
9
|
types:[],
|
|
10
10
|
// 按 type 排除(会自动包含所有特殊列类型)
|
|
11
|
-
fixed:!0}},A=[...P.FRONT_COLUMNS,...P.BACK_COLUMNS],O=f((e=>e&&P.FRONT_COLUMNS.includes(e)),"isFrontSpecialColumn"),L=f((e=>e&&P.BACK_COLUMNS.includes(e)),"isBackSpecialColumn"),F=f((e=>{const{type:t,prop:r,fixed:a}=e;return!(!t||!A.includes(t))||(!(!r||!P.EXCLUDE_FROM_SETTING.props.includes(r))||!(!P.EXCLUDE_FROM_SETTING.fixed||!a))}),"shouldExcludeFromSetting"),M=e.ref(N.searchFormShow),z=f((e=>Array.isArray(N.toolButton)?N.toolButton.includes(e):N.toolButton),"showToolButton"),j=e.ref(""),{selectionChange:$,selectedList:U,selectedListIds:I,isSelected:D}=r.useSelection(N.rowKey),
|
|
11
|
+
fixed:!0}},A=[...P.FRONT_COLUMNS,...P.BACK_COLUMNS],O=f((e=>e&&P.FRONT_COLUMNS.includes(e)),"isFrontSpecialColumn"),L=f((e=>e&&P.BACK_COLUMNS.includes(e)),"isBackSpecialColumn"),F=f((e=>{const{type:t,prop:r,fixed:a}=e;return!(!t||!A.includes(t))||(!(!r||!P.EXCLUDE_FROM_SETTING.props.includes(r))||!(!P.EXCLUDE_FROM_SETTING.fixed||!a))}),"shouldExcludeFromSetting"),M=e.ref(N.searchFormShow),z=f((e=>Array.isArray(N.toolButton)?N.toolButton.includes(e):N.toolButton),"showToolButton"),j=e.ref(""),{selectionChange:$,selectedList:U,selectedListIds:I,isSelected:D}=r.useSelection(N.rowKey),H=f((()=>{const e=x.value?.$el;if(e){const t=e.querySelector(".el-scrollbar__wrap");t&&(t.scrollTop=0)}}),"scrollToTop"),R=f((()=>{le.value=!0,ae.value=!1,oe.value=!1}),"resetScrollPagination"),{tableData:K,pageable:G,searchParam:X,searchInitParam:J,getTableList:Z,search:Q,reset:W,handleSizeChange:Y,handleCurrentChange:ee,loading:te}=a.useTable(N.requestApi,N.initParam,N.pagination||N.enableScrollPagination,N.dataCallback,N.requestError,N.pageSize,H,R,N.enableScrollPagination),re=f((async()=>{N.enableScrollPagination&&R(),await Z()}),"getTableList"),ae=e.ref(!1),le=e.ref(!0),oe=e.ref(!1),ne=f((async()=>{if(ae.value||!le.value||oe.value||!N.enableScrollPagination)return;if(0===G.value.total)return;const e=Math.ceil(G.value.total/G.value.pageSize);if(G.value.pageNum>=e)le.value=!1;else try{ae.value=!0,oe.value=!0;const e=G.value.pageNum+1,t={...J.value,...X.value,currPage:e,pageSize:G.value.pageSize,params:{...J.value,...X.value}};if(N.requestApi){const{result:e}=await N.requestApi(t),r=N.dataCallback?N.dataCallback(e):e;if(r&&r.list&&Array.isArray(r.list)&&r.list.length>0){Array.isArray(K.value)||(K.value=[]),K.value.push(...r.list);const{currPage:e,limit:t,total:a}=r;G.value.pageNum=e,G.value.pageSize=t,G.value.total=a;const l=Math.ceil(a/t);le.value=e<l}else le.value=!1,console.log("❌ 滚动翻页没有更多数据")}}catch(e){N.requestError&&N.requestError(e)}finally{ae.value=!1,setTimeout((()=>{oe.value=!1}),1e3)}}),"handleScrollPagination"),ie=f((e=>{if(!N.enableScrollPagination||!N.requestApi)return;if(ae.value||!le.value)return;const t=x.value?.$el;if(!t)return;const r=t.querySelector(".el-scrollbar__wrap");if(!r)return;const a=r.scrollTop;r.scrollHeight-a-r.clientHeight<=N.scrollPaginationThreshold&&ne()}),"handleScroll"),se=f((()=>{x.value&&x.value.clearSelection()}),"clearSelection");e.onMounted((()=>{N.requestAuto&&re(),N.data&&(G.value.total=N.data.length),N.enableScrollPagination&&setTimeout((()=>{const e=x.value?.$el;if(e){const t=e.querySelector(".el-scrollbar__wrap");t&&(t.removeEventListener("scroll",ie),t.addEventListener("scroll",ie,{passive:!0}))}}),500)})),e.onUnmounted((()=>{if(N.enableScrollPagination){const e=x.value?.$el;if(e){const t=e.querySelector(".el-scrollbar__wrap");t&&t.removeEventListener("scroll",ie)}}}));const ce=e.computed((()=>{if(Array.isArray(K.value)||(K.value=[]),N.data){if(!Array.isArray(N.data))return console.warn("props.data 不是数组:",N.data),[];if(!N.pagination)return N.data;const t=e.toRaw(N.data).slice((G.value.pageNum-1)*G.value.pageSize,G.value.pageSize*G.value.pageNum);return e.reactive(t)}return K.value}));e.watch((()=>N.initParam),(()=>{re()}),{deep:!0}),e.watch((()=>K.value),(()=>{N.enableScrollPagination&&le.value&&e.nextTick((()=>{setTimeout((()=>{const e=x.value?.$el;if(e){e.querySelector(".el-scrollbar__wrap")&&ie({})}}),100)}))}),{deep:!0});let ue=e.reactive(N.columns);const de=e.computed((()=>fe(ue))),pe=e.ref(new Map),me=f((async({prop:t,enum:r,dictCode:a})=>{if(a&&V&&V.value?.dictMap)return void pe.value.set(t,V.value.dictMap[a?.toString()]??[]);if(!r)return;if(pe.value.has(t)&&("function"==typeof r||pe.value.get(t)===r))return;if("function"!=typeof r)return pe.value.set(t,e.unref(r));pe.value.set(t,[]);let l=await r();l=l?.result||l,pe.value.set(t,l)}),"setEnumMap");e.provide("enumMap",pe);const fe=f(((e,t=[])=>(e.forEach((async e=>{e._children?.length&&t.push(...fe(e._children)),t.push(e),e.isShow=e.isShow??!0,e.isShowInView=e.isShowInView??!0,e.isFilterEnum=e.isFilterEnum??!0,await me(e)})),t.filter((e=>!e._children?.length)))),"flatColumnsFunc"),he=e.computed((()=>de.value?.filter((e=>e.search?.el||e.search?.render)).sort(((e,t)=>e.search.order-t.search.order))));he.value?.forEach(((e,t)=>{e.search.order=e.search?.order??t+2;const r=e.search?.key??l.handleProp(e.prop),a=e.search?.defaultValue;null!=a&&(J.value[r]=a,X.value[r]=a)}));const ve=e.ref(),ge=e.ref([]),ye=e.ref(!1),Se=f((()=>{ge.value=ue.filter((e=>!F(e)))}),"initColSetting");Se(),e.watch((()=>ue),(()=>{ye.value||(console.log("检测到 tableColumns 变化,同步更新 colSetting"),Se())}),{deep:!0});const Ce=f((e=>{if(!ye.value)if(q&&!q.isUnmounted)try{if(ye.value=!0,!e||!Array.isArray(e)||0===e.length)return void console.warn("updateTableColumns: 无效的列设置数据",{hasNewColSetting:!!e,isArray:Array.isArray(e),length:e?.length});let t;try{t=JSON.parse(JSON.stringify(e))}catch(r){console.warn("深拷贝列设置数据失败,使用浅拷贝"),t=[...e]}const r=new Map,a=[...ue];a.forEach((e=>{e&&e.prop&&r.set(e.prop,e)}));const l=[],o=new Set;a.forEach((e=>{e&&(O(e.type)||"left"===e.fixed)&&(l.push(e),e.prop&&o.add(e.prop))})),t.forEach((e=>{if(e&&e.prop&&r.has(e.prop)&&!o.has(e.prop)){const t=r.get(e.prop);if(t)try{const r={...t};r.isShow=e.isShow,r.sortable=e.sortable,l.push(r),o.add(e.prop)}catch(r){console.warn("更新列配置时出错:",r),l.push(t),o.add(e.prop)}}})),a.forEach((e=>{!e||e.prop&&o.has(e.prop)||!L(e.type)&&(A.includes(e.type)||"left"===e.fixed)||l.push(e)})),setTimeout((()=>{if(q&&!q.isUnmounted)try{ue.length=0,l.forEach((e=>{e&&ue.push(e)})),ge.value=t}catch(e){console.warn("更新表格列时出错:",e)}finally{ye.value=!1}else console.warn("延迟更新时组件已销毁")}),50)}catch(e){console.warn("updateTableColumns执行时出错:",e),ye.value=!1}else console.warn("组件已销毁,跳过列更新")}),"updateTableColumns"),be=f((()=>{ve.value.openColSetting()}),"openColSetting"),ke=f((()=>{ve.value.closeColSetting()}),"closeColSetting"),we=B,Be=f((()=>{Q(),we("search")}),"_search"),Ne=f((()=>{W(),we("reset")}),"_reset"),qe=f(((e,t,r,a)=>{we("handleOperateBtnsClick",e,t,r,a)}),"handleOperateBtnsClick"),Ve=f((()=>{re()}),"refreshTable");return w({element:x,tableData:ce,radio:j,pageable:G,searchParam:X,searchInitParam:J,getTableList:re,search:Q,reset:W,handleSizeChange:Y,handleCurrentChange:ee,clearSelection:se,enumMap:pe,isSelected:D,selectedList:U,selectedListIds:I,refreshTable:Ve,setSearchFormShow:f((e=>{M.value=e}),"setSearchFormShow"),getColumns:f((()=>ue),"getColumns"),getColSetting:f((()=>ge.value),"getColSetting"),openColSetting:be,closeColSetting:ke}),(r,a)=>{const l=e.resolveComponent("el-button"),i=e.resolveComponent("el-radio"),w=e.resolveComponent("el-icon"),B=e.resolveComponent("el-tag"),q=e.resolveComponent("el-table-column"),V=e.resolveDirective("loading");return e.openBlock(),e.createElementBlock("div",h,[e.createCommentVNode(" 查询表单 "),e.withDirectives(e.createVNode(s.default,{search:Be,reset:Ne,columns:he.value,"search-param":e.unref(X),"search-col":m.searchCol},null,8,["columns","search-param","search-col"]),[[e.vShow,M.value]]),e.createCommentVNode(" 表格主体 "),e.createElementVNode("div",{class:e.normalizeClass([m.onlyTable?"only-table":"card table-main"])},[e.createCommentVNode(" 表格头部 操作按钮 "),e.createElementVNode("div",v,[e.createElementVNode("div",g,[e.renderSlot(r.$slots,"tableHeader",{selectedList:e.unref(U),selectedListIds:e.unref(I),isSelected:e.unref(D)})]),m.toolButton?(e.openBlock(),e.createElementBlock("div",y,[e.renderSlot(r.$slots,"toolButton",{},(()=>[z("refresh")?(e.openBlock(),e.createBlock(l,{key:0,icon:e.unref(o.Refresh),circle:"",onClick:re},null,8,["icon"])):e.createCommentVNode("v-if",!0),z("setting")&&m.columns.length?(e.openBlock(),e.createBlock(l,{key:1,icon:e.unref(o.Operation),circle:"",onClick:be},null,8,["icon"])):e.createCommentVNode("v-if",!0),z("search")&&he.value?.length?(e.openBlock(),e.createBlock(l,{key:2,icon:e.unref(o.Search),circle:"",onClick:a[0]||(a[0]=e=>M.value=!M.value)},null,8,["icon"])):e.createCommentVNode("v-if",!0)]))])):e.createCommentVNode("v-if",!0)]),e.createCommentVNode(" 表格主体 "),e.withDirectives((e.openBlock(),e.createBlock(e.unref(n.ElTable),e.mergeProps({ref_key:"tableRef",ref:x},r.$attrs,{data:ce.value,border:m.border,id:T.value,"row-key":m.rowKey,height:E.value,onSelectionChange:e.unref($),onScroll:ie}),{append:e.withCtx((()=>[e.renderSlot(r.$slots,"append"),e.createCommentVNode(" 滚动翻页加载状态 "),!N.enableScrollPagination||!ae.value&&le.value?e.createCommentVNode("v-if",!0):(e.openBlock(),e.createElementBlock("div",S,[ae.value?(e.openBlock(),e.createElementBlock("div",C,[e.createVNode(w,{class:"is-loading"},{default:e.withCtx((()=>[e.createVNode(e.unref(o.Loading))])),_:1
|
|
12
12
|
/* STABLE */}),a[3]||(a[3]=e.createElementVNode("span",null,"正在加载更多数据...",-1
|
|
13
13
|
/* HOISTED */))])):le.value?e.createCommentVNode("v-if",!0):(e.openBlock(),e.createElementBlock("div",b,a[4]||(a[4]=[e.createElementVNode("span",null,"没有更多数据了",-1
|
|
14
14
|
/* HOISTED */)])))]))])),empty:e.withCtx((()=>[e.createElementVNode("div",k,[e.renderSlot(r.$slots,"empty",{},(()=>[a[5]||(a[5]=e.createElementVNode("img",{src:t.default,alt:"notData"},null,-1
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.vue2.js","sources":["../../../../../../packages/components/znTable/src/index.vue"],"sourcesContent":["<!-- 📚📚📚 Pro-Table 文档: https://juejin.cn/post/7166068828202336263 -->\n\n<template>\n <div class=\"table-box\">\n <!-- 查询表单 -->\n <SearchForm v-show=\"isShowSearch\" :search=\"_search\" :reset=\"_reset\" :columns=\"searchColumns\" :search-param=\"searchParam\" :search-col=\"searchCol\" />\n\n <!-- 表格主体 -->\n <div :class=\"[onlyTable ? 'only-table' : 'card table-main']\">\n <!-- 表格头部 操作按钮 -->\n <div class=\"table-header\">\n <div class=\"header-button-lf\">\n <slot name=\"tableHeader\" :selected-list=\"selectedList\" :selected-list-ids=\"selectedListIds\" :is-selected=\"isSelected\"></slot>\n </div>\n <div v-if=\"toolButton\" class=\"header-button-ri\">\n <slot name=\"toolButton\">\n <el-button v-if=\"showToolButton('refresh')\" :icon=\"Refresh\" circle @click=\"getTableList\" />\n <el-button v-if=\"showToolButton('setting') && columns.length\" :icon=\"Operation\" circle @click=\"openColSetting\" />\n <el-button v-if=\"showToolButton('search') && searchColumns?.length\" :icon=\"Search\" circle @click=\"isShowSearch = !isShowSearch\" />\n </slot>\n </div>\n </div>\n <!-- 表格主体 -->\n <el-table\n ref=\"tableRef\"\n v-bind=\"$attrs\"\n :data=\"processTableData\"\n :border=\"border\"\n :id=\"uuid\"\n :row-key=\"rowKey\"\n :height=\"tableHeight\"\n v-loading=\"loading\"\n @selection-change=\"selectionChange\"\n @scroll.enter=\"handleScroll\">\n <!-- 默认插槽 -->\n <slot></slot>\n <template v-for=\"item in tableColumns\" :key=\"item\">\n <!-- selection || radio || index || expand || sort -->\n <el-table-column\n v-if=\"item.type && columnTypes.includes(item.type)\"\n v-bind=\"item\"\n :selectable=\"(row: any) => (row.selectable != null && row.selectable != undefined ? row.selectable : true)\"\n :align=\"item.align ?? 'center'\"\n :reserve-selection=\"item.type == 'selection'\">\n <template #default=\"scope\">\n <!-- expand -->\n <template v-if=\"item.type == 'expand'\">\n <component :is=\"item.render\" v-bind=\"scope\" v-if=\"item.render\" />\n <slot v-else :name=\"item.type\" v-bind=\"scope\"></slot>\n </template>\n <!-- radio -->\n <el-radio v-if=\"item.type == 'radio'\" v-model=\"radio\" :label=\"scope.row[rowKey]\">\n <i></i>\n </el-radio>\n <!-- sort -->\n <el-tag v-if=\"item.type == 'sort'\" class=\"move\">\n <el-icon><DCaret /></el-icon>\n </el-tag>\n <!-- operationBtns -->\n <OperationBtns v-if=\"item.type == 'operationBtns'\" v-bind=\"item.props\" :row=\"scope.row\" :index=\"scope.$index\" @btn-click=\"handleOperateBtnsClick\" />\n </template>\n </el-table-column>\n <!-- other -->\n <TableColumn\n v-if=\"!item.type && item.prop && item.isShow && (!unref(isView) || (unref(isView) && item.isShowInView))\"\n :column=\"item\"\n :is-view=\"isView\">\n <template v-for=\"slot in Object.keys($slots)\" #[slot]=\"scope\">\n <slot :name=\"slot\" v-bind=\"scope\"></slot>\n </template>\n </TableColumn>\n </template>\n <!-- 插入表格最后一行之后的插槽 -->\n <template #append>\n <slot name=\"append\"></slot>\n <!-- 滚动翻页加载状态 -->\n <div\n v-if=\"props.enableScrollPagination && (isScrollLoading || !hasMoreData)\"\n style=\"display: flex; align-items: center; justify-content: center; padding: 20px 0; color: #909399; font-size: 14px\">\n <div v-if=\"isScrollLoading\" style=\"display: flex; align-items: center; gap: 8px\">\n <el-icon class=\"is-loading\"><Loading /></el-icon>\n <span>正在加载更多数据...</span>\n </div>\n <div v-else-if=\"!hasMoreData\" style=\"color: #909399\">\n <span>没有更多数据了</span>\n </div>\n </div>\n </template>\n <!-- 无数据 -->\n <template #empty>\n <div class=\"table-empty\">\n <slot name=\"empty\">\n <img src=\"./assets/notData.png\" alt=\"notData\" />\n <div>暂无数据</div>\n </slot>\n </div>\n </template>\n </el-table>\n <!-- 分页组件 -->\n <slot name=\"pagination\">\n <Pagination\n v-if=\"pagination && !enableScrollPagination\"\n :pageable=\"pageable\"\n :handle-size-change=\"handleSizeChange\"\n :handle-current-change=\"handleCurrentChange\"\n :page-size-options=\"pageSizeOptions\" />\n </slot>\n </div>\n <!-- 列设置 -->\n <ColSetting v-if=\"toolButton\" ref=\"colRef\" :col-setting=\"colSetting\" @update-columns=\"updateTableColumns\">\n <!-- 列设置头部插槽 -->\n <template #colSettingHeader>\n <slot name=\"colSettingHeader\"></slot>\n </template>\n </ColSetting>\n </div>\n</template>\n\n<script setup lang=\"ts\" name=\"ZnTable\">\n import { computed, onMounted, provide, reactive, ref, toRaw, unref, watch, nextTick, getCurrentInstance, onUnmounted } from 'vue'\n\n import ColSetting from './components/ColSetting.vue'\n import Pagination from './components/Pagination.vue'\n import TableColumn from './components/TableColumn.vue'\n import SearchForm from './components/SearchForm/index.vue'\n import OperationBtns from './components/OperationBtns/index.vue'\n\n import { BreakPoint } from './components/Grid/interface'\n import { ColumnProps, TypeProps, OperationBtnProps } from './interface'\n import { useSelection } from './hooks/useSelection'\n import { useTable } from './hooks/useTable'\n import { generateUUID, handleProp } from './utils'\n import { Operation, Refresh, Search, DCaret, Loading } from '@element-plus/icons-vue'\n import { ElTable } from 'element-plus'\n // import Sortable from 'sortablejs'\n import { useResizeObserver, useLocalStorage } from '@vueuse/core'\n defineOptions({\n name: 'ZnTable'\n })\n\n export interface ZnTableProps {\n columns: ColumnProps[] // 列配置项 ==> 必传\n data?: any[] // 静态 table data 数据,若存在则不会使用 requestApi 返回的 data ==> 非必传\n requestApi?: (params: any) => Promise<any> // 请求表格数据的 api ==> 非必传\n requestAuto?: boolean // 是否自动执行请求 api ==> 非必传(默认为true)\n requestError?: (params: any) => void // 表格 api 请求错误监听 ==> 非必传\n dataCallback?: (data: any) => any // 返回数据的回调函数,可以对数据进行处理 ==> 非必传\n title?: string // 表格标题 ==> 非必传\n pagination?: boolean // 是否需要分页组件 ==> 非必传(默认为true)\n pageSizeOptions?: number[] // 分页每页条数选项 ==> 非必传(默认为[10, 25, 50, 100])\n pageSize?: number // 默认每页显示条数 ==> 非必传(默认为15)\n initParam?: any // 初始化请求参数 ==> 非必传(默认为{})\n border?: boolean // 是否带有纵向边框 ==> 非必传(默认为true)\n toolButton?: ('refresh' | 'setting' | 'search')[] | boolean // 是否显示表格功能按钮 ==> 非必传(默认为true)\n rowKey?: string // 行数据的 Key,用来优化 Table 的渲染,当表格数据多选时,所指定的 id ==> 非必传(默认为 id)\n searchCol?: number | Record<BreakPoint, number> // 表格搜索项 每列占比配置 ==> 非必传 { xs: 1, sm: 2, md: 2, lg: 3, xl: 4 }\n height?: string | number // 表格高度,如果传了,则直接使用这个高度 未传则自动计算\n heightOffset?: number // 如果没传height,自动计算时,去除的高度\n minHeight?: string | number // 表格最小高度 ==> 非必传(默认为200)\n // hiddenTableHeader?: boolean // 隐藏表格头部\n onlyTable?: boolean // 只展示el-table部分\n isView?: boolean // 是否查看,默认为否\n searchFormShow?: boolean // 是否显示筛选行,默认为true\n enableScrollPagination?: boolean // 是否启用滚动翻页(无限滚动)==> 非必传(默认为false)\n scrollPaginationThreshold?: number // 滚动翻页触发阈值(距离底部多少像素时触发)==> 非必传(默认为100)\n }\n\n // 接受父组件参数,配置默认值\n const props = defineProps({\n columns: { type: Array, required: true, default: () => [] },\n data: { type: Array, required: false },\n requestApi: { type: Function, required: false },\n requestAuto: { type: Boolean, required: false, default: true },\n requestError: { type: Function, required: false },\n dataCallback: { type: Function, required: false },\n title: { type: String, required: false },\n pagination: { type: Boolean, required: false, default: true },\n pageSizeOptions: { type: Array, required: false, default: () => [10, 25, 50, 100] },\n pageSize: { type: Number, required: false, default: 15 },\n initParam: { required: false, default: {} },\n border: { type: Boolean, required: false, default: true },\n toolButton: { type: [Array, Boolean], required: false, default: true },\n rowKey: { type: String, required: false, default: 'id' },\n searchCol: { type: [Number, Object], required: false, default: () => ({ xs: 1, sm: 2, md: 2, lg: 3, xl: 4 }) },\n height: { type: [String, Number], required: false },\n heightOffset: { type: Number, required: false, default: 0 },\n minHeight: { type: [String, Number], required: false, default: 200 },\n onlyTable: { type: Boolean, required: false, default: false },\n isView: { type: Boolean, required: false, default: false },\n searchFormShow: { type: Boolean, required: false, default: true },\n enableScrollPagination: { type: Boolean, required: false, default: false },\n scrollPaginationThreshold: { type: Number, required: false, default: 100 }\n})\n\n // 在 setup 顶层获取组件实例,确保能正确获取\n const componentInstance = getCurrentInstance()\n\n const znygStore = useLocalStorage('znyg', { dictMap: {} })\n\n const bodyHeight = ref(0)\n useResizeObserver(document.body, (entries) => {\n const entry = entries[0]\n const { height } = entry.contentRect\n bodyHeight.value = height\n })\n // 计算表格高度\n const tableHeight = computed(() => {\n if (props.height) {\n return props.height\n }\n const ret = bodyHeight.value - 100 - (isShowSearch.value ? 120 : 40) - (props.pagination ? 150 : 0) - props.heightOffset\n // console.log(bodyHeight.value + '-' + 100 + '-' + (isShowSearch.value ? 120 : 0) + '-' + (props.pagination ? 70 : 0))\n // console.log('bodyHeight:' + bodyHeight.value, 'isShowSearch:' + (isShowSearch.value ? 80 : 0), 'ret:' + ret)\n\n // 确保返回的高度不小于最小高度\n const minHeightValue = typeof props.minHeight === 'number' ? props.minHeight : parseInt(props.minHeight.toString())\n return ret > minHeightValue ? ret : minHeightValue\n })\n\n // table 实例\n const tableRef = ref<InstanceType<typeof ElTable>>()\n\n // 生成组件唯一id\n const uuid = ref('id-' + generateUUID())\n\n /**\n * 特殊列配置管理\n *\n * 如何添加新的特殊列类型:\n * 1. 在 interface/index.ts 中的 TypeProps 类型中添加新的列类型\n * 2. 根据列的显示位置,将新类型添加到 FRONT_COLUMNS 或 BACK_COLUMNS 数组中\n * 3. 如果需要从列设置中排除特定的 prop,添加到 EXCLUDE_FROM_SETTING.props 中\n * 4. 在模板中添加对应的渲染逻辑\n *\n * 就这样!不需要在其他地方修改代码了。\n */\n const SPECIAL_COLUMN_CONFIG = {\n // 前置特殊列(显示在表格最前面)\n FRONT_COLUMNS: ['selection', 'radio', 'index', 'expand', 'sort'] as TypeProps[],\n // 后置特殊列(显示在表格最后面)\n BACK_COLUMNS: ['operationBtns'] as TypeProps[],\n // 需要从列设置中排除的列(除了特殊列类型,还可以包括特定的 prop)\n EXCLUDE_FROM_SETTING: {\n props: ['operation'], // 按 prop 排除\n types: [] as TypeProps[], // 按 type 排除(会自动包含所有特殊列类型)\n fixed: true // 排除固定列\n }\n }\n\n // 所有特殊列类型(合并前置和后置)\n const columnTypes: TypeProps[] = [...SPECIAL_COLUMN_CONFIG.FRONT_COLUMNS, ...SPECIAL_COLUMN_CONFIG.BACK_COLUMNS]\n\n // 判断是否为前置特殊列\n const isFrontSpecialColumn = (type?: TypeProps) => {\n return type && SPECIAL_COLUMN_CONFIG.FRONT_COLUMNS.includes(type)\n }\n\n // 判断是否为后置特殊列\n const isBackSpecialColumn = (type?: TypeProps) => {\n return type && SPECIAL_COLUMN_CONFIG.BACK_COLUMNS.includes(type)\n }\n\n // 判断是否应该从列设置中排除\n const shouldExcludeFromSetting = (column: ColumnProps) => {\n const { type, prop, fixed } = column\n\n // 排除所有特殊列类型\n if (type && columnTypes.includes(type)) return true\n\n // 排除指定的 prop\n if (prop && SPECIAL_COLUMN_CONFIG.EXCLUDE_FROM_SETTING.props.includes(prop)) return true\n\n // 排除固定列\n if (SPECIAL_COLUMN_CONFIG.EXCLUDE_FROM_SETTING.fixed && fixed) return true\n\n return false\n }\n\n // 是否显示搜索模块\n const isShowSearch = ref(props.searchFormShow)\n\n // 控制 ToolButton 显示\n const showToolButton = (key: 'refresh' | 'setting' | 'search') => {\n return Array.isArray(props.toolButton) ? props.toolButton.includes(key) : props.toolButton\n }\n\n // 单选值\n const radio = ref('')\n\n // 表格多选 Hooks\n const { selectionChange, selectedList, selectedListIds, isSelected } = useSelection(props.rowKey)\n // 滚动到顶部\n const scrollToTop = () => {\n const tableEl = tableRef.value?.$el\n if (tableEl) {\n const scrollWrap = tableEl.querySelector('.el-scrollbar__wrap')\n if (scrollWrap) {\n scrollWrap.scrollTop = 0\n }\n }\n }\n // 重置滚动翻页状态\n const resetScrollPagination = () => {\n hasMoreData.value = true\n isScrollLoading.value = false\n scrollPaginationDisabled.value = false\n }\n // 表格操作 Hooks\n const {\n tableData,\n pageable,\n searchParam,\n searchInitParam,\n getTableList: originalGetTableList,\n search,\n reset,\n handleSizeChange,\n handleCurrentChange,\n loading\n } = useTable(\n props.requestApi,\n props.initParam,\n props.pagination || props.enableScrollPagination,\n props.dataCallback,\n props.requestError,\n props.pageSize,\n scrollToTop,\n resetScrollPagination,\n props.enableScrollPagination\n )\n\n // 包装 getTableList,确保重置滚动翻页状态\n const getTableList = async () => {\n // 重置滚动翻页状态\n if (props.enableScrollPagination) {\n resetScrollPagination()\n }\n await originalGetTableList()\n }\n\n // 滚动翻页相关状态\n const isScrollLoading = ref(false) // 滚动翻页加载状态\n const hasMoreData = ref(true) // 是否还有更多数据\n const scrollPaginationDisabled = ref(false) // 是否禁用滚动翻页\n\n // 滚动翻页处理函数\n const handleScrollPagination = async () => {\n // 如果正在加载、没有更多数据、或已禁用滚动翻页,则直接返回\n if (isScrollLoading.value || !hasMoreData.value || scrollPaginationDisabled.value || !props.enableScrollPagination) {\n return\n }\n\n // 如果总数为0,说明还没有初始数据,不应该触发滚动翻页\n if (pageable.value.total === 0) {\n return\n }\n\n // 检查是否还有下一页数据\n const totalPages = Math.ceil(pageable.value.total / pageable.value.pageSize)\n if (pageable.value.pageNum >= totalPages) {\n hasMoreData.value = false\n return\n }\n\n try {\n isScrollLoading.value = true\n scrollPaginationDisabled.value = true // 防止重复触发\n\n // 获取下一页数据\n const nextPage = pageable.value.pageNum + 1\n const nextPageParams = {\n ...searchInitParam.value,\n ...searchParam.value,\n currPage: nextPage,\n pageSize: pageable.value.pageSize,\n params: {\n ...searchInitParam.value,\n ...searchParam.value\n }\n }\n if (props.requestApi) {\n const { result } = await props.requestApi(nextPageParams)\n const processedResult = props.dataCallback ? props.dataCallback(result) : result\n if (processedResult && processedResult.list && Array.isArray(processedResult.list) && processedResult.list.length > 0) {\n // 确保 tableData.value 是数组\n if (!Array.isArray(tableData.value)) {\n tableData.value = []\n }\n // 将新数据追加到现有数据中\n tableData.value.push(...processedResult.list)\n\n // 更新分页信息\n const { currPage, limit, total } = processedResult\n pageable.value.pageNum = currPage\n pageable.value.pageSize = limit\n pageable.value.total = total\n\n // 检查是否还有更多数据\n const totalPages = Math.ceil(total / limit)\n hasMoreData.value = currPage < totalPages\n } else {\n hasMoreData.value = false\n console.log('❌ 滚动翻页没有更多数据')\n }\n }\n } catch (error) {\n props.requestError && props.requestError(error)\n } finally {\n isScrollLoading.value = false\n // 延迟重新启用滚动翻页,防止频繁触发\n setTimeout(() => {\n scrollPaginationDisabled.value = false\n }, 1000)\n }\n }\n\n // 滚动事件处理函数\n const handleScroll = (event: any) => {\n if (!props.enableScrollPagination || !props.requestApi) return\n\n // 如果正在加载或没有更多数据,直接返回\n if (isScrollLoading.value || !hasMoreData.value) return\n\n // 直接从表格元素获取滚动容器\n const tableEl = tableRef.value?.$el\n if (!tableEl) return\n\n // Element Plus 使用自定义滚动条,实际的滚动容器是 .el-scrollbar__wrap\n const scrollWrap = tableEl.querySelector('.el-scrollbar__wrap')\n if (!scrollWrap) return\n\n // 从滚动容器获取滚动信息\n const scrollTop = scrollWrap.scrollTop\n const scrollHeight = scrollWrap.scrollHeight\n const clientHeight = scrollWrap.clientHeight\n const threshold = props.scrollPaginationThreshold\n\n // 计算距离底部的距离\n const distanceToBottom = scrollHeight - scrollTop - clientHeight\n if (distanceToBottom <= threshold) {\n handleScrollPagination()\n }\n }\n\n // 清空选中数据列表\n const clearSelection = () => {\n if (!tableRef.value) return\n tableRef.value!.clearSelection()\n }\n // 初始化表格数据 && 拖拽排序\n onMounted(() => {\n // dragSort()\n props.requestAuto && getTableList()\n props.data && (pageable.value.total = props.data.length)\n\n // 如果启用滚动翻页,设置滚动监听\n if (props.enableScrollPagination) {\n // 延迟设置滚动监听,确保表格完全渲染\n setTimeout(() => {\n const tableEl = tableRef.value?.$el\n if (tableEl) {\n const scrollWrap = tableEl.querySelector('.el-scrollbar__wrap')\n if (scrollWrap) {\n // 移除可能存在的旧监听器\n scrollWrap.removeEventListener('scroll', handleScroll)\n // 添加新的滚动监听器\n scrollWrap.addEventListener('scroll', handleScroll, { passive: true })\n }\n }\n }, 500)\n }\n })\n\n // 组件卸载时清理事件监听\n onUnmounted(() => {\n if (props.enableScrollPagination) {\n const tableEl = tableRef.value?.$el\n if (tableEl) {\n const scrollWrap = tableEl.querySelector('.el-scrollbar__wrap')\n if (scrollWrap) {\n scrollWrap.removeEventListener('scroll', handleScroll)\n }\n }\n }\n })\n\n // 处理表格数据\n const processTableData = computed(() => {\n // 确保 tableData.value 是数组\n if (!Array.isArray(tableData.value)) {\n tableData.value = []\n }\n\n // 如果使用静态数据\n if (props.data) {\n // 确保 props.data 是数组\n if (!Array.isArray(props.data)) {\n console.warn('props.data 不是数组:', props.data)\n return []\n }\n\n if (!props.pagination) {\n return props.data\n }\n\n // 分页处理\n const rawData = toRaw(props.data)\n const slicedData = rawData.slice((pageable.value.pageNum - 1) * pageable.value.pageSize, pageable.value.pageSize * pageable.value.pageNum)\n return reactive(slicedData)\n }\n return tableData.value\n })\n\n // 监听页面 initParam 改化,重新获取表格数据\n watch(\n () => props.initParam,\n () => {\n getTableList()\n },\n { deep: true }\n )\n\n // 监听表格数据变化,检查是否需要重新启用滚动翻页\n watch(\n () => tableData.value,\n () => {\n if (props.enableScrollPagination && hasMoreData.value) {\n // 数据更新后,延迟检查滚动状态\n nextTick(() => {\n setTimeout(() => {\n const tableEl = tableRef.value?.$el\n if (tableEl) {\n const scrollWrap = tableEl.querySelector('.el-scrollbar__wrap')\n if (scrollWrap) {\n // 手动触发一次滚动检查\n handleScroll({})\n }\n }\n }, 100)\n })\n }\n },\n { deep: true }\n )\n\n // 接收 columns 并设置为响应式\n let tableColumns = reactive<ColumnProps[]>(props.columns)\n\n // 扁平化 columns\n const flatColumns = computed(() => flatColumnsFunc(tableColumns))\n\n // 定义 enumMap 存储 enum 值(避免异步请求无法格式化单元格内容 || 无法填充搜索下拉选择)\n const enumMap = ref(new Map<string, { [key: string]: any }[]>())\n const setEnumMap = async ({ prop, enum: enumValue, dictCode }: ColumnProps) => {\n if (dictCode) {\n // let znygStore = globalThis.localStorage.getItem('znyg')\n // if (znygStore) znygStore = JSON.parse(znygStore)\n if (znygStore && znygStore.value?.dictMap) {\n enumMap.value.set(prop!, znygStore.value.dictMap[dictCode?.toString()] ?? [])\n return\n }\n }\n if (!enumValue) return\n\n // 如果当前 enumMap 存在相同的值 return\n if (enumMap.value.has(prop!) && (typeof enumValue === 'function' || enumMap.value.get(prop!) === enumValue)) return\n\n // 当前 enum 为静态数据,则直接存储到 enumMap\n if (typeof enumValue !== 'function') return enumMap.value.set(prop!, unref(enumValue!))\n\n // 为了防止接口执行慢,而存储慢,导致重复请求,所以预先存储为[],接口返回后再二次存储\n enumMap.value.set(prop!, [])\n\n // 当前 enum 为后台数据需要请求数据,则调用该请求接口,并存储到 enumMap\n // const { data } = await enumValue()\n // 如果当前 enum 为后台数据需要请求数据,则调用该请求接口,并存储到 enumMap\n let data = await enumValue()\n // 适配 enum 接口返回 data 以及自定义函数返回数组\n data = data?.result || data\n enumMap.value.set(prop!, data)\n }\n // 注入 enumMap\n provide('enumMap', enumMap)\n\n // 扁平化 columns 的方法\n const flatColumnsFunc = (columns: ColumnProps[], flatArr: ColumnProps[] = []) => {\n columns.forEach(async (col) => {\n if (col._children?.length) flatArr.push(...flatColumnsFunc(col._children))\n flatArr.push(col)\n\n // column 添加默认 isShow && isFilterEnum 属性值\n col.isShow = col.isShow ?? true\n col.isShowInView = col.isShowInView ?? true\n col.isFilterEnum = col.isFilterEnum ?? true\n\n // 设置 enumMap\n await setEnumMap(col)\n })\n return flatArr.filter((item) => !item._children?.length)\n }\n\n // 过滤需要搜索的配置项 && 排序\n const searchColumns = computed(() => {\n return flatColumns.value?.filter((item) => item.search?.el || item.search?.render).sort((a, b) => a.search!.order! - b.search!.order!)\n })\n\n // 设置 搜索表单默认排序 && 搜索表单项的默认值\n searchColumns.value?.forEach((column, index) => {\n column.search!.order = column.search?.order ?? index + 2\n const key = column.search?.key ?? handleProp(column.prop!)\n const defaultValue = column.search?.defaultValue\n if (defaultValue !== undefined && defaultValue !== null) {\n searchInitParam.value[key] = defaultValue\n searchParam.value[key] = defaultValue\n }\n })\n\n // 列设置\n const colRef = ref()\n const colSetting = ref<ColumnProps[]>([])\n // 添加更新标志,避免循环更新\n const isUpdatingColumns = ref(false)\n\n // const colSetting = computed(() => {\n // return tableColumns.filter((item) => !shouldExcludeFromSetting(item))\n // })\n\n // 初始化列设置数据\n const initColSetting = () => {\n colSetting.value = tableColumns.filter((item) => !shouldExcludeFromSetting(item))\n }\n\n // 初始化时设置列配置\n initColSetting()\n\n // 监听 tableColumns 变化,同步更新 colSetting\n watch(\n () => tableColumns,\n () => {\n // 如果正在更新中,跳过同步\n if (isUpdatingColumns.value) {\n return\n }\n\n console.log('检测到 tableColumns 变化,同步更新 colSetting')\n initColSetting()\n },\n { deep: true }\n )\n\n // 手动更新表格列顺序的函数\n const updateTableColumns = (newColSetting: ColumnProps[]) => {\n // 如果正在更新中,避免循环调用\n if (isUpdatingColumns.value) {\n return\n }\n\n // console.log('updateTableColumns调用:', {\n // hasNewColSetting: !!newColSetting,\n // newColSettingLength: Array.isArray(newColSetting) ? newColSetting.length : 'not array',\n // currentTableColumnsLength: tableColumns.length\n // })\n\n // console.log('组件实例状态:', {\n // hasInstance: !!componentInstance,\n // isUnmounted: componentInstance?.isUnmounted\n // })\n\n if (!componentInstance || componentInstance.isUnmounted) {\n console.warn('组件已销毁,跳过列更新')\n return\n }\n\n try {\n // 设置更新标志\n isUpdatingColumns.value = true\n\n // 安全检查\n if (!newColSetting || !Array.isArray(newColSetting) || newColSetting.length === 0) {\n console.warn('updateTableColumns: 无效的列设置数据', {\n hasNewColSetting: !!newColSetting,\n isArray: Array.isArray(newColSetting),\n length: newColSetting?.length\n })\n return\n }\n\n // console.log('开始处理列设置数据')\n\n // 深拷贝输入数据,避免响应式问题\n let clonedColSetting: ColumnProps[]\n try {\n clonedColSetting = JSON.parse(JSON.stringify(newColSetting))\n // console.log('深拷贝成功')\n } catch (error) {\n console.warn('深拷贝列设置数据失败,使用浅拷贝')\n clonedColSetting = [...newColSetting]\n }\n\n // 创建一个映射,用于快速查找列配置\n const colMap = new Map()\n const currentColumns = [...tableColumns] // 创建当前列的副本\n\n currentColumns.forEach((col) => {\n if (col && col.prop) {\n colMap.set(col.prop, col)\n }\n })\n\n // console.log('创建列映射完成:', {\n // colMapSize: colMap.size,\n // currentColumnsLength: currentColumns.length\n // })\n\n // 根据新的列设置顺序重新排列列\n const reorderedColumns: ColumnProps[] = []\n const processedProps = new Set()\n\n // 首先添加前置特殊列(selection, radio, index 等)\n currentColumns.forEach((col) => {\n if (col && (isFrontSpecialColumn(col.type) || col.fixed === 'left')) {\n // console.log('添加前置特殊列:', { type: col.type, prop: col.prop, label: col.label })\n reorderedColumns.push(col)\n if (col.prop) {\n processedProps.add(col.prop)\n }\n }\n })\n\n // console.log('前置特殊列添加完成,当前列数:', reorderedColumns.length)\n\n // 然后添加按新顺序排列的普通列\n clonedColSetting.forEach((colSetting) => {\n if (colSetting && colSetting.prop && colMap.has(colSetting.prop) && !processedProps.has(colSetting.prop)) {\n const originalCol = colMap.get(colSetting.prop)\n if (originalCol) {\n // console.log('添加普通列:', { prop: colSetting.prop, label: colSetting.label, isShow: colSetting.isShow })\n try {\n // 创建列的副本并更新属性\n const updatedCol = { ...originalCol }\n updatedCol.isShow = colSetting.isShow\n updatedCol.sortable = colSetting.sortable\n reorderedColumns.push(updatedCol)\n processedProps.add(colSetting.prop)\n } catch (error) {\n console.warn('更新列配置时出错:', error)\n // 如果更新失败,使用原始列\n reorderedColumns.push(originalCol)\n processedProps.add(colSetting.prop)\n }\n }\n }\n })\n\n // console.log('普通列添加完成,当前列数:', reorderedColumns.length)\n\n // 最后添加后置特殊列(如操作列、operationBtns、右侧固定列等)\n currentColumns.forEach((col) => {\n if (\n col &&\n (!col.prop || !processedProps.has(col.prop)) &&\n (isBackSpecialColumn(col.type) || (!columnTypes.includes(col.type!) && col.fixed !== 'left'))\n ) {\n // console.log('添加后置特殊列:', { type: col.type, prop: col.prop, label: col.label })\n reorderedColumns.push(col)\n }\n })\n\n // console.log('列重排完成:', {\n // reorderedColumnsLength: reorderedColumns.length,\n // processedPropsSize: processedProps.size\n // })\n\n // 使用setTimeout而不是nextTick,确保在下一个事件循环中更新\n setTimeout(() => {\n // console.log('开始更新表格列,检查组件状态:', {\n // hasInstance: !!componentInstance,\n // isUnmounted: componentInstance?.isUnmounted\n // })\n\n if (!componentInstance || componentInstance.isUnmounted) {\n console.warn('延迟更新时组件已销毁')\n return\n }\n\n try {\n // console.log('执行表格列更新')\n // 简单直接的数组替换方法\n tableColumns.length = 0\n reorderedColumns.forEach((col) => {\n if (col) {\n tableColumns.push(col as any)\n }\n })\n\n // 同步更新 colSetting,但不触发新的更新\n colSetting.value = clonedColSetting\n\n // console.log('表格列更新完成:', {\n // newLength: tableColumns.length\n // })\n } catch (error) {\n console.warn('更新表格列时出错:', error)\n } finally {\n // 重置更新标志\n isUpdatingColumns.value = false\n }\n }, 50) // 50ms延迟\n } catch (error) {\n console.warn('updateTableColumns执行时出错:', error)\n // 确保在出错时也重置标志\n isUpdatingColumns.value = false\n }\n }\n\n const openColSetting = () => {\n // 直接打开列设置,不重新初始化以避免递归更新\n colRef.value.openColSetting()\n }\n\n const closeColSetting = () => {\n // 关闭列设置\n colRef.value.closeColSetting()\n }\n\n // 定义 emit 事件\n const emit = defineEmits([\"search\", \"reset\", \"dragSort\", \"handleOperateBtnsClick\"])\n\n const _search = () => {\n search()\n emit('search')\n }\n\n const _reset = () => {\n reset()\n emit('reset')\n }\n\n // 处理操作按钮点击事件\n const handleOperateBtnsClick = (btnName: string, row: any, btn: OperationBtnProps, index: number) => {\n emit('handleOperateBtnsClick', btnName, row, btn, index)\n }\n\n // 拖拽排序 // ! 列表数据需要有id\n const dragSort = () => {\n // const tbody = document.querySelector(`#${uuid.value} tbody`) as HTMLElement\n // Sortable.create(tbody, {\n // handle: '.move',\n // animation: 300,\n // onEnd({ newIndex, oldIndex }) {\n // const [removedItem] = processTableData.value.splice(oldIndex!, 1)\n // processTableData.value.splice(newIndex!, 0, removedItem)\n // console.log('newIndex', newIndex, 'oldIndex', oldIndex)\n // emit('dragSort', { newIndex, oldIndex })\n // }\n // })\n }\n\n const refreshTable = () => {\n getTableList()\n }\n\n const setSearchFormShow = (show: boolean) => {\n isShowSearch.value = show\n }\n\n // 获取当前列配置\n const getColumns = () => {\n return tableColumns\n }\n\n // 获取当前列设置配置\n const getColSetting = () => {\n return colSetting.value\n }\n\n // 暴露给父组件的参数和方法 (外部需要什么,都可以从这里暴露出去)\n defineExpose({\n element: tableRef,\n tableData: processTableData,\n radio,\n pageable,\n searchParam,\n searchInitParam,\n getTableList,\n search,\n reset,\n handleSizeChange,\n handleCurrentChange,\n clearSelection,\n enumMap,\n isSelected,\n selectedList,\n selectedListIds,\n refreshTable,\n setSearchFormShow,\n getColumns,\n getColSetting,\n openColSetting,\n closeColSetting\n })\n</script>\n"],"names":["props","__props","componentInstance","getCurrentInstance","znygStore","useLocalStorage","dictMap","bodyHeight","ref","useResizeObserver","document","body","entries","entry","height","contentRect","value","tableHeight","computed","ret","isShowSearch","pagination","heightOffset","minHeightValue","minHeight","parseInt","toString","tableRef","uuid","generateUUID","SPECIAL_COLUMN_CONFIG","FRONT_COLUMNS","BACK_COLUMNS","EXCLUDE_FROM_SETTING","types","fixed","columnTypes","isFrontSpecialColumn","type","includes","isBackSpecialColumn","shouldExcludeFromSetting","column","prop","searchFormShow","showToolButton","key","Array","isArray","toolButton","radio","selectionChange","selectedList","selectedListIds","isSelected","useSelection","rowKey","scrollToTop","__name","tableEl","$el","scrollWrap","querySelector","scrollTop","resetScrollPagination","hasMoreData","isScrollLoading","scrollPaginationDisabled","tableData","pageable","searchParam","searchInitParam","getTableList","originalGetTableList","search","reset","handleSizeChange","handleCurrentChange","loading","useTable","requestApi","initParam","enableScrollPagination","dataCallback","requestError","pageSize","async","handleScrollPagination","total","totalPages","Math","ceil","pageNum","nextPage","nextPageParams","currPage","params","result","processedResult","list","length","push","limit","console","log","error","setTimeout","handleScroll","event","scrollHeight","clientHeight","scrollPaginationThreshold","clearSelection","onMounted","requestAuto","data","removeEventListener","addEventListener","passive","onUnmounted","processTableData","warn","slicedData","toRaw","slice","reactive","watch","deep","nextTick","tableColumns","columns","flatColumns","flatColumnsFunc","enumMap","Map","setEnumMap","enum","enumValue","dictCode","set","has","get","unref","provide","flatArr","forEach","col","_children","isShow","isShowInView","isFilterEnum","filter","item","searchColumns","el","render","sort","a","b","order","index","handleProp","defaultValue","colRef","colSetting","isUpdatingColumns","initColSetting","updateTableColumns","newColSetting","isUnmounted","hasNewColSetting","clonedColSetting","JSON","parse","stringify","colMap","currentColumns","reorderedColumns","processedProps","Set","add","originalCol","updatedCol","sortable","openColSetting","closeColSetting","emit","__emit","_search","_reset","handleOperateBtnsClick","btnName","row","btn","refreshTable","__expose","element","setSearchFormShow","show","getColumns","getColSetting"],"mappings":"2/EAwKE,MAAMA,EAAQC,EA2BRC,EAAoBC,EAAAA,qBAEpBC,EAAYC,EAAAA,gBAAgB,OAAQ,CAAEC,QAAS,KAE/CC,EAAaC,MAAI,GACLC,EAAAA,kBAAAC,SAASC,MAAOC,IAC1B,MAAAC,EAAQD,EAAQ,IAChBE,OAAEA,GAAWD,EAAME,YACzBR,EAAWS,MAAQF,CAAA,IAGf,MAAAG,EAAcC,EAAAA,UAAS,KAC3B,GAAIlB,EAAMc,OACR,OAAOd,EAAMc,OAEf,MAAMK,EAAMZ,EAAWS,MAAQ,KAAOI,EAAaJ,MAAQ,IAAM,KAAOhB,EAAMqB,WAAa,IAAM,GAAKrB,EAAMsB,aAKtGC,EAA4C,iBAApBvB,EAAMwB,UAAyBxB,EAAMwB,UAAYC,SAASzB,EAAMwB,UAAUE,YACjG,OAAAP,EAAMI,EAAiBJ,EAAMI,CAAA,IAIhCI,EAAWnB,EAAAA,MAGXoB,EAAOpB,EAAAA,IAAI,MAAQqB,EAAAA,gBAanBC,EAAwB;;AAE5BC,cAAe,CAAC,YAAa,QAAS,QAAS,SAAU;;AAEzDC,aAAc,CAAC;;AAEfC,qBAAsB,CACpBjC,MAAO,CAAC;;AACRkC,MAAO;;AACPC,OAAO,IAKLC,EAA2B,IAAIN,EAAsBC,iBAAkBD,EAAsBE,cAG7FK,KAAwBC,GACrBA,GAAQR,EAAsBC,cAAcQ,SAASD,IADjC,wBAKvBE,KAAuBF,GACpBA,GAAQR,EAAsBE,aAAaO,SAASD,IADjC,uBAKtBG,KAA4BC,IAChC,MAAMJ,KAAEA,EAAAK,KAAMA,EAAMR,MAAAA,GAAUO,EAG9B,SAAIJ,IAAQF,EAAYG,SAASD,SAG7BK,IAAQb,EAAsBG,qBAAqBjC,MAAMuC,SAASI,QAGlEb,EAAsBG,qBAAqBE,QAASA,GAEjD,GAZwB,4BAgB3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KZlE,GACCF,QAAAkB,KAAK,YAAahB,EAAK,CAC/B,QAEA4D,GAAkBrJ,OAAQ,CAAA,MAxB1BuF,QAAQkB,KAAK,aAwBa,GAE3B,UACIhB,GACCF,QAAAkB,KAAK,2BAA4BhB,GAEzC4D,GAAkBrJ,OAAQ,CAAA,MA9I1BuF,QAAQkB,KAAK,cA8Ia,GAhKH,sBAoKrB+D,GAAuB9H,GAAA,KAE3ByG,GAAOnJ,MAAMwK,gBAAe,GAFP,kBAKjBC,GAAwB/H,GAAA,KAE5ByG,GAAOnJ,MAAMyK,iBAAgB,GAFP,mBAMlBC,GAAOC,EAEPC,GAAgBlI,GAAA,KACbgB,IACPgH,GAAK,SAAQ,GAFC,WAKVG,GAAenI,GAAA,KACbiB,IACN+G,GAAK,QAAO,GAFC,UAMTI,GAAyBpI,GAAA,CAACqI,EAAiBC,EAAUC,EAAwBjC,KACjF0B,GAAK,yBAA0BK,EAASC,EAAKC,EAAKjC,EAAK,GAD1B,0BAmBzBkC,GAAqBxI,GAAA,KACZc,IAAA,GADM,uBAmBR2H,EAAA,CACXC,QAASzK,EACTyC,UAAWoD,GACXtE,QACAmB,WACAC,cACAC,kBACAC,gBACAE,SACAC,QACAC,mBACAC,uBACAmC,kBACAqB,WACA/E,aACAF,eACAC,kBACA6I,gBACAG,qBAjCyBC,IACzBlL,EAAaJ,MAAQsL,CAAA,GADG,qBAkCxBC,WA7BuB7I,GAAA,IAChBuE,IADU,cA8BjBuE,cAzB0B9I,GAAA,IACnB0G,GAAWpJ,OADE,iBA0BpBwK,kBACAC;;;;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.vue2.js","sources":["../../../../../../packages/components/znTable/src/index.vue"],"sourcesContent":["<!-- 📚📚📚 Pro-Table 文档: https://juejin.cn/post/7166068828202336263 -->\n\n<template>\n <div class=\"table-box\">\n <!-- 查询表单 -->\n <SearchForm v-show=\"isShowSearch\" :search=\"_search\" :reset=\"_reset\" :columns=\"searchColumns\" :search-param=\"searchParam\" :search-col=\"searchCol\" />\n\n <!-- 表格主体 -->\n <div :class=\"[onlyTable ? 'only-table' : 'card table-main']\">\n <!-- 表格头部 操作按钮 -->\n <div class=\"table-header\">\n <div class=\"header-button-lf\">\n <slot name=\"tableHeader\" :selected-list=\"selectedList\" :selected-list-ids=\"selectedListIds\" :is-selected=\"isSelected\"></slot>\n </div>\n <div v-if=\"toolButton\" class=\"header-button-ri\">\n <slot name=\"toolButton\">\n <el-button v-if=\"showToolButton('refresh')\" :icon=\"Refresh\" circle @click=\"getTableList\" />\n <el-button v-if=\"showToolButton('setting') && columns.length\" :icon=\"Operation\" circle @click=\"openColSetting\" />\n <el-button v-if=\"showToolButton('search') && searchColumns?.length\" :icon=\"Search\" circle @click=\"isShowSearch = !isShowSearch\" />\n </slot>\n </div>\n </div>\n <!-- 表格主体 -->\n <el-table\n ref=\"tableRef\"\n v-bind=\"$attrs\"\n :data=\"processTableData\"\n :border=\"border\"\n :id=\"uuid\"\n :row-key=\"rowKey\"\n :height=\"tableHeight\"\n v-loading=\"loading\"\n @selection-change=\"selectionChange\"\n @scroll.enter=\"handleScroll\">\n <!-- 默认插槽 -->\n <slot></slot>\n <template v-for=\"item in tableColumns\" :key=\"item\">\n <!-- selection || radio || index || expand || sort -->\n <el-table-column\n v-if=\"item.type && columnTypes.includes(item.type)\"\n v-bind=\"item\"\n :selectable=\"(row: any) => (row.selectable != null && row.selectable != undefined ? row.selectable : true)\"\n :align=\"item.align ?? 'center'\"\n :reserve-selection=\"item.type == 'selection'\">\n <template #default=\"scope\">\n <!-- expand -->\n <template v-if=\"item.type == 'expand'\">\n <component :is=\"item.render\" v-bind=\"scope\" v-if=\"item.render\" />\n <slot v-else :name=\"item.type\" v-bind=\"scope\"></slot>\n </template>\n <!-- radio -->\n <el-radio v-if=\"item.type == 'radio'\" v-model=\"radio\" :label=\"scope.row[rowKey]\">\n <i></i>\n </el-radio>\n <!-- sort -->\n <el-tag v-if=\"item.type == 'sort'\" class=\"move\">\n <el-icon><DCaret /></el-icon>\n </el-tag>\n <!-- operationBtns -->\n <OperationBtns v-if=\"item.type == 'operationBtns'\" v-bind=\"item.props\" :row=\"scope.row\" :index=\"scope.$index\" @btn-click=\"handleOperateBtnsClick\" />\n </template>\n </el-table-column>\n <!-- other -->\n <TableColumn\n v-if=\"!item.type && item.prop && item.isShow && (!unref(isView) || (unref(isView) && item.isShowInView))\"\n :column=\"item\"\n :is-view=\"isView\">\n <template v-for=\"slot in Object.keys($slots)\" #[slot]=\"scope\">\n <slot :name=\"slot\" v-bind=\"scope\"></slot>\n </template>\n </TableColumn>\n </template>\n <!-- 插入表格最后一行之后的插槽 -->\n <template #append>\n <slot name=\"append\"></slot>\n <!-- 滚动翻页加载状态 -->\n <div\n v-if=\"props.enableScrollPagination && (isScrollLoading || !hasMoreData)\"\n style=\"display: flex; align-items: center; justify-content: center; padding: 20px 0; color: #909399; font-size: 14px\">\n <div v-if=\"isScrollLoading\" style=\"display: flex; align-items: center; gap: 8px\">\n <el-icon class=\"is-loading\"><Loading /></el-icon>\n <span>正在加载更多数据...</span>\n </div>\n <div v-else-if=\"!hasMoreData\" style=\"color: #909399\">\n <span>没有更多数据了</span>\n </div>\n </div>\n </template>\n <!-- 无数据 -->\n <template #empty>\n <div class=\"table-empty\">\n <slot name=\"empty\">\n <img src=\"./assets/notData.png\" alt=\"notData\" />\n <div>暂无数据</div>\n </slot>\n </div>\n </template>\n </el-table>\n <!-- 分页组件 -->\n <slot name=\"pagination\">\n <Pagination\n v-if=\"pagination && !enableScrollPagination\"\n :pageable=\"pageable\"\n :handle-size-change=\"handleSizeChange\"\n :handle-current-change=\"handleCurrentChange\"\n :page-size-options=\"pageSizeOptions\" />\n </slot>\n </div>\n <!-- 列设置 -->\n <ColSetting v-if=\"toolButton\" ref=\"colRef\" :col-setting=\"colSetting\" @update-columns=\"updateTableColumns\">\n <!-- 列设置头部插槽 -->\n <template #colSettingHeader>\n <slot name=\"colSettingHeader\"></slot>\n </template>\n </ColSetting>\n </div>\n</template>\n\n<script setup lang=\"ts\" name=\"ZnTable\">\n import { computed, onMounted, provide, reactive, ref, toRaw, unref, watch, nextTick, getCurrentInstance, onUnmounted } from 'vue'\n\n import ColSetting from './components/ColSetting.vue'\n import Pagination from './components/Pagination.vue'\n import TableColumn from './components/TableColumn.vue'\n import SearchForm from './components/SearchForm/index.vue'\n import OperationBtns from './components/OperationBtns/index.vue'\n\n import { BreakPoint } from './components/Grid/interface'\n import { ColumnProps, TypeProps, OperationBtnProps } from './interface'\n import { useSelection } from './hooks/useSelection'\n import { useTable } from './hooks/useTable'\n import { generateUUID, handleProp } from './utils'\n import { Operation, Refresh, Search, DCaret, Loading } from '@element-plus/icons-vue'\n import { ElTable } from 'element-plus'\n // import Sortable from 'sortablejs'\n import { useResizeObserver, useLocalStorage } from '@vueuse/core'\n defineOptions({\n name: 'ZnTable'\n })\n\n export interface ZnTableProps {\n columns: ColumnProps[] // 列配置项 ==> 必传\n data?: any[] // 静态 table data 数据,若存在则不会使用 requestApi 返回的 data ==> 非必传\n requestApi?: (params: any) => Promise<any> // 请求表格数据的 api ==> 非必传\n requestAuto?: boolean // 是否自动执行请求 api ==> 非必传(默认为true)\n requestError?: (params: any) => void // 表格 api 请求错误监听 ==> 非必传\n dataCallback?: (data: any) => any // 返回数据的回调函数,可以对数据进行处理 ==> 非必传\n title?: string // 表格标题 ==> 非必传\n pagination?: boolean // 是否需要分页组件 ==> 非必传(默认为true)\n pageSizeOptions?: number[] // 分页每页条数选项 ==> 非必传(默认为[10, 25, 50, 100])\n pageSize?: number // 默认每页显示条数 ==> 非必传(默认为15)\n initParam?: any // 初始化请求参数 ==> 非必传(默认为{})\n border?: boolean // 是否带有纵向边框 ==> 非必传(默认为true)\n toolButton?: ('refresh' | 'setting' | 'search')[] | boolean // 是否显示表格功能按钮 ==> 非必传(默认为true)\n rowKey?: string // 行数据的 Key,用来优化 Table 的渲染,当表格数据多选时,所指定的 id ==> 非必传(默认为 id)\n searchCol?: number | Record<BreakPoint, number> // 表格搜索项 每列占比配置 ==> 非必传 { xs: 1, sm: 2, md: 2, lg: 3, xl: 4 }\n height?: string | number // 表格高度,如果传了,则直接使用这个高度 未传则自动计算\n heightOffset?: number // 如果没传height,自动计算时,去除的高度\n minHeight?: string | number // 表格最小高度 ==> 非必传(默认为200)\n // hiddenTableHeader?: boolean // 隐藏表格头部\n onlyTable?: boolean // 只展示el-table部分\n isView?: boolean // 是否查看,默认为否\n searchFormShow?: boolean // 是否显示筛选行,默认为true\n enableScrollPagination?: boolean // 是否启用滚动翻页(无限滚动)==> 非必传(默认为false)\n scrollPaginationThreshold?: number // 滚动翻页触发阈值(距离底部多少像素时触发)==> 非必传(默认为100)\n }\n\n // 接受父组件参数,配置默认值\n const props = defineProps({\n columns: { type: Array, required: true, default: () => [] },\n data: { type: Array, required: false },\n requestApi: { type: Function, required: false },\n requestAuto: { type: Boolean, required: false, default: true },\n requestError: { type: Function, required: false },\n dataCallback: { type: Function, required: false },\n title: { type: String, required: false },\n pagination: { type: Boolean, required: false, default: true },\n pageSizeOptions: { type: Array, required: false, default: () => [10, 25, 50, 100] },\n pageSize: { type: Number, required: false, default: 15 },\n initParam: { required: false, default: {} },\n border: { type: Boolean, required: false, default: true },\n toolButton: { type: [Array, Boolean], required: false, default: true },\n rowKey: { type: String, required: false, default: 'id' },\n searchCol: { type: [Number, Object], required: false, default: () => ({ xs: 1, sm: 2, md: 2, lg: 3, xl: 4 }) },\n height: { type: [String, Number], required: false },\n heightOffset: { type: Number, required: false, default: 0 },\n minHeight: { type: [String, Number], required: false, default: 200 },\n onlyTable: { type: Boolean, required: false, default: false },\n isView: { type: Boolean, required: false, default: false },\n searchFormShow: { type: Boolean, required: false, default: true },\n enableScrollPagination: { type: Boolean, required: false, default: false },\n scrollPaginationThreshold: { type: Number, required: false, default: 100 }\n})\n\n // 在 setup 顶层获取组件实例,确保能正确获取\n const componentInstance = getCurrentInstance()\n\n const znygStore = useLocalStorage('znyg', { dictMap: {} })\n\n const bodyHeight = ref(0)\n useResizeObserver(document.body, (entries) => {\n const entry = entries[0]\n const { height } = entry.contentRect\n bodyHeight.value = height\n })\n // 计算表格高度\n const tableHeight = computed(() => {\n if (props.height) {\n // 如果 height 设置为 'auto',需要特殊处理空数据状态\n if (props.height === 'auto') {\n // 当没有数据时,确保有足够的高度显示空数据提示\n const hasData = processTableData.value && processTableData.value.length > 0\n if (!hasData) {\n // 没有数据时,使用最小高度确保空数据提示能正常显示\n const minHeightValue = typeof props.minHeight === 'number' ? props.minHeight : parseInt(props.minHeight.toString())\n return Math.max(minHeightValue, 200) // 至少200px高度\n }\n }\n return props.height\n }\n const ret = bodyHeight.value - 100 - (isShowSearch.value ? 120 : 40) - (props.pagination ? 150 : 0) - props.heightOffset\n // console.log(bodyHeight.value + '-' + 100 + '-' + (isShowSearch.value ? 120 : 0) + '-' + (props.pagination ? 70 : 0))\n // console.log('bodyHeight:' + bodyHeight.value, 'isShowSearch:' + (isShowSearch.value ? 80 : 0), 'ret:' + ret)\n\n // 确保返回的高度不小于最小高度\n const minHeightValue = typeof props.minHeight === 'number' ? props.minHeight : parseInt(props.minHeight.toString())\n return ret > minHeightValue ? ret : minHeightValue\n })\n\n // table 实例\n const tableRef = ref<InstanceType<typeof ElTable>>()\n\n // 生成组件唯一id\n const uuid = ref('id-' + generateUUID())\n\n /**\n * 特殊列配置管理\n *\n * 如何添加新的特殊列类型:\n * 1. 在 interface/index.ts 中的 TypeProps 类型中添加新的列类型\n * 2. 根据列的显示位置,将新类型添加到 FRONT_COLUMNS 或 BACK_COLUMNS 数组中\n * 3. 如果需要从列设置中排除特定的 prop,添加到 EXCLUDE_FROM_SETTING.props 中\n * 4. 在模板中添加对应的渲染逻辑\n *\n * 就这样!不需要在其他地方修改代码了。\n */\n const SPECIAL_COLUMN_CONFIG = {\n // 前置特殊列(显示在表格最前面)\n FRONT_COLUMNS: ['selection', 'radio', 'index', 'expand', 'sort'] as TypeProps[],\n // 后置特殊列(显示在表格最后面)\n BACK_COLUMNS: ['operationBtns'] as TypeProps[],\n // 需要从列设置中排除的列(除了特殊列类型,还可以包括特定的 prop)\n EXCLUDE_FROM_SETTING: {\n props: ['operation'], // 按 prop 排除\n types: [] as TypeProps[], // 按 type 排除(会自动包含所有特殊列类型)\n fixed: true // 排除固定列\n }\n }\n\n // 所有特殊列类型(合并前置和后置)\n const columnTypes: TypeProps[] = [...SPECIAL_COLUMN_CONFIG.FRONT_COLUMNS, ...SPECIAL_COLUMN_CONFIG.BACK_COLUMNS]\n\n // 判断是否为前置特殊列\n const isFrontSpecialColumn = (type?: TypeProps) => {\n return type && SPECIAL_COLUMN_CONFIG.FRONT_COLUMNS.includes(type)\n }\n\n // 判断是否为后置特殊列\n const isBackSpecialColumn = (type?: TypeProps) => {\n return type && SPECIAL_COLUMN_CONFIG.BACK_COLUMNS.includes(type)\n }\n\n // 判断是否应该从列设置中排除\n const shouldExcludeFromSetting = (column: ColumnProps) => {\n const { type, prop, fixed } = column\n\n // 排除所有特殊列类型\n if (type && columnTypes.includes(type)) return true\n\n // 排除指定的 prop\n if (prop && SPECIAL_COLUMN_CONFIG.EXCLUDE_FROM_SETTING.props.includes(prop)) return true\n\n // 排除固定列\n if (SPECIAL_COLUMN_CONFIG.EXCLUDE_FROM_SETTING.fixed && fixed) return true\n\n return false\n }\n\n // 是否显示搜索模块\n const isShowSearch = ref(props.searchFormShow)\n\n // 控制 ToolButton 显示\n const showToolButton = (key: 'refresh' | 'setting' | 'search') => {\n return Array.isArray(props.toolButton) ? props.toolButton.includes(key) : props.toolButton\n }\n\n // 单选值\n const radio = ref('')\n\n // 表格多选 Hooks\n const { selectionChange, selectedList, selectedListIds, isSelected } = useSelection(props.rowKey)\n // 滚动到顶部\n const scrollToTop = () => {\n const tableEl = tableRef.value?.$el\n if (tableEl) {\n const scrollWrap = tableEl.querySelector('.el-scrollbar__wrap')\n if (scrollWrap) {\n scrollWrap.scrollTop = 0\n }\n }\n }\n // 重置滚动翻页状态\n const resetScrollPagination = () => {\n hasMoreData.value = true\n isScrollLoading.value = false\n scrollPaginationDisabled.value = false\n }\n // 表格操作 Hooks\n const {\n tableData,\n pageable,\n searchParam,\n searchInitParam,\n getTableList: originalGetTableList,\n search,\n reset,\n handleSizeChange,\n handleCurrentChange,\n loading\n } = useTable(\n props.requestApi,\n props.initParam,\n props.pagination || props.enableScrollPagination,\n props.dataCallback,\n props.requestError,\n props.pageSize,\n scrollToTop,\n resetScrollPagination,\n props.enableScrollPagination\n )\n\n // 包装 getTableList,确保重置滚动翻页状态\n const getTableList = async () => {\n // 重置滚动翻页状态\n if (props.enableScrollPagination) {\n resetScrollPagination()\n }\n await originalGetTableList()\n }\n\n // 滚动翻页相关状态\n const isScrollLoading = ref(false) // 滚动翻页加载状态\n const hasMoreData = ref(true) // 是否还有更多数据\n const scrollPaginationDisabled = ref(false) // 是否禁用滚动翻页\n\n // 滚动翻页处理函数\n const handleScrollPagination = async () => {\n // 如果正在加载、没有更多数据、或已禁用滚动翻页,则直接返回\n if (isScrollLoading.value || !hasMoreData.value || scrollPaginationDisabled.value || !props.enableScrollPagination) {\n return\n }\n\n // 如果总数为0,说明还没有初始数据,不应该触发滚动翻页\n if (pageable.value.total === 0) {\n return\n }\n\n // 检查是否还有下一页数据\n const totalPages = Math.ceil(pageable.value.total / pageable.value.pageSize)\n if (pageable.value.pageNum >= totalPages) {\n hasMoreData.value = false\n return\n }\n\n try {\n isScrollLoading.value = true\n scrollPaginationDisabled.value = true // 防止重复触发\n\n // 获取下一页数据\n const nextPage = pageable.value.pageNum + 1\n const nextPageParams = {\n ...searchInitParam.value,\n ...searchParam.value,\n currPage: nextPage,\n pageSize: pageable.value.pageSize,\n params: {\n ...searchInitParam.value,\n ...searchParam.value\n }\n }\n if (props.requestApi) {\n const { result } = await props.requestApi(nextPageParams)\n const processedResult = props.dataCallback ? props.dataCallback(result) : result\n if (processedResult && processedResult.list && Array.isArray(processedResult.list) && processedResult.list.length > 0) {\n // 确保 tableData.value 是数组\n if (!Array.isArray(tableData.value)) {\n tableData.value = []\n }\n // 将新数据追加到现有数据中\n tableData.value.push(...processedResult.list)\n\n // 更新分页信息\n const { currPage, limit, total } = processedResult\n pageable.value.pageNum = currPage\n pageable.value.pageSize = limit\n pageable.value.total = total\n\n // 检查是否还有更多数据\n const totalPages = Math.ceil(total / limit)\n hasMoreData.value = currPage < totalPages\n } else {\n hasMoreData.value = false\n console.log('❌ 滚动翻页没有更多数据')\n }\n }\n } catch (error) {\n props.requestError && props.requestError(error)\n } finally {\n isScrollLoading.value = false\n // 延迟重新启用滚动翻页,防止频繁触发\n setTimeout(() => {\n scrollPaginationDisabled.value = false\n }, 1000)\n }\n }\n\n // 滚动事件处理函数\n const handleScroll = (event: any) => {\n if (!props.enableScrollPagination || !props.requestApi) return\n\n // 如果正在加载或没有更多数据,直接返回\n if (isScrollLoading.value || !hasMoreData.value) return\n\n // 直接从表格元素获取滚动容器\n const tableEl = tableRef.value?.$el\n if (!tableEl) return\n\n // Element Plus 使用自定义滚动条,实际的滚动容器是 .el-scrollbar__wrap\n const scrollWrap = tableEl.querySelector('.el-scrollbar__wrap')\n if (!scrollWrap) return\n\n // 从滚动容器获取滚动信息\n const scrollTop = scrollWrap.scrollTop\n const scrollHeight = scrollWrap.scrollHeight\n const clientHeight = scrollWrap.clientHeight\n const threshold = props.scrollPaginationThreshold\n\n // 计算距离底部的距离\n const distanceToBottom = scrollHeight - scrollTop - clientHeight\n if (distanceToBottom <= threshold) {\n handleScrollPagination()\n }\n }\n\n // 清空选中数据列表\n const clearSelection = () => {\n if (!tableRef.value) return\n tableRef.value!.clearSelection()\n }\n // 初始化表格数据 && 拖拽排序\n onMounted(() => {\n // dragSort()\n props.requestAuto && getTableList()\n props.data && (pageable.value.total = props.data.length)\n\n // 如果启用滚动翻页,设置滚动监听\n if (props.enableScrollPagination) {\n // 延迟设置滚动监听,确保表格完全渲染\n setTimeout(() => {\n const tableEl = tableRef.value?.$el\n if (tableEl) {\n const scrollWrap = tableEl.querySelector('.el-scrollbar__wrap')\n if (scrollWrap) {\n // 移除可能存在的旧监听器\n scrollWrap.removeEventListener('scroll', handleScroll)\n // 添加新的滚动监听器\n scrollWrap.addEventListener('scroll', handleScroll, { passive: true })\n }\n }\n }, 500)\n }\n })\n\n // 组件卸载时清理事件监听\n onUnmounted(() => {\n if (props.enableScrollPagination) {\n const tableEl = tableRef.value?.$el\n if (tableEl) {\n const scrollWrap = tableEl.querySelector('.el-scrollbar__wrap')\n if (scrollWrap) {\n scrollWrap.removeEventListener('scroll', handleScroll)\n }\n }\n }\n })\n\n // 处理表格数据\n const processTableData = computed(() => {\n // 确保 tableData.value 是数组\n if (!Array.isArray(tableData.value)) {\n tableData.value = []\n }\n\n // 如果使用静态数据\n if (props.data) {\n // 确保 props.data 是数组\n if (!Array.isArray(props.data)) {\n console.warn('props.data 不是数组:', props.data)\n return []\n }\n\n if (!props.pagination) {\n return props.data\n }\n\n // 分页处理\n const rawData = toRaw(props.data)\n const slicedData = rawData.slice((pageable.value.pageNum - 1) * pageable.value.pageSize, pageable.value.pageSize * pageable.value.pageNum)\n return reactive(slicedData)\n }\n return tableData.value\n })\n\n // 监听页面 initParam 改化,重新获取表格数据\n watch(\n () => props.initParam,\n () => {\n getTableList()\n },\n { deep: true }\n )\n\n // 监听表格数据变化,检查是否需要重新启用滚动翻页\n watch(\n () => tableData.value,\n () => {\n if (props.enableScrollPagination && hasMoreData.value) {\n // 数据更新后,延迟检查滚动状态\n nextTick(() => {\n setTimeout(() => {\n const tableEl = tableRef.value?.$el\n if (tableEl) {\n const scrollWrap = tableEl.querySelector('.el-scrollbar__wrap')\n if (scrollWrap) {\n // 手动触发一次滚动检查\n handleScroll({})\n }\n }\n }, 100)\n })\n }\n },\n { deep: true }\n )\n\n // 接收 columns 并设置为响应式\n let tableColumns = reactive<ColumnProps[]>(props.columns)\n\n // 扁平化 columns\n const flatColumns = computed(() => flatColumnsFunc(tableColumns))\n\n // 定义 enumMap 存储 enum 值(避免异步请求无法格式化单元格内容 || 无法填充搜索下拉选择)\n const enumMap = ref(new Map<string, { [key: string]: any }[]>())\n const setEnumMap = async ({ prop, enum: enumValue, dictCode }: ColumnProps) => {\n if (dictCode) {\n // let znygStore = globalThis.localStorage.getItem('znyg')\n // if (znygStore) znygStore = JSON.parse(znygStore)\n if (znygStore && znygStore.value?.dictMap) {\n enumMap.value.set(prop!, znygStore.value.dictMap[dictCode?.toString()] ?? [])\n return\n }\n }\n if (!enumValue) return\n\n // 如果当前 enumMap 存在相同的值 return\n if (enumMap.value.has(prop!) && (typeof enumValue === 'function' || enumMap.value.get(prop!) === enumValue)) return\n\n // 当前 enum 为静态数据,则直接存储到 enumMap\n if (typeof enumValue !== 'function') return enumMap.value.set(prop!, unref(enumValue!))\n\n // 为了防止接口执行慢,而存储慢,导致重复请求,所以预先存储为[],接口返回后再二次存储\n enumMap.value.set(prop!, [])\n\n // 当前 enum 为后台数据需要请求数据,则调用该请求接口,并存储到 enumMap\n // const { data } = await enumValue()\n // 如果当前 enum 为后台数据需要请求数据,则调用该请求接口,并存储到 enumMap\n let data = await enumValue()\n // 适配 enum 接口返回 data 以及自定义函数返回数组\n data = data?.result || data\n enumMap.value.set(prop!, data)\n }\n // 注入 enumMap\n provide('enumMap', enumMap)\n\n // 扁平化 columns 的方法\n const flatColumnsFunc = (columns: ColumnProps[], flatArr: ColumnProps[] = []) => {\n columns.forEach(async (col) => {\n if (col._children?.length) flatArr.push(...flatColumnsFunc(col._children))\n flatArr.push(col)\n\n // column 添加默认 isShow && isFilterEnum 属性值\n col.isShow = col.isShow ?? true\n col.isShowInView = col.isShowInView ?? true\n col.isFilterEnum = col.isFilterEnum ?? true\n\n // 设置 enumMap\n await setEnumMap(col)\n })\n return flatArr.filter((item) => !item._children?.length)\n }\n\n // 过滤需要搜索的配置项 && 排序\n const searchColumns = computed(() => {\n return flatColumns.value?.filter((item) => item.search?.el || item.search?.render).sort((a, b) => a.search!.order! - b.search!.order!)\n })\n\n // 设置 搜索表单默认排序 && 搜索表单项的默认值\n searchColumns.value?.forEach((column, index) => {\n column.search!.order = column.search?.order ?? index + 2\n const key = column.search?.key ?? handleProp(column.prop!)\n const defaultValue = column.search?.defaultValue\n if (defaultValue !== undefined && defaultValue !== null) {\n searchInitParam.value[key] = defaultValue\n searchParam.value[key] = defaultValue\n }\n })\n\n // 列设置\n const colRef = ref()\n const colSetting = ref<ColumnProps[]>([])\n // 添加更新标志,避免循环更新\n const isUpdatingColumns = ref(false)\n\n // const colSetting = computed(() => {\n // return tableColumns.filter((item) => !shouldExcludeFromSetting(item))\n // })\n\n // 初始化列设置数据\n const initColSetting = () => {\n colSetting.value = tableColumns.filter((item) => !shouldExcludeFromSetting(item))\n }\n\n // 初始化时设置列配置\n initColSetting()\n\n // 监听 tableColumns 变化,同步更新 colSetting\n watch(\n () => tableColumns,\n () => {\n // 如果正在更新中,跳过同步\n if (isUpdatingColumns.value) {\n return\n }\n\n console.log('检测到 tableColumns 变化,同步更新 colSetting')\n initColSetting()\n },\n { deep: true }\n )\n\n // 手动更新表格列顺序的函数\n const updateTableColumns = (newColSetting: ColumnProps[]) => {\n // 如果正在更新中,避免循环调用\n if (isUpdatingColumns.value) {\n return\n }\n\n // console.log('updateTableColumns调用:', {\n // hasNewColSetting: !!newColSetting,\n // newColSettingLength: Array.isArray(newColSetting) ? newColSetting.length : 'not array',\n // currentTableColumnsLength: tableColumns.length\n // })\n\n // console.log('组件实例状态:', {\n // hasInstance: !!componentInstance,\n // isUnmounted: componentInstance?.isUnmounted\n // })\n\n if (!componentInstance || componentInstance.isUnmounted) {\n console.warn('组件已销毁,跳过列更新')\n return\n }\n\n try {\n // 设置更新标志\n isUpdatingColumns.value = true\n\n // 安全检查\n if (!newColSetting || !Array.isArray(newColSetting) || newColSetting.length === 0) {\n console.warn('updateTableColumns: 无效的列设置数据', {\n hasNewColSetting: !!newColSetting,\n isArray: Array.isArray(newColSetting),\n length: newColSetting?.length\n })\n return\n }\n\n // console.log('开始处理列设置数据')\n\n // 深拷贝输入数据,避免响应式问题\n let clonedColSetting: ColumnProps[]\n try {\n clonedColSetting = JSON.parse(JSON.stringify(newColSetting))\n // console.log('深拷贝成功')\n } catch (error) {\n console.warn('深拷贝列设置数据失败,使用浅拷贝')\n clonedColSetting = [...newColSetting]\n }\n\n // 创建一个映射,用于快速查找列配置\n const colMap = new Map()\n const currentColumns = [...tableColumns] // 创建当前列的副本\n\n currentColumns.forEach((col) => {\n if (col && col.prop) {\n colMap.set(col.prop, col)\n }\n })\n\n // console.log('创建列映射完成:', {\n // colMapSize: colMap.size,\n // currentColumnsLength: currentColumns.length\n // })\n\n // 根据新的列设置顺序重新排列列\n const reorderedColumns: ColumnProps[] = []\n const processedProps = new Set()\n\n // 首先添加前置特殊列(selection, radio, index 等)\n currentColumns.forEach((col) => {\n if (col && (isFrontSpecialColumn(col.type) || col.fixed === 'left')) {\n // console.log('添加前置特殊列:', { type: col.type, prop: col.prop, label: col.label })\n reorderedColumns.push(col)\n if (col.prop) {\n processedProps.add(col.prop)\n }\n }\n })\n\n // console.log('前置特殊列添加完成,当前列数:', reorderedColumns.length)\n\n // 然后添加按新顺序排列的普通列\n clonedColSetting.forEach((colSetting) => {\n if (colSetting && colSetting.prop && colMap.has(colSetting.prop) && !processedProps.has(colSetting.prop)) {\n const originalCol = colMap.get(colSetting.prop)\n if (originalCol) {\n // console.log('添加普通列:', { prop: colSetting.prop, label: colSetting.label, isShow: colSetting.isShow })\n try {\n // 创建列的副本并更新属性\n const updatedCol = { ...originalCol }\n updatedCol.isShow = colSetting.isShow\n updatedCol.sortable = colSetting.sortable\n reorderedColumns.push(updatedCol)\n processedProps.add(colSetting.prop)\n } catch (error) {\n console.warn('更新列配置时出错:', error)\n // 如果更新失败,使用原始列\n reorderedColumns.push(originalCol)\n processedProps.add(colSetting.prop)\n }\n }\n }\n })\n\n // console.log('普通列添加完成,当前列数:', reorderedColumns.length)\n\n // 最后添加后置特殊列(如操作列、operationBtns、右侧固定列等)\n currentColumns.forEach((col) => {\n if (\n col &&\n (!col.prop || !processedProps.has(col.prop)) &&\n (isBackSpecialColumn(col.type) || (!columnTypes.includes(col.type!) && col.fixed !== 'left'))\n ) {\n // console.log('添加后置特殊列:', { type: col.type, prop: col.prop, label: col.label })\n reorderedColumns.push(col)\n }\n })\n\n // console.log('列重排完成:', {\n // reorderedColumnsLength: reorderedColumns.length,\n // processedPropsSize: processedProps.size\n // })\n\n // 使用setTimeout而不是nextTick,确保在下一个事件循环中更新\n setTimeout(() => {\n // console.log('开始更新表格列,检查组件状态:', {\n // hasInstance: !!componentInstance,\n // isUnmounted: componentInstance?.isUnmounted\n // })\n\n if (!componentInstance || componentInstance.isUnmounted) {\n console.warn('延迟更新时组件已销毁')\n return\n }\n\n try {\n // console.log('执行表格列更新')\n // 简单直接的数组替换方法\n tableColumns.length = 0\n reorderedColumns.forEach((col) => {\n if (col) {\n tableColumns.push(col as any)\n }\n })\n\n // 同步更新 colSetting,但不触发新的更新\n colSetting.value = clonedColSetting\n\n // console.log('表格列更新完成:', {\n // newLength: tableColumns.length\n // })\n } catch (error) {\n console.warn('更新表格列时出错:', error)\n } finally {\n // 重置更新标志\n isUpdatingColumns.value = false\n }\n }, 50) // 50ms延迟\n } catch (error) {\n console.warn('updateTableColumns执行时出错:', error)\n // 确保在出错时也重置标志\n isUpdatingColumns.value = false\n }\n }\n\n const openColSetting = () => {\n // 直接打开列设置,不重新初始化以避免递归更新\n colRef.value.openColSetting()\n }\n\n const closeColSetting = () => {\n // 关闭列设置\n colRef.value.closeColSetting()\n }\n\n // 定义 emit 事件\n const emit = defineEmits([\"search\", \"reset\", \"dragSort\", \"handleOperateBtnsClick\"])\n\n const _search = () => {\n search()\n emit('search')\n }\n\n const _reset = () => {\n reset()\n emit('reset')\n }\n\n // 处理操作按钮点击事件\n const handleOperateBtnsClick = (btnName: string, row: any, btn: OperationBtnProps, index: number) => {\n emit('handleOperateBtnsClick', btnName, row, btn, index)\n }\n\n // 拖拽排序 // ! 列表数据需要有id\n const dragSort = () => {\n // const tbody = document.querySelector(`#${uuid.value} tbody`) as HTMLElement\n // Sortable.create(tbody, {\n // handle: '.move',\n // animation: 300,\n // onEnd({ newIndex, oldIndex }) {\n // const [removedItem] = processTableData.value.splice(oldIndex!, 1)\n // processTableData.value.splice(newIndex!, 0, removedItem)\n // console.log('newIndex', newIndex, 'oldIndex', oldIndex)\n // emit('dragSort', { newIndex, oldIndex })\n // }\n // })\n }\n\n const refreshTable = () => {\n getTableList()\n }\n\n const setSearchFormShow = (show: boolean) => {\n isShowSearch.value = show\n }\n\n // 获取当前列配置\n const getColumns = () => {\n return tableColumns\n }\n\n // 获取当前列设置配置\n const getColSetting = () => {\n return colSetting.value\n }\n\n // 暴露给父组件的参数和方法 (外部需要什么,都可以从这里暴露出去)\n defineExpose({\n element: tableRef,\n tableData: processTableData,\n radio,\n pageable,\n searchParam,\n searchInitParam,\n getTableList,\n search,\n reset,\n handleSizeChange,\n handleCurrentChange,\n clearSelection,\n enumMap,\n isSelected,\n selectedList,\n selectedListIds,\n refreshTable,\n setSearchFormShow,\n getColumns,\n getColSetting,\n openColSetting,\n closeColSetting\n })\n</script>\n"],"names":["props","__props","componentInstance","getCurrentInstance","znygStore","useLocalStorage","dictMap","bodyHeight","ref","useResizeObserver","document","body","entries","entry","height","contentRect","value","tableHeight","computed","processTableData","length","minHeightValue","minHeight","parseInt","toString","Math","max","ret","isShowSearch","pagination","heightOffset","tableRef","uuid","generateUUID","SPECIAL_COLUMN_CONFIG","FRONT_COLUMNS","BACK_COLUMNS","EXCLUDE_FROM_SETTING","types","fixed","columnTypes","isFrontSpecialColumn","type","includes","isBackSpecialColumn","shouldExcludeFromSetting","column","prop","searchFormShow","showToolButton","key","Array","isArray","toolButton","radio","selectionChange","selectedList","selectedListIds","isSelected","useSelection","rowKey","scrollToTop","__name","tableEl","$el","scrollWrap","querySelector","scrollTop","resetScrollPagination","hasMoreData","isScrollLoading","scrollPaginationDisabled","tableData","pageable","searchParam","searchInitParam","getTableList","originalGetTableList","search","reset","handleSizeChange","handleCurrentChange","loading","useTable","requestApi","initParam","enableScrollPagination","dataCallback","requestError","pageSize","async","handleScrollPagination","total","totalPages","ceil","pageNum","nextPage","nextPageParams","currPage","params","result","processedResult","list","push","limit","console","log","error","setTimeout","handleScroll","event","scrollHeight","clientHeight","scrollPaginationThreshold","clearSelection","onMounted","requestAuto","data","removeEventListener","addEventListener","passive","onUnmounted","warn","slicedData","toRaw","slice","reactive","watch","deep","nextTick","tableColumns","columns","flatColumns","flatColumnsFunc","enumMap","Map","setEnumMap","enum","enumValue","dictCode","set","has","get","unref","provide","flatArr","forEach","col","_children","isShow","isShowInView","isFilterEnum","filter","item","searchColumns","el","render","sort","a","b","order","index","handleProp","defaultValue","colRef","colSetting","isUpdatingColumns","initColSetting","updateTableColumns","newColSetting","isUnmounted","hasNewColSetting","clonedColSetting","JSON","parse","stringify","colMap","currentColumns","reorderedColumns","processedProps","Set","add","originalCol","updatedCol","sortable","openColSetting","closeColSetting","emit","__emit","_search","_reset","handleOperateBtnsClick","btnName","row","btn","refreshTable","__expose","element","setSearchFormShow","show","getColumns","getColSetting"],"mappings":"2/EAwKE,MAAMA,EAAQC,EA2BRC,EAAoBC,EAAAA,qBAEpBC,EAAYC,EAAAA,gBAAgB,OAAQ,CAAEC,QAAS,KAE/CC,EAAaC,MAAI,GACLC,EAAAA,kBAAAC,SAASC,MAAOC,IAC1B,MAAAC,EAAQD,EAAQ,IAChBE,OAAEA,GAAWD,EAAME,YACzBR,EAAWS,MAAQF,CAAA,IAGf,MAAAG,EAAcC,EAAAA,UAAS,KAC3B,GAAIlB,EAAMc,OAAQ,CAEZ,GAAiB,SAAjBd,EAAMc,OAAmB,CAG3B,KADgBK,GAAiBH,OAASG,GAAiBH,MAAMI,OAAS,GAC5D,CAENC,MAAAA,EAA4C,iBAApBrB,EAAMsB,UAAyBtB,EAAMsB,UAAYC,SAASvB,EAAMsB,UAAUE,YACjG,OAAAC,KAAKC,IAAIL,EAAgB,IAAG,CACrC,CAEF,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FP,mBAMlBC,GAAOC,EAEPC,GAAgB/H,GAAA,KACbgB,IACP6G,GAAK,SAAQ,GAFC,WAKVG,GAAehI,GAAA,KACbiB,IACN4G,GAAK,QAAO,GAFC,UAMTI,GAAyBjI,GAAA,CAACkI,EAAiBC,EAAUC,EAAwBjC,KACjF0B,GAAK,yBAA0BK,EAASC,EAAKC,EAAKjC,EAAK,GAD1B,0BAmBzBkC,GAAqBrI,GAAA,KACZc,IAAA,GADM,uBAmBRwH,EAAA,CACXC,QAAStK,EACTyC,UAAWrD,GACXmC,QACAmB,WACAC,cACAC,kBACAC,gBACAE,SACAC,QACAC,mBACAC,uBACAiC,kBACAoB,WACA5E,aACAF,eACAC,kBACA0I,gBACAG,qBAjCyBC,IACzB3K,EAAaZ,MAAQuL,CAAA,GADG,qBAkCxBC,WA7BuB1I,GAAA,IAChBoE,IADU,cA8BjBuE,cAzB0B3I,GAAA,IACnBuG,GAAWrJ,OADE,iBA0BpByK,kBACAC;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("vue"),t=require("element-plus");require("../../../functions/index.js");var l=require("../../../functions/modules/uitls.js"),a=Object.defineProperty,r=(e,t)=>a(e,"name",{value:t,configurable:!0});const d={key:0,class:"title sle"},u={class:"flex gap-10"},n={key:1,class:"el-tree-node__label"};var i=e.defineComponent({name:"ZnTreeFilter",__name:"index",props:{requestApi:{type:Function,required:!1},requestParams:{required:!1,default:r((()=>({})),"default")},data:{type:Array,required:!1},title:{type:String,required:!1},id:{type:String,required:!1,default:"id"},label:{type:String,required:!1,default:"label"},multiple:{type:Boolean,required:!1,default:!1},defaultValue:{required:!1},transformDataToTree:{type:Boolean,required:!1,default:!0},width:{type:String,required:!1,default:"460px"},height:{type:String,required:!1,default:"calc(100vh - 200px)"},defaultExpandAll:{type:Boolean,required:!1,default:!0},defaultExpandKeys:{type:Array,required:!1,default:r((()=>[]),"default")},expandOnClickNode:{type:Boolean,required:!1,default:!1},render:{type:Function,required:!1}},emits:["dataReady","change"],setup(a,{expose:i,emit:o}){const c=a,s={children:"children",label:c.label},p=e.ref(),f=e.ref([]),y=e.ref([]),h=o,m=e.ref(),k=r((()=>{c.multiple?m.value=Array.isArray(c.defaultValue)?c.defaultValue:[c.defaultValue]:m.value="string"==typeof c.defaultValue?c.defaultValue:""}),"setSelected"),v=r((async()=>{if(c.requestApi){const e=await c.requestApi(c.requestParams);let t=e.result.list??e.result;t.map(((e,t)=>{e.id||(e.id=`${e.treeLevel}-${t}`)})),c.transformDataToTree?f.value=l.default.treeListUtil(t):f.value=t,y.value=[...f.value],h("dataReady",t)}}),"getList");e.onBeforeMount((async()=>{await v(),!c.multiple&&c.defaultValue&&(
|
|
2
|
-
/* TEXT */)):e.createCommentVNode("v-if",!0),e.createElementVNode("div",u,[e.
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("vue"),t=require("element-plus");require("../../../functions/index.js");var l=require("../../../functions/modules/uitls.js"),a=Object.defineProperty,r=(e,t)=>a(e,"name",{value:t,configurable:!0});const d={key:0,class:"title sle"},u={class:"flex gap-10"},n={key:1,class:"el-tree-node__label"};var i=e.defineComponent({name:"ZnTreeFilter",__name:"index",props:{requestApi:{type:Function,required:!1},requestParams:{required:!1,default:r((()=>({})),"default")},data:{type:Array,required:!1},title:{type:String,required:!1},id:{type:String,required:!1,default:"id"},label:{type:String,required:!1,default:"label"},multiple:{type:Boolean,required:!1,default:!1},defaultValue:{required:!1},transformDataToTree:{type:Boolean,required:!1,default:!0},width:{type:String,required:!1,default:"460px"},height:{type:String,required:!1,default:"calc(100vh - 200px)"},defaultExpandAll:{type:Boolean,required:!1,default:!0},defaultExpandKeys:{type:Array,required:!1,default:r((()=>[]),"default")},expandOnClickNode:{type:Boolean,required:!1,default:!1},render:{type:Function,required:!1},showFilterText:{type:Boolean,required:!1,default:!0}},emits:["dataReady","change"],setup(a,{expose:i,emit:o}){const c=a,s={children:"children",label:c.label},p=e.ref(),f=e.ref([]),y=e.ref([]),h=o,m=e.ref(),k=r((()=>{c.multiple?m.value=Array.isArray(c.defaultValue)?c.defaultValue:[c.defaultValue]:m.value="string"==typeof c.defaultValue?c.defaultValue:""}),"setSelected"),v=r((async()=>{if(c.requestApi){const e=await c.requestApi(c.requestParams);let t=e.result.list??e.result;t.map(((e,t)=>{e.id||(e.id=`${e.treeLevel}-${t}`)})),c.transformDataToTree?f.value=l.default.treeListUtil(t):f.value=t,y.value=[...f.value],h("dataReady",t)}}),"getList");e.onBeforeMount((async()=>{await v(),!c.multiple&&c.defaultValue&&(B(c.defaultValue),await e.nextTick(),p.value?.$el.querySelector(".is-current").firstChild.click())})),e.watch((()=>c.requestParams),(e=>{e&&v()}),{deep:!0}),e.watch((()=>c.defaultValue),(()=>e.nextTick((()=>k()))),{deep:!0,immediate:!0}),e.watch((()=>c.data),(()=>{c.data?.length&&(f.value=c.data,y.value=[...c.data])}),{deep:!0,immediate:!0});const x=e.ref("");e.watch(x,(e=>{p.value.filter(e)}));const g=r(((e,t,l)=>{if(!e)return!0;let a=l.parent,r=[l.label],d=1;for(;d<l.level;)r=[...r,a.label],a=a.parent,d++;return r.some((t=>-1!==t.indexOf(e)))}),"filterNode"),q=r((e=>{c.multiple||h("change",e[c.id],e)}),"handleNodeClick"),C=r((()=>{h("change",p.value?.getCheckedNodes())}),"handleCheckChange"),V=r((e=>{p.value?.setCheckedKeys(e)}),"setCheckedKeys"),B=r((e=>{p.value?.setCurrentKey(e)}),"setCurrentKey");return i({treeData:f,treeAllData:y,treeRef:p,setCheckedKeys:V,getList:v,setCurrentKey:B}),(l,r)=>{const i=e.resolveComponent("el-input"),o=e.resolveComponent("el-scrollbar");return e.openBlock(),e.createElementBlock("div",{class:"zn-tree-filter",style:e.normalizeStyle({width:a.width,height:a.height})},[a.title?(e.openBlock(),e.createElementBlock("h4",d,e.toDisplayString(a.title),1
|
|
2
|
+
/* TEXT */)):e.createCommentVNode("v-if",!0),e.createElementVNode("div",u,[a.showFilterText?(e.openBlock(),e.createBlock(i,{key:0,modelValue:x.value,"onUpdate:modelValue":r[0]||(r[0]=e=>x.value=e),placeholder:"输入关键字进行过滤",clearable:""},null,8,["modelValue"])):e.createCommentVNode("v-if",!0),e.renderSlot(l.$slots,"toolButton")]),e.renderSlot(l.$slots,"treeHeader"),e.createVNode(o,{style:e.normalizeStyle({height:a.title?"calc(100% - 95px)":"calc(100% - 56px)"})},{default:e.withCtx((()=>[e.createVNode(e.unref(t.ElTree),{ref_key:"treeRef",ref:p,"default-expand-all":a.defaultExpandAll,"node-key":a.id,data:a.multiple?f.value:y.value,"show-checkbox":a.multiple,"check-strictly":!1,"current-node-key":a.multiple?"":m.value,"highlight-current":!a.multiple,"expand-on-click-node":a.expandOnClickNode,"check-on-click-node":a.multiple,props:s,"filter-node-method":g,"default-checked-keys":a.multiple?m.value:[],"default-expanded-keys":a.defaultExpandKeys,onNodeClick:q,onCheck:C},{default:e.withCtx((t=>[c.render?(e.openBlock(),e.createBlock(e.resolveDynamicComponent(c.render),e.normalizeProps(e.mergeProps({key:0},t)),null,16
|
|
3
3
|
/* FULL_PROPS */)):(e.openBlock(),e.createElementBlock("span",n,[e.renderSlot(l.$slots,"default",e.normalizeProps(e.guardReactiveProps(t)),(()=>[e.createTextVNode(e.toDisplayString(t.node.label),1
|
|
4
4
|
/* TEXT */)]))]))])),_:3
|
|
5
5
|
/* FORWARDED */},8,["default-expand-all","node-key","data","show-checkbox","current-node-key","highlight-current","expand-on-click-node","check-on-click-node","default-checked-keys","default-expanded-keys"])])),_:3
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.vue2.js","sources":["../../../../../../packages/components/znTreeFilter/src/index.vue"],"sourcesContent":["<template>\n <div class=\"zn-tree-filter\" :style=\"{ width, height }\">\n <h4 v-if=\"title\" class=\"title sle\">\n {{ title }}\n </h4>\n <div class=\"flex gap-10\">\n <el-input v-model=\"filterText\" placeholder=\"输入关键字进行过滤\" clearable />\n <slot name=\"toolButton\"></slot>\n </div>\n <el-scrollbar :style=\"{ height: title ? `calc(100% - 95px)` : `calc(100% - 56px)` }\">\n <el-tree\n ref=\"treeRef\"\n :default-expand-all=\"defaultExpandAll\"\n :node-key=\"id\"\n :data=\"multiple ? treeData : treeAllData\"\n :show-checkbox=\"multiple\"\n :check-strictly=\"false\"\n :current-node-key=\"!multiple ? selected : ''\"\n :highlight-current=\"!multiple\"\n :expand-on-click-node=\"expandOnClickNode\"\n :check-on-click-node=\"multiple\"\n :props=\"defaultProps\"\n :filter-node-method=\"filterNode\"\n :default-checked-keys=\"multiple ? selected : []\"\n :default-expanded-keys=\"defaultExpandKeys\"\n @node-click=\"handleNodeClick\"\n @check=\"handleCheckChange\">\n <template #default=\"scope\">\n <component v-if=\"props.render\" :is=\"props.render\" v-bind=\"scope\" />\n <span v-else class=\"el-tree-node__label\">\n <slot v-bind=\"scope\">\n {{ scope.node.label }}\n </slot>\n </span>\n </template>\n </el-tree>\n </el-scrollbar>\n </div>\n</template>\n\n<script setup lang=\"ts\" name=\"ZnTreeFilter\">\n import { nextTick, onBeforeMount, ref, watch, VNode } from 'vue'\n\n import { ElTree } from 'element-plus'\n import { utils } from '../../../functions'\n defineOptions({ name: 'ZnTreeFilter' })\n // 接收父组件参数并设置默认值\n interface TreeFilterProps {\n requestApi?: (data?: any) => Promise<any> /** 请求分类数据的 api ==> 非必传 */\n requestParams?: any /** 请求分类数据的参数 ==> 非必传 */\n data?: { [key: string]: any }[] /** 分类数据,如果有分类数据,则不会执行 api 请求 ==> 非必传 */\n title?: string /** treeFilter 标题 ==> 非必传 */\n id?: string /** 选择的id ==> 非必传,默认为 “id” */\n label?: string /** 显示的label ==> 非必传,默认为 “label” */\n multiple?: boolean /** 是否为多选 ==> 非必传,默认为 false */\n defaultValue?: any /** 默认选中的值 ==> 非必传 */\n transformDataToTree?: boolean /** 是否将数据转换为树形结构 ==> 非必传,默认为 true */\n width?: string /** 默认460px */\n height?: string /** 默认calc(100vh - 200px) */\n defaultExpandAll?: boolean /** 默认全部展开 */\n defaultExpandKeys?: any[]\n expandOnClickNode?: boolean\n render?: (scope: any) => VNode\n }\n const props = defineProps({\n requestApi: { type: Function, required: false },\n requestParams: { required: false, default: () => ({}) },\n data: { type: Array, required: false },\n title: { type: String, required: false },\n id: { type: String, required: false, default: 'id' },\n label: { type: String, required: false, default: 'label' },\n multiple: { type: Boolean, required: false, default: false },\n defaultValue: { required: false },\n transformDataToTree: { type: Boolean, required: false, default: true },\n width: { type: String, required: false, default: '460px' },\n height: { type: String, required: false, default: 'calc(100vh - 200px)' },\n defaultExpandAll: { type: Boolean, required: false, default: true },\n defaultExpandKeys: { type: Array, required: false, default: () => [] },\n expandOnClickNode: { type: Boolean, required: false, default: false },\n render: { type: Function, required: false }\n})\n\n const defaultProps = {\n children: 'children',\n label: props.label\n }\n\n const treeRef = ref<InstanceType<typeof ElTree>>()\n const treeData = ref<{ [key: string]: any }[]>([])\n const treeAllData = ref<{ [key: string]: any }[]>([])\n\n const emits = defineEmits(['dataReady', 'change'])\n\n const selected = ref()\n const setSelected = () => {\n if (props.multiple) selected.value = Array.isArray(props.defaultValue) ? props.defaultValue : [props.defaultValue]\n else selected.value = typeof props.defaultValue === 'string' ? props.defaultValue : ''\n }\n\n const getList = async () => {\n if (props.requestApi) {\n const res = await props.requestApi!(props.requestParams)\n let list = res.result.list ?? res.result\n // 后端说第六层没有id,所以补上 转树形的时候要用到\n list.map((item: any, index: number) => {\n if (!item.id) {\n item.id = `${item.treeLevel}-${index}`\n }\n })\n if (props.transformDataToTree) {\n treeData.value = utils.treeListUtil(list)\n } else {\n treeData.value = list\n }\n // treeAllData.value = [{ id: '', [props.label]: '全部' }, ...treeData.value]\n treeAllData.value = [...treeData.value]\n emits('dataReady', list)\n }\n }\n\n onBeforeMount(async () => {\n await getList()\n if (!props.multiple && props.defaultValue) {\n setCurrentKey(props.defaultValue)\n await nextTick()\n treeRef.value?.$el.querySelector('.is-current').firstChild.click()\n }\n })\n\n watch(\n () => props.requestParams,\n (val) => {\n if (val) {\n getList()\n }\n },\n {\n deep: true\n }\n )\n\n // 使用 nextTick 防止打包后赋值不生效,开发环境是正常的\n watch(\n () => props.defaultValue,\n () => nextTick(() => setSelected()),\n { deep: true, immediate: true }\n )\n\n watch(\n () => props.data,\n () => {\n if (props.data?.length) {\n treeData.value = props.data\n // treeAllData.value = [{ id: '', [props.label]: '全部' }, ...props.data]\n treeAllData.value = [...props.data]\n }\n },\n { deep: true, immediate: true }\n )\n\n const filterText = ref('')\n watch(filterText, (val) => {\n treeRef.value!.filter(val)\n })\n\n // 过滤\n const filterNode = (value: string, data: { [key: string]: any }, node: any) => {\n if (!value) return true\n let parentNode = node.parent\n let labels = [node.label]\n let level = 1\n while (level < node.level) {\n labels = [...labels, parentNode.label]\n parentNode = parentNode.parent\n level++\n }\n return labels.some((label) => label.indexOf(value) !== -1)\n }\n\n // emit\n // const emit = defineEmits<{\n // change: [value: any],\n // }>()\n\n // 单选\n const handleNodeClick = (data: { [key: string]: any }) => {\n if (props.multiple) return\n emits('change', data[props.id], data)\n }\n\n // 多选\n const handleCheckChange = () => {\n emits('change', treeRef.value?.getCheckedNodes())\n }\n\n const setCheckedKeys = (keys) => {\n treeRef.value?.setCheckedKeys(keys)\n }\n\n const setCurrentKey = (key) => {\n treeRef.value?.setCurrentKey(key)\n }\n\n // 暴露给父组件使用\n defineExpose({ treeData, treeAllData, treeRef, setCheckedKeys, getList, setCurrentKey })\n</script>\n"],"names":["props","__props","defaultProps","children","label","treeRef","ref","treeData","treeAllData","emits","__emit","selected","setSelected","__name","multiple","value","Array","isArray","defaultValue","getList","async","requestApi","res","requestParams","list","result","map","item","index","id","treeLevel","transformDataToTree","utils","treeListUtil","onBeforeMount","setCurrentKey","nextTick","$el","querySelector","firstChild","click","watch","val","deep","immediate","data","length","filterText","filter","filterNode","node","parentNode","parent","labels","level","some","indexOf","handleNodeClick","handleCheckChange","getCheckedNodes","setCheckedKeys","keys","key","__expose"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.vue2.js","sources":["../../../../../../packages/components/znTreeFilter/src/index.vue"],"sourcesContent":["<template>\n <div class=\"zn-tree-filter\" :style=\"{ width, height }\">\n <h4 v-if=\"title\" class=\"title sle\">\n {{ title }}\n </h4>\n <div class=\"flex gap-10\">\n <el-input v-if=\"showFilterText\" v-model=\"filterText\" placeholder=\"输入关键字进行过滤\" clearable />\n <slot name=\"toolButton\"></slot>\n </div>\n <slot name=\"treeHeader\"></slot>\n <el-scrollbar :style=\"{ height: title ? `calc(100% - 95px)` : `calc(100% - 56px)` }\">\n <el-tree\n ref=\"treeRef\"\n :default-expand-all=\"defaultExpandAll\"\n :node-key=\"id\"\n :data=\"multiple ? treeData : treeAllData\"\n :show-checkbox=\"multiple\"\n :check-strictly=\"false\"\n :current-node-key=\"!multiple ? selected : ''\"\n :highlight-current=\"!multiple\"\n :expand-on-click-node=\"expandOnClickNode\"\n :check-on-click-node=\"multiple\"\n :props=\"defaultProps\"\n :filter-node-method=\"filterNode\"\n :default-checked-keys=\"multiple ? selected : []\"\n :default-expanded-keys=\"defaultExpandKeys\"\n @node-click=\"handleNodeClick\"\n @check=\"handleCheckChange\">\n <template #default=\"scope\">\n <component v-if=\"props.render\" :is=\"props.render\" v-bind=\"scope\" />\n <span v-else class=\"el-tree-node__label\">\n <slot v-bind=\"scope\">\n {{ scope.node.label }}\n </slot>\n </span>\n </template>\n </el-tree>\n </el-scrollbar>\n </div>\n</template>\n\n<script setup lang=\"ts\" name=\"ZnTreeFilter\">\n import { nextTick, onBeforeMount, ref, watch, VNode } from 'vue'\n\n import { ElTree } from 'element-plus'\n import { utils } from '../../../functions'\n defineOptions({ name: 'ZnTreeFilter' })\n // 接收父组件参数并设置默认值\n interface TreeFilterProps {\n requestApi?: (data?: any) => Promise<any> /** 请求分类数据的 api ==> 非必传 */\n requestParams?: any /** 请求分类数据的参数 ==> 非必传 */\n data?: { [key: string]: any }[] /** 分类数据,如果有分类数据,则不会执行 api 请求 ==> 非必传 */\n title?: string /** treeFilter 标题 ==> 非必传 */\n id?: string /** 选择的id ==> 非必传,默认为 “id” */\n label?: string /** 显示的label ==> 非必传,默认为 “label” */\n multiple?: boolean /** 是否为多选 ==> 非必传,默认为 false */\n defaultValue?: any /** 默认选中的值 ==> 非必传 */\n transformDataToTree?: boolean /** 是否将数据转换为树形结构 ==> 非必传,默认为 true */\n width?: string /** 默认460px */\n height?: string /** 默认calc(100vh - 200px) */\n defaultExpandAll?: boolean /** 默认全部展开 */\n defaultExpandKeys?: any[]\n expandOnClickNode?: boolean\n render?: (scope: any) => VNode\n showFilterText?: boolean /** 是否显示过滤文本框 ==> 非必传,默认为 true */\n }\n const props = defineProps({\n requestApi: { type: Function, required: false },\n requestParams: { required: false, default: () => ({}) },\n data: { type: Array, required: false },\n title: { type: String, required: false },\n id: { type: String, required: false, default: 'id' },\n label: { type: String, required: false, default: 'label' },\n multiple: { type: Boolean, required: false, default: false },\n defaultValue: { required: false },\n transformDataToTree: { type: Boolean, required: false, default: true },\n width: { type: String, required: false, default: '460px' },\n height: { type: String, required: false, default: 'calc(100vh - 200px)' },\n defaultExpandAll: { type: Boolean, required: false, default: true },\n defaultExpandKeys: { type: Array, required: false, default: () => [] },\n expandOnClickNode: { type: Boolean, required: false, default: false },\n render: { type: Function, required: false },\n showFilterText: { type: Boolean, required: false, default: true }\n})\n\n const defaultProps = {\n children: 'children',\n label: props.label\n }\n\n const treeRef = ref<InstanceType<typeof ElTree>>()\n const treeData = ref<{ [key: string]: any }[]>([])\n const treeAllData = ref<{ [key: string]: any }[]>([])\n\n const emits = defineEmits(['dataReady', 'change'])\n\n const selected = ref()\n const setSelected = () => {\n if (props.multiple) selected.value = Array.isArray(props.defaultValue) ? props.defaultValue : [props.defaultValue]\n else selected.value = typeof props.defaultValue === 'string' ? props.defaultValue : ''\n }\n\n const getList = async () => {\n if (props.requestApi) {\n const res = await props.requestApi!(props.requestParams)\n let list = res.result.list ?? res.result\n // 后端说第六层没有id,所以补上 转树形的时候要用到\n list.map((item: any, index: number) => {\n if (!item.id) {\n item.id = `${item.treeLevel}-${index}`\n }\n })\n if (props.transformDataToTree) {\n treeData.value = utils.treeListUtil(list)\n } else {\n treeData.value = list\n }\n // treeAllData.value = [{ id: '', [props.label]: '全部' }, ...treeData.value]\n treeAllData.value = [...treeData.value]\n emits('dataReady', list)\n }\n }\n\n onBeforeMount(async () => {\n await getList()\n if (!props.multiple && props.defaultValue) {\n setCurrentKey(props.defaultValue)\n await nextTick()\n treeRef.value?.$el.querySelector('.is-current').firstChild.click()\n }\n })\n\n watch(\n () => props.requestParams,\n (val) => {\n if (val) {\n getList()\n }\n },\n {\n deep: true\n }\n )\n\n // 使用 nextTick 防止打包后赋值不生效,开发环境是正常的\n watch(\n () => props.defaultValue,\n () => nextTick(() => setSelected()),\n { deep: true, immediate: true }\n )\n\n watch(\n () => props.data,\n () => {\n if (props.data?.length) {\n treeData.value = props.data\n // treeAllData.value = [{ id: '', [props.label]: '全部' }, ...props.data]\n treeAllData.value = [...props.data]\n }\n },\n { deep: true, immediate: true }\n )\n\n const filterText = ref('')\n watch(filterText, (val) => {\n treeRef.value!.filter(val)\n })\n\n // 过滤\n const filterNode = (value: string, data: { [key: string]: any }, node: any) => {\n if (!value) return true\n let parentNode = node.parent\n let labels = [node.label]\n let level = 1\n while (level < node.level) {\n labels = [...labels, parentNode.label]\n parentNode = parentNode.parent\n level++\n }\n return labels.some((label) => label.indexOf(value) !== -1)\n }\n\n // emit\n // const emit = defineEmits<{\n // change: [value: any],\n // }>()\n\n // 单选\n const handleNodeClick = (data: { [key: string]: any }) => {\n if (props.multiple) return\n emits('change', data[props.id], data)\n }\n\n // 多选\n const handleCheckChange = () => {\n emits('change', treeRef.value?.getCheckedNodes())\n }\n\n const setCheckedKeys = (keys) => {\n treeRef.value?.setCheckedKeys(keys)\n }\n\n const setCurrentKey = (key) => {\n treeRef.value?.setCurrentKey(key)\n }\n\n // 暴露给父组件使用\n defineExpose({ treeData, treeAllData, treeRef, setCheckedKeys, getList, setCurrentKey })\n</script>\n"],"names":["props","__props","defaultProps","children","label","treeRef","ref","treeData","treeAllData","emits","__emit","selected","setSelected","__name","multiple","value","Array","isArray","defaultValue","getList","async","requestApi","res","requestParams","list","result","map","item","index","id","treeLevel","transformDataToTree","utils","treeListUtil","onBeforeMount","setCurrentKey","nextTick","$el","querySelector","firstChild","click","watch","val","deep","immediate","data","length","filterText","filter","filterNode","node","parentNode","parent","labels","level","some","indexOf","handleNodeClick","handleCheckChange","getCheckedNodes","setCheckedKeys","keys","key","__expose"],"mappings":"gvCAkEE,MAAMA,EAAQC,EAmBRC,EAAe,CACnBC,SAAU,WACVC,MAAOJ,EAAMI,OAGTC,EAAUC,EAAAA,MACVC,EAAWD,EAA8BA,IAAA,IACzCE,EAAcF,EAA8BA,IAAA,IAE5CG,EAAQC,EAERC,EAAWL,EAAAA,MACXM,EAAoBC,GAAA,KACpBb,EAAMc,SAAmBH,EAAAI,MAAQC,MAAMC,QAAQjB,EAAMkB,cAAgBlB,EAAMkB,aAAe,CAAClB,EAAMkB,gBACvFH,MAAsC,iBAAvBf,EAAMkB,aAA4BlB,EAAMkB,aAAe,EAAA,GAFlE,eAKdC,EAAsBN,GAAAO,UAC1B,GAAIpB,EAAMqB,WAAY,CACpB,MAAMC,QAAYtB,EAAMqB,WAAYrB,EAAMuB,eAC1C,IAAIC,EAAOF,EAAIG,OAAOD,MAAQF,EAAIG,OAE7BD,EAAAE,KAAI,CAACC,EAAWC,KACdD,EAAKE,KACRF,EAAKE,GAAK,GAAGF,EAAKG,aAAaF,IAAK,IAGpC5B,EAAM+B,oBACCxB,EAAAQ,MAAQiB,UAAMC,aAAaT,GAEpCjB,EAASQ,MAAQS,EAGnBhB,EAAYO,MAAQ,IAAIR,EAASQ,OACjCN,EAAM,YAAae,EAAI,IAjBX,WAqBhBU,EAAAA,eAAcd,gBACND,KACDnB,EAAMc,UAAYd,EAAMkB,eAC3BiB,E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ANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./installer.js");require("./functions/index.js"),require("./hooks/index.js");var o=require("./utils/index.js");require("./directives/index.js"),require("./components/index.js");var r=require("./functions/modules/log.js"),s=require("./hooks/useDialogV2/index.js"),t=require("./hooks/useDrawerV2/index.js"),n=require("./hooks/useDrawerV2/src/index.js"),i=require("./hooks/usePopWindow/src/index.js"),u=require("./hooks/usePopWindow/index.js"),l=require("./hooks/usePopWindowV2/src/index.js"),p=require("./hooks/usePopWindowV2/index.js"),d=require("./hooks/useDialog/index.js"),a=require("./hooks/useImageViewer/src/index.vue2.js"),x=require("./hooks/useImageViewer/index.js"),c=require("./hooks/useDrawer/index.js"),m=require("./utils/install.js"),q=require("./directives/modules/copy.js"),j=require("./directives/modules/drag.js"),h=require("./directives/modules/autoScroll.js"),w=require("./directives/modules/tooltip.js"),V=require("./directives/modules/confirm.js"),T=require("./directives/modules/countTo.js"),Z=require("./functions/modules/uitls.js"),g=require("./functions/modules/is.js"),f=require("./components/znForm/src/hooks/useZnForm.js"),I=require("./components/znFormV2/src/hooks/useZnFormV2.js"),W=require("./components/znSearch/src/hooks/useProSearch.js"),F=require("./components/znChart/index.js"),P=require("./components/znCountTo/index.js"),z=require("./components/znForm/src/components/ZnFormItem.vue2.js"),v=require("./components/znForm/index.js"),b=require("./components/znFormV2/src/helper/index.js"),y=require("./components/znFormV2/src/components/ZnFormV2Item.vue2.js"),k=require("./components/znFormV2/index.js"),D=require("./components/znGrid/index.js"),S=require("./components/znNumberScroll/index.js"),E=require("./components/znSearch/index.js"),C=require("./components/znTable/index.js"),B=require("./components/znTest/index.js"),G=require("./components/znTimeLine/index.js"),A=require("./components/znTreeFilter/index.js"),U=require("./components/znTreeSelect/index.js"),L=require("./components/znVirtualTable/src/utils/vxe-setup.js"),O=require("./components/znWorkGrid/index.js"),H=require("./components/znVirtualTable/src/index.vue2.js");globalThis.log=r.default;"function"==typeof globalThis?.log?.success&&globalThis.log.primary("1.1.
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("./installer.js");require("./functions/index.js"),require("./hooks/index.js");var o=require("./utils/index.js");require("./directives/index.js"),require("./components/index.js");var r=require("./functions/modules/log.js"),s=require("./hooks/useDialogV2/index.js"),t=require("./hooks/useDrawerV2/index.js"),n=require("./hooks/useDrawerV2/src/index.js"),i=require("./hooks/usePopWindow/src/index.js"),u=require("./hooks/usePopWindow/index.js"),l=require("./hooks/usePopWindowV2/src/index.js"),p=require("./hooks/usePopWindowV2/index.js"),d=require("./hooks/useDialog/index.js"),a=require("./hooks/useImageViewer/src/index.vue2.js"),x=require("./hooks/useImageViewer/index.js"),c=require("./hooks/useDrawer/index.js"),m=require("./utils/install.js"),q=require("./directives/modules/copy.js"),j=require("./directives/modules/drag.js"),h=require("./directives/modules/autoScroll.js"),w=require("./directives/modules/tooltip.js"),V=require("./directives/modules/confirm.js"),T=require("./directives/modules/countTo.js"),Z=require("./functions/modules/uitls.js"),g=require("./functions/modules/is.js"),f=require("./components/znForm/src/hooks/useZnForm.js"),I=require("./components/znFormV2/src/hooks/useZnFormV2.js"),W=require("./components/znSearch/src/hooks/useProSearch.js"),F=require("./components/znChart/index.js"),P=require("./components/znCountTo/index.js"),z=require("./components/znForm/src/components/ZnFormItem.vue2.js"),v=require("./components/znForm/index.js"),b=require("./components/znFormV2/src/helper/index.js"),y=require("./components/znFormV2/src/components/ZnFormV2Item.vue2.js"),k=require("./components/znFormV2/index.js"),D=require("./components/znGrid/index.js"),S=require("./components/znNumberScroll/index.js"),E=require("./components/znSearch/index.js"),C=require("./components/znTable/index.js"),B=require("./components/znTest/index.js"),G=require("./components/znTimeLine/index.js"),A=require("./components/znTreeFilter/index.js"),U=require("./components/znTreeSelect/index.js"),L=require("./components/znVirtualTable/src/utils/vxe-setup.js"),O=require("./components/znWorkGrid/index.js"),H=require("./components/znVirtualTable/src/index.vue2.js");globalThis.log=r.default;"function"==typeof globalThis?.log?.success&&globalThis.log.primary("1.1.14","欢迎使用znyg-frontend-common,在线文档:http://192.168.99.34:10000/znyg-frontend-common-docs/"),exports.default=e.default,exports.install=e.install,exports.copyText=o.copyText,exports.formatValue=o.formatValue,exports.treeListUtil=o.treeListUtil,exports.treeToList=o.treeToList,exports.log=r.default,exports.useDialogV2=s.useDialogV2,exports.useDrawerV2=t.useDrawerV2,exports.closeAllDrawers=n.closeAllDrawers,exports.closePopWindowById=i.closePopWindowById,exports.closePopWindowByTag=i.closePopWindowByTag,exports.getAllPopWindows=i.getAllPopWindows,exports.showPopWindow=i.showPopWindow,exports.usePopWindow=u.usePopWindow,exports.closePopWindowByIdV2=l.closePopWindowByIdV2,exports.closePopWindowByTagV2=l.closePopWindowByTagV2,exports.getAllPopWindowsV2=l.getAllPopWindowsV2,exports.showPopWindowV2=l.showPopWindowV2,exports.usePopWindowV2=p.usePopWindowV2,exports.useDialog=d.useDialog,exports.ImageViewer=a.default,exports.useImageViewer=x.useImageViewer,exports.useDrawer=c.useDrawer,exports.withInstall=m.withInstall,exports.withInstallDirectives=m.withInstallDirectives,exports.vCopy=q.default,exports.vDrag=j.default,exports.vAutoScroll=h.default,exports.vTooltip=w.default,exports.vConfirm=V.default,exports.vCountTo=T.default,exports.utils=Z.default,exports.is=g,exports.useZnForm=f.useZnForm,exports.useZnFormV2=I.useZnFormV2,exports.useZnSearch=W.useZnSearch,exports.ZnChart=F.ZnChart,exports.ZnCountTo=P.ZnCountTo,exports.ZnFormItem=z.default,exports.ZnForm=v.ZnForm,exports.batchExecute=b.batchExecute,exports.camelCaseToHyphen=b.camelCaseToHyphen,exports.checkFeatureSupport=b.checkFeatureSupport,exports.createUniqueId=b.createUniqueId,exports.debounce=b.debounce,exports.delay=b.delay,exports.executeInIdle=b.executeInIdle,exports.getElementOffsetTop=b.getElementOffsetTop,exports.getMemoryUsage=b.getMemoryUsage,exports.getObjectHash=b.getObjectHash,exports.isDeepEqual=b.isDeepEqual,exports.isElementInViewport=b.isElementInViewport,exports.isShallowEqual=b.isShallowEqual,exports.throttle=b.throttle,exports.ZnFormV2Item=y.default,exports.ZnFormV2=k.ZnFormV2,exports.ZnGrid=D.ZnGrid,exports.ZnGridItem=D.ZnGridItem,exports.ZnNumberScroll=S.ZnNumberScroll,exports.ZnSearch=E.ZnSearch,exports.ZnTable=C.ZnTable,exports.ZnTest=B.ZnTest,exports.ZnTimeline=G.ZnTimeline,exports.ZnTreeFilter=A.ZnTreeFilter,exports.ZnTreeSelect=U.ZnTreeSelect,exports.initVXETable=L.initVXETable,exports.isVXETableInitialized=L.isVXETableInitialized,exports.ZnWorkGrid=O.ZnWorkGrid,exports.ZnVirtualTable=H.default;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../packages/index.ts"],"sourcesContent":["import installer from './installer'\nimport { log } from './functions'\nexport * from './hooks'\nexport * from './utils'\nexport * from './installer'\nexport * from './directives'\nexport * from './functions'\nexport * from './components'\n\nexport default installer\nglobalThis.log = log\nconst version = '1.1.
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../packages/index.ts"],"sourcesContent":["import installer from './installer'\nimport { log } from './functions'\nexport * from './hooks'\nexport * from './utils'\nexport * from './installer'\nexport * from './directives'\nexport * from './functions'\nexport * from './components'\n\nexport default installer\nglobalThis.log = log\nconst version = '1.1.14'\nif (typeof globalThis?.log?.success === 'function') {\n globalThis.log.primary(version, '欢迎使用znyg-frontend-common,在线文档:http://192.168.99.34:10000/znyg-frontend-common-docs/')\n}\n"],"names":["globalThis","log","default","success","primary"],"mappings":"6sEAUAA,WAAWC,IAAMA,EAAAC,QAEuB,mBAA7BF,YAAYC,KAAKE,SACfH,WAAAC,IAAIG,QAFD,SAEkB"}
|