From b77c5e22f1ff192d9b09dda8d2376ba40641451c Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期四, 06 八月 2020 12:06:50 +0800
Subject: [PATCH] 2020-08-06

---
 src/templates/zshare/codemirror/index.jsx |   33 ++++++++++++++++++++++++---------
 1 files changed, 24 insertions(+), 9 deletions(-)

diff --git a/src/templates/zshare/codemirror/index.jsx b/src/templates/zshare/codemirror/index.jsx
index 9c3a7c5..28cd658 100644
--- a/src/templates/zshare/codemirror/index.jsx
+++ b/src/templates/zshare/codemirror/index.jsx
@@ -28,7 +28,8 @@
     value: '',      // 瀹炴椂鍐呭
     options: null,  // mode : text/javascript銆乼ext/x-mysql ; theme : cobalt - 榛戝簳
     fullScreen: false,
-    style: null
+    style: null,
+    display: true
   }
 
   UNSAFE_componentWillMount () {
@@ -78,35 +79,49 @@
     this.setState({options: {...options, fullScreen: !fullScreen}, fullScreen: !fullScreen})
   }
 
-  changeSize = () => {
+  changeSize = (size) => {
+    let _style = null
+    if (size === 14) {
+      _style = {fontSize: '14px', lineHeight: '25px'}
+    } else if (size === 16) {
+      _style = {fontSize: '16px', lineHeight: '28px'}
+    } else if (size === 18) {
+      _style = {fontSize: '18px', lineHeight: '32px'}
+    } else if (size === 20) {
+      _style = {fontSize: '20px', lineHeight: '34px'}
+    }
 
+    // 鍒囨崲瀛椾綋澶у皬锛屽埛鏂扮紪杈戝櫒绐楀彛锛岃В鍐宠皟鏁村悗鐨勯�夋嫨鍖哄煙閿欎贡闂
+    this.setState({style: _style, display: false, editor: null, defaultVal: this.state.value}, () => {
+      this.setState({display: true})
+    })
   }
 
   render() {
-    const { defaultVal, options, fullScreen, style } = this.state
+    const { defaultVal, options, fullScreen, style, display } = this.state
     const menu = (
       <Menu>
         <Menu.Item
           style={!style || style.fontSize === '14px' ? {backgroundColor: '#bae7ff'} : ''}
-          onClick={() => {this.setState({style: {fontSize: '14px', lineHeight: '25px'}})}}
+          onClick={() => {this.changeSize(14)}}
         >
           <span style={{padding: '0 10px 0px 5px'}}>14px</span>
         </Menu.Item>
         <Menu.Item
           style={style && style.fontSize === '16px' ? {backgroundColor: '#bae7ff'} : ''}
-          onClick={() => {this.setState({style: {fontSize: '16px', lineHeight: '28px'}})}}
+          onClick={() => {this.changeSize(16)}}
         >
           <span style={{padding: '0 10px 0px 5px'}}>16px</span>
         </Menu.Item>
         <Menu.Item
           style={style && style.fontSize === '18px' ? {backgroundColor: '#bae7ff'} : ''}
-          onClick={() => {this.setState({style: {fontSize: '18px', lineHeight: '32px'}})}}
+          onClick={() => {this.changeSize(18)}}
         >
           <span style={{padding: '0 10px 0px 5px'}}>18px</span>
         </Menu.Item>
         <Menu.Item
           style={style && style.fontSize === '20px' ? {backgroundColor: '#bae7ff'} : ''}
-          onClick={() => {this.setState({style: {fontSize: '20px', lineHeight: '34px'}})}}
+          onClick={() => {this.changeSize(20)}}
         >
           <span style={{padding: '0 10px 0px 5px'}}>20px</span>
         </Menu.Item>
@@ -120,7 +135,7 @@
         {fullScreen ? <Dropdown overlay={menu} placement="bottomRight">
           <Icon type="font-size" />
         </Dropdown> : null}
-        <CodeMirror
+        {display ? <CodeMirror
           className="code-mirror-area"
           value={defaultVal}
           options={options}
@@ -128,7 +143,7 @@
             this.setState({editor, value})
             this.props.onChange(value)
           }}
-        />
+        /> : null}
       </div>
     )
   }

--
Gitblit v1.8.0