UNPKG

@aplus-frontend/ui

Version:

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