UNPKG

@schema-render/search-table-react

Version:
113 lines (110 loc) 3.99 kB
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime"; import { DownOutlined } from "@ant-design/icons"; import { utils } from "@schema-render/core-react"; import { cij } from "@schema-render/form-render-react"; import { Button, Dropdown, Popconfirm } from "antd"; import { Fragment } from "react"; import ButtonLoading from "../../../components/ButtonLoading"; const { isArray, isString, omit } = utils; const dropdownCls = cij` background-color: #fff; border-radius: 8px; box-shadow: 0 4px 12px 0 #ececec; min-width: 70px; padding: 6px; > * { display: block; width: 100%; height: auto !important; padding: 3px 6px !important; &:hover { background: #f6f6f6 !important; } } `; /** * 创建「操作栏」按钮 */ export function createActionItem(item, index) { const { text, confirmAgain, confirmProps, onClick, ...restItem } = item; const content = isString(text) ? /*#__PURE__*/ _jsx(ButtonLoading, { type: "link", size: "small", ...omit(restItem, 'isShow'), onClick: (e)=>!confirmAgain && (onClick === null || onClick === void 0 ? void 0 : onClick(e)), children: text }, index) : text; // 增加二次确认 if (confirmAgain) { return /*#__PURE__*/ _jsx(Popconfirm, { title: "温馨提示", description: "请二次确认您的操作!", ...confirmProps, onConfirm: onClick, children: content }, index); } return content; } /** * 创建 “操作栏” 按钮组 */ export function createActions({ record, index, actionItems, actionItemsCount, actionItemsDropdownProps, locale }) { const items = actionItems === null || actionItems === void 0 ? void 0 : actionItems(record, index); if (!isArray(items)) { return null; } // 可展示项 const displayableItems = items.filter((item)=>{ return item.isShow !== false; }); // 最后渲染的内容 let contents; if (displayableItems.length > actionItemsCount) { const displayedItems = []; const dropdownItems = []; displayableItems.forEach((item, i)=>{ /** * 显示个数减一,以保证“更多”按钮对齐 */ if (i < actionItemsCount - 1) { displayedItems.push(item); } else { dropdownItems.push(createActionItem(item, i)); } }); return /*#__PURE__*/ _jsxs(_Fragment, { children: [ displayedItems.map((item, i)=>createActionItem(item, i)), /*#__PURE__*/ _jsx(Dropdown, { placement: "bottomRight", ...actionItemsDropdownProps, dropdownRender: ()=>/*#__PURE__*/ _jsx("div", { className: dropdownCls, children: dropdownItems.map((label, i)=>/*#__PURE__*/ _jsx(Fragment, { children: label }, i)) }), children: /*#__PURE__*/ _jsxs(Button, { type: "link", size: "small", style: { gap: 2, display: 'inline-flex', alignItems: 'center' }, children: [ locale.SearchTable.more, " ", /*#__PURE__*/ _jsx(DownOutlined, { style: { margin: 0 } }) ] }) }) ] }); } else { contents = displayableItems.map((item, i)=>createActionItem(item, i)); } return contents; }