denwa-react-shared
Version:
91 lines (90 loc) • 2.1 kB
JavaScript
import { jsx as e } from "react/jsx-runtime";
import { Button as t, Dropdown as n, Table as r } from "antd";
import { LoadingOutlined as i } from "@ant-design/icons";
//#region src/shared/ui/base-table/index.tsx
var a = ({ viewText: a, actionsText: o, editText: s, deleteText: c, columns: l, serverPagination: u, scroll: d, loading: f, dataSource: p, isHiddenUpdate: m, isCanRead: h, isCanUpdate: g, isCanDelete: _, isFixedActions: v, onView: y, onDropdownClick: b, onEdit: x, onDelete: S, onShowSizeChange: C, ...w }) => {
let T = p?.map((e) => {
let t = {};
return Object.entries(e).forEach(([e, n]) => {
t[e] = n || "-";
}), t;
}), E = l ?? [], D = u ? {
current: u.page ?? 1,
pageSize: u.limit ?? 1,
total: u.count ?? 0,
pageSizeOptions: [
10,
20,
50,
100,
200,
500
],
showSizeChanger: !0,
showQuickJumper: !0,
onShowSizeChange: C,
showTotal: (e, t) => `${t[0]}-${t[1]} / ${e}`
} : null, O = (e) => {
"id" in e && typeof e.id == "string" && y(e.id);
}, k = (e) => {
"id" in e && typeof e.id == "string" && b(e.id);
}, A = [];
!m && g && A.push({
key: "edit",
label: /* @__PURE__ */ e(t, {
type: "link",
block: !0,
onClick: x,
children: s
})
}), _ && S && A.push({
key: "delete",
label: /* @__PURE__ */ e(t, {
type: "link",
block: !0,
danger: !0,
onClick: S,
children: c
})
});
let j = [...E, {
title: o,
key: "action",
width: 180,
fixed: v ? "right" : !1,
render: (r) => A.length ? /* @__PURE__ */ e(n.Button, {
disabled: !h,
menu: {
items: A,
onClick: () => k(r)
},
onClick: () => O(r),
children: a
}) : /* @__PURE__ */ e(t, {
disabled: !h,
onClick: () => O(r),
children: a
})
}];
return /* @__PURE__ */ e(r, {
...w,
className: "baseTable",
dataSource: T,
columns: j,
pagination: D ? {
...D,
size: "small"
} : !1,
scroll: {
...d,
y: "50vh",
scrollToFirstRowOnChange: !0
},
loading: {
spinning: !!f,
indicator: /* @__PURE__ */ e(i, { style: { fontSize: 36 } })
}
});
};
//#endregion
export { a as BaseTable };