UNPKG

@aplus-frontend/ui

Version:

246 lines (245 loc) 7.42 kB
import { defineComponent as E, ref as d, unref as r, computed as G, h as H, createBlock as w, openBlock as g, mergeProps as m, withCtx as k, createCommentVNode as U, createVNode as h, resolveDynamicComponent as q } from "vue"; import { message as R, Modal as V } from "@aplus-frontend/antdv"; import "../../config-provider/index.mjs"; import { ApTable as $ } from "../../ap-table/index.mjs"; import { cloneDeep as j, omit as T } from "lodash-unified"; import { transformTableParams as z } from "@aplus-frontend/utils"; import "./modal-title.vue.mjs"; import { AsyncOpenResultError as y } from "./interface.mjs"; import "./table-layout/index.vue.mjs"; import { useLocale as W } from "../../config-provider/hooks/use-locale.mjs"; import J from "./modal-title.vue2.mjs"; import Q from "./table-layout/index.vue2.mjs"; const ue = /* @__PURE__ */ E({ __name: "table-modal", props: { columns: {}, getRowKey: {}, api: { type: Function, default: async () => ({ records: [], total: 0 }) }, apTableProps: {}, maxCount: { default: 1 / 0 }, isRenderModalTitleSuffix: { type: Boolean, default: !0 }, renderModalTitleSuffix: {}, disabledCheckbox: { type: [Boolean, Function] }, rowSelection: {}, tableLayoutConfig: {}, renderHeader: {}, onOk: {}, prefixCls: {}, confirmLoading: { type: Boolean, default: void 0 }, title: {}, closable: { type: Boolean, default: void 0 }, closeIcon: {}, onCancel: {}, "onUpdate:visible": {}, "onUpdate:open": {}, onChange: {}, afterClose: {}, afterOpenChange: {}, centered: { type: Boolean, default: void 0 }, width: {}, footer: {}, okText: {}, okType: {}, cancelText: {}, icon: {}, maskClosable: { type: Boolean, default: void 0 }, forceRender: { type: Boolean, default: void 0 }, okButtonProps: {}, cancelButtonProps: {}, destroyOnClose: { type: Boolean, default: void 0 }, wrapClassName: {}, maskTransitionName: {}, transitionName: {}, getContainer: { type: [String, Boolean, Function], default: void 0 }, zIndex: {}, bodyStyle: {}, maskStyle: {}, mask: { type: Boolean, default: void 0 }, keyboard: { type: Boolean, default: void 0 }, wrapProps: {}, focusTriggerAfterClose: { type: Boolean, default: void 0 }, modalRender: {}, mousePosition: {}, loading: { type: Boolean } }, emits: ["finish"], setup(S, { expose: B, emit: P }) { const e = S, M = P, s = d(!1), v = d({}), i = d(null), a = d([]), C = d(); let f = null, u = null; const { t: b } = W(), K = async (t = [], o = {}) => { switch (a.value = [...t], s.value = !0, v.value = o?.extraParams, C.value = o.apTableDataSources || e.apTableProps?.dataSource, o.refreshMode || "reset") { case "reset": i.value?.reset(); break; case "submit": i.value?.submit(); break; case "none": break; } return new Promise((n, l) => { f = n, u = l; }); }, x = () => { s.value = !1, f = null, u?.(y.ModalCancel), u = null; }, O = async (t) => { t = z({ ...t, ...v.value }); const o = e.api, { records: n, total: l } = await o(t); return { data: n, total: l }; }, _ = async () => { if (a.value.length > e.maxCount) { u?.(y.ExceedMaxCount); return; } if (e.getRowKey) { const t = j(r(a)), o = t.map(e.getRowKey); if (e.onOk && await e.onOk({ keys: o, rows: t }) === !1) return; M("finish", o, t), f?.({ keys: o, rows: t }); } else { u?.(y.NotFineGetRowKey); return; } s.value = !1; }, I = G(() => { if (!e.getRowKey) return; const t = e.getRowKey; return { fixed: !0, selectedRowKeys: a.value.map(t), columnWidth: 50, preserveSelectedRowKeys: !0, onSelectAll(o, n) { if (n.length > e.maxCount) { R.warning( b("ap.apTableModal.messageMaxCount", { maxCount: e.maxCount }) ); return; } const l = i.value?.dataSource; if (o) { const c = r(l).filter((p) => !a.value.some((F) => t(F) === t(p))); a.value = a.value.concat(c); } else a.value = a.value?.filter((c) => !l.some((p) => t(p) === t(c))); }, onSelect(o, n) { if (n) { if (a.value.length >= e.maxCount) { R.warning( b("ap.apTableModal.messageMaxCount", { maxCount: e.maxCount }) ); return; } e.rowSelection?.type === "radio" ? a.value = [o] : a.value.push(o); } else { const l = a.value.findIndex( (c) => t(o) === t(c) ); a.value.splice(l, 1); } }, getCheckboxProps: (o) => ({ disabled: typeof e.disabledCheckbox == "function" ? e.disabledCheckbox(o, a.value) : e.disabledCheckbox // Column configuration not to be checked }), ...e.rowSelection || {} }; }), D = () => e.isRenderModalTitleSuffix ? H( J, { title: e.title, count: a.value.length || 0, maxCount: e.maxCount }, { default: e.renderModalTitleSuffix ?? void 0 } ) : e.title, L = () => i.value, N = () => { a.value = []; }, A = (t) => { const o = e.getRowKey; if (!o) return; const n = a.value.findIndex( (l) => o(t) === o(l) ); a.value.splice(n, 1); }; return B({ open: K, close: x, getApTableInstance: L }), (t, o) => (g(), w(r(V), m( { open: s.value, "onUpdate:open": o[0] || (o[0] = (n) => s.value = n) }, r(T)(e, [ "api", "getRowKey", "centered", "apTableProps", "onOk", "maxCount", "title", "renderModalTitleSuffix", "isRenderModalTitleSuffix", "rowSelection", "disabledCheckbox", "tableLayoutConfig" ]), { title: D(), centered: e.centered ?? !0, onOk: _, onCancel: x } ), { default: k(() => [ e.renderHeader ? (g(), w(q(e.renderHeader), { key: 0 })) : U("", !0), h(Q, m(e.tableLayoutConfig || {}, { "selected-list": a.value, onClear: N, onDeleteItem: A }), { default: k(() => [ h(r($), m({ ref_key: "apTableRef", ref: i, scroll: { y: 450 }, style: { padding: "0px" }, columns: t.columns, request: O, "row-key": t.getRowKey, "row-selection": I.value, "data-source": C.value, "search-form": { sortable: !1, countPerRow: 2 } }, r(T)(e.apTableProps, "dataSource")), null, 16, ["columns", "row-key", "row-selection", "data-source"]) ]), _: 1 }, 16, ["selected-list"]) ]), _: 1 }, 16, ["open", "title", "centered"])); } }); export { ue as default };