Bladeren bron

linecharts

许静 5 jaren geleden
bovenliggende
commit
672f03f4ef

+ 4
- 4
config/dev.js Bestand weergeven

@@ -7,10 +7,10 @@ module.exports = {
7 7
     // WSS_HOST: '"wss://47.101.36.130:8085"',
8 8
     // HOST:  '"https://dev.jinchengjiaye.com"',//测试
9 9
     // WSS_HOST: '"wss://dev.jinchengjiaye.com"',
10
-    HOST: '"https://lt.pawoma.cn"',
11
-    WSS_HOST: '"wss://lt.pawoma.cn"',
12
-    // HOST: '"http://127.0.0.1:8080"',
13
-    // WSS_HOST: '"ws://127.0.0.1:8080"',
10
+    // HOST: '"https://lt.pawoma.cn"',
11
+    // WSS_HOST: '"wss://lt.pawoma.cn"',
12
+    HOST: '"http://192.168.0.218:8080"',
13
+    WSS_HOST: '"ws://192.168.0.218:8080"',
14 14
   },
15 15
   weapp: {},
16 16
   h5: {}

+ 0
- 65
src/components/PieChart.js Bestand weergeven

@@ -1,65 +0,0 @@
1
-import Taro, { Component } from "@tarojs/taro";
2
-import * as echarts from "../components/ec-canvas/echarts";
3
-
4
-function setChartData(chart, data) {
5
-  let option = {
6
-    series : [
7
-      {
8
-        name: '访问来源',
9
-        type: 'pie',
10
-        center: ['50%', '50%'],
11
-        radius: [0, '60%'],
12
-        data: data,
13
-        itemStyle: {
14
-          emphasis: {
15
-            shadowBlur: 10,
16
-            shadowOffsetX: 0,
17
-            shadowColor: 'rgba(0, 0, 0, 0.5)'
18
-          }
19
-        }
20
-      }
21
-    ]
22
-  };
23
-  chart.setOption(option);
24
-}
25
-
26
-export default class PieChart extends Component {
27
-  config = {
28
-    usingComponents: {
29
-      "ec-canvas": "./ec-canvas/ec-canvas"
30
-    }
31
-  };
32
-
33
-  constructor(props) {
34
-    super(props);
35
-  }
36
-
37
-  state = {
38
-    ec: {
39
-      lazyLoad: true
40
-    }
41
-  };
42
-
43
-  refresh(data) {
44
-    this.Chart.init((canvas, width, height) => {
45
-      const chart = echarts.init(canvas, null, {
46
-        width: width,
47
-        height: height
48
-      });
49
-      setChartData(chart, data);
50
-      return chart;
51
-    });
52
-  }
53
-
54
-  refChart = node => (this.Chart = node);
55
-
56
-  render() {
57
-    return (
58
-      <ec-canvas
59
-        ref={this.refChart}
60
-        canvas-id="mychart-area"
61
-        ec={this.state.ec}
62
-      />
63
-    );
64
-  }
65
-}

+ 36
- 25
src/components/charts/Line.js Bestand weergeven

@@ -1,13 +1,15 @@
1 1
 import Taro, { Component } from '@tarojs/taro'
2 2
 import echarts from '../ec-canvas/echarts'
3
+import './style.scss'
3 4
 
