From 6c56a138c17dc9aff9d175d20645eb176d2e024b Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期三, 03 三月 2021 19:03:18 +0800
Subject: [PATCH] 2021-03-03

---
 src/menu/stylecontroller/index.jsx |  155 +++++++++++++++++++++++++++++++++++----------------
 1 files changed, 107 insertions(+), 48 deletions(-)

diff --git a/src/menu/stylecontroller/index.jsx b/src/menu/stylecontroller/index.jsx
index c0e8205..cc674a1 100644
--- a/src/menu/stylecontroller/index.jsx
+++ b/src/menu/stylecontroller/index.jsx
@@ -1,18 +1,19 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
 import { is, fromJS } from 'immutable'
-import { Collapse, Form, Input, Col, Icon, InputNumber, Select, Radio, Drawer } from 'antd'
+import { Collapse, Form, Col, Icon, InputNumber, Select, Radio, Drawer, Button } from 'antd'
 
 import MKEmitter from '@/utils/events.js'
 import zhCN from '@/locales/zh-CN/mob.js'
 import enUS from '@/locales/en-US/mob.js'
-import ColorSketch from '@/mob/colorsketch'
+import asyncComponent from '@/utils/asyncComponent'
 import StyleInput from './styleInput'
-import FileUpload from '@/tabviews/zshare/fileupload'
 import './index.scss'
 
 const { Panel } = Collapse
 const { Option } = Select
