UNPKG

@aplus-frontend/ui

Version:

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