张延森 5 年之前
父節點
當前提交
4d0a5d2bec

+ 2
- 2
config/dev.js 查看文件

@@ -9,8 +9,8 @@ module.exports = {
9 9
     // WSS_HOST: '"wss://dev.jinchengjiaye.com"',
10 10
     // HOST: '"https://lt.pawoma.cn"',
11 11
     // WSS_HOST: '"wss://lt.pawoma.cn"',
12
-    HOST: '"http://192.168.0.84:8080"',
13
-    WSS_HOST: '"ws://192.168.0.84:8080"',
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: {}

+ 71
- 0
src/components/charts/Line.js 查看文件

@@ -0,0 +1,71 @@
1
+import Taro, { Component } from '@tarojs/taro'
2
+import echart from '../ec-canvas/echarts'
3
+
4
+function initChart(callback) {
5
+  return function (canvas, width, height) {
6
+    const chart = echarts.init(canvas, null, {
7
+      width: width,
8
+      height: height
9
+    });
10
+    canvas.setChart(chart);
11
+    callback && callback(chart);
12
+    return chart;
13
+  }
14
+}
15
+
16
+export default class LineChart extends Component {
17
+  config = {
18
+    usingComponents: {
19
+      "ec-canvas": "../ec-canvas/ec-canvas"
20
+    }
21
+  }
22
+
23
+  // this.echart
24
+  echart = null
25
+
26
+  state = {
27
+    ec: { onInit: initChart(this.handleChart.bind(this)) },
28
+    loading: false,
29
+  }
30
+
31
+  componentWillMount() {
32
+
33
+  }
34
+
35
+  handleChart (chart) {
36
+    this.echart = chart
37
+    if (!this.props.source) {
38
+      this.setState({ loading: true })
39
+      this.echart.showLoading()
40
+    } else {
41
+      this.refreshChart()
42
+    }
43
+  }
44
+
45
+  refreshChart() {
46
+    const defaultOpt = {
47
+      color: ['#BB9C79', '#666666'],
48
+      tooltip: {},
49
+      xAxis: {type: 'category'},
50
+      yAxis: {},
51
+      dataset: {},
52
+      series: [],
53
+    }
54
+
55
+    const options = {
56
+      ...defaultOpt,
57
+      dataset: { source: this.props.source },
58
+      series: {
59
+        type: 'line',
60
+        dimensions: [ 'item' ],
61
+      },
62
+    }
63
+
64
+    this.echart.setOption(options)
65
+    this.echart.hideLoading()
66
+  }
67
+
68
+  render() {
69
+    <ec-canvas id="mychart-dom-line" canvas-id="mychart-line" ec={this.state.ec}></ec-canvas>
70
+  }
71
+}

+ 11
- 8
src/components/ec-canvas/ec-canvas.js 查看文件

@@ -82,41 +82,44 @@ Component({
82 82
     touchStart(e) {
83 83
       if (this.chart && e.touches.length > 0) {
84 84
         var touch = e.touches[0];
85
-        this.chart._zr.handler.dispatch('mousedown', {
85
+        var handler = this.chart.getZr().handler;
86
+        handler.dispatch('mousedown', {
86 87
           zrX: touch.x,
87 88
           zrY: touch.y
88 89
         });
89
-        this.chart._zr.handler.dispatch('mousemove', {
90
+        handler.dispatch('mousemove', {
90 91
           zrX: touch.x,
91 92
           zrY: touch.y
92 93
         });
93
-        this.chart._zr.handler.proxy.processGesture(wrapTouch(e), 'start');
94
+        handler.processGesture(wrapTouch(e), 'start');
94 95
       }
95 96
     },
96 97
 
97 98
     touchMove(e) {
98 99
       if (this.chart && e.touches.length > 0) {
99 100
         var touch = e.touches[0];
100
-        this.chart._zr.handler.dispatch('mousemove', {
101
+        var handler = this.chart.getZr().handler;
102
+        handler.dispatch('mousemove', {
101 103
           zrX: touch.x,
102 104
           zrY: touch.y
103 105
         });
104
-        this.chart._zr.handler.proxy.processGesture(wrapTouch(e), 'change');
106
+        handler.processGesture(wrapTouch(e), 'change');
105 107
       }
106 108
     },
107 109
 
108 110
     touchEnd(e) {
109 111
       if (this.chart) {
110 112
         const touch = e.changedTouches ? e.changedTouches[0] : {};
111
-        this.chart._zr.handler.dispatch('mouseup', {
113
+        var handler = this.chart.getZr().handler;
114
+        handler.dispatch('mouseup', {
112 115
           zrX: touch.x,
113 116
           zrY: touch.y
114 117
         });
115
-        this.chart._zr.handler.dispatch('click', {
118
+        handler.dispatch('click', {
116 119
           zrX: touch.x,
117 120
           zrY: touch.y
118 121
         });
119
-        this.chart._zr.handler.proxy.processGesture(wrapTouch(e), 'end');
122
+        handler.processGesture(wrapTouch(e), 'end');
120 123
       }
121 124
     }
122 125
   }

+ 10
- 22
src/components/ec-canvas/echarts.js
文件差異過大導致無法顯示
查看文件


+ 1
- 1
src/components/ec-canvas/wx-canvas.js 查看文件

@@ -87,7 +87,7 @@ export default class WxCanvas {
87 87
     eventNames.forEach(name => {
88 88
       this.event[name.wxName] = e => {
89 89
         const touch = e.touches[0];
90
-        this.chart._zr.handler.dispatch(name.ecName, {
90
+        this.chart.getZr().handler.dispatch(name.ecName, {
91 91
           zrX: name.wxName === 'tap' ? touch.clientX : touch.x,
92 92
           zrY: name.wxName === 'tap' ? touch.clientY : touch.y
93 93
         });