+const ColorSketch = asyncComponent(() => import('@/mob/colorsketch'))
+const SourceComponent = asyncComponent(() => import('@/menu/components/share/sourcecomponent'))
 
 class MobController extends Component {
   static propTpyes = {
@@ -21,10 +22,9 @@
   }
 
   state = {
-    dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
+    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
     card: null,
     comIds: [],
-    bgimages: [],
     backgroundImage: '',
     options: [],
     borposition: 'outer'
@@ -50,12 +50,8 @@
 
   initStyle = (comIds, options, style = {}) => {
     let backgroundImage = ''
-    if (style.backgroundImage) {
-      if (/^url/ig.test(style.backgroundImage)) {
-        backgroundImage = style.backgroundImage.replace(/^url\(/ig, '').replace(/\)$/ig, '')
-      } else if (/^linear-gradient/ig.test(style.backgroundImage)) {
-        backgroundImage = style.backgroundImage.replace(/^linear-gradient\(/ig, '').replace(/\)$/ig, '')
-      }
+    if (style.backgroundImage && /^url/ig.test(style.backgroundImage)) {
+      backgroundImage = style.backgroundImage.replace(/^url\(/ig, '').replace(/\)$/ig, '')
     }
 
     this.setState({
@@ -69,6 +65,35 @@
   }
 
   onCloseDrawer = () => {
+    let { card } = this.state
+
+    let check = false
+    if (card.borderWidth === '0px') {
+      delete card.borderWidth
+      delete card.borderColor
+      check = true
+    } else if (card.borderLeftWidth === '0px') {
+      delete card.borderLeftWidth
+      delete card.borderLeftColor
+      check = true
+    } else if (card.borderRightWidth === '0px') {
+      delete card.borderRightWidth
+      delete card.borderRightWidth
+      check = true
+    } else if (card.borderTopWidth === '0px') {
+      delete card.borderTopWidth
+      delete card.borderTopWidth
+      check = true
+    } else if (card.borderBottomWidth === '0px') {
+      delete card.borderBottomWidth
+      delete card.borderBottomWidth
+      check = true
+    }
+
+    if (check) {
+      MKEmitter.emit('submitStyle', this.state.comIds, card)
+    }
+
     this.setState({
       visible: false,
       comIds: [],
@@ -168,30 +193,22 @@
     this.updateStyle({backgroundColor: val})
   }
 
-  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})
-    }
+  /**
+   * @description 淇敼闃村奖棰滆壊 锛岄鑹叉帶浠�
+   */
+  changeShadowColor = (val) => {
+    this.updateStyle({shadow: val})
   }
 
-  changeBackgroundImageInput = (e) => {
-    let val = e.target.value
-    val = val.replace(/^\s*|\s*$/ig, '')
-
-    if (/^http|^\/\//.test(val)) {
-      val = `url(${val})`
-    } else if (/,/ig.test(val) && !/^(radial-gradient|linear-gradient)/ig.test(val)) {
-      val = `linear-gradient(${val})`
+  imgChange = (val) => {
+    this.setState({
+      backgroundImage: val
+    })
+    if (val) {
+      this.updateStyle({backgroundImage: `url(${val})`})
+    } else {
+      this.updateStyle({backgroundImage: ''})
     }
-
-    this.setState({backgroundImage: e.target.value})
-    this.updateStyle({backgroundImage: val})
   }
 
   changeBorderStyle = (val) => {
@@ -251,6 +268,15 @@
     this.updateStyle(_style)
   }
 
+  changeWidth = (val) => {
+    let _val = val
+    if (_val === '0px') {
+      _val = 'auto'
+    }
+
+    this.updateStyle({width: _val})
+  }
+
   changeHeight = (val) => {
     let _val = val
     if (_val === '0px') {
@@ -265,7 +291,7 @@
   }
 
   render () {
-    const { card, options, backgroundImage, bgimages, borposition } = this.state
+    const { card, options, backgroundImage, borposition } = this.state
     const formItemLayout = {
       labelCol: {
         xs: { span: 24 },
@@ -288,13 +314,25 @@
         width="300"
         className="menu-style-drawer"
         closable={true}
+        maskClosable={false}
         onClose={this.onCloseDrawer}
         maskStyle={{opacity: 0.1}}
         visible={this.state.visible}
       >
         <div className="menu-style-controller">
           <Form {...formItemLayout}>
-            {card ? <Collapse expandIconPosition="right" destroyInactivePanel={true} defaultActiveKey={options[0]} accordion={true}>
+            {card ? <Collapse expandIconPosition="right" destroyInactivePanel={true} defaultActiveKey={options[0]}>
+              {options.includes('width') ? <Panel header="瀹藉害" key="width">
+                <Col span={24}>
+                  <Form.Item
+                    colon={false}
+                    label={<Icon title="瀹藉害" type="column-width" />}
+                    labelCol={{xs: { span: 24 }, sm: { span: 4 }}} wrapperCol={ {xs: { span: 24 }, sm: { span: 20 }} }
+                  >
+                    <StyleInput defaultValue={card.width || ''} options={['px']} onChange={this.changeWidth}/>
+                  </Form.Item>
+                </Col>
+              </Panel> : null}
               {options.includes('height') ? <Panel header="楂樺害" key="height">
                 <Col span={24}>
                   <Form.Item
@@ -391,7 +429,7 @@
                   </Form.Item>
                 </Col>
               </Panel> : null}
-              {options.includes('background') ? <Panel header="鑳屾櫙" key="background">
+              {options.includes('background') || options.includes('backgroundColor') ? <Panel header="鑳屾櫙" key="background">
                 <Col span={24}>
                   <Form.Item
                     colon={false}
@@ -401,16 +439,15 @@
                     <ColorSketch value={card.backgroundColor || '#ffffff'} onChange={this.changeBackgroundColor} />
                   </Form.Item>
                 </Col>
-                <Col span={24}>
+                {!options.includes('backgroundColor') ? <Col span={24}>
                   <Form.Item
                     colon={false}
                     label={<Icon title="鑳屾櫙鍥剧墖" type="picture" />}
                     labelCol={{xs: { span: 24 }, sm: { span: 4 }}} wrapperCol={ {xs: { span: 24 }, sm: { span: 20 }} }
                   >
-                    <FileUpload value={bgimages} maxFile={2} fileType="text" onChange={this.imgChange}/>
-                    <Input placeholder="" value={backgroundImage} autoComplete="off" onChange={this.changeBackgroundImageInput} />
+                    <SourceComponent value={backgroundImage} type="" placement="right" onChange={this.imgChange}/>
                   </Form.Item>
-                </Col>
+                </Col> : null}
               </Panel> : null}
               {options.includes('border') ? <Panel header="杈规" key="border">
                 <Col span={24}>
@@ -498,73 +535,92 @@
                     label={<Icon title="鍦嗚" type="radius-setting" />}
                     labelCol={{xs: { span: 24 }, sm: { span: 4 }}} wrapperCol={ {xs: { span: 24 }, sm: { span: 20 }} }
                   >
-                    <StyleInput defaultValue={card.borderRadius || ''} options={['px', '%']} onChange={(val) => this.changeNormalStyle(val, 'borderRadius')}/>
+                    <StyleInput defaultValue={card.borderRadius || '0px'} options={['px', '%']} onChange={(val) => this.changeNormalStyle(val, 'borderRadius')}/>
+                  </Form.Item>
+                </Col>
+              </Panel> : null}
+              {options.includes('shadow') ? <Panel header="闃村奖" key="shadow">
+                <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 value={card.shadow || 'transparent'} onChange={this.changeShadowColor} />
                   </Form.Item>
                 </Col>
               </Panel> : null}
               {options.includes('margin') ? <Panel header="澶栬竟璺�" key="margin">
-                <Col span={12}>
+                <Col span={24}>
                   <Form.Item
                     colon={false}
                     label={<Icon title="涓婅竟璺�" type="arrow-up"/>}
+                    labelCol={{xs: { span: 24 }, sm: { span: 4 }}} wrapperCol={ {xs: { span: 24 }, sm: { span: 20 }} }
                   >
                     <StyleInput defaultValue={card.marginTop || '0px'} options={['px', 'vh', 'vw']} onChange={(val) => this.changeNormalStyle(val, 'marginTop')}/>
                   </Form.Item>
                 </Col>
-                <Col span={12}>
+                <Col span={24}>
                   <Form.Item
                     colon={false}
                     label={<Icon title="涓嬭竟璺�" type="arrow-down"/>}
+                    labelCol={{xs: { span: 24 }, sm: { span: 4 }}} wrapperCol={ {xs: { span: 24 }, sm: { span: 20 }} }
                   >
                     <StyleInput defaultValue={card.marginBottom || '0px'} options={['px', 'vh', 'vw']} onChange={(val) => this.changeNormalStyle(val, 'marginBottom')}/>
                   </Form.Item>
                 </Col>
-                <Col span={12}>
+                <Col span={24}>
                   <Form.Item
                     colon={false}
                     label={<Icon title="宸﹁竟璺�" type="arrow-left"/>}
+                    labelCol={{xs: { span: 24 }, sm: { span: 4 }}} wrapperCol={ {xs: { span: 24 }, sm: { span: 20 }} }
                   >
                     <StyleInput defaultValue={card.marginLeft || '0px'} options={['px', 'vh', 'vw']} onChange={(val) => this.changeNormalStyle(val, 'marginLeft')}/>
                   </Form.Item>
                 </Col>
-                <Col span={12}>
+                <Col span={24}>
                   <Form.Item
                     colon={false}
                     label={<Icon title="鍙宠竟璺�" type="arrow-right"/>}
+                    labelCol={{xs: { span: 24 }, sm: { span: 4 }}} wrapperCol={ {xs: { span: 24 }, sm: { span: 20 }} }
                   >
                     <StyleInput defaultValue={card.marginRight || '0px'} options={['px', 'vh', 'vw']} onChange={(val) => this.changeNormalStyle(val, 'marginRight')}/>
                   </Form.Item>
                 </Col>
               </Panel> : null}
               {options.includes('padding') ? <Panel header="鍐呰竟璺�" key="padding">
-                <Col span={12}>
+                <Col span={24}>
                   <Form.Item
                     colon={false}
                     label={<Icon title="涓婅竟璺�" type="arrow-up"/>}
+                    labelCol={{xs: { span: 24 }, sm: { span: 4 }}} wrapperCol={ {xs: { span: 24 }, sm: { span: 20 }} }
                   >
                     <StyleInput defaultValue={card.paddingTop || '0px'} options={['px', 'vh', 'vw']} onChange={(val) => this.changeNormalStyle(val, 'paddingTop')}/>
                   </Form.Item>
                 </Col>
-                <Col span={12}>
+                <Col span={24}>
                   <Form.Item
                     colon={false}
                     label={<Icon title="涓嬭竟璺�" type="arrow-down"/>}
+                    labelCol={{xs: { span: 24 }, sm: { span: 4 }}} wrapperCol={ {xs: { span: 24 }, sm: { span: 20 }} }
                   >
                     <StyleInput defaultValue={card.paddingBottom || '0px'} options={['px', 'vh', 'vw']} onChange={(val) => this.changeNormalStyle(val, 'paddingBottom')}/>
                   </Form.Item>
                 </Col>
-                <Col span={12}>
+                <Col span={24}>
                   <Form.Item
                     colon={false}
                     label={<Icon title="宸﹁竟璺�" type="arrow-left"/>}
+                    labelCol={{xs: { span: 24 }, sm: { span: 4 }}} wrapperCol={ {xs: { span: 24 }, sm: { span: 20 }} }
                   >
                     <StyleInput defaultValue={card.paddingLeft || '0px'} options={['px', 'vh', 'vw']} onChange={(val) => this.changeNormalStyle(val, 'paddingLeft')}/>
                   </Form.Item>
                 </Col>
-                <Col span={12}>
+                <Col span={24}>
                   <Form.Item
                     colon={false}
                     label={<Icon title="鍙宠竟璺�" type="arrow-right"/>}
+                    labelCol={{xs: { span: 24 }, sm: { span: 4 }}} wrapperCol={ {xs: { span: 24 }, sm: { span: 20 }} }
                   >
                     <StyleInput defaultValue={card.paddingRight || '0px'} options={['px', 'vh', 'vw']} onChange={(val) => this.changeNormalStyle(val, 'paddingRight')}/>
                   </Form.Item>
@@ -587,6 +643,9 @@
               </Panel> : null}
             </Collapse> : null}
           </Form>
+          <div style={{textAlign: 'right'}}>
+            <Button style={{margin: '30px 10px 30px 0px'}} onClick={this.onCloseDrawer}>鍏抽棴</Button>
+          </div>
         </div>
       </Drawer>
     )

--
Gitblit v1.8.0