UNPKG

@aplus-frontend/ui

Version:

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