Commit c8d15790956dc21934b5f755eab7cf66285d2ea6

Authored by 陈鑫涛
2 parents 549cd80d 1ab4995c

Merge branch 'main' of http://git.xlyprint.cn/zhangz/xlyUmi into main

# Conflicts:
#	src/components/Common/CommonTable/index.js
src/components/Common/CommonComponent/index.js
... ... @@ -3,6 +3,7 @@ import React, { Component, createRef } from "react";
3 3 import reactComponentDebounce from "@/components/Common/ReactDebounce";
4 4 import * as commonFunc from "@/components/Common//commonFunc"; /* 通用单据方法 */ /* 通用单据方法 */
5 5 // import '@ant-design/compatible/assets/index.css';
  6 +import InstructSetSetting from "@/components/Common/InstructSetSetting"
6 7 import {
7 8 InputNumber,
8 9 Checkbox,
... ... @@ -32,6 +33,7 @@ import {
32 33 FileOutlined,
33 34 RightOutlined,
34 35 PlaySquareOutlined,
  36 + EditOutlined,
35 37 } from "@ant-design/icons";
36 38 import * as commonUtils from "@/utils/utils";
37 39 import styles from "@/index.less";
... ... @@ -1840,6 +1842,15 @@ export default class CommonComponent extends Component {
1840 1842 ),
1841 1843 rows: commonUtils.isNotEmptyNumber(this.props.showConfig.iRowValue) ? this.props.showConfig.iRowValue : 1,
1842 1844 };
  1845 +
  1846 + if (this.props.showConfig.sName.toLowerCase().includes('instruct')) {
  1847 + obj.suffix = (
  1848 + <span style={{ width: "8px" }} onClick={this.handleEditInstruct}>
  1849 + <EditOutlined style={{ color: "rgba(0,0,0,.85)" }} />
  1850 + </span>
  1851 + );
  1852 + }
  1853 +
1843 1854 if (this.props.readOnly) {
1844 1855 obj.readOnly = "readOnly";
1845 1856 } else {
... ... @@ -2081,6 +2092,15 @@ export default class CommonComponent extends Component {
2081 2092 ""
2082 2093 ),
2083 2094 };
  2095 +
  2096 + if (this.props.showConfig.sName.toLowerCase().includes('instruct')) {
  2097 + obj.suffix = (
  2098 + <span style={{ width: "8px" }} onClick={this.handleEditInstruct}>
  2099 + <EditOutlined style={{ color: "rgba(0,0,0,.85)" }} />
  2100 + </span>
  2101 + );
  2102 + }
  2103 +
2084 2104 if (this.props.readOnly) {
2085 2105 obj.readOnly = "readOnly";
2086 2106 } else {
... ... @@ -3325,6 +3345,22 @@ export default class CommonComponent extends Component {
3325 3345 }
3326 3346 };
3327 3347  
  3348 + // 编辑指令集
  3349 + handleEditInstruct = () => {
  3350 + this.setState({
  3351 + instructSetSettingProps: {
  3352 + ...this.props,
  3353 + ...this.state,
  3354 + instructSetSettingVisible: true,
  3355 + onSaveData: (value) => {
  3356 + this.handleSelectOptionEvent(value);
  3357 + this.setState({ instructSetSettingProps: {} });
  3358 + },
  3359 + onCancelInstructSetSettingModal: () => this.setState({ instructSetSettingProps: {} }),
  3360 + }
  3361 + });
  3362 + }
  3363 +
3328 3364 handlePreviewImage = (e, dataUrl) => {
3329 3365 e.stopPropagation();
3330 3366 this.props.onPreviewImage(e, dataUrl);
... ... @@ -3743,6 +3779,7 @@ export default class CommonComponent extends Component {
3743 3779 <div className={`${this.props.className} ${readonlyStyle} ${costomStyle}`} onClick={this.props.onCostomClick?.bind(this, showConfig)}>
3744 3780 {commonAssembly}
3745 3781 </div>
  3782 + <InstructSetSetting {...this.state.instructSetSettingProps} />
3746 3783 </div>
3747 3784 );
3748 3785 }
... ...
src/components/Common/CommonTable/index.js
... ... @@ -288,7 +288,10 @@ class CommonTableRc extends React.Component {
288 288 window[`${this.tableId}FieldPopupModal`] = this.handleFieldPopupModal;
289 289 }
290 290  
291   - document.addEventListener("mouseover", this.handleLastTdMouseOver);
  291 + document.addEventListener('mouseover', this.handleLastTdMouseOver);
  292 +
  293 + // 监听鼠标右击事件
  294 + this.mydiv.addEventListener('contextmenu', this.handleContextMenu);
