UNPKG

@aplus-frontend/ui

Version:

173 lines (172 loc) 5.2 kB
import { defineComponent as _, ref as H, createVNode as i, mergeProps as L, onUnmounted as j } from "vue"; import { message as q } from "@aplus-frontend/antdv"; import { isFunction as u, cloneDeep as D, isEmpty as b, omitBy as G, isUndefined as T, omit as S } from "lodash-unified"; import "../../../ag-grid/index.mjs"; import { ApModal as F } from "../../../ap-modal/index.mjs"; import "../../../config-provider/index.mjs"; import { ROW_KEY as E } from "../constants.mjs"; import "../modal-layout/index.vue.mjs"; import { AsyncCallback as U, genRequest as W, delRowKeyField as $, addRowKeyField as z, getModalLayoutConfig as B } from "../utils.mjs"; import "../wrapper/index.vue.mjs"; import { useAgGridInstance as N } from "./use-ag-grid-instance.mjs"; import { useModalTitle as V } from "./use-modal-title.mjs"; import { useLocale as Y } from "../../../config-provider/hooks/use-locale.mjs"; import J from "../wrapper/index.vue2.mjs"; import Q from "../modal-layout/index.vue2.mjs"; import X from "../../../ag-grid/index.vue.mjs"; function we(t) { let d, f = null, g = null; const c = new U(), [x, K] = V(), { t: k } = Y(), [s, p] = N({ onSelectedRows(e) { K.setCount(e?.length || 0); } }), w = W(t.api, t.getRowKey, s.setDataSourceLength), y = (e) => { const { title: o, width: l, modalProps: n, ...a } = u(e) ? e(D(t)) : e; b(a) || g?.(a); const r = G({ title: o, width: l, modalProps: n }, T); b(r) || f?.update(r); }, m = u(t.getRowKey) ? t.getRowKey : (e) => e[t.getRowKey], P = () => { const e = t.mergeRule || "old", o = s.getSelectedRows() || []; return { keys: A(o), rows: o.map((a) => { const r = m(a); return e === "old" && d?.[r] ? d[r] : $(a); }) }; }, h = async () => { const e = P(), o = t.maxCount || 1 / 0; return e.keys.length > o ? (q.warning(k("ap.apTableModal.messageMaxCount", { maxCount: o })), Promise.reject()) : (await t.beforeOk?.(e), t.finishCallback?.(e), c.resolve(e), e); }, M = () => { c.reject("modal is closed!"); }, I = /* @__PURE__ */ _({ name: "AgGridModalSelectContent", props: { modalConfig: { type: Object, required: !0 }, selectedRows: { type: Array, default: () => [] } }, setup(e) { const o = H(e.modalConfig); return g = (l) => { o.value = { ...o.value, ...l }; }, () => { const l = e.selectedRows?.map((r) => z(r, o.value.getRowKey)), n = o.value, a = B(n.modalLayout); return i(p, null, { default: () => [i(J, { height: n.height, rowHeight: n.rowHeight }, { default: () => [t.renderHeader?.(S(s, "setInstance"), { updateProps: y }), i(Q, a.props, { default: () => [i(X, L({ ref: s.setInstance, searchForm: { sortable: !1, resize: { target: "form" } }, rowKey: u(n.getRowKey) ? E : n.getRowKey, request: w.request, style: { padding: "0px" }, rowHeight: n.rowHeight, columns: n.columns, rowSelection: { defaultSelectedRows: l, preserveSelectedRowKeys: !0, type: n.mode || "checkbox", fixed: "left", columnWidth: 38, disabled(r) { return u(n.disabledCheckbox) ? n.disabledCheckbox(r, S(s, "setInstance")) : n.disabledCheckbox ?? !1; }, ...t.rowSelection }, autoHeight: !!o.value.height }, t.gridProps), n.gridSlots)], ...a.slots })] })] }); }; } }); function C(e) { return i(I, { modalConfig: t, selectedRows: e }, null); } function v() { const e = Object.values(d || {}), o = C(e); f = F.createModal({ title: i(x, { title: t.title, maxCount: t.maxCount || 1 / 0, isShowDefaultSuffix: t.mode !== "radio" }, t.modalTitleSlots), width: t.width, destroyOnClose: !0, maskClosable: !1, onOk: h, onCancel: M, afterOpenChange(l) { l === !1 && (s.setInstance(void 0), s.setDataSourceLength(0)); }, content: o, ...t.modalProps || {} }); } function A(e) { return e?.map(m) || []; } function R(e, o, l = !1) { if (d = e?.reduce((n, a) => { const r = m(a); return n[r] = a, n; }, {}), w.setExtraParams(o?.extraParams), v(), l) return c.buildPromise(); } function O(e, o) { return R(e, o, !0); } return j(() => { c.reject("component is Unmounted!"); }), { open: R, asyncOpen: O, refresh: s.refresh, getAgGridInstance: s.getInstance, genContent: C, validate: h, updateProps: y }; } export { we as useAgGridSelectModal };