From bc5ec1017fd8a140ec5c30ea9e8ea839d5bf1bda Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期二, 15 十二月 2020 16:22:20 +0800
Subject: [PATCH] 2020-12-15

---
 src/menu/components/card/cardcellcomponent/elementform/index.jsx |   56 +++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 47 insertions(+), 9 deletions(-)

diff --git a/src/menu/components/card/cardcellcomponent/elementform/index.jsx b/src/menu/components/card/cardcellcomponent/elementform/index.jsx
index 25490a1..1ae5fd3 100644
--- a/src/menu/components/card/cardcellcomponent/elementform/index.jsx
+++ b/src/menu/components/card/cardcellcomponent/elementform/index.jsx
@@ -10,11 +10,10 @@
 
 const cardTypeOptions = {
   sequence: ['eleType', 'width'],
-  text: ['eleType', 'datatype', 'format', 'width', 'height', 'prefix', 'postfix'],
+  text: ['eleType', 'datatype', 'format', 'width', 'height', 'prefix', 'postfix', 'link'],
   number: ['eleType', 'datatype', 'format', 'width', 'height', 'prefix', 'postfix'],
-  picture: ['eleType', 'datatype', 'width', 'lenWidRadio', 'url'],
+  picture: ['eleType', 'datatype', 'width', 'lenWidRadio', 'url', 'link'],
   icon: ['eleType', 'icon', 'datatype', 'width'],
-  link: ['eleType', 'datatype', 'label', 'width', 'height', 'joint'],
   slider: ['eleType', 'datatype', 'width', 'color', 'maxValue'],
   splitline: ['eleType', 'color', 'width', 'borderWidth'],
   barcode: ['eleType', 'datatype', 'width', 'barHeight', 'displayValue', 'interval'],
@@ -34,21 +33,23 @@
   state = {
     formlist: null,  // 琛ㄥ崟淇℃伅
     eleType: '',
-    datatype: ''
+    datatype: '',
+    link: ''
   }
 
   
   UNSAFE_componentWillMount () {
     const { card, config } = this.props
-    let _options = this.getOptions(card.eleType, card.datatype)
+    let _options = this.getOptions(card.eleType, card.datatype, card.link)
     
     this.setState({
+      link: card.link,
       eleType: card.eleType,
       datatype: card.datatype,
       formlist: this.props.formlist.map(item => {
         item.hidden = !_options.includes(item.key)
 
-        if (item.key === 'field') {
+        if (item.key === 'field' || item.key === 'linkurl') {
           item.options = []
           config.columns.forEach(col => {
             if (!/^Nvarchar/ig.test(col.datatype) && (card.eleType === 'number' || card.eleType === 'slider')) {
@@ -66,6 +67,15 @@
         } else if (item.key === 'value' && card.eleType === 'slider') {
           item.type = 'number'
           item.label = '鍊�'
+        } else if (item.key === 'format') {
+          if (card.eleType === 'text') {
+            item.options = item.oriOptions.filter(op => op.value !== 'percent' && op.value !== 'thdSeparator')
+          } else if (card.eleType === 'number') {
+            item.options = item.oriOptions.filter(op => op.value !== 'YYYY-MM-DD')
+          }
+        }
+        if (item.key === 'linkurl') {
+          item.type = card.link === 'dynamic' ? 'select' : 'text'
         }
 
         return item
@@ -73,7 +83,7 @@
     })
   }
 
-  getOptions = (eleType, datatype) => {
+  getOptions = (eleType, datatype, link) => {
     let _options = fromJS(cardTypeOptions[eleType]).toJS() // 閫夐」鍒楄〃
     
     if (['text', 'number', 'picture', 'link', 'slider', 'barcode', 'qrcode'].includes(eleType)) {
@@ -81,6 +91,10 @@
         _options.push('field')
       } else if (eleType !== 'picture') {
         _options.push('value')
+      }
+
+      if (['text', 'picture'].includes(eleType) && link) {
+        _options.push('linkurl', 'joint')
       }
     } else if (eleType === 'icon') {
       if (datatype === 'dynamic') {
@@ -104,7 +118,7 @@
     const { datatype } = this.state
 
     if (key === 'eleType') {
-      let _options = this.getOptions(value, datatype)
+      let _options = this.getOptions(value, datatype, '')
       
       let _formlist = this.state.formlist.map(item => {
         item.hidden = !_options.includes(item.key)
@@ -132,12 +146,19 @@
             item.type = 'text'
             item.label = '鍐呭'
           }
+        } else if (item.key === 'format') {
+          if (value === 'text') {
+            item.options = item.oriOptions.filter(op => op.value !== 'percent' && op.value !== 'thdSeparator')
+          } else if (value === 'number') {
+            item.options = item.oriOptions.filter(op => op.value !== 'YYYY-MM-DD')
+          }
         }
 
         return item
       })
 
       this.setState({
+        link: '',
         eleType: value,
         formlist: _formlist
       }, () => {
@@ -145,6 +166,11 @@
           this.props.form.setFieldsValue({width: 24, color: '#1890ff'})
         } else if (value === 'splitline') {
           this.props.form.setFieldsValue({width: 24, color: '#e8e8e8'})
+        } else if (value === 'text' || value === 'number') {
+          this.props.form.setFieldsValue({format: ''})
+        }
+        if (value === 'text' || value === 'picture') {
+          this.props.form.setFieldsValue({link: ''})
         }
       })
     } else if (key === 'field') {
@@ -159,7 +185,7 @@
     let value = e.target.value
 
     if (key === 'datatype') {
-      let _options = this.getOptions(eleType, value)
+      let _options = this.getOptions(eleType, value, this.state.link)
 
       this.setState({
         datatype: value,
@@ -169,6 +195,18 @@
           return item
         })
       })
+    } else if (key === 'link') {
+      let _options = this.getOptions(eleType, this.state.datatype, value)
+      this.setState({
+        link: value,
+        formlist: this.state.formlist.map(item => {
+          item.hidden = !_options.includes(item.key)
+          if (item.key === 'linkurl') {
+            item.type = value === 'dynamic' ? 'select' : 'text'
+          }
+          return item
+        })
+      })
     }
   }
 

--
Gitblit v1.8.0