UNPKG

@aplus-frontend/ui

Version:

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