From 41e2d4b6af42302bb37bb54394a489e017c0de4f Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期一, 05 七月 2021 09:56:24 +0800
Subject: [PATCH] 2021-07-05

---
 src/menu/components/form/normal-form/index.jsx |   73 +++++++++++++++++++++++++++++++-----
 1 files changed, 62 insertions(+), 11 deletions(-)

diff --git a/src/menu/components/form/normal-form/index.jsx b/src/menu/components/form/normal-form/index.jsx
index 7da0e9e..7b5a75b 100644
--- a/src/menu/components/form/normal-form/index.jsx
+++ b/src/menu/components/form/normal-form/index.jsx
@@ -8,6 +8,7 @@
 import asyncComponent from '@/utils/asyncComponent'
 import asyncIconComponent from '@/utils/asyncIconComponent'
 import { getModalForm } from '@/templates/zshare/formconfig'
+import { resetStyle } from '@/utils/utils-custom.js'
 import ModalForm from '@/templates/zshare/modalform'
 import MKEmitter from '@/utils/events.js'
 import Utils from '@/utils/utils.js'
@@ -68,7 +69,7 @@
         name: card.name,
         subtype: card.subtype,
         setting: { },
-        wrap: { name: card.name, width: card.width || 24, datatype: 'static', color: '#1890ff' },
+        wrap: { name: card.name, width: card.width || 24, datatype: 'static', groupLabel: 'show', color: '#1890ff' },
         style: { marginLeft: '0px', marginRight: '0px', marginTop: '8px', marginBottom: '8px' },
         columns: [],
         scripts: [],
@@ -364,7 +365,7 @@
     })
   }
 
-  handleList = (list) => {
+  handleList = (list, newcard) => {
     let group = fromJS(this.state.group).toJS()
     let card = fromJS(this.state.card).toJS()
 
@@ -377,7 +378,11 @@
       return item
     })
 
-    this.setState({card, group})
+    this.setState({card, group}, () => {
+      if (newcard) {
+        this.handleForm(newcard)
+      }
+    })
     this.props.updateConfig(card)
   }
 
@@ -445,13 +450,14 @@
     group.fields = group.fields.filter(item => !item.focus)
 
     this.setState({group, visible: false, editform: null})
+    this.updateGroup(group)
   }
 
   /**
    * @description 琛ㄥ崟缂栬緫
    */
   handleForm = (_item) => {
-    const { card, group } = this.state
+    const { card, group, appType } = this.state
     let _form = fromJS(_item).toJS()
     let _inputfields = []
     let _tabfields = []
@@ -463,7 +469,11 @@
     let standardform = null
 
     _inputfields = group.fields.filter(item => item.type === 'text' || item.type === 'number' || item.type === 'textarea' || item.type === 'color')
-    _tabfields = group.fields.filter(item => _form.field !== item.field && item.hidden !== 'true' && ['text', 'number', 'select', 'link'].includes(item.type))
+    if (appType === 'mob') {
+      _tabfields = group.fields.filter(item => _form.field !== item.field && item.hidden !== 'true' && ['text', 'number'].includes(item.type))
+    } else {
+      _tabfields = group.fields.filter(item => _form.field !== item.field && item.hidden !== 'true' && ['text', 'number', 'select', 'link'].includes(item.type))
+    }
     _tabfields.unshift({field: '', text: '鍘熻〃鍗�'})
 
     let uniq = new Map()
@@ -473,7 +483,8 @@
       if (_form.uuid === item.uuid) {
         index = i
       }
-      if (item.type !== 'select' && item.type !== 'link' && item.type !== 'radio') return
+      
+      if (!['select', 'link', 'radio', 'checkcard'].includes(item.type)) return
       if (item.field && !uniq.has(item.field)) {
         uniq.set(item.field, true)
 
@@ -511,7 +522,7 @@
       _form.linkSubField = _form.linkSubField.filter(item => fields.includes(item))
     }
 
-    if (!_form.span && standardform && standardform.span) {
+    if (appType !== 'mob' && !_form.span && standardform && standardform.span) {
       _form.span = standardform.span
       _form.labelwidth = standardform.labelwidth
     }
@@ -566,7 +577,7 @@
         return
       }
 
-      if ((res.type === 'select' || res.type === 'multiselect' || res.type === 'link') && res.resourceType === '1' && /\s/.test(res.dataSource)) {
+      if (['select', 'multiselect', 'link', 'checkbox', 'radio', 'checkcard'].includes(res.type) && res.resourceType === '1' && /\s/.test(res.dataSource)) {
         this.setState({
           sqlVerifing: true
         })
@@ -613,6 +624,47 @@
     })
   }
 
+  pasteForm = (res) => {
+    let _config = fromJS(this.state.group).toJS()
+    let fieldrepet = false // 瀛楁閲嶅
+    let labelrepet = false // 鎻愮ず鏂囧瓧閲嶅
+
+    _config.fields.forEach(item => {
+      if (res.field && item.field && item.field.toLowerCase() === res.field.toLowerCase()) {
+        fieldrepet = true
+      } else if (res.label && item.label === res.label) {
+        labelrepet = true
+      }
+    })
+
+    if (fieldrepet) {
+      notification.warning({
+        top: 92,
+        message: '瀛楁宸插瓨鍦紒',
+        duration: 10
+      })
+      return
+    } else if (labelrepet) {
+      notification.warning({
+        top: 92,
+        message: '鍚嶇О宸插瓨鍦紒',
+        duration: 10
+      })
+      return
+    }
+    _config.fields.push(res)
+
+    this.updateGroup(_config)
+
+    this.handleForm(res)
+
+    notification.success({
+      top: 92,
+      message: '绮樿创鎴愬姛锛�',
+      duration: 2
+    })
+  }
+
   clickComponent = (e) => {
     if (sessionStorage.getItem('style-control') === 'true' || sessionStorage.getItem('style-control') === 'component') {
       e.stopPropagation()
@@ -624,13 +676,13 @@
     const { card, dict, group, appType } = this.state
 
     return (
-      <div className="menu-normal-form-edit-box" style={{...card.style}} onClick={this.clickComponent} id={card.uuid}>
+      <div className="menu-normal-form-edit-box" style={resetStyle(card.style)} onClick={this.clickComponent} id={card.uuid}>
         <Popover overlayClassName="mk-popover-control-wrap" mouseLeaveDelay={0.2} mouseEnterDelay={0.2} content={
           <div className="mk-popover-control">
             <Icon className="plus" title="娣诲姞鍒嗙粍" onClick={this.addCard} type="plus" />
             <WrapComponent config={card} updateConfig={this.updateComponent} />
             <CopyComponent type="propcard" card={card}/>
-            <PasteComponent config={card} options={['cardcell']} updateConfig={this.updateComponent} />
+            <PasteComponent config={card} options={['form']} updateConfig={this.pasteForm} />
             <Icon className="style" title="璋冩暣鏍峰紡" onClick={this.changeStyle} type="font-colors" />
             <UserComponent config={card}/>
             <Icon className="close" title="鍒犻櫎缁勪欢" type="delete" onClick={() => this.props.deletecomponent(card.uuid)} />
@@ -669,7 +721,6 @@
             list={group.fields}
             setting={group.setting}
             showField={this.state.showField}
-            placeholder={dict['header.form.modal.placeholder']}
             handleList={this.handleList}
             handleForm={this.handleForm}
             closeForm={this.closeForm}

--
Gitblit v1.8.0