From 9cf5fc474d2159aad973e3208fbef670f325307f Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期三, 25 十一月 2020 17:57:41 +0800
Subject: [PATCH] 2020-11-25

---
 src/tabviews/custom/components/chart/antv-pie/index.jsx |   77 ++++++++++++++++++++++++++++++++++----
 1 files changed, 69 insertions(+), 8 deletions(-)

diff --git a/src/tabviews/custom/components/chart/antv-pie/index.jsx b/src/tabviews/custom/components/chart/antv-pie/index.jsx
index 4f7ce11..2cedfda 100644
--- a/src/tabviews/custom/components/chart/antv-pie/index.jsx
+++ b/src/tabviews/custom/components/chart/antv-pie/index.jsx
@@ -2,17 +2,19 @@
 import PropTypes from 'prop-types'
 import { is, fromJS } from 'immutable'
 import { Chart } from '@antv/g2'
+import { connect } from 'react-redux'
 import DataSet from '@antv/data-set'
 import { Spin, Empty, notification } from 'antd'
 
 // import searchLine from '../../share/searchLine'
 import Api from '@/api'
 import Utils from '@/utils/utils.js'
+import { modifyTabview } from '@/store/action'
 import { chartColors } from '@/utils/option.js'
 import UtilsDM from '@/utils/utils-datamanage.js'
 import './index.scss'
 
-class LineChart extends Component {
+class PieChart extends Component {
   static propTpyes = {
     BID: PropTypes.any,              // 鐖剁骇Id
     data: PropTypes.array,           // 缁熶竴鏌ヨ鏁版嵁
@@ -329,18 +331,14 @@
       chart.legend(X_axis, {
         position: plot.legend,
         itemName: {
-          style: {
-            fill: color,
-          }
+          style: { fill: color }
         }
       })
     } else {
       chart.legend({
         position: plot.legend,
         itemName: {
-          style: {
-            fill: color,
-          }
+          style: { fill: color }
         }
       })
     }
@@ -476,6 +474,55 @@
         })
       }
     }
+    
+    if (plot.linkmenu && plot.linkmenu.length > 0) {
+      let menu_id = plot.linkmenu[plot.linkmenu.length - 1]
+      let menu = this.props.permMenus.filter(m => m.MenuID === menu_id)[0] || ''
+
+      chart.on('element:dblclick', (ev) => {
+        if (!menu) {
+          notification.warning({
+            top: 92,
+            message: '鑿滃崟宸插垹闄ゆ垨娌℃湁璁块棶鏉冮檺锛�',
+            duration: 5
+          })
+          return
+        }
+
+        try {
+          let data = ev.data.data
+          let primaryId = ''
+          if (this.state.config.setting.primaryKey && data) {
+            primaryId = data[this.state.config.setting.primaryKey] || ''
+          }
+
+          let newtab = {
+            ...menu,
+            selected: true,
+            param: {
+              BID: primaryId,
+              data: data
+            }
+          }
+  
+          let tabs = this.props.tabviews.filter(tab => {
+            tab.selected = false
+            return tab.MenuID !== newtab.MenuID
+          })
+  
+          if (this.props.tabviews.length !== tabs.length) {
+            this.props.modifyTabview(fromJS(tabs).toJS())
+          }
+  
+          this.setState({}, () => {
+            tabs.push(newtab)
+            this.props.modifyTabview(tabs)
+          })
+        } catch {
+          console.warn('鑿滃崟鎵撳紑澶辫触锛�')
+        }
+      })
+    }
 
     chart.render()
   }
@@ -504,4 +551,18 @@
   }
 }
 
-export default LineChart
\ No newline at end of file
+
+const mapStateToProps = (state) => {
+  return {
+    tabviews: state.tabviews,
+    permMenus: state.permMenus,
+  }
+}
+
+const mapDispatchToProps = (dispatch) => {
+  return {
+    modifyTabview: (tabviews) => dispatch(modifyTabview(tabviews))
+  }
+}
+
+export default connect(mapStateToProps, mapDispatchToProps)(PieChart)
\ No newline at end of file

--
Gitblit v1.8.0