292 295 }
293 296  
294 297 componentDidUpdate() {
... ... @@ -423,8 +426,8 @@ class CommonTableRc extends React.Component {
423 426 this.computedTableHeight();
424 427 this.forceUpdate();
425 428 });
426   - document.removeEventListener("mouseover", this.handleLastTdMouseOver);
427   -
  429 + document.removeEventListener('mouseover', this.handleLastTdMouseOver);
  430 + this.mydiv.removeEventListener('contextmenu', this.handleContextMenu);
428 431 if (this.tableId && window[`${this.tableId}FieldPopupModal`]) {
429 432 delete window[`${this.tableId}FieldPopupModal`];
430 433 }
... ... @@ -851,16 +854,29 @@ class CommonTableRc extends React.Component {
851 854 };
852 855 };
853 856  
854   - onRowMouseEnter = record => {
855   - // recor
856   - if (
857   - this.props.enabled &&
858   - this.props.tableBelone !== "list" &&
859   - commonUtils.isNotEmptyObject(this.props.tableProps) &&
860   - !this.beSelectDropdownOpen &&
861   - commonUtils.isEmptyObject(this.props.tableProps.rowSelection) &&
862   - this.state.currentHoverSid !== record.sId
863   - ) {
  857 + handleContextMenu = (event) => {
  858 + // 判断右键位置是否有选中文本
  859 + if (!window.getSelection().toString()) {
  860 + const { target } = event;
  861 + const { tagName } = target;
  862 + const oDiv = {
  863 + 'span': target.parentNode,
  864 + 'td': target.childNodes[0].childNodes[0],
  865 + 'div': target.getAttribute('data-name') ? target : target.childNodes[0],
  866 + }[tagName.toLowerCase()];
  867 +
  868 + if (!oDiv) return;
  869 + if (!oDiv.getAttribute('data-control-name')?.includes('_Sum')) return;
  870 + // 阻止右键菜单
  871 + event.preventDefault();
  872 + this.setState({ totalDataNew: undefined, sumGroup: {} });
  873 + }
  874 +
  875 + }
  876 +
  877 + onRowMouseEnter= (record) => { // recor
  878 + if (this.props.enabled && this.props.tableBelone !== 'list' && commonUtils.isNotEmptyObject(this.props.tableProps) &&
  879 + !this.beSelectDropdownOpen && commonUtils.isEmptyObject(this.props.tableProps.rowSelection) && this.state.currentHoverSid !== record.sId) {
864 880 if (this.timerSelectRowChange) {
865 881 clearTimeout(this.timerSelectRowChange);
866 882 }
... ... @@ -887,6 +903,8 @@ class CommonTableRc extends React.Component {
887 903  
888 904 /** 行选择 */
889 905 onRowClick = (record, index, type, name, tabType) => {
  906 + if (this.handleCellClick(record)) return;
  907 +
890 908 if (this.stopRowClick) {
891 909 this.stopRowClick = false;
892 910 return;
... ... @@ -4861,6 +4879,66 @@ class CommonTableRc extends React.Component {
4861 4879 });
4862 4880 };
4863 4881  
  4882 + handleCellClick = (record) => {
  4883 + const { enabled } = this.props;
  4884 + if (enabled) return false;
  4885 +
  4886 + const { target } = event;
  4887 + const { tagName } = target;
  4888 + const oDiv = {
  4889 + 'span': target.parentNode,
  4890 + 'td': target.childNodes[0].childNodes[0],
  4891 + 'div': target.getAttribute('data-name') ? target : target.childNodes[0],
  4892 + }[tagName.toLowerCase()];
  4893 +
  4894 + if (!oDiv || window.getSelection().toString()) return false;
  4895 +
  4896 + const [sName, sControlName] = [oDiv.getAttribute('data-name'), oDiv.getAttribute('data-control-name')];
  4897 + if (sControlName?.includes('_Sum')) {
  4898 + const { sumGroup = {}, totalData = [{}], totalDataNew: totalDataNew0 = [{}] } = this.state;
  4899 + const { dNetMoney, dNetPrice } = this.props.app.decimals;
  4900 + sumGroup[sName] = sumGroup[sName] || [];
  4901 + if (sumGroup[sName].includes(record[this.rowKey])) {
  4902 + sumGroup[sName] = sumGroup[sName].filter(item => item !== record[this.rowKey]);
  4903 + } else {
  4904 + sumGroup[sName].push(record[this.rowKey]);
  4905 + }
  4906 +
  4907 + let totalDataNew = [...totalDataNew0];
  4908 + if (sumGroup[sName].length) {
  4909 + const sum = sumGroup[sName].reduce((pre, cur) => {
  4910 + const curData = this.props.data.find(item => item[this.rowKey] === cur);
  4911 + if (curData) {
  4912 + let tempValue = 0;
  4913 + if (sName.toLowerCase().endsWith('price')) { /* 价格 */
  4914 + tempValue = commonUtils.convertFixNum(commonUtils.convertFixNum(commonUtils.isNull(curData[sName], 0), dNetPrice) + commonUtils.convertFixNum(commonUtils.isNull(pre, 0), dNetPrice), dNetPrice);
  4915 + } else { /* 金额 */
  4916 + tempValue = commonUtils.convertFixNum(commonUtils.convertFixNum(commonUtils.isNull(curData[sName], 0), dNetMoney) + commonUtils.convertFixNum(commonUtils.isNull(pre, 0), dNetMoney), dNetMoney);
  4917 + }
  4918 + return tempValue;
  4919 + }
  4920 + return pre;
  4921 + }, 0);
  4922 +
  4923 + totalDataNew = [{ ...totalData[0], ...totalDataNew[0], [sName]: sum }];
  4924 + } else {
  4925 + totalDataNew[0][sName] = totalData[0][sName];
  4926 + }
  4927 +
  4928 + this.setState({ sumGroup, totalDataNew });
  4929 + return true;
  4930 + }
  4931 + return false;
  4932 + }
  4933 +
  4934 + handleGetSumStyle = (sName, index) => {
  4935 + const { data = [] } = this.props;
  4936 + const { sumGroup = {} } = this.state;
  4937 + const sumList = sumGroup[sName] || [];
  4938 + const record = data[index];
  4939 + return sumList.includes(record[this.rowKey]) ? " tableSumColor" : "";
  4940 + }
  4941 +
4864 4942 /* 点击图片预览 */
4865 4943 handlePreviewImage = (e, dataUrlArr) => {
4866 4944 e.stopPropagation(); /* 阻止父级穿透 */
... ... @@ -5106,12 +5184,12 @@ class CommonTableRc extends React.Component {
5106 5184 };
5107 5185 };
5108 5186  
5109   - genFooter = () => {
5110   - const { tableColumn, totalData, totalData1 } = this.state;
5111   - const { dNetMoney, dNetPrice } = this.props.app.decimals;
5112   - const sModelsType =
5113   - commonUtils.isNotEmptyObject(this.props) && commonUtils.isNotEmptyObject(this.props.app) ? this.props.app.currentPane.sModelsType : "";
5114   - const sumset = commonFunc.showMessage(this.props.app.commonConst, "sumSet") || "合计";
  5187 + genFooter= () => {
  5188 + const { tableColumn, totalData: totalData0, totalDataNew, sumGroup = {}, totalData1 } = this.state;
  5189 + const totalData = Object.keys(sumGroup).some(key => sumGroup[key]?.length) ? totalDataNew : totalData0;
  5190 + const { dNetMoney, dNetPrice } = this.props.app.decimals;
  5191 + const sModelsType = commonUtils.isNotEmptyObject(this.props) && commonUtils.isNotEmptyObject(this.props.app) ? this.props.app.currentPane.sModelsType : '';
  5192 + const sumset = commonFunc.showMessage(this.props.app.commonConst, 'sumSet') || '合计';
5115 5193  
5116 5194 let colSpan = 0;
5117 5195 if ((!totalData.length && !totalData1.length) || this.props.footer !== undefined) {
... ... @@ -7378,6 +7456,7 @@ class CommonTableRc extends React.Component {
7378 7456 });
7379 7457 });
7380 7458 }
  7459 + obj.props.className = `${obj.props.className || ''}${this.handleGetSumStyle(sName, index)}`;
7381 7460 return obj;
7382 7461 };
7383 7462  
... ...
src/components/Common/CommonTable/index.less
... ... @@ -149,4 +149,8 @@
149 149 }
150 150 }
151 151 }
  152 +
  153 + .ant-table-bordered .virtuallist > table > .ant-table-tbody > tr > td.tableSumColor{
  154 + background-color: #BEE7E9 !important;
  155 + }
