From 40436544f55558d2c8d1c14c68cce79546c60dff Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期五, 15 一月 2021 16:59:41 +0800
Subject: [PATCH] 2021-01-15

---
 src/mob/controller/index.jsx |  262 ++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 221 insertions(+), 41 deletions(-)

diff --git a/src/mob/controller/index.jsx b/src/mob/controller/index.jsx
index 6e9ebc0..603c459 100644
--- a/src/mob/controller/index.jsx
+++ b/src/mob/controller/index.jsx
@@ -1,11 +1,12 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
 import { is, fromJS } from 'immutable'
-import { Collapse, Form, Input, Col, Icon, InputNumber, Select, Radio } from 'antd'
+import { Collapse, Form, Input, Col, Icon, InputNumber, Select, Radio, Popover, Menu } from 'antd'
 
 import zhCN from '@/locales/zh-CN/mob.js'
 import enUS from '@/locales/en-US/mob.js'
 import ColorSketch from '@/mob/colorsketch'
+import FileUpload from '@/tabviews/zshare/fileupload'
 import './index.scss'
 
 const { Panel } = Collapse
@@ -21,7 +22,12 @@
     dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
     card: null,
     fontColor: '#000000',
-    backgroundColor: '#ffffff'
+    backgroundColor: '#ffffff',
+    bgimages: [],
+    marginTop: '',
+    marginTopVal: '',
+    marginBottom: '',
+    marginBottomVal: '',
   }
 
   UNSAFE_componentWillReceiveProps (nextProps) {
@@ -31,11 +37,25 @@
       }, () => {
         if (!nextProps.editElem) return
         let _card = fromJS(nextProps.editElem).toJS()
+        let bgImg = _card.backgroundImage || ''
+
+        if (bgImg && /^linear-gradient/.test(bgImg)) {
+          bgImg = bgImg.replace('linear-gradient(', '')
+          bgImg = bgImg.replace(')', '')
+        } else if (bgImg && /^url/.test(bgImg)) {
+          bgImg = bgImg.replace('url(', '')
+          bgImg = bgImg.replace(')', '')
+        }
 
         this.setState({
           card: _card,
           fontColor: _card.color || '#000000',
-          backgroundColor: _card.backgroundColor || '#ffffff'
+          backgroundColor: _card.backgroundColor || '#ffffff',
+          backgroundImage: bgImg,
+          marginTop: _card.marginTop ? _card.marginTop : '',
+          marginTopVal: _card.marginTop ? parseInt(_card.marginTop) : '',
+          marginBottom: _card.marginBottom ? _card.marginBottom : '',
+          marginBottomVal: _card.marginBottomVal ? parseInt(_card.marginBottomVal) : ''
         })
       })
     }
@@ -45,61 +65,60 @@
     return !is(fromJS(this.state), fromJS(nextState))
   }
 
