UNPKG

@aplus-frontend/ui

Version:

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