张延森 5 years ago
parent
commit
86c813b8f4
4 changed files with 32 additions and 21 deletions
  1. 4
    4
      config/dev.js
  2. 1
    1
      project.config.json
  3. 22
    10
      src/components/charts/Line.js
  4. 5
    6
      src/pages/person/customerAnalysis/analysis.js

+ 4
- 4
config/dev.js View File

@@ -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://127.0.0.1:8080"',
13
+    // WSS_HOST: '"ws://127.0.0.1:8080"',
14 14
   },
15 15
   weapp: {},
16 16
   h5: {}

+ 1
- 1
project.config.json View File

@@ -2,7 +2,7 @@
2 2
 	"miniprogramRoot": "dist/",
3 3
 	"projectname": "mini-chengjiao",
4 4
 	"description": "知与行",
5
-	"appid": "wxda1f84b79b3edeb3",
5
+	"appid": "wxd6f47a9bb3052175",
6 6
 	"setting": {
7 7
 		"urlCheck": false,
8 8
 		"es6": false,

+ 22
- 10
src/components/charts/Line.js View File

@@ -1,5 +1,5 @@
1 1
 import Taro, { Component } from '@tarojs/taro'
2
-import echart from '../ec-canvas/echarts'
2
+import echarts from '../ec-canvas/echarts'
3 3
 
4 4
 function initChart(callback) {
5 5
   return function (canvas, width, height) {
@@ -13,6 +13,9 @@ function initChart(callback) {
13 13
   }
14 14
 }
15 15
 
16
+/**
17
+ * 传入 source 的格式为 [{ name: xxx, value: xxx }, {}]
18
+ */
16 19
 export default class LineChart extends Component {
17 20
   config = {
18 21
     usingComponents: {
@@ -25,24 +28,32 @@ export default class LineChart extends Component {
25 28
 
26 29
   state = {
27 30
     ec: { onInit: initChart(this.handleChart.bind(this)) },
28
-    loading: false,
29 31
   }
30 32
 
31
-  componentWillMount() {
33
+  // 禁止 props 变更时渲染
34
+  shouldComponentUpdate(nextProps) {
35
+    if (nextProps.source && nextProps.source.length) {
36
+      this.refreshChart(this.props.source)
37
+    }
32 38
 
39
+    return false
33 40
   }
34 41
 
35 42
   handleChart (chart) {
36 43
     this.echart = chart
37
-    if (!this.props.source) {
38
-      this.setState({ loading: true })
44
+    if (!this.props.source || !this.props.source.length) {
39 45
       this.echart.showLoading()
40 46
     } else {
41
-      this.refreshChart()
47
+      this.refreshChart(this.props.source)
42 48
     }
43 49
   }
44 50
 
45
-  refreshChart() {
51
+  refreshChart(source) {
52
+    if (!this.echart) {
53
+      console.warn('echarts not ready')
54
+      return;
55
+    }
56
+
46 57
     const defaultOpt = {
47 58
       color: ['#BB9C79', '#666666'],
48 59
       tooltip: {},
@@ -54,10 +65,10 @@ export default class LineChart extends Component {
54 65
 
55 66
     const options = {
56 67
       ...defaultOpt,
57
-      dataset: { source: this.props.source },
68
+      dataset: { source },
58 69
       series: {
59 70
         type: 'line',
60
-        dimensions: [ 'item' ],
71
+        dimensions: [ 'name' ],
61 72
       },
62 73
     }
63 74
 
@@ -66,6 +77,7 @@ export default class LineChart extends Component {
66 77
   }
67 78
 
68 79
   render() {
69
-    <ec-canvas id="mychart-dom-line" canvas-id="mychart-line" ec={this.state.ec}></ec-canvas>
80
+    return (
81
+      <ec-canvas style="width: 100%; height: 100%" ec={this.state.ec}></ec-canvas>)
70 82
   }
71 83
 }

+ 5
- 6
src/pages/person/customerAnalysis/analysis.js View File

@@ -8,7 +8,7 @@ import "taro-ui/dist/style/components/progress.scss";
8 8
 import { savePoint, updatePoint } from '@services/common'
9 9
 import { querySexInfo } from '@services/person'
10 10
 import { connect } from '@tarojs/redux'
11
-import PieChart from "../../../components/PieChart";
11
+import LineChart from "../../../components/charts/Line";
12 12
 
13 13
 
14 14
 @connect(({ user, city }) => ({ user, city }))
@@ -69,9 +69,8 @@ export default class analysis extends Taro.Component {
69 69
       { value: 135, name: '视频广告' },
70 70
       { value: 1548, name: '搜索引擎' }
71 71
     ];
72
-    this.pieChart.refresh(chartData);
72
+
73 73
   }
74
-  refPieChart = (node) => this.pieChart = node
75 74
 
76 75
   render() {
77 76
 
@@ -83,7 +82,7 @@ export default class analysis extends Taro.Component {
83 82
         <AtTabs className="tab-bar" current={this.state.current} tabList={tabList} onClick={this.handleClick.bind(this)}>
84 83
           <AtTabsPane current={this.state.current} index={0} >
85 84
             <View>
86
-              <PieChart ref={this.refPieChart} />
85
+              <LineChart />
87 86
               <View style="height:20rpx;background:#f5f5f5;"> </View>
88 87
               <View style="padding: 40rpx;">
89 88
                 <View style="font-size: 36rpx;color: #666;margin-bottom:20rpx;">性别</View>
@@ -97,7 +96,7 @@ export default class analysis extends Taro.Component {
97 96
           </AtTabsPane>
98 97
           <AtTabsPane current={this.state.current} index={1}>
99 98
           <View>
100
-              <PieChart ref={this.refPieChart} />
99
+              <LineChart />
101 100
               <View style="height:20rpx;background:#f5f5f5;"> </View>
102 101
               <View style="padding: 40rpx;">
103 102
                 <View style="font-size: 36rpx;color: #666;margin-bottom:20rpx;">性别</View>
@@ -111,7 +110,7 @@ export default class analysis extends Taro.Component {
111 110
           </AtTabsPane>
112 111
           <AtTabsPane current={this.state.current} index={2}>
113 112
           <View>
114
-              <PieChart ref={this.refPieChart} />
113
+              <LineChart />
115 114
               <View style="height:20rpx;background:#f5f5f5;"> </View>
116 115
               <View style="padding: 40rpx;">
117 116
                 <View style="font-size: 36rpx;color: #666;margin-bottom:20rpx;">性别</View>