import React from "react";
import { ActionRenderProps, ColumnConfig, DtmplData, LtmplConfig, CustomButton, CQueryConfig } from "../../tmpl/interface";
import TableUnits from "../table-util";
import SupportInputTypes from "../../tmpl/control-type-supportor";
import { Button, Popconfirm, Popover, Space, Tooltip, Form as AntdForm, theme, message, Dropdown } from "antd";
import { SortableHandle } from "react-sortable-hoc";
import {
AlignLeftOutlined, CopyOutlined, DeleteOutlined,
EllipsisOutlined,
EyeInvisibleOutlined,
EyeOutlined,
FormOutlined,
KeyOutlined,
MenuOutlined, QuestionCircleOutlined, PlaySquareOutlined,
SettingOutlined, UpSquareFilled, DownSquareFilled, AlignCenterOutlined,
EditOutlined, PlusOutlined
} from "@ant-design/icons";
import ActionUtils from "../../controls/action/utils";
import ViewButton from "../../detail/button/view-button";
import EditButton from "../../detail/button/edit-button";
import InlineEditButton from "../../detail/button/inline-edit-button";
import HcserviceV3 from "../../tmpl/hcservice-v3";
import Action from "../../controls/action";
import CquickButton from "../../controls/cquery/cquick-button";
import { ViewControl } from "../../index";
import NewinFileView from "../../controls/file-view/newin-file-view";
import { EntryControl } from "../../index";
import TmplConfigAnalysis from "../../tmpl/tmpl-config-analysis";
import Icon from "../../icon/aliIcon";
import SelectCodeExport from "../../controls/file-export/select-code-export";
import "./index.less";
const FormItem = AntdForm.Item;
// 负责提取 token
const ThemeToken = (props) => {
const { token } = theme.useToken();
return props.children(token); // 使用 render props 模式
};
interface ColumnBuilderProps extends ActionRenderProps {
ltmplConfig: LtmplConfig,
hiddenColIds?: string[],
hiddenRowCodes?: string[],
sortedColConfigs?: ColumnConfig[],
unHiden?: () => any,
onHide?: (code: string) => any,
operatable?: boolean,
mainCode?: string,
criteriaData?: object,
actTableDoSearch?: (data: object) => void,
columnResize?: { [key: string]: number }
}
interface ReportColumnBuilderProps {
columnConfigs: ColumnConfig[],
hiddenColIds?: string[],
translate: (...strs: string[]) => string;
leftFixedCols: number,
hiddenRowCodes?: string[],
unHiden?: () => any,
onHide?: (code: string) => any,
tableLayout?: "auto" | "fixed"; // 表格布局(自适应列宽/固定列宽)
}
export default {
buildTableColumns(props: ColumnBuilderProps) {
const {
ltmplConfig,
hiddenColIds,
hiddenRowCodes,
sortedColConfigs, unHiden,
onHide, translate,
sortColumns, serverKey,
editings, mainCode, criteriaData, actTableDoSearch, showView,
columnResize, doRowJump
} = props;
const { primaryColumn, secondColumn, primaryColumnLabel } = ltmplConfig.extDisplayConfig || {};
const fieldJumps = ltmplConfig.fieldJumps || [];
let tableColumns = [];
let s = 0;
let colConfigs = sortedColConfigs ? sortedColConfigs : ltmplConfig.columns;
let buttons = ltmplConfig.buttons || [];
let currentDataColIndex = 0;
colConfigs.forEach((item) => {
let column = {};
if (hiddenColIds && hiddenColIds.includes(item.originalId)) {
return
} else {
if (item.columnGroupName) { // 表头分组功能实现
const groupIndex = tableColumns.findIndex(r => r.children?.length && r.title === item.columnGroupName);
if (groupIndex !== -1) {
tableColumns[groupIndex].children.push(column);
} else {
tableColumns.push({ title: item.columnGroupName, align: "center", children: [column] });
}
} else {
tableColumns.push(column);
}
}
let title1 = translate("${" + item.title + "}");
column["title"] = item.tip ? <>{title1}
} /> > : title1;
column["dataIndex"] = item.id;
column["key"] = item.id;
if (item["colWidth"]) column["width"] = item["colWidth"];
if (item["statColType"]) column["statColType"] = item["statColType"];
if (item["aggFunc"]) column["cal"] = item["aggFunc"];
if (item["order"]) column["order"] = Number(item["order"]);
// column['ellipsis']= true;
s++;
let itemType = SupportInputTypes.getSupportControlType(item);
if (s < 12 && item.title != "操作" && item.title != "序号") {
if (hiddenColIds.includes("10000")) {
const order = this.handleColumnOrder(column["dataIndex"], sortColumns);
if (item.sortable) {
TableUnits.sort(column, itemType, order);
} else if (item.pageSortable) {
column["sorter"] = (a, b) => {
let aVal = a[column["dataIndex"]];
let bVal = b[column["dataIndex"]];
if (Array.isArray(aVal)) aVal = aVal[0];
if (Array.isArray(bVal)) bVal = bVal[0];
if (aVal?.includes("@R@")) aVal = aVal.split("@R@")[1];
if (bVal?.includes("@R@")) bVal = bVal.split("@R@")[1];
// 判断是否为字符串数字
const numA = Number(aVal);
const numB = Number(bVal);
const isNumeric = aVal && bVal && !isNaN(numA) && !isNaN(numB);
return isNumeric ? numA - numB : aVal?.localeCompare(bVal);
};
column["showSorterTooltip"] = false;
column["sortIcon"] = ({ sortOrder }) =>
{(token) =>
}
}
}
}
//特殊列处理
//序号
if (item.title === "序号") {
column["width"] = item.colWidth ? item.colWidth : 50;
column["title"] = translate("${序号}");
column["align"] = item.valueAlign ? item.valueAlign : "center";
column["render"] = (text, record, index) => ;
item["sorter"] = undefined;
} else if (item.id == "10000") {
this.setSortProps(column, item, translate);
} else if (item.id == "20000") {
this.setHiddenRecordOpt(column, hiddenRowCodes, unHiden, onHide, translate);
} else if (item.title === "操作" && props.operatable) {
column["操作"] = "1";
column["fixed"] = "right";
column["align"] = "left";
column["width"] = item.colWidth ? item.colWidth : 160;
if (ltmplConfig.tableLayout !== "auto") column["className"] = "opsColumn"; // 表格非自适应设置
column["title"] = <>{translate("${操作}")}>;
column["render"] = (text, record) => this.renderAction(props, record, ltmplConfig.tableLayout !== "auto");
} else {
currentDataColIndex++;
if (ltmplConfig.tableLayout !== "auto") column["className"] = "opsColumn"; // 表格非自适应设置
// column["title"] = item.tip? <>{title1}
// } /> >: title1;
column["width"] = item.colWidth ? item.colWidth : 160;
column["onCell"] = () => ({ style: { maxWidth: item.maxColWidth || undefined, minWidth: item.minColWidth || undefined } });
column["ellipsis"] = { showTitle: true };
column["align"] = item.valueAlign ? item.valueAlign : "left";
if (
ltmplConfig.leftFixedCols &&
ltmplConfig.leftFixedCols >= currentDataColIndex
) {
column["fixed"] = "left";
} else {
column["fixed"] = item.colFixed
? item.colFixed == "right"
? "right"
: "left"
: false;
}
const fieldJump = fieldJumps.find(r => r.appendMstrucId === item.mstrucId); // 当前列对应的跳转按钮配置
column["render"] = (text, record) => {
let detailParams = undefined;
if (showView && primaryColumn?.id === item.id) { // 首字段增加主题色显示/查看详情功能
if (buttons.includes("detail")) {
const classView = ltmplConfig.classViewConfigs?.find(r => ActionUtils.isShow(r.preposes, [record], undefined));
if (classView) {
detailParams = { code: record.code, dtmplSourceId: classView.id };
} else {
const isdetail = ActionUtils.isShow(ltmplConfig.buttonViewAction?.preposes, [record], undefined);
detailParams = isdetail ? { code: record.code } : undefined;
}
} else if (buttons.includes("customDetail")) {
detailParams = { code: record.code, toCustomPage: true };
}
}
// 跳转按钮是否可以跳转
const isShowFieldJump = fieldJump ? ActionUtils.isShow(fieldJump.preposes, [record], undefined) : false;
// 渲染内容
const renderView = ;
// 首字段渲染
const renderPrimaryColumn =
{
if (isShowFieldJump) {
doRowJump(fieldJump, record);
return;
}
detailParams && showView(detailParams);
}}>
{renderView}
{primaryColumnLabel?.id ?
:
""}
{/* 首字段操作按钮 */}
{this.renderColumnAction(props, record, "primary")}
;
// 次字段渲染
const renderSecondColumn =
{isShowFieldJump ?
doRowJump(fieldJump, record)}>{renderView}
: renderView}
{this.renderColumnAction(props, record, "secondary")}
;
return (editings.includes(record.code) || buttons.includes("multiRowEdit") ?
:
{primaryColumn?.id === item.id ? renderPrimaryColumn : secondColumn?.id === item.id ? renderSecondColumn :
(isShowFieldJump ?
doRowJump(fieldJump, record)}>{renderView}
: renderView)
}
);
};
}
// 表头列搜索
if (item.appendCriteria) {
const criteria = item.appendCriteria;
let searchVal = criteriaData?.[`c_${criteria.id}`];
column["filterDropdown"] = ({ setSelectedKeys, selectedKeys, confirm, clearFilters }) => ( e.stopPropagation()}>
{
const value = val?.target ? val.target.value : val;
setSelectedKeys(value ? [value] : []);
searchVal = value;
}}
/>
);
column["filteredValue"] = searchVal || undefined;
}
if (columnResize?.[item.id]) { // 本地缓存存在列宽配置
column["width"] = columnResize[item.id];
}
});
return tableColumns;
},
setSortProps(column: object, item: ColumnConfig, translate) {
column["title"] = (
{translate("${" + item.title + "}")}
);
column["width"] = 40;
column["dataIndex"] = item.id;
column["key"] = item.id;
column["className"] = "drag-visible";
column["render"] = () => ;
},
setHiddenRecordOpt(column: object, hiddenRowCodes, unHiden, onHide, translate) {
//隐藏
column["align"] = "center";
column["width"] = 40;
column["title"] = (
<>
{hiddenRowCodes.length > 0 ? (
}
type={"text"}
onClick={() => unHiden()}
>
) : (
""
)}
>
);
column["render"] = (text, record) => (
{" "}
}
type="dashed"
size="small"
onClick={() => onHide(record.code)}
>
);
},
buildReportTableColumns(props: ReportColumnBuilderProps) {
const {
columnConfigs, translate, leftFixedCols, hiddenColIds, hiddenRowCodes, unHiden, onHide, tableLayout
} = props;
let tableColumns = [];
let s = 0;
let colConfigs = columnConfigs;
let currentDataColIndex = 0;
colConfigs.forEach((item) => {
if (item.hidden || (hiddenColIds && hiddenColIds.includes(item.originalId))) {
return
}
let column = {};
if (item.upperColumnTitle) {
let parent;
tableColumns.forEach(t => {
if (t.title == item.upperColumnTitle && t.children) {
parent = t;
return
}
})
if (parent) {
parent.children.push(column);
} else {
tableColumns.push({ title: item.upperColumnTitle, children: [column] })
}
} else {
tableColumns.push(column);
}
let title1 = translate("${" + item.title + "}");
column["title"] = item.tip ? <>{title1}
} /> > : title1;
column["dataIndex"] = item.id;
column["key"] = item.id;
if (item["colWidth"]) column["width"] = item["colWidth"];
if (item["order"]) column["order"] = Number(item["order"]);
// column['ellipsis']= true;
s++;
//特殊列处理
//序号
if (item.title === "序号") {
column["width"] = item.colWidth ? item.colWidth : 50;
column["title"] = translate("${序号}");
column["align"] = item.valueAlign ? item.valueAlign : "center";
column["render"] = (text, record, index) =>
;
item["sorter"] = undefined;
} else if (item.id == "10000") {
this.setSortProps(column, item, translate);
} else if (item.id == "20000") {
this.setHiddenRecordOpt(column, hiddenRowCodes, unHiden, onHide, translate);
} else {
currentDataColIndex++;
if (tableLayout !== "auto") column["className"] = "opsColumn"; // 表格非自适应设置
//column["title"] = translate("${" + item.title + "}");
column["width"] = item.colWidth ? item.colWidth : 160;
column["onCell"] = () => ({ style: { maxWidth: item.maxColWidth || undefined, minWidth: item.minColWidth || undefined } });
column["ellipsis"] = { showTitle: true };
column["align"] = item.valueAlign ? item.valueAlign : "left";
if (
leftFixedCols &&
leftFixedCols >= currentDataColIndex
) {
column["fixed"] = "left";
} else {
column["fixed"] = item.colFixed
? item.colFixed == "right"
? "right"
: "left"
: false;
}
column["render"] = (text, record) => {
return (
);
};
}
});
// console.log("columns", tableColumns);
return tableColumns;
},
handleColumnOrder(columnId, sortColumns) {
//const sortColumns = this.props.criteriaData["sortColIds"];
if (!Array.isArray(sortColumns)) return undefined;
for (const column of sortColumns) {
const [key, sort] = column.split("_");
if (key === columnId) {
if (sort === "asc") return "ascend";
if (sort === "desc") return "descend";
continue;
}
}
return undefined;
},
renderColumnAction(props: ActionRenderProps, record: DtmplData, type: "primary" | "secondary") { // 主列/次列悬浮按钮渲染
const { ltmplConfig, serverKey, doRowAction, doRAction, doCustomButton, translate, readOnly } = props;
const { primaryColumnButtons, secondColumnButtons } = ltmplConfig;
const temButtons = type === "primary" ? primaryColumnButtons : secondColumnButtons;
if (readOnly || !temButtons?.length) {
return null;
}
const actionButtons: any[] = temButtons.map(item => {
switch (item.functionType) {
case "action": // 操作按钮
if (ActionUtils.isShow(item.preposes, [record], undefined)) {
return ;
} else {
return undefined;
}
case "raction": // 关系按钮
if (ActionUtils.isShow(item?.preposes, [record], undefined)) {
return ;
} else {
return undefined;
}
case "customButton": // 自由按钮
if (ActionUtils.isShow(item.preposes, [record], undefined)) {
return
} else {
return undefined;
};
case "fileExport": // 文件导出
if (ActionUtils.isShow(item.preposes, [record], undefined)) {
return ;
} else {
return undefined;
}
case "customExport": // 自定义导出
return undefined;
case "cQuery": // 关联查询
if (ActionUtils.isShow(item.preposes, [record], undefined)) {
const config: CQueryConfig = item;
return ;
} else {
return undefined;
}
default:
return undefined;
}
}).filter(Boolean);
return actionButtons?.length ? {actionButtons}
: undefined;
},
renderAction(props: ActionRenderProps, record: DtmplData, isWrap = true) { // 操作列按钮渲染
const { ltmplConfig, showView,
doEdit,
doRAction,
customEditable,
serverKey,
readOnly,
sourceId, translate, doCustomButton, doRowJump, blockMenuTreeDrawerOpen,
doRowAction, doDeleteByCode, editRowEdit, editings, cancelRowEdit, saveRowData, doDelModalOpen,
doView2D, doEdit2D, actTableDoSearch, doAuditView, doAuditEdit, doAddRaction
} = props;
const { buttons, builtInButtons, defShowRowActionCount, strongDeleteConfirmText, edit2DBtnTitle, view2DBtnTitle, deleteBtnTitle, copyMode, rowRactionAddConfigs } = ltmplConfig;
let actionButtons: any[] = [];
const isShowDetail = buttons.includes("detail") && showView && ActionUtils.isShow(ltmplConfig.buttonViewAction?.preposes, [record], undefined);
const isShowCustomDetail = buttons.includes("customDetail") && showView && ActionUtils.isShow(ltmplConfig.buttonViewAction?.preposes, [record], undefined);
if (isShowCustomDetail) { // 自定义详情
actionButtons.push(}
onClick={() => showView({ code: record.code, toCustomPage: true, })}
/>)
}
if (isShowDetail) { // 默认详情
actionButtons.push();
}
// 展开树行操作添加按钮
if (rowRactionAddConfigs?.length && doAddRaction && !readOnly) {
const temConfigs = rowRactionAddConfigs.filter(item => ActionUtils.isShow(item.addableActionConfig?.preposes, [record], undefined)); // 过滤前置条件
if (temConfigs?.length > 1) {
const temItems = temConfigs.map(item => ({ key: item.id, label: doAddRaction(item.id, record.code)}>
{item.title} }));
actionButtons.push(
}
/>
);
} else if (temConfigs[0]) {
const tItem = temConfigs[0];
actionButtons.push(
);
}
}
if (buttons.includes("dtmplEdit") && doEdit && !readOnly) {
(
actionButtons.push()
)
};
// 审计查看
if (buttons.includes("auditView") && doAuditView && !readOnly && ActionUtils.isShow(ltmplConfig.buttonAuditViewAction?.preposes, [record], undefined)) {
actionButtons.push();
};
// 审计编辑
if (buttons.includes("auditEdit") && doAuditEdit && !readOnly && ActionUtils.isShow(ltmplConfig.buttonAuditEditAction?.preposes, [record], undefined)) {
actionButtons.push();
};
// 2D图编辑
if (buttons.includes("edit2D") && doEdit2D && !readOnly) {
actionButtons.push((!edit2DBtnTitle || edit2DBtnTitle?.length < 4) ? :
)
}
// 2D图查看
if (buttons.includes("view2D") && doView2D && !readOnly) {
actionButtons.push((!view2DBtnTitle || view2DBtnTitle?.length < 4) ? :
)
}
// 行内编辑
if (buttons.includes("rowEdit") && !buttons.includes("multiRowEdit")) {
actionButtons.push();
}
if (builtInButtons?.includes("blockAuthMenuTree") && !readOnly) {
actionButtons.push(
}
onClick={() => blockMenuTreeDrawerOpen(record)
}
>)
}
if ((buttons.includes("dtmplCustomEdit") || customEditable) &&
doEdit &&
!readOnly &&
ActionUtils.isShow(
ltmplConfig.buttonEditAction?.preposes,
[record],
undefined
)) {
actionButtons.push(}
onClick={() =>
doEdit({
code: record.code,
mode: "update",
toCustomPage: true,
})
}
>)
}
if (buttons.includes("copy") && doEdit && !readOnly) {
actionButtons.push(
}
onClick={async () => {
//先复制
let toCustomPage = false;
if (buttons.includes("dtmplCustomEdit") || customEditable) {
toCustomPage = true;
}
if (copyMode === "editCopy") { // 修改后再复制
doEdit({ code: record.code, mode: "copy", toCustomPage });
} else {
let code = await HcserviceV3.doCopy(
serverKey,
sourceId,
record.code
); // 复制
if (code && copyMode !== "copyOnly") { // 先复制再编辑
doEdit({ code, mode: "update", toCustomPage });
} else if (code) { // 仅复制
message.success(translate("${复制成功}"));
actTableDoSearch(null);
}
}
}}
>
)
}
if (ltmplConfig.rowCustomButtons) {
ltmplConfig.rowCustomButtons.map((customButton) => {
if (ActionUtils.isShow(
customButton.preposes,
[record],
undefined
)) {
actionButtons.push(
)
};
})
}
if (ltmplConfig.ractions && !readOnly) {
ltmplConfig.ractions.map((raction) => {
if (ActionUtils.isShow(
raction?.preposes,
[record],
undefined
)) {
actionButtons.push(
);
}
})
}
if (!readOnly && ltmplConfig.rowActions?.length) {
ltmplConfig.rowActions.map((action) => {
actionButtons.push(
);
})
}
if (!!ltmplConfig.rowJumps?.length && !readOnly) {
ltmplConfig.rowJumps.map((jump) => {
if (ActionUtils.isShow(jump.preposes, [record], undefined)) {
actionButtons.push(
)
};
})
}
if (ltmplConfig.rowCQuerys &&
ltmplConfig.rowCQuerys.length > 0 &&
!readOnly
) {
ltmplConfig.rowCQuerys.map((cquery) => {
if (ActionUtils.isShow(
cquery.preposes,
[record],
undefined
)) {
actionButtons.push(
)
};
})
}
if (ltmplConfig.rowFileButtons &&
ltmplConfig.rowFileButtons.length > 0) {
ltmplConfig.rowFileButtons.map((openFileButton) => {
let v = record[openFileButton.fieldId];
if (v) {
if (v instanceof Array) {
v = v[0];
}
if (v.includes("@R@") > 0) {
v = v.split("@R@")[1];
}
actionButtons.push(
);
}
})
}
if (buttons.includes("singleDelete") &&
!readOnly &&
ActionUtils.isShow(
ltmplConfig.buttonDeleteAction?.preposes,
[record],
undefined
)) {
actionButtons.push(
strongDeleteConfirmText ?
((!deleteBtnTitle || deleteBtnTitle?.length < 4) ?
:
)
:
doDeleteByCode(record)}
okText={translate("${确定}")}
cancelText={translate("${取消}")}
okType={"danger"}
>
{(!deleteBtnTitle || deleteBtnTitle?.length < 4) ?
:
} />}
)
}
let showButtons = [];
if (defShowRowActionCount <= 0 || defShowRowActionCount >= actionButtons.length) {
showButtons = actionButtons
} else {
showButtons = actionButtons.slice(0, defShowRowActionCount)
showButtons.push(
{actionButtons.slice(defShowRowActionCount, actionButtons.length)}
} title={"更多操作"} trigger="hover">
} shape="circle" >
);
}
return
{showButtons}
}
}
const DragHandle = SortableHandle(() => (
))