UNPKG

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>

101 lines (100 loc) 4 kB
import "../../../../utils/index.mjs"; import { ElMessage as S } from "element-plus"; import { EditPen as w, Delete as x, View as L } from "@element-plus/icons-vue"; import q from "../../../dialog/src/dialog.mjs"; import { COLUMN_TYPE_FIELDS as A } from "../props.mjs"; import { useLocale as F } from "../../../../hooks/useLocale.mjs"; import { ref as m, getCurrentInstance as H, markRaw as y, computed as M } from "vue"; import { isFunction as b, isObject as O } from "../../../../utils/is.mjs"; function J(e, v, s) { const { t: r } = F(), u = m({}), C = m(!1), h = m(!1), { proxy: c } = H(), k = m("add"), D = () => { const l = c.$refs.zTableRef; l.clearSelection(), l.clearSort(), l.clearFilter(), s(); }, $ = () => { var l, i, a; return { label: ((l = e.edit) == null ? void 0 : l.referenceLabel) || r("common.edit"), type: "primary", link: !0, icon: y(w), disabled: (i = e.edit) == null ? void 0 : i.referenceDisabled, hide: (a = e.edit) == null ? void 0 : a.referenceHide, onClick: ({ row: t }) => { u.value = t, k.value = "edit", C.value = !0; } }; }, g = () => { var l, i, a; return { label: ((l = e.delete) == null ? void 0 : l.referenceLabel) || r("common.delete"), type: "danger", link: !0, icon: y(x), disabled: (i = e.delete) == null ? void 0 : i.referenceDisabled, hide: (a = e.delete) == null ? void 0 : a.referenceHide, onClick: ({ row: t }) => { var z; if (u.value = t, b(e.delete) && e.delete({ row: t, tableRef: c.$refs.zTableRef, getTableData: s }), (z = e.request) != null && z.deleteApi) { const n = O(e.delete) ? e.delete : {}; q({ type: "danger", ...n, message: b(n.message) ? n.message({ row: t }) : r("crud.deleteTip"), onConfirm: b(n.onConfirm) ? ({ done: R, confirmButtonLoading: f }) => { var d; return (d = n.onConfirm) == null ? void 0 : d.call(n, { done: R, confirmButtonLoading: f, row: t, tableRef: c.$refs.zTableRef, getTableData: s }); } : async ({ done: R, confirmButtonLoading: f }) => { var o, T; const d = e.dataKey; f.value = !0; try { await ((T = (o = e.request) == null ? void 0 : o.deleteApi) == null ? void 0 : T.call(o, { [d]: t[d], row: t })), f.value = !1, R(), S.success(r("common.success")), D(); } catch { } f.value = !1; } }); } v("operate-delete", { row: t, tableRef: c.$refs.zTableRef, getTableData: s }); } }; }, E = () => { var l, i, a; return { label: ((l = e.detail) == null ? void 0 : l.referenceLabel) || r("common.view"), type: "primary", link: !0, icon: y(L), disabled: (i = e.detail) == null ? void 0 : i.referenceDisabled, hide: (a = e.detail) == null ? void 0 : a.referenceHide, onClick: ({ row: t }) => { if (b(e.detail) && e.detail({ row: t, tableRef: c.$refs.zTableRef }), e.onOperateView) { v("operate-view", { row: t, tableRef: c.$refs.zTableRef }); return; } u.value = t, h.value = !0; } }; }; return { tableColumns: M(() => { var i; const l = ((i = e.columns) == null ? void 0 : i.filter((a) => A.some((t) => a[t]))) || []; if (e.action && (e.detail !== !1 || e.edit !== !1 || e.delete !== !1)) { const a = [e.detail !== !1 && E(), e.edit !== !1 && $(), e.delete !== !1 && g()].filter((t) => t); return l.concat([ { type: "button", label: r("table.action"), fixed: "right", width: a.length * 60, buttons: a } ]); } return l; }), isShowDialog: C, rowData: u, currentMode: k, isShowDrawer: h, refreshAfterRequest: D }; } export { J as useTableColumns }; //# sourceMappingURL=useTableColumns.mjs.map