diff --git a/src/components/Common/CommonComponent/index.js b/src/components/Common/CommonComponent/index.js index 98b755a..cf789d6 100644 --- a/src/components/Common/CommonComponent/index.js +++ b/src/components/Common/CommonComponent/index.js @@ -3,6 +3,7 @@ import React, { Component, createRef } from "react"; import reactComponentDebounce from "@/components/Common/ReactDebounce"; import * as commonFunc from "@/components/Common//commonFunc"; /* 通用单据方法 */ /* 通用单据方法 */ // import '@ant-design/compatible/assets/index.css'; +import InstructSetSetting from "@/components/Common/InstructSetSetting" import { InputNumber, Checkbox, @@ -32,6 +33,7 @@ import { FileOutlined, RightOutlined, PlaySquareOutlined, + EditOutlined, } from "@ant-design/icons"; import * as commonUtils from "@/utils/utils"; import styles from "@/index.less"; @@ -1840,6 +1842,15 @@ export default class CommonComponent extends Component { ), rows: commonUtils.isNotEmptyNumber(this.props.showConfig.iRowValue) ? this.props.showConfig.iRowValue : 1, }; + + if (this.props.showConfig.sName.toLowerCase().includes('instruct')) { + obj.suffix = ( + + + + ); + } + if (this.props.readOnly) { obj.readOnly = "readOnly"; } else { @@ -2081,6 +2092,15 @@ export default class CommonComponent extends Component { "" ), }; + + if (this.props.showConfig.sName.toLowerCase().includes('instruct')) { + obj.suffix = ( + + + + ); + } + if (this.props.readOnly) { obj.readOnly = "readOnly"; } else { @@ -3325,6 +3345,22 @@ export default class CommonComponent extends Component { } }; + // 编辑指令集 + handleEditInstruct = () => { + this.setState({ + instructSetSettingProps: { + ...this.props, + ...this.state, + instructSetSettingVisible: true, + onSaveData: (value) => { + this.handleSelectOptionEvent(value); + this.setState({ instructSetSettingProps: {} }); + }, + onCancelInstructSetSettingModal: () => this.setState({ instructSetSettingProps: {} }), + } + }); + } + handlePreviewImage = (e, dataUrl) => { e.stopPropagation(); this.props.onPreviewImage(e, dataUrl); @@ -3743,6 +3779,7 @@ export default class CommonComponent extends Component {
{commonAssembly}
+ ); } diff --git a/src/components/Common/CommonTable/index.js b/src/components/Common/CommonTable/index.js index 4891d6a..d314b6e 100644 --- a/src/components/Common/CommonTable/index.js +++ b/src/components/Common/CommonTable/index.js @@ -288,7 +288,10 @@ class CommonTableRc extends React.Component { window[`${this.tableId}FieldPopupModal`] = this.handleFieldPopupModal; } - document.addEventListener("mouseover", this.handleLastTdMouseOver); + document.addEventListener('mouseover', this.handleLastTdMouseOver); + + // 监听鼠标右击事件 + this.mydiv.addEventListener('contextmenu', this.handleContextMenu); } componentDidUpdate() { @@ -423,8 +426,8 @@ class CommonTableRc extends React.Component { this.computedTableHeight(); this.forceUpdate(); }); - document.removeEventListener("mouseover", this.handleLastTdMouseOver); - + document.removeEventListener('mouseover', this.handleLastTdMouseOver); + this.mydiv.removeEventListener('contextmenu', this.handleContextMenu); if (this.tableId && window[`${this.tableId}FieldPopupModal`]) { delete window[`${this.tableId}FieldPopupModal`]; } @@ -851,16 +854,29 @@ class CommonTableRc extends React.Component { }; }; - onRowMouseEnter = record => { - // recor - if ( - this.props.enabled && - this.props.tableBelone !== "list" && - commonUtils.isNotEmptyObject(this.props.tableProps) && - !this.beSelectDropdownOpen && - commonUtils.isEmptyObject(this.props.tableProps.rowSelection) && - this.state.currentHoverSid !== record.sId - ) { + handleContextMenu = (event) => { + // 判断右键位置是否有选中文本 + if (!window.getSelection().toString()) { + const { target } = event; + const { tagName } = target; + const oDiv = { + 'span': target.parentNode, + 'td': target.childNodes[0].childNodes[0], + 'div': target.getAttribute('data-name') ? target : target.childNodes[0], + }[tagName.toLowerCase()]; + + if (!oDiv) return; + if (!oDiv.getAttribute('data-control-name')?.includes('_Sum')) return; + // 阻止右键菜单 + event.preventDefault(); + this.setState({ totalDataNew: undefined, sumGroup: {} }); + } + + } + + onRowMouseEnter= (record) => { // recor + if (this.props.enabled && this.props.tableBelone !== 'list' && commonUtils.isNotEmptyObject(this.props.tableProps) && + !this.beSelectDropdownOpen && commonUtils.isEmptyObject(this.props.tableProps.rowSelection) && this.state.currentHoverSid !== record.sId) { if (this.timerSelectRowChange) { clearTimeout(this.timerSelectRowChange); } @@ -887,6 +903,8 @@ class CommonTableRc extends React.Component { /** 行选择 */ onRowClick = (record, index, type, name, tabType) => { + if (this.handleCellClick(record)) return; + if (this.stopRowClick) { this.stopRowClick = false; return; @@ -4861,6 +4879,66 @@ class CommonTableRc extends React.Component { }); }; + handleCellClick = (record) => { + const { enabled } = this.props; + if (enabled) return false; + + const { target } = event; + const { tagName } = target; + const oDiv = { + 'span': target.parentNode, + 'td': target.childNodes[0].childNodes[0], + 'div': target.getAttribute('data-name') ? target : target.childNodes[0], + }[tagName.toLowerCase()]; + + if (!oDiv || window.getSelection().toString()) return false; + + const [sName, sControlName] = [oDiv.getAttribute('data-name'), oDiv.getAttribute('data-control-name')]; + if (sControlName?.includes('_Sum')) { + const { sumGroup = {}, totalData = [{}], totalDataNew: totalDataNew0 = [{}] } = this.state; + const { dNetMoney, dNetPrice } = this.props.app.decimals; + sumGroup[sName] = sumGroup[sName] || []; + if (sumGroup[sName].includes(record[this.rowKey])) { + sumGroup[sName] = sumGroup[sName].filter(item => item !== record[this.rowKey]); + } else { + sumGroup[sName].push(record[this.rowKey]); + } + + let totalDataNew = [...totalDataNew0]; + if (sumGroup[sName].length) { + const sum = sumGroup[sName].reduce((pre, cur) => { + const curData = this.props.data.find(item => item[this.rowKey] === cur); + if (curData) { + let tempValue = 0; + if (sName.toLowerCase().endsWith('price')) { /* 价格 */ + tempValue = commonUtils.convertFixNum(commonUtils.convertFixNum(commonUtils.isNull(curData[sName], 0), dNetPrice) + commonUtils.convertFixNum(commonUtils.isNull(pre, 0), dNetPrice), dNetPrice); + } else { /* 金额 */ + tempValue = commonUtils.convertFixNum(commonUtils.convertFixNum(commonUtils.isNull(curData[sName], 0), dNetMoney) + commonUtils.convertFixNum(commonUtils.isNull(pre, 0), dNetMoney), dNetMoney); + } + return tempValue; + } + return pre; + }, 0); + + totalDataNew = [{ ...totalData[0], ...totalDataNew[0], [sName]: sum }]; + } else { + totalDataNew[0][sName] = totalData[0][sName]; + } + + this.setState({ sumGroup, totalDataNew }); + return true; + } + return false; + } + + handleGetSumStyle = (sName, index) => { + const { data = [] } = this.props; + const { sumGroup = {} } = this.state; + const sumList = sumGroup[sName] || []; + const record = data[index]; + return sumList.includes(record[this.rowKey]) ? " tableSumColor" : ""; + } + /* 点击图片预览 */ handlePreviewImage = (e, dataUrlArr) => { e.stopPropagation(); /* 阻止父级穿透 */ @@ -5106,12 +5184,12 @@ class CommonTableRc extends React.Component { }; }; - genFooter = () => { - const { tableColumn, totalData, totalData1 } = this.state; - const { dNetMoney, dNetPrice } = this.props.app.decimals; - const sModelsType = - commonUtils.isNotEmptyObject(this.props) && commonUtils.isNotEmptyObject(this.props.app) ? this.props.app.currentPane.sModelsType : ""; - const sumset = commonFunc.showMessage(this.props.app.commonConst, "sumSet") || "合计"; + genFooter= () => { + const { tableColumn, totalData: totalData0, totalDataNew, sumGroup = {}, totalData1 } = this.state; + const totalData = Object.keys(sumGroup).some(key => sumGroup[key]?.length) ? totalDataNew : totalData0; + const { dNetMoney, dNetPrice } = this.props.app.decimals; + const sModelsType = commonUtils.isNotEmptyObject(this.props) && commonUtils.isNotEmptyObject(this.props.app) ? this.props.app.currentPane.sModelsType : ''; + const sumset = commonFunc.showMessage(this.props.app.commonConst, 'sumSet') || '合计'; let colSpan = 0; if ((!totalData.length && !totalData1.length) || this.props.footer !== undefined) { @@ -7378,6 +7456,7 @@ class CommonTableRc extends React.Component { }); }); } + obj.props.className = `${obj.props.className || ''}${this.handleGetSumStyle(sName, index)}`; return obj; }; diff --git a/src/components/Common/CommonTable/index.less b/src/components/Common/CommonTable/index.less index 1e38d84..e2ecc5b 100644 --- a/src/components/Common/CommonTable/index.less +++ b/src/components/Common/CommonTable/index.less @@ -149,4 +149,8 @@ } } } + + .ant-table-bordered .virtuallist > table > .ant-table-tbody > tr > td.tableSumColor{ + background-color: #BEE7E9 !important; + } } diff --git a/src/components/Common/InstructSetSetting/index.js b/src/components/Common/InstructSetSetting/index.js new file mode 100644 index 0000000..7e9d206 --- /dev/null +++ b/src/components/Common/InstructSetSetting/index.js @@ -0,0 +1,102 @@ +import { useEffect, useState, useRef } from "react"; +import AntDraggableModal from "../AntdDraggableModal"; +import * as commonUtils from "@/utils/utils"; +import styles from "./index.less"; +import { Input, Button, Space } from "antd-v4"; + +const IFRAMEURL = "http://project.xlyprint.cn"; + +const InstructSetSetting = (props = {}) => { + const { instructSetSettingVisible } = props; + if (!instructSetSettingVisible) return ""; + + const { onCancelInstructSetSettingModal, showConfig, dataValue } = props; + const { showName, sName } = showConfig; + + const instructSet = commonUtils.convertStrToObj(dataValue, {}); + const { bConfigured } = instructSet; + + const [value, setValue] = useState(dataValue); + const [mode, setMode] = useState(bConfigured ? "config" : "edit"); + const iframeRef = useRef(null); + + const onReceiveData = event => { + // 验证来源 + if (event.origin !== IFRAMEURL) { + return; + } + + const { command, data } = event.data; + + if (command === "initData") { + if (!bConfigured) return; + iframeRef.current.contentWindow.postMessage( + { + command: "initData", + value: instructSet.data || [], + }, + IFRAMEURL + ); + return; + } + + let newValue = data; + if (props.name === "master" && sName === "sInstruct") { + newValue = { + opr: "btnhandle", + bConfigured: true, + data: newValue, + }; + } else if (sName === "sOnChangeInstruct") { + newValue = { + opr: "onchange", + bConfigured: true, + data: newValue, + }; + } + + props.onSaveData(JSON.stringify(newValue)) + // setMode("edit"); + // setValue(JSON.stringify(newValue)); + }; + + useEffect(() => { + // 监听来自 iframe 的消息 + window.addEventListener("message", onReceiveData); + return () => { + window.removeEventListener("message", onReceiveData); + }; + }, []); + + return ( + +
+ {mode === "edit" ? ( + <> + setValue(e.target.value)} /> + + + + + + ) : ( +