mali-applet-ui 1.0.12 → 1.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/components/ml-echart2/ec-canvas.vue +140 -0
- package/lib/components/ml-echart2/echarts.js +11 -0
- package/lib/components/ml-echart2/echarts.simple.min.js +18 -0
- package/lib/components/ml-echart2/ml-echart2.vue +182 -0
- package/lib/components/ml-echart2/wx-canvas.js +111 -0
- package/lib/components/ml-upload/ml-upload.vue +2 -2
- package/package.json +1 -1
- package/utils/applet.js +8 -1
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view class="ml-echarts" :class="className" :style="{height: height || '400rpx', width: width || '100%'}">
|
|
3
|
+
<canvas class="ec-canvas ec-canvas ec-canvas-aaa" ref="saveChildRef0" :id="canvasId" :width="width" :height="height" @touchStart="touchStart" @touchMove="touchMove" @touchEnd="touchEnd" @init="init"></canvas>
|
|
4
|
+
</view>
|
|
5
|
+
</template>
|
|
6
|
+
|
|
7
|
+
<script>
|
|
8
|
+
/* eslint-disable */
|
|
9
|
+
import WxCanvas from './wx-canvas'
|
|
10
|
+
import echarts from './echarts'
|
|
11
|
+
import { getAppDpr } from '../../../utils'
|
|
12
|
+
|
|
13
|
+
let ctx
|
|
14
|
+
|
|
15
|
+
function wrapTouch (event) {
|
|
16
|
+
for (let i = 0; i < event.touches.length; ++i) {
|
|
17
|
+
const touch = event.touches[i]
|
|
18
|
+
touch.offsetX = touch.x
|
|
19
|
+
touch.offsetY = touch.y
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return event
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export default {
|
|
26
|
+
props: {
|
|
27
|
+
options: Object,
|
|
28
|
+
height: String,
|
|
29
|
+
width: String,
|
|
30
|
+
lazyLoad: Boolean,
|
|
31
|
+
formatLegend: Function,
|
|
32
|
+
className: String
|
|
33
|
+
},
|
|
34
|
+
data () {
|
|
35
|
+
return {
|
|
36
|
+
canvasId: 'aaa',
|
|
37
|
+
width: '',
|
|
38
|
+
height: ''
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
mounted () {
|
|
42
|
+
this.init()
|
|
43
|
+
},
|
|
44
|
+
methods: {
|
|
45
|
+
init: function () {
|
|
46
|
+
ctx = uni.createCanvasContext(this.canvasId, this)
|
|
47
|
+
const canvas = new WxCanvas(ctx, this.canvasId)
|
|
48
|
+
echarts.setCanvasCreator(() => {
|
|
49
|
+
return canvas
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
const query = uni.createSelectorQuery().in(this)
|
|
53
|
+
|
|
54
|
+
const selector = '.ec-canvas-' + this.canvasId
|
|
55
|
+
const ratio = getAppDpr()
|
|
56
|
+
query
|
|
57
|
+
.select(selector)
|
|
58
|
+
.boundingClientRect(res => {
|
|
59
|
+
const _w = ratio * res.width
|
|
60
|
+
|
|
61
|
+
const _h = ratio * res.height
|
|
62
|
+
|
|
63
|
+
const w = res.width
|
|
64
|
+
const h = res.height
|
|
65
|
+
this.width= _w
|
|
66
|
+
this.height= _h
|
|
67
|
+
|
|
68
|
+
const chart = echarts.init(canvas, null, {
|
|
69
|
+
width: w,
|
|
70
|
+
height: h
|
|
71
|
+
})
|
|
72
|
+
canvas.setChart(chart)
|
|
73
|
+
chart.setOption(this.options)
|
|
74
|
+
})
|
|
75
|
+
.exec()
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
canvasToTempFilePath (opt) {
|
|
79
|
+
if (!opt.canvasId) {
|
|
80
|
+
opt.canvasId = this.canvasId
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
ctx.draw(true, () => {
|
|
84
|
+
uni.canvasToTempFilePath(opt, this)
|
|
85
|
+
})
|
|
86
|
+
},
|
|
87
|
+
|
|
88
|
+
touchStart (e) {
|
|
89
|
+
if (this.chart && e.touches.length > 0) {
|
|
90
|
+
const touch = e.touches[0]
|
|
91
|
+
const handler = this.chart.getZr().handler
|
|
92
|
+
handler.dispatch('mousedown', {
|
|
93
|
+
zrX: touch.x,
|
|
94
|
+
zrY: touch.y
|
|
95
|
+
})
|
|
96
|
+
handler.dispatch('mousemove', {
|
|
97
|
+
zrX: touch.x,
|
|
98
|
+
zrY: touch.y
|
|
99
|
+
})
|
|
100
|
+
handler.processGesture(wrapTouch(e), 'start')
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
|
|
104
|
+
touchMove (e) {
|
|
105
|
+
if (this.chart && e.touches.length > 0) {
|
|
106
|
+
const touch = e.touches[0]
|
|
107
|
+
const handler = this.chart.getZr().handler
|
|
108
|
+
handler.dispatch('mousemove', {
|
|
109
|
+
zrX: touch.x,
|
|
110
|
+
zrY: touch.y
|
|
111
|
+
})
|
|
112
|
+
handler.processGesture(wrapTouch(e), 'change')
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
|
|
116
|
+
touchEnd (e) {
|
|
117
|
+
if (this.chart) {
|
|
118
|
+
const touch = e.changedTouches ? e.changedTouches[0] : {}
|
|
119
|
+
const handler = this.chart.getZr().handler
|
|
120
|
+
handler.dispatch('mouseup', {
|
|
121
|
+
zrX: touch.x,
|
|
122
|
+
zrY: touch.y
|
|
123
|
+
})
|
|
124
|
+
handler.dispatch('click', {
|
|
125
|
+
zrX: touch.x,
|
|
126
|
+
zrY: touch.y
|
|
127
|
+
})
|
|
128
|
+
handler.processGesture(wrapTouch(e), 'end')
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
</script>
|
|
134
|
+
|
|
135
|
+
<style lang="scss">
|
|
136
|
+
.ml-canvas {
|
|
137
|
+
width: 100%;
|
|
138
|
+
height: 100%;
|
|
139
|
+
}
|
|
140
|
+
</style>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as echarts from './echarts.simple.min.js'
|
|
2
|
+
import { getAppDpr } from '../../../utils'
|
|
3
|
+
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
const eInit = echarts.init
|
|
6
|
+
echarts.init = function (p1, p2, opts = {}) {
|
|
7
|
+
opts.devicePixelRatio = opts.devicePixelRatio || getAppDpr()
|
|
8
|
+
return eInit.call(this, p1, p2, opts)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default echarts
|