Skip to content

Commit 48aa0c8

Browse files
committed
test: test picker with canvas
1 parent a197b97 commit 48aa0c8

File tree

5 files changed

+82
-0
lines changed

5 files changed

+82
-0
lines changed

example/pages/dev-test/index.vue

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<template>
2+
<div class="dev-test=content">
3+
<picker class="weui-btn" mode="date" :value="date" start="2015-09-01" end="2017-09-01" @change="bindDateChange">
4+
<button type="default">日期选择器</button>
5+
</picker>
6+
<canvas style="width: 300px; height: 200px;" canvas-id="firstCanvas"></canvas>
7+
</div>
8+
</template>
9+
10+
<script>
11+
export default {
12+
data() {
13+
return {
14+
date: '2016-09-01'
15+
};
16+
},
17+
mounted() {
18+
this.drawCanvas();
19+
},
20+
methods: {
21+
bindDateChange() {
22+
// TODO
23+
},
24+
drawCanvas() {
25+
/* eslint-disable */
26+
// 使用 wx.createContext 获取绘图上下文 context
27+
var context = wx.createCanvasContext('firstCanvas')
28+
29+
context.setStrokeStyle("#00ff00")
30+
context.setLineWidth(5)
31+
context.rect(0, 0, 200, 200)
32+
context.stroke()
33+
context.setStrokeStyle("#ff0000")
34+
context.setLineWidth(2)
35+
context.moveTo(160, 100)
36+
context.arc(100, 100, 60, 0, 2 * Math.PI, true)
37+
context.moveTo(140, 100)
38+
context.arc(100, 100, 40, 0, Math.PI, false)
39+
context.moveTo(85, 80)
40+
context.arc(80, 80, 5, 0, 2 * Math.PI, true)
41+
context.moveTo(125, 80)
42+
context.arc(120, 80, 5, 0, 2 * Math.PI, true)
43+
context.stroke()
44+
context.draw()
45+
}
46+
}
47+
};
48+
</script>
49+
50+
<style>
51+
</style>

example/pages/dev-test/main.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import Vue from 'vue';
2+
import App from './index';
3+
4+
const app = new Vue(App);
5+
app.$mount();

example/pages/picker/index.vue

+26
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<template>
22
<page-content title="picker" :scopedObj="scopedObj" desc="选择器,这里使用小程序原生的picker, 并在此基础上进行了封装,统一了样式,支持联动。">
3+
<canvas style="width: 300px; height: 200px;" canvas-id="firstCanvas"></canvas>
34
<div class="mpvue-weui-picker">
45
<div class="page__desc">选中的值:</div>
56
<div class="picker-text">{{scopedObj.pickerText}}</div>
@@ -211,6 +212,9 @@ export default {
211212
]
212213
};
213214
},
215+
mounted() {
216+
this.drawCanvas();
217+
},
214218
methods: {
215219
onChange(e) {
216220
console.log(e);
@@ -270,6 +274,28 @@ export default {
270274
} else if (this.mode === 'multiLinkageSelector' && this.deepLength === 3) {
271275
this.scopedObj.pickerText = e.label;
272276
}
277+
},
278+
drawCanvas() {
279+
/* eslint-disable */
280+
// 使用 wx.createContext 获取绘图上下文 context
281+
var context = wx.createCanvasContext('firstCanvas')
282+
283+
context.setStrokeStyle("#00ff00")
284+
context.setLineWidth(5)
285+
context.rect(0, 0, 200, 200)
286+
context.stroke()
287+
context.setStrokeStyle("#ff0000")
288+
context.setLineWidth(2)
289+
context.moveTo(160, 100)
290+
context.arc(100, 100, 60, 0, 2 * Math.PI, true)
291+
context.moveTo(140, 100)
292+
context.arc(100, 100, 40, 0, Math.PI, false)
293+
context.moveTo(85, 80)
294+
context.arc(80, 80, 5, 0, 2 * Math.PI, true)
295+
context.moveTo(125, 80)
296+
context.arc(120, 80, 5, 0, 2 * Math.PI, true)
297+
context.stroke()
298+
context.draw()
273299
}
274300
}
275301
};
77.3 KB
Loading
67.6 KB
Loading

0 commit comments

Comments
 (0)