Commit 1ab4995c07197a02d1c3d3f162a7ad535b6d062f
1 parent
4cb48e53
集成指令集配置页面;
Showing
3 changed files
with
143 additions
and
0 deletions
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"; |
| ... | ... | @@ -1822,6 +1824,15 @@ export default class CommonComponent extends Component { |
| 1822 | 1824 | ), |
| 1823 | 1825 | rows: commonUtils.isNotEmptyNumber(this.props.showConfig.iRowValue) ? this.props.showConfig.iRowValue : 1, |
| 1824 | 1826 | }; |
| 1827 | + | |
| 1828 | + if (this.props.showConfig.sName.toLowerCase().includes('instruct')) { | |
| 1829 | + obj.suffix = ( | |
| 1830 | + <span style={{ width: "8px" }} onClick={this.handleEditInstruct}> | |
| 1831 | + <EditOutlined style={{ color: "rgba(0,0,0,.85)" }} /> | |
| 1832 | + </span> | |
| 1833 | + ); | |
| 1834 | + } | |
| 1835 | + | |
| 1825 | 1836 | if (this.props.readOnly) { |
| 1826 | 1837 | obj.readOnly = "readOnly"; |
| 1827 | 1838 | } else { |
| ... | ... | @@ -2063,6 +2074,15 @@ export default class CommonComponent extends Component { |
| 2063 | 2074 | "" |
| 2064 | 2075 | ), |
| 2065 | 2076 | }; |
| 2077 | + | |
| 2078 | + if (this.props.showConfig.sName.toLowerCase().includes('instruct')) { | |
| 2079 | + obj.suffix = ( | |
| 2080 | + <span style={{ width: "8px" }} onClick={this.handleEditInstruct}> | |
| 2081 | + <EditOutlined style={{ color: "rgba(0,0,0,.85)" }} /> | |
| 2082 | + </span> | |
| 2083 | + ); | |
| 2084 | + } | |
| 2085 | + | |
| 2066 | 2086 | if (this.props.readOnly) { |
| 2067 | 2087 | obj.readOnly = "readOnly"; |
| 2068 | 2088 | } else { |
| ... | ... | @@ -3307,6 +3327,22 @@ export default class CommonComponent extends Component { |
| 3307 | 3327 | } |
| 3308 | 3328 | }; |
| 3309 | 3329 | |
| 3330 | + // 编辑指令集 | |
| 3331 | + handleEditInstruct = () => { | |
| 3332 | + this.setState({ | |
| 3333 | + instructSetSettingProps: { | |
| 3334 | + ...this.props, | |
| 3335 | + ...this.state, | |
| 3336 | + instructSetSettingVisible: true, | |
| 3337 | + onSaveData: (value) => { | |
| 3338 | + this.handleSelectOptionEvent(value); | |
| 3339 | + this.setState({ instructSetSettingProps: {} }); | |
| 3340 | + }, | |
| 3341 | + onCancelInstructSetSettingModal: () => this.setState({ instructSetSettingProps: {} }), | |
| 3342 | + } | |
| 3343 | + }); | |
| 3344 | + } | |
| 3345 | + | |
| 3310 | 3346 | handlePreviewImage = (e, dataUrl) => { |
| 3311 | 3347 | e.stopPropagation(); |
| 3312 | 3348 | this.props.onPreviewImage(e, dataUrl); |
| ... | ... | @@ -3725,6 +3761,7 @@ export default class CommonComponent extends Component { |
| 3725 | 3761 | <div className={`${this.props.className} ${readonlyStyle} ${costomStyle}`} onClick={this.props.onCostomClick?.bind(this, showConfig)}> |
| 3726 | 3762 | {commonAssembly} |
| 3727 | 3763 | </div> |
| 3764 | + <InstructSetSetting {...this.state.instructSetSettingProps} /> | |
| 3728 | 3765 | </div> |
| 3729 | 3766 | ); |
| 3730 | 3767 | } | ... | ... |
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; | ... | ... |