4
-function initChart(callback) {
5
+function initChart(callback, options) {
5 6
   return function (canvas, width, height) {
6 7
     const chart = echarts.init(canvas, null, {
7 8
       width: width,
8 9
       height: height
9 10
     });
10 11
     canvas.setChart(chart);
12
+    chart.setOption(options);
11 13
     callback && callback(chart);
12 14
     return chart;
13 15
   }
@@ -25,9 +27,10 @@ export default class LineChart extends Component {
25 27
 
26 28
   // this.echart
27 29
   echart = null
30
+  ecComponent = null
28 31
 
29 32
   state = {
30
-    ec: { onInit: initChart(this.handleChart.bind(this)) },
33
+    ec: { lazyLoad: true },
31 34
   }
32 35
 
33 36
   // 禁止 props 变更时渲染
@@ -39,45 +42,53 @@ export default class LineChart extends Component {
39 42
     return false
40 43
   }
41 44
 
42
-  handleChart (chart) {
43
-    this.echart = chart
44
-    if (!this.props.source || !this.props.source.length) {
45
-      this.echart.showLoading()
46
-    } else {
47
-      this.refreshChart(this.props.source)
48
-    }
45
+  handleEcComponent (ref) {
46
+    this.ecComponent = ref
49 47
   }
50 48
 
51
-  refreshChart(source) {
52
-    if (!this.echart) {
53
-      console.warn('echarts not ready')
54
-      return;
55
-    }
49
+  handleChart(chart) {
50
+    this.echart = chart
51
+  }
56 52
 
53
+  createOptions(source = []) {
57 54
     const defaultOpt = {
58 55
       color: ['#BB9C79', '#666666'],
59
-      tooltip: {},
60
-      xAxis: {type: 'category'},
61
-      yAxis: {},
62
-      dataset: {},
56
+      xAxis: { type: 'category' },
57
+      yAxis: { type: 'value' },
63 58
       series: [],
64 59
     }
65 60
 
66
-    const options = {
61
+    return {
67 62
       ...defaultOpt,
68 63
       dataset: { source },
69
-      series: {
64
+      series: [{
70 65
         type: 'line',
71
-        dimensions: [ 'name' ],
72
-      },
66
+        areaStyle: {},
67
+        dimensions: ['name', 'value'],
68
+      }],
73 69
     }
70
+  }
71
+
72
+  refreshChart(source) {    
73
+    const options = this.createOptions(source)
74 74
 
75
-    this.echart.setOption(options)
76
-    this.echart.hideLoading()
75
+    if (!this.echart) {
76
+      if (this.ecComponent) {
77
+        const initFunc = initChart(this.handleChart.bind(this), options)
78
+        this.ecComponent.init(initFunc)
79
+      } else {
80
+        console.warn('echart componet not ready')
81
+      }
82
+    } else {
83
+      this.echart.setOption(options)
84
+    }
77 85
   }
78 86
 
79 87
   render() {
80 88
     return (
81
-      <ec-canvas style="width: 100%; height: 100%" ec={this.state.ec}></ec-canvas>)
89
+      <View className="map-container">
90
+        <ec-canvas ref={this.handleEcComponent} ec={this.state.ec}></ec-canvas>
91
+      </View>
92
+    )
82 93
   }
83 94
 }

+ 37430
- 10
src/components/ec-canvas/echarts.js
Diff onderdrukt omdat het te groot bestand
Bestand weergeven


+ 19
- 10
src/pages/person/customerAnalysis/analysis.js Bestand weergeven

@@ -22,6 +22,15 @@ export default class analysis extends Taro.Component {
22 22
     current: 0,
23 23
     recordId: undefined, // 埋点ID
24 24
     sexInfo: [],
25
+    chartInfo: [
26
+      { name: '周一', value: '26' },
27
+      { name: '周二', value: '84' },
28
+      { name: '周三', value: '107' },
29
+      { name: '周四', value: '93' },
30
+      { name: '周五', value: '127' },
31
+      { name: '周六', value: '64' },
32
+      { name: '周日', value: '94' },
33
+    ]
25 34
   }
26 35
 
27 36
   componentWillUnmount() {
@@ -75,48 +84,48 @@ export default class analysis extends Taro.Component {
75 84
   render() {
76 85
 
77 86
     const tabList = [{ title: '新增客户' }, { title: '跟进客户' }, { title: '到访客户' }]
78
-    const { sexInfo } = this.state
87
+    const { sexInfo, chartInfo } = this.state
79 88
 
80 89
     return (
81 90
       <View>
82 91
         <AtTabs className="tab-bar" current={this.state.current} tabList={tabList} onClick={this.handleClick.bind(this)}>
83 92
           <AtTabsPane current={this.state.current} index={0} >
84 93
             <View>
85
-              <LineChart source={} />
94
+              <LineChart source={chartInfo} />
86 95
               <View style="height:20rpx;background:#f5f5f5;"> </View>
87 96
               <View style="padding: 40rpx;">
88 97
                 <View style="font-size: 36rpx;color: #666;margin-bottom:20rpx;">性别</View>
89 98
                 {
90
-                  sexInfo.map(item => (
91
-                    <View style="display: flex;align-items: center;"><View style="font-size: 32rpx;color: #666;min-width:80rpx">{item.genderType == 1 ? '男' : item.genderType == 2 ? '女' : '未知'}</View><AtProgress percent={(item.percentage * 100).toFixed(2)} strokeWidth={6} color={item.genderType == 1 ? '#BB9C79' : item.genderType == 2 ? '#F6B61D' : '#A2A2A2'} /></View>
99
+                  sexInfo.map((item, index) => (
100
+                    <View key={index + 'sex3'} style="display: flex;align-items: center;"><View style="font-size: 32rpx;color: #666;min-width:80rpx">{item.genderType == 1 ? '男' : item.genderType == 2 ? '女' : '未知'}</View><AtProgress percent={(item.percentage * 100).toFixed(2)} strokeWidth={6} color={item.genderType == 1 ? '#BB9C79' : item.genderType == 2 ? '#F6B61D' : '#A2A2A2'} /></View>
92 101
                   ))
93 102
                 }
94 103
               </View>
95 104
             </View>
96 105
           </AtTabsPane>
97 106
           <AtTabsPane current={this.state.current} index={1}>
98
-          <View>
107
+            <View>
99 108
               <LineChart />
100 109
               <View style="height:20rpx;background:#f5f5f5;"> </View>
101 110
               <View style="padding: 40rpx;">
102 111
                 <View style="font-size: 36rpx;color: #666;margin-bottom:20rpx;">性别</View>
103 112
                 {
104
-                  sexInfo.map(item => (
105
-                    <View style="display: flex;align-items: center;"><View style="font-size: 32rpx;color: #666;min-width:80rpx">{item.genderType == 1 ? '男' : item.genderType == 2 ? '女' : '未知'}</View><AtProgress percent={(item.percentage * 100).toFixed(2)} strokeWidth={6} color={item.genderType == 1 ? '#BB9C79' : item.genderType == 2 ? '#F6B61D' : '#A2A2A2'} /></View>
113
+                  sexInfo.map((item, index) => (
114
+                    <View key={index + 'sex3'} style="display: flex;align-items: center;"><View style="font-size: 32rpx;color: #666;min-width:80rpx">{item.genderType == 1 ? '男' : item.genderType == 2 ? '女' : '未知'}</View><AtProgress percent={(item.percentage * 100).toFixed(2)} strokeWidth={6} color={item.genderType == 1 ? '#BB9C79' : item.genderType == 2 ? '#F6B61D' : '#A2A2A2'} /></View>
106 115
                   ))
107 116
                 }
108 117
               </View>
109 118
             </View>
110 119
           </AtTabsPane>
111 120
           <AtTabsPane current={this.state.current} index={2}>
112
-          <View>
121
+            <View>
113 122
               <LineChart />
114 123
               <View style="height:20rpx;background:#f5f5f5;"> </View>
115 124
               <View style="padding: 40rpx;">
116 125
                 <View style="font-size: 36rpx;color: #666;margin-bottom:20rpx;">性别</View>
117 126
                 {
118
-                  sexInfo.map(item => (
119
-                    <View style="display: flex;align-items: center;"><View style="font-size: 32rpx;color: #666;min-width:80rpx">{item.genderType == 1 ? '男' : item.genderType == 2 ? '女' : '未知'}</View><AtProgress percent={(item.percentage * 100).toFixed(2)} strokeWidth={6} color={item.genderType == 1 ? '#BB9C79' : item.genderType == 2 ? '#F6B61D' : '#A2A2A2'} /></View>
127
+                  sexInfo.map((item, index) => (
128
+                    <View key={index + 'sex3'} style="display: flex;align-items: center;"><View style="font-size: 32rpx;color: #666;min-width:80rpx">{item.genderType == 1 ? '男' : item.genderType == 2 ? '女' : '未知'}</View><AtProgress percent={(item.percentage * 100).toFixed(2)} strokeWidth={6} color={item.genderType == 1 ? '#BB9C79' : item.genderType == 2 ? '#F6B61D' : '#A2A2A2'} /></View>
120 129
                   ))
121 130
                 }
122 131
               </View>

+ 9
- 0
src/pages/person/customerAnalysis/myCustomer.js Bestand weergeven

@@ -224,6 +224,15 @@ export default class myCustomer extends Taro.Component {
224 224
     }
225 225
     addFollowRecord(params).then(res => {
226 226
       this.queryFollowRecord(1)
227
+      Taro.showToast({
228
+        title: '添加跟进成功',
229
+        icon: 'none'
230
+      })
231
+    }).catch(err => {
232
+      Taro.showToast({
233
+        title: '添加跟进失败',
234
+        icon: 'none'
235
+      })
227 236
     })
228 237
     this.setState({
229 238
       followVisible: false,