152 156 }
... ...
src/components/Common/InstructSetSetting/index.js 0 → 100644
  1 +import { useEffect, useState, useRef } from "react";
  2 +import AntDraggableModal from "../AntdDraggableModal";
  3 +import * as commonUtils from "@/utils/utils";
  4 +import styles from "./index.less";
  5 +import { Input, Button, Space } from "antd-v4";
  6 +
  7 +const IFRAMEURL = "http://project.xlyprint.cn";
  8 +
  9 +const InstructSetSetting = (props = {}) => {
  10 + const { instructSetSettingVisible } = props;
  11 + if (!instructSetSettingVisible) return "";
  12 +
  13 + const { onCancelInstructSetSettingModal, showConfig, dataValue } = props;
  14 + const { showName, sName } = showConfig;
  15 +
  16 + const instructSet = commonUtils.convertStrToObj(dataValue, {});
  17 + const { bConfigured } = instructSet;
  18 +
  19 + const [value, setValue] = useState(dataValue);
  20 + const [mode, setMode] = useState(bConfigured ? "config" : "edit");
  21 + const iframeRef = useRef(null);
  22 +
  23 + const onReceiveData = event => {
  24 + // 验证来源
  25 + if (event.origin !== IFRAMEURL) {
  26 + return;
  27 + }
  28 +
  29 + const { command, data } = event.data;
  30 +
  31 + if (command === "initData") {
  32 + if (!bConfigured) return;
  33 + iframeRef.current.contentWindow.postMessage(
  34 + {
  35 + command: "initData",
  36 + value: instructSet.data || [],
  37 + },
  38 + IFRAMEURL
  39 + );
  40 + return;
  41 + }
  42 +
  43 + let newValue = data;
  44 + if (props.name === "master" && sName === "sInstruct") {
  45 + newValue = {
  46 + opr: "btnhandle",
  47 + bConfigured: true,
  48 + data: newValue,
  49 + };
  50 + } else if (sName === "sOnChangeInstruct") {
  51 + newValue = {
  52 + opr: "onchange",
  53 + bConfigured: true,
  54 + data: newValue,
  55 + };
  56 + }
  57 +
  58 + props.onSaveData(JSON.stringify(newValue))
  59 + // setMode("edit");
  60 + // setValue(JSON.stringify(newValue));
  61 + };
  62 +
  63 + useEffect(() => {
  64 + // 监听来自 iframe 的消息
  65 + window.addEventListener("message", onReceiveData);
  66 + return () => {
  67 + window.removeEventListener("message", onReceiveData);
  68 + };
  69 + }, []);
  70 +
  71 + return (
  72 + <AntDraggableModal
  73 + title={showName}
  74 + visible={instructSetSettingVisible}
  75 + onCancel={onCancelInstructSetSettingModal}
  76 + width="100w"
  77 + height="100vh"
  78 + style={{ top: 0 }}
  79 + footer={null}
  80 + >
  81 + <div className={styles.contents}>
  82 + {mode === "edit" ? (
  83 + <>
  84 + <Input.TextArea rows={10} value={value} onChange={e => setValue(e.target.value)} />
  85 + <Space style={{ marginTop: 6, float: "right" }}>
  86 + <Button type="primary" onClick={() => props.onSaveData(value)}>
  87 + 保存
  88 + </Button>
  89 + <Button type="primary" onClick={() => setMode("config")}>
  90 + 切换配置模式
  91 + </Button>
  92 + </Space>
  93 + </>
  94 + ) : (
  95 + <iframe ref={iframeRef} src={`${IFRAMEURL}/InsSet/?parentDomain=${document.location.origin}`} width="100%" height="100%" frameBorder={0} />
  96 + )}
  97 + </div>
  98 + </AntDraggableModal>
  99 + );
  100 +};
  101 +
  102 +export default InstructSetSetting;
... ...
src/components/Common/InstructSetSetting/index.less 0 → 100644
  1 +.contents {
  2 + width: 100%;
  3 + height: calc(100vh - 65px);
  4 +}
0 5 \ No newline at end of file
... ...