From 76a4300654a18d228838c3f27455dc8e7a8cd616 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期五, 15 一月 2021 17:04:42 +0800
Subject: [PATCH] Merge branch 'master' into bms

---
 src/menu/modelsource/index.jsx |   64 ++++++++++++++++++++++++++++++--
 1 files changed, 60 insertions(+), 4 deletions(-)

diff --git a/src/menu/modelsource/index.jsx b/src/menu/modelsource/index.jsx
index 91f4c24..03f268a 100644
--- a/src/menu/modelsource/index.jsx
+++ b/src/menu/modelsource/index.jsx
@@ -1,18 +1,29 @@
 import React, {Component} from 'react'
 import { is, fromJS } from 'immutable'
+import { Modal, notification } from 'antd'
 
+import Api from '@/api'
 import { menuOptions } from './option'
 import SourceWrap from './dragsource'
+import MKEmitter from '@/utils/events.js'
 import './index.scss'
+
+const { confirm } = Modal
 
 class ModelSource extends Component {
   state = {
-    menuOptions: null
+    menuOptions: null,
   }
 
   UNSAFE_componentWillMount () {
-    const { MenuType } = this.props
-    let options = fromJS(menuOptions).toJS()
+    const { MenuType, components } = this.props
+    let options = []
+    
+    if (components) {
+      options = fromJS(components).toJS()
+    } else {
+      options = fromJS(menuOptions).toJS()
+    }
 
     options = options.filter(item => !item.forbid || !item.forbid.includes(MenuType))
 
@@ -21,8 +32,53 @@
     })
   }
 
+  UNSAFE_componentWillReceiveProps (nextProps) {
+    if (nextProps.components && !is(fromJS(this.props.components), fromJS(nextProps.components))) {
+      this.setState({
+        menuOptions: fromJS(nextProps.components).toJS()
+      })
+    }
+  }
+
   shouldComponentUpdate (nextProps, nextState) {
     return !is(fromJS(this.state), fromJS(nextState))
+  }
+
+  triggerDel = (item) => {
+    confirm({
+      title: `纭畾鍒犻櫎<${item.title}>鍚楋紵`,
+      content: '',
+      onOk() {
+        return new Promise(resolve => {
+          Api.getSystemConfig({
+            func: 's_custom_components_adduptdel',
+            c_id: item.uuid,
+            images: '',
+            c_name: item.title,
+            long_param: '',
+            del_type: 'Y'
+          }).then(result => {
+            if (result.status) {
+              notification.success({
+                top: 92,
+                message: '鍒犻櫎鎴愬姛锛�',
+                duration: 5
+              })
+
+              MKEmitter.emit('updateCustomComponent')
+            } else {
+              notification.warning({
+                top: 92,
+                message: result.message,
+                duration: 5
+              })
+            }
+            resolve()
+          })
+        })
+      },
+      onCancel() {}
+    })
   }
 
   render() {
@@ -30,7 +86,7 @@
 
     return (
       <div className="mob-card-source-box">
-        {menuOptions.map((item, index) => (<SourceWrap key={index} content={item} />))}
+        {menuOptions.map((item, index) => (<SourceWrap key={index} item={item} triggerDel={this.triggerDel} />))}
       </div>
     )
   }

--
Gitblit v1.8.0