ideaz-element
Version:
<p align="center"> <a href="" target="_blank" rel="noopener noreferrer"> <img src="./docs/public/logo.svg" alt="Ideaz Element" width="180" style="width: 180px;" /> </a> </p>
89 lines (88 loc) • 4.1 kB
JavaScript
import "../../../../utils/index.mjs";
import "../../../../node_modules/.pnpm/lodash-unified@1.0.3_@types_lodash-es@4.17.12_lodash-es@4.17.21_lodash@4.17.21/node_modules/lodash-unified/import.mjs";
import F from "../../../dialog/src/dialog.mjs";
import { ref as y, watch as O, markRaw as S } from "vue";
import { useLocale as T } from "../../../../hooks/useLocale.mjs";
import { isObject as f, isFunction as m } from "../../../../utils/is.mjs";
import P from "../../../../node_modules/.pnpm/lodash-es@4.17.21/node_modules/lodash-es/isEqual.mjs";
import { uid as b } from "../../../../utils/uid.mjs";
function C(e, s = !1) {
for (const u in e)
if (u.endsWith("Prop")) {
const o = u.slice(0, -4);
Object.hasOwnProperty.call(e, o) && (s ? e[o] = e[u] : e[u] = e[o]);
}
return e;
}
function B(e, s, u) {
const o = y(f(e.editable) && e.editable.type || "single"), d = y(), v = y([]), { t: c } = T(), { editable: _ } = e, R = (t) => u.value.length ? Object.keys(u.value[0]).map((r) => `tableData.${t}.${r}`) : [], g = () => ({
label: c("common.edit"),
type: "primary",
link: !0,
hide: ({ row: t }) => t.__isEdit || o.value === "multiple",
onClick: ({ row: t, $index: r, column: i }) => {
var n, a;
f(e.editable) && m((n = e.editable) == null ? void 0 : n.onEdit) ? (a = e.editable) == null || a.onEdit({ row: t, $index: r, column: i, formRef: d.value }) : (t.__isEdit = !0, s("update:data", u.value));
}
}), h = () => ({
label: c("common.save"),
type: "primary",
link: !0,
hide: ({ row: t }) => !t.__isEdit || o.value === "multiple",
onClick: ({ row: t, $index: r, column: i }) => {
var n, a;
d.value && (f(e.editable) && m((n = e.editable) == null ? void 0 : n.onSave) ? (a = e.editable) == null || a.onSave({ row: t, $index: r, column: i, formRef: d.value }) : d.value.validateField && d.value.validateField(R(r), (l) => {
l && (C(t), t.__isEdit = !1, s("update:data", u.value));
}));
}
}), E = () => ({
label: c("common.cancel"),
type: "primary",
link: !0,
hide: ({ row: t }) => !t.__isEdit || o.value === "multiple",
onClick: ({ row: t, $index: r, column: i }) => {
var n, a;
f(e.editable) && m((n = e.editable) == null ? void 0 : n.onCancel) ? (a = e.editable) == null || a.onCancel({ row: t, $index: r, column: i, formRef: d.value }) : (C(t, !0), t.__isEdit = !1, s("update:data", u.value));
}
}), k = () => ({
label: c("common.delete"),
type: "primary",
link: !0,
onClick: ({ row: t, $index: r, column: i }) => {
var a;
const n = () => {
var l, p;
f(e.editable) && m((l = e.editable) == null ? void 0 : l.onDelete) ? (p = e.editable) == null || p.onDelete({ row: t, $index: r, column: i, formRef: d.value }) : (u.value.splice(r, 1), s("update:data", u.value));
};
f(e.editable) && ((a = e.editable) != null && a.deleteConfirm) ? F({
type: "warning",
title: c("dialog.tip"),
message: c("table.deleteTip"),
onConfirm: ({ done: l }) => {
l(), n();
}
}) : n();
}
});
return O(() => e.columns, (t, r) => {
var n, a;
if (P(t, r))
return;
const i = e.columns.map((l) => l.type === "sort" ? { width: 48, ...l, __uid: b() } : f(l.component) ? { ...l, __uid: b(), component: S(l.component) } : { ...l, __uid: b() });
_ && i.length > 0 && ((n = i[i.length - 1]) == null ? void 0 : n.type) !== "button" ? v.value = i.concat({
type: "button",
__uid: b(),
label: c("table.action"),
buttons: [
g(),
h(),
E(),
k()
]
}) : _ && i.length > 0 && ((a = i[i.length - 1]) == null ? void 0 : a.type) === "button" ? v.value = i.map((l) => (l.type === "button" && m(l.buttons) && (l.buttons = l.buttons({ renderEdit: g(), renderSave: h(), renderCancel: E(), renderDelete: k() }, u)), l)) : v.value = i;
}, { immediate: !0, deep: !0 }), { columns: v, zTableFormRef: d };
}
export {
B as useEditableColumns
};
//# sourceMappingURL=useEditableColumns.mjs.map