@aplus-frontend/ui
Version:
249 lines (248 loc) • 7.71 kB
JavaScript
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 { transformTableParams as z } from "@aplus-frontend/utils";
import { cloneDeep as W, omit as T } from "lodash-unified";
import { ApTable as J } from "../../ap-table/index.mjs";
import "../../config-provider/index.mjs";
import { AsyncOpenResultError as y } from "./interface.mjs";
import "./modal-title.vue.mjs";
import Q from "./style/index.mjs";
import "./table-layout/index.vue.mjs";
import { useNamespace as X } from "../../config-provider/hooks/use-namespace.mjs";
import { useLocale as Y } from "../../config-provider/hooks/use-locale.mjs";
import Z from "./modal-title.vue2.mjs";
import ee from "./table-layout/index.vue2.mjs";
const ye = /* @__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: [Object, 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, i = d(!1), v = d({}), u = d(null), a = d([]), b = d();
let f = null, c = null;
const { b: K } = X("ap-table-modal"), I = Q("ap-table-modal"), { t: C } = Y(), O = async (t = [], o = {}) => {
switch (a.value = [...t], i.value = !0, v.value = o?.extraParams, b.value = o.apTableDataSources || e.apTableProps?.dataSource, o.refreshMode || "reset") {
case "reset":
u.value?.reset();
break;
case "submit":
u.value?.submit();
break;
case "none":
break;
}
return new Promise((n, l) => {
f = n, c = (s) => l("Ignored Reject: " + s);
});
}, x = () => {
i.value = !1, f = null, c?.(y.ModalCancel), c = null;
}, _ = async (t) => {
t = z({
...t,
...v.value
});
const o = e.api, { records: n, total: l } = await o(t);
return {
data: n,
total: l
};
}, N = async () => {
if (a.value.length > e.maxCount) {
c?.(y.ExceedMaxCount);
return;
}
if (e.getRowKey) {
const t = W(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 {
c?.(y.NotFineGetRowKey);
return;
}
i.value = !1;
}, D = 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(
C("ap.apTableModal.messageMaxCount", {
maxCount: e.maxCount
})
);
return;
}
const l = u.value?.dataSource;
if (o) {
const s = r(l).filter((p) => !a.value.some((j) => t(j) === t(p)));
a.value = a.value.concat(s);
} else
a.value = a.value?.filter((s) => !l.some((p) => t(p) === t(s)));
},
onSelect(o, n) {
if (n) {
if (a.value.length >= e.maxCount) {
R.warning(
C("ap.apTableModal.messageMaxCount", {
maxCount: e.maxCount
})
);
return;
}
e.rowSelection?.type === "radio" ? a.value = [o] : a.value.push(o);
} else {
const l = a.value.findIndex(
(s) => t(o) === t(s)
);
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 || {}
};
}), L = () => e.isRenderModalTitleSuffix ? H(
Z,
{
title: e.title,
count: a.value.length || 0,
maxCount: e.maxCount
},
{
default: e.renderModalTitleSuffix ?? void 0
}
) : e.title, A = () => u.value, F = () => {
a.value = [];
}, $ = (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: O,
close: x,
getApTableInstance: A
}), (t, o) => (g(), w(r(V), m(
{
open: i.value,
"onUpdate:open": o[0] || (o[0] = (n) => i.value = n)
},
r(T)(e, [
"api",
"getRowKey",
"centered",
"apTableProps",
"onOk",
"maxCount",
"title",
"renderModalTitleSuffix",
"isRenderModalTitleSuffix",
"rowSelection",
"disabledCheckbox",
"tableLayoutConfig"
]),
{
title: L(),
centered: e.centered ?? !0,
"wrap-class-name": `${r(K)()} ${r(I)}`,
onOk: N,
onCancel: x
}
), {
default: k(() => [
e.renderHeader ? (g(), w(q(e.renderHeader), { key: 0 })) : U("", !0),
h(ee, m(e.tableLayoutConfig || {}, {
"selected-list": a.value,
onClear: F,
onDeleteItem: $
}), {
default: k(() => [
h(r(J), m({
ref_key: "apTableRef",
ref: u,
scroll: { y: 450 },
style: { padding: "0px" },
columns: t.columns,
request: _,
"row-key": t.getRowKey,
"row-selection": D.value,
"data-source": b.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", "wrap-class-name"]));
}
});
export {
ye as default
};