UNPKG

@aplus-frontend/ui

Version:

204 lines (203 loc) 7.11 kB
import { defineComponent as J, ref as B, computed as m, watch as Q, createElementBlock as M, openBlock as s, Fragment as T, createBlock as d, createCommentVNode as S, unref as o, mergeProps as x, withCtx as l, createTextVNode as y, toDisplayString as v, normalizeClass as W, createVNode as L } from "vue"; import { DownOutlined as X } from "@ant-design/icons-vue"; import { message as Y, Dropdown as Z, Menu as ee, MenuItem as R } from "@aplus-frontend/antdv"; import { usePermission as te } from "@aplus-frontend/hooks"; import { transformTableParamsNoTimezone as oe } from "@aplus-frontend/utils"; import { merge as ae } from "lodash-unified"; import "../../ap-button/index.mjs"; import { useInjectApTable as re } from "../../ap-table/context.mjs"; import "../../config-provider/index.mjs"; import { ApBatchActionGroup as se } from "../ap-batch-action-group/index.mjs"; import { convertExportField as le } from "./convertExportField.mjs"; import { handleExportDownload as ne } from "./handleExportDownload.mjs"; import { ApExportGroupActionType as n } from "./interface.mjs"; import { useNamespace as ue } from "../../config-provider/hooks/use-namespace.mjs"; import { useLocale as ie } from "../../config-provider/hooks/use-locale.mjs"; import { useGlobalConfig as pe } from "../../config-provider/hooks/use-global-config.mjs"; import C from "../../ap-button/ap-button.vue.mjs"; const Fe = /* @__PURE__ */ J({ __name: "ApExportGroup", props: { type: { default: "button" }, selectedRowKeys: {}, groupList: {}, buttonProps: {}, disabled: { type: Boolean }, auth: {}, ifShow: {}, text: {}, idKey: {}, request: {}, getRequestParams: {}, getInitialParams: {}, beforeRequest: {}, successMessage: { type: [Boolean, String], default: !1 }, exportField: { type: [Boolean, Object], default: void 0 } }, setup(q) { const { hasPermission: P } = te(), t = q, { columns: F, dataSource: A, getSearchFormValues: K, getLastParams: D } = re(), { b: N } = ue("ap-export-group"), { t: u } = ie(), _ = pe("exportField"), i = B(!1), h = B(!1), p = m( () => !!t?.disabled || (A !== void 0 ? !A?.value?.length : !1) || i.value ); Q( () => p.value, () => { p.value && (h.value = !1); }, { immediate: !0 } ); const $ = m(() => t?.successMessage === !0 ? u("ap.apExportGroup.exportSuccess") : t?.successMessage ? t.successMessage : ""), j = (e = t?.exportField) => { const r = "exportFieldList", a = e ?? (_.value === "" ? !0 : _.value) ?? !1; return a === !0 ? { key: r } : typeof a == "object" ? { ...a, key: a.key ?? r } : a; }, I = { textAlign: "center" }, g = m(() => t?.selectedRowKeys || []), k = m(() => { let e = t?.ifShow; return !t?.ifShow && t?.auth && (e = () => P(t.auth)), e?.() ?? !0; }); async function V() { g.value.length > 0 ? c({ key: n.SELECT }) : c({ key: n.ALL }); } async function c({ key: e, option: r }) { const a = ae({}, t, r || {}), { getRequestParams: O, request: z } = a || {}, G = D?.()?.sort, U = G ? oe({ sort: G }) : {}, w = j(a?.exportField); let E = {}; e === n.SELECT ? E = { [a?.idKey || "ids"]: g.value } : e === n.ALL && (E = O?.() || K?.(!0) || {}); const H = a?.getInitialParams?.() || {}; try { i.value = !0; let b = Object.assign( { ...E, ...H, ...U }, w && F?.value ? { [w.key]: le( F.value, w?.convertField ) } : {} ); b = a?.beforeRequest?.(b) || b, await ne(async () => await z?.(b)), a?.successMessage && Y.success($.value); } finally { i.value = !1; } } const f = m(() => t?.groupList?.filter((e) => { let r = e?.ifShow; return !e?.ifShow && e?.auth && (r = () => P(e.auth)), r?.() ?? !0; })?.map((e, r) => ({ key: r, content: e?.text, auth: e?.auth, ifShow: e?.ifShow, disabled: e?.disabled, onClick: () => { g.value.length > 0 ? c({ key: n.SELECT, option: e }) : c({ key: n.ALL, option: e }); } })) || []); return (e, r) => (s(), M(T, null, [ k.value && t.type === "button" ? (s(), d(o(C), x({ key: 0 }, { ...e.$attrs }, { disabled: p.value, loading: i.value, "min-width": "", onClick: V }), { default: l(() => [ y(v(t?.text ?? o(u)("ap.apExportGroup.export")), 1) ]), _: 1 }, 16, ["disabled", "loading"])) : S("", !0), k.value && t.type === "dropdown" ? (s(), d(o(Z), { key: 1, open: h.value, "onUpdate:open": r[0] || (r[0] = (a) => h.value = a), class: W([o(N)()]), "overlay-style": I, disabled: p.value }, { overlay: l(() => [ L(o(ee), { onClick: c }, { default: l(() => [ (s(), d(o(R), { key: o(n).SELECT, disabled: g.value?.length === 0 }, { default: l(() => [ y(v(o(u)("ap.apExportGroup.exportSelected")), 1) ]), _: 1 }, 8, ["disabled"])), (s(), d(o(R), { key: o(n).ALL }, { default: l(() => [ y(v(o(u)("ap.apExportGroup.exportAll")), 1) ]), _: 1 })) ]), _: 1 }) ]), default: l(() => [ L(o(C), x({ ...e.$attrs }, { loading: i.value }), { default: l(() => [ y(v(t?.text ?? o(u)("ap.apExportGroup.export")) + " ", 1), L(o(X)) ]), _: 1 }, 16, ["loading"]) ]), _: 1 }, 8, ["open", "class", "disabled"])) : S("", !0), k.value && t.type === "group" ? (s(), M(T, { key: 2 }, [ f.value.length === 1 ? (s(), d(o(C), x({ key: 0 }, { ...e.$attrs }, { disabled: p.value || f.value?.[0]?.disabled, loading: i.value, "min-width": "", onClick: f.value?.[0]?.onClick }), { default: l(() => [ y(v(f.value?.[0]?.content ?? t?.text ?? o(u)("ap.apExportGroup.export")), 1) ]), _: 1 }, 16, ["disabled", "loading", "onClick"])) : (s(), d(o(se), x({ key: 1 }, { ...e.$attrs }, { disabled: p.value, loading: i.value, "button-props": { ...t.buttonProps, content: t?.buttonProps?.content ?? o(u)("ap.apExportGroup.export"), type: t?.buttonProps?.type ?? "default" }, "menu-list": f.value }), null, 16, ["disabled", "loading", "button-props", "menu-list"])) ], 64)) : S("", !0) ], 64)); } }); export { Fe as default };