UNPKG

@aplus-frontend/ui

Version:

2 lines (1 loc) 4.57 kB
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("vue"),B=require("@aplus-frontend/utils"),j=require("../../ap-table/context.js");require("../../config-provider/index.js");const k=require("../ap-batch-action-group/index.js");require("./components/main-button-content.vue.js");require("./components/menu-list-content.vue.js");const A=require("./hooks/use-view-provide.js"),G=require("./icons/line-down.vue.js"),U=require("./style/index.js"),m=require("./utils/enum.js"),$=require("../../config-provider/hooks/use-global-config.js"),z=require("../../config-provider/hooks/use-namespace.js"),R=require("../../config-provider/hooks/use-locale.js"),H=require("./components/main-button-content.vue2.js"),J=require("./components/menu-list-content.vue2.js"),Q=t.defineComponent({name:"ApView",__name:"ap-view",props:{tableKey:{},saveDataSource:{},viewCacheOption:{},maxViewNum:{default:20},isDefaultSystemView:{type:Boolean,default:!1},isFirstDefaultSystemView:{type:Boolean,default:!1},manual:{type:Boolean,default:!1},emptyData:{},extraParams:{}},setup(g,{expose:C}){const r=g,D=$.useGlobalConfig("viewCacheOption"),{b:y}=z.useNamespace("ap-view"),{t:E}=R.useLocale(),_=U.default("ap-view"),d=t.computed(()=>({viewKey:m.SYSTEM_VIEW_KEY,viewName:E("ap.apView.systemView")})),{getSearchFormValues:q,setSearchFormValues:F,submit:I,reset:N,submitWith:Y,getSearchFormSorterItems:x,setSearchFormSorterItems:O,resetSearchFormSorterItems:T}=j.useInjectApTable(),L=t.ref(!1),V=t.ref(!1),w=t.ref("");let f=!1,K=!1;const W={dropdownType:"dropdown",content:t.createVNode(H.default,{maxViewNum:r.maxViewNum},null)},s=t.ref([d.value]),M=t.computed(()=>s.value.map(a=>({id:a.viewKey,content:t.createVNode(J.default,{view:a},null)}))),o={getSearchFormValues:q,setSearchFormValues:F,submit:I,reset:N,submitWith:Y,getSearchFormSorterItems:x,setSearchFormSorterItems:O,resetSearchFormSorterItems:T,...r.saveDataSource},p={...D.value,...r.viewCacheOption},h=()=>r.isDefaultSystemView||(r.isFirstDefaultSystemView||K)&&f?m.SYSTEM_VIEW_KEY:s.value.find(i=>i.isDefault)?.viewKey??m.SYSTEM_VIEW_KEY,l=a=>{w.value=a;const i=s.value.find(e=>e.viewKey===w.value);i&&setTimeout(()=>{i.viewKey===m.SYSTEM_VIEW_KEY?f?r.manual||o?.submitWith?.():r.manual||(o?.resetSearchFormSorterItems?.(),o?.reset?.()):(o?.setSearchFormValues?.({...Object.fromEntries(Object.keys(o?.getSearchFormValues?.()??{}).map(e=>[e,void 0]))??{},...r?.emptyData??{},...[...o?.getSearchFormSorterItems?.()??[],...r?.extraParams?.map(e=>({name:e}))??[]].reduce((e,n)=>(i.viewConfig?.searchForm?.[n.name]&&(e[n.name]=i.viewConfig?.searchForm?.[n.name]),e),{})??{}}),o?.setSearchFormSorterItems?.(i.viewConfig?.sorterItems??[]),f?r.manual||o?.submitWith?.():o?.submit?.()),f=!1})},b={getViewList:async a=>{try{const{tableKey:i}=a,e=await p?.getViewList?.({tableKey:i});return s.value=[d.value,...e??[]],l(h()),s.value}catch{return s.value=[d.value],l(m.SYSTEM_VIEW_KEY),s.value}},addView:async a=>{const{tableKey:i,viewKey:e,viewName:n,isDefault:u,viewConfig:v}=a;await p?.addView?.({tableKey:i,viewKey:e,viewName:n,isDefault:u,viewConfig:v}),u&&(s.value=s.value.map(c=>({...c,isDefault:!1}))),s.value=[...s.value,{viewKey:e,viewName:n,isDefault:u,viewConfig:v}],l(e)},changeView:async a=>{const{tableKey:i,viewKey:e,viewName:n,isDefault:u,viewConfig:v}=a;await p?.changeView?.({tableKey:i,viewKey:e,viewName:n,isDefault:u,viewConfig:v}),u&&(s.value=s.value.map(S=>({...S,isDefault:!1})));const c=s.value.find(S=>S.viewKey===e);c&&(c.viewName=n,c.isDefault=u,c.viewConfig=v),l(e)},removeView:async a=>{const{tableKey:i,viewKey:e}=a;await p?.removeView?.({tableKey:i,viewKey:e}),s.value=s.value.filter(n=>n.viewKey!==e),e===w.value&&l(h())}},P={tableKey:r.tableKey,currentViewKey:w,changeCurrentViewKey:l,popoverOpen:L,menuOpen:V,viewList:s,viewListCRUD:b,saveDataSource:o};return A.useViewProvide(P),t.watch(()=>r.tableKey,a=>{B.isValid(a)&&(f=!0,b?.getViewList?.({tableKey:a}))},{immediate:!0}),C({setFirstDefaultSystemView:a=>{K=a}}),(a,i)=>(t.openBlock(),t.createBlock(t.unref(k.ApBatchActionGroup),t.mergeProps({...a.$attrs},{open:V.value,"onUpdate:open":i[0]||(i[0]=e=>V.value=e),class:[t.unref(y)(),t.unref(_)],"button-props":W,"menu-list":M.value,"overlay-class-name":[t.unref(y)("overlay"),t.unref(_)],trigger:"click",placement:"bottom"}),{icon:t.withCtx(()=>[t.createElementVNode("div",{class:t.normalizeClass([t.unref(y)("icon")])},[t.createVNode(G.default)],2)]),_:1},16,["open","class","menu-list","overlay-class-name"]))}});exports.default=Q;