+  updateStyle = (style) => {
+    const { card } = this.state
+
+    this.props.updateStyle({componentId: card.componentId, classId: card.classId, uuid: card.uuid, style})
+  }
+
   /**
    * @description 瀛椾綋澶у皬鍒囨崲锛岃秴鍑鸿寖鍥村拷鐣�
    */
   changeFontSize = (val) => {
-    const { card } = this.state
     let value = parseInt(val)
 
     if (isNaN(value) || value < 12 || value > 100) return
 
-    this.props.updateStyle({componentId: card.componentId, uuid: card.uuid, style: {fontSize: `${value}px`}})
+    this.updateStyle({fontSize: `${value}px`})
   }
 
   /**
    * @description 淇敼琛岄棿璺濓紝瓒呭嚭鑼冨洿蹇界暐
    */
   changeLineHeight = (val) => {
-    const { card } = this.state
     let value = parseFloat(val)
 
     if (isNaN(value) || value < 1 || value > 10) return
 
-    this.props.updateStyle({componentId: card.componentId, uuid: card.uuid, style: {lineHeight: value}})
+    this.updateStyle({lineHeight: value})
   }
 
   /**
    * @description 瀛椾綋闂磋窛淇敼锛岃秴鍑鸿寖鍥村拷鐣�
    */
   changeLetterSpacing = (val) => {
-    const { card } = this.state
     let value = parseFloat(val)
 
     if (isNaN(value) || value < 0 || value > 100) return
 
-    this.props.updateStyle({componentId: card.componentId, uuid: card.uuid, style: {letterSpacing: `${value}px`}})
+    this.updateStyle({letterSpacing: `${value}px`})
   }
 
   /**
    * @description 淇敼瀛椾綋绮楃粏
    */
   boldChange = (val) => {
-    const { card } = this.state
-
-    this.props.updateStyle({componentId: card.componentId, uuid: card.uuid, style: {fontWeight: val}})
+    this.updateStyle({fontWeight: val})
   }
 
   /**
    * @description 淇敼瀛椾綋棰滆壊 锛岄鑹叉帶浠�
    */
   changeFontColor = (val) => {
-    const { card } = this.state
-
     this.setState({
       fontColor: val
     })
-    this.props.updateStyle({componentId: card.componentId, uuid: card.uuid, style: {color: val}})
+    this.updateStyle({color: val})
   }
 
   /**
@@ -115,39 +134,31 @@
    * @description 瀛椾綋瀵归綈
    */
   changeTextAlign = (e) => {
-    const { card } = this.state
-
-    this.props.updateStyle({componentId: card.componentId, uuid: card.uuid, style: {textAlign: e.target.value}})
+    this.updateStyle({textAlign: e.target.value})
   }
 
   /**
    * @description 瀛椾綋鏍峰紡锛屽�炬枩
    */
   changeFontStyle = (e) => {
-    const { card } = this.state
-
-    this.props.updateStyle({componentId: card.componentId, uuid: card.uuid, style: {fontStyle: e.target.value}})
+    this.updateStyle({fontStyle: e.target.value})
   }
 
   /**
    * @description 瀛椾綋瑁呴グ锛屼笅鍒掔嚎銆佽疮绌跨嚎銆佷笂鍒掔嚎
    */
   changeTextDecoration = (e) => {
-    const { card } = this.state
-
-    this.props.updateStyle({componentId: card.componentId, uuid: card.uuid, style: {textDecoration: e.target.value}})
+    this.updateStyle({textDecoration: e.target.value})
   }
 
   /**
    * @description 淇敼鑳屾櫙棰滆壊 锛岄鑹叉帶浠�
    */
   changeBackgroundColor = (val) => {
-    const { card } = this.state
-
     this.setState({
       backgroundColor: val
     })
-    this.props.updateStyle({componentId: card.componentId, uuid: card.uuid, style: {backgroundColor: val}})
+    this.updateStyle({backgroundColor: val})
   }
 
   /**
@@ -159,8 +170,95 @@
     })
   }
 
+  imgChange = (list) => {
+    if (list[0] && list[0].response) {
+      this.setState({
+        bgimages: [],
+        backgroundImage: list[0].response
+      })
+      this.updateStyle({backgroundImage: `url(${list[0].response})`})
+    } else {
+      this.setState({bgimages: list})
+    }
+  }
+
+  changeBackgroundImageInput = (e) => {
+    this.setState({
+      backgroundImage: e.target.value
+    })
+  }
+
+  submitBackgroundImage = (e) => {
+    let val = e.target.value
+    val = val.replace(/^\s*|\s*$/ig, '')
+
+    if (/^http|^\/\//.test(val)) {
+      val = `url(${val})`
+    } else if (/^#|,/ig.test(val)) {
+      val = `linear-gradient(${val})`
+    }
+
+    this.updateStyle({backgroundImage: val})
+  }
+
+  submitBorder = (val, type) => {
+    this.updateStyle({[type]: val})
+  }
+
+  changeBorderRadius = (val) => {
+    let value = parseFloat(val)
+
+    if (isNaN(value) || value < 0 || value > 500) return
+
+    this.updateStyle({borderRadius: `${value}px`})
+  }
+
+  changeMarginTop = (e) => {
+    let val = e.target.value
+    let _val = parseInt(val)
+
+    this.setState({
+      marginTop: val
+    })
+
+    if (isNaN(_val)) return
+
+    this.setState({
+      marginTopVal: _val
+    })
+  }
+
+  submitMarginTop = (val) => {
+    this.setState({
+      marginTop: val
+    })
+    this.updateStyle({marginTop: val})
+  }
+
+  changeMarginBottom = (e) => {
+    let val = e.target.value
+    let _val = parseInt(val)
+
+    this.setState({
+      marginBottom: val
+    })
+
+    if (isNaN(_val)) return
+
+    this.setState({
+      marginBottomVal: _val
+    })
+  }
+
+  submitMarginBottom = (val) => {
+    this.setState({
+      marginBottom: val
+    })
+    this.updateStyle({marginBottom: val})
+  }
+
   render () {
-    const { card, fontColor, backgroundColor } = this.state
+    const { card, backgroundImage, bgimages, marginTop, marginTopVal, marginBottom, marginBottomVal } = this.state
     const formItemLayout = {
       labelCol: {
         xs: { span: 24 },
@@ -217,8 +315,7 @@
                   label={<Icon title="瀛椾綋棰滆壊" type="font-colors" />}
                   labelCol={{xs: { span: 24 }, sm: { span: 4 }}} wrapperCol={ {xs: { span: 24 }, sm: { span: 20 }} }
                 >
-                  <ColorSketch color={card.color || '#000000'} changeColor={this.changeFontColor} />
-                  <Input value={fontColor} onChange={this.changeFontColorInput} />
+                  <ColorSketch value={card.color || '#000000'} onChange={this.changeFontColor} />
                 </Form.Item>
               </Col>
               <Col span={24}>
@@ -262,15 +359,14 @@
                 </Form.Item>
               </Col>
             </Panel> : null}
-            {card.items.includes('background') ? <Panel header="鑳屾櫙" key="1">
+            {card.items.includes('background') ? <Panel header="鑳屾櫙" key="background">
               <Col span={24}>
                 <Form.Item
                   colon={false}
                   label={<Icon title="鑳屾櫙棰滆壊" type="bg-colors" />}
                   labelCol={{xs: { span: 24 }, sm: { span: 4 }}} wrapperCol={ {xs: { span: 24 }, sm: { span: 20 }} }
                 >
-                  <ColorSketch color={card.backgroundColor || '#ffffff'} changeColor={this.changeBackgroundColor} />
-                  <Input value={backgroundColor} onChange={this.changeBackgroundColorInput} />
+                  <ColorSketch value={card.backgroundColor || '#ffffff'} onChange={this.changeBackgroundColor} />
                 </Form.Item>
               </Col>
               <Col span={24}>
@@ -279,17 +375,101 @@
                   label={<Icon title="鑳屾櫙鍥剧墖" type="picture" />}
                   labelCol={{xs: { span: 24 }, sm: { span: 4 }}} wrapperCol={ {xs: { span: 24 }, sm: { span: 20 }} }
                 >
-                  <ColorSketch color={card.backgroundColor || '#ffffff'} changeColor={this.changeBackgroundColor} />
-                  <Input value={backgroundColor} onChange={this.changeBackgroundColorInput} />
+                  <FileUpload accept=".jpg,.png,.gif,.svg" value={bgimages} maxFile={2} fileType="text" onChange={this.imgChange}/>
+                  <Input placeholder="" value={backgroundImage} autoComplete="off" onBlur={this.submitBackgroundImage} onPressEnter={this.submitBackgroundImage} onChange={this.changeBackgroundImageInput} />
                 </Form.Item>
               </Col>
             </Panel> : null}
-            <Panel header="杈硅窛" key="2">
-              杈硅窛
-            </Panel>
-            <Panel header="鍏朵粬" key="3">
-              鍏朵粬
-            </Panel>
+            {card.items.includes('border') ? <Panel header="杈规" key="border">
+              <Col span={24}>
+                <Form.Item
+                  colon={false}
+                  label={<Icon title="澶栬竟妗�" type="border-outer" />}
+                  labelCol={{xs: { span: 24 }, sm: { span: 4 }}} wrapperCol={ {xs: { span: 24 }, sm: { span: 20 }} }
+                >
+                  <Input placeholder="" defaultValue={card.border || ''} autoComplete="off" onBlur={(e) => this.submitBorder(e.target.value, 'border')} onPressEnter={(e) => this.submitBorder(e.target.value, 'border')}/>
+                </Form.Item>
+              </Col>
+              <Col span={24}>
+                <Form.Item
+                  colon={false}
+                  label={<Icon title="宸﹁竟妗�" type="border-left" />}
+                  labelCol={{xs: { span: 24 }, sm: { span: 4 }}} wrapperCol={ {xs: { span: 24 }, sm: { span: 20 }} }
+                >
+                  <Input placeholder="" defaultValue={card.borderLeft || ''} autoComplete="off" onBlur={(e) => this.submitBorder(e.target.value, 'borderLeft')} onPressEnter={(e) => this.submitBorder(e.target.value, 'borderLeft')}/>
+                </Form.Item>
+              </Col>
+              <Col span={24}>
+                <Form.Item
+                  colon={false}
+                  label={<Icon title="鍙宠竟妗�" type="border-right" />}
+                  labelCol={{xs: { span: 24 }, sm: { span: 4 }}} wrapperCol={ {xs: { span: 24 }, sm: { span: 20 }} }
+                >
+                  <Input placeholder="" defaultValue={card.borderRight || ''} autoComplete="off" onBlur={(e) => this.submitBorder(e.target.value, 'borderRight')} onPressEnter={(e) => this.submitBorder(e.target.value, 'borderRight')}/>
+                </Form.Item>
+              </Col>
+              <Col span={24}>
+                <Form.Item
+                  colon={false}
+                  label={<Icon title="涓婅竟妗�" type="border-top" />}
+                  labelCol={{xs: { span: 24 }, sm: { span: 4 }}} wrapperCol={ {xs: { span: 24 }, sm: { span: 20 }} }
+                >
+                  <Input placeholder="" defaultValue={card.borderTop || ''} autoComplete="off" onBlur={(e) => this.submitBorder(e.target.value, 'borderTop')} onPressEnter={(e) => this.submitBorder(e.target.value, 'borderTop')}/>
+                </Form.Item>
+              </Col>
+              <Col span={24}>
+                <Form.Item
+                  colon={false}
+                  label={<Icon title="涓嬭竟妗�" type="border-bottom" />}
+                  labelCol={{xs: { span: 24 }, sm: { span: 4 }}} wrapperCol={ {xs: { span: 24 }, sm: { span: 20 }} }
+                >
+                  <Input placeholder="" defaultValue={card.borderBottom || ''} autoComplete="off" onBlur={(e) => this.submitBorder(e.target.value, 'borderBottom')} onPressEnter={(e) => this.submitBorder(e.target.value, 'borderBottom')}/>
+                </Form.Item>
+              </Col>
+              <Col span={24}>
+                <Form.Item
+                  colon={false}
+                  label={<Icon title="鍦嗚" type="radius-setting" />}
+                  labelCol={{xs: { span: 24 }, sm: { span: 4 }}} wrapperCol={ {xs: { span: 24 }, sm: { span: 20 }} }
+                >
+                  <InputNumber defaultValue={card.borderRadius || 0} min={0} max={500} precision={0} onChange={this.changeBorderRadius}/>
+                </Form.Item>
+              </Col>
+            </Panel> : null}
+            {card.items.includes('margin') ? <Panel header="澶栬竟璺�" key="margin">
+              <Col span={12}>
+                <Form.Item
+                  colon={false}
+                  label={<Icon title="涓婅竟璺�" type="vertical-align-top"/>}
+                >
+                  <Popover placement="bottom" overlayClassName="margin-popover" content={
+                    marginTopVal !== '' ?
+                    <Menu>
+                      <Menu.Item onClick={() => this.submitMarginTop(`${marginTopVal}px`)}>{marginTopVal} px</Menu.Item>
+                      <Menu.Item onClick={() => this.submitMarginTop(`${marginTopVal}vh`)}>{marginTopVal} vh</Menu.Item>
+                    </Menu> : null
+                  } trigger="hover">
+                    <Input value={marginTop} onChange={this.changeMarginTop}/>
+                  </Popover>
+                </Form.Item>
+              </Col>
+              <Col span={12}>
+                <Form.Item
+                  colon={false}
+                  label={<Icon title="涓嬭竟璺�" type="vertical-align-bottom"/>}
+                >
+                  <Popover placement="bottom" overlayClassName="margin-popover" content={
+                    marginBottomVal !== '' ?
+                    <Menu>
+                      <Menu.Item onClick={() => this.submitMarginBottom(`${marginBottomVal}px`)}>{marginBottomVal} px</Menu.Item>
+                      <Menu.Item onClick={() => this.submitMarginBottom(`${marginBottomVal}vh`)}>{marginBottomVal} vh</Menu.Item>
+                    </Menu> : null
+                  } trigger="hover">
+                    <Input value={marginBottom} onChange={this.changeMarginBottom}/>
+                  </Popover>
+                </Form.Item>
+              </Col>
+            </Panel> : null}
           </Collapse> : null}
         </Form>
       </div>

--
Gitblit v1.8.0