123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- Component({
-
- properties: {
-
- progress: {
- type: Number,
- value: 0,
- observer(newVal) {
- this.updateProgress(newVal);
- }
- },
- disabled: {
- type: Boolean,
- value: false,
- observer(newVal) {
- this.updateDisabled(newVal);
- }
- },
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- },
-
-
- data: {
- progress_txt: '加载中...',
- progress: 0,
- disabled: false,
- width:110,
- r:110,
- lw:7,
- },
-
- lifetimes: {
- attached() {
- const container = this.selectComponent('#container')
-
-
- console.log("xxxxxxxxxxxxxxxxxxxxxxx")
- console.log(container)
-
-
- console.log("xxxxxxxxxxxxxxxxxxxxxxx")
-
- this.initCanvas();
- },
- },
-
-
- methods: {
-
- initCanvas() {
- let that = this
-
- this.bgContext = wx.createCanvasContext('canvasProgressbg', this);
- this.progressContext = wx.createCanvasContext('canvasProgress', this);
- const container = this.selectComponent('#container')
- var query = wx.createSelectorQuery().in(this);
- query.select('#container').boundingClientRect()
- query.exec(function (res) {
-
- console.log(res);
- that.data.width = res[0].width / 2
- that.data.r = that.data.width - 1
- that.data.lw = 1
- that.drawProgressbg();
- that.drawCircle(that.data.progress);
- })
-
- },
-
-
- drawProgressbg() {
- let w = this.data.width;
- let r = this.data.r;
- let lw = this.data.lw;
- this.progressContext.setFillStyle('#FFFFFF');
- this.progressContext.beginPath();
- this.progressContext.arc(w, w, r, 0, 2 * Math.PI, false);
- this.progressContext.fill();
- this.bgContext.setLineWidth(lw);
- this.bgContext.setStrokeStyle('#FFFFFF');
- this.bgContext.setLineCap('round');
- this.bgContext.beginPath();
- this.bgContext.arc(w, w, r, 0, 2 * Math.PI, false);
- this.bgContext.stroke();
- this.bgContext.draw(false, () => {});
- this.progressContext.setFillStyle('red');
- },
-
- updateProgress(progressPercentage) {
- this.setData({
- progress:progressPercentage
- })
-
- if(this.progressContext){
- this.drawCircle(this.data.progressPercentage);
- }
- },
-
- updateDisabled(dis) {
- this.setData({
- disabled:dis
- })
-
- if(this.progressContext){
- this.drawCircle(this.data.progress);
- }
- },
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- drawCircle(step) {
- step = step * 2 / 100;
- let w = this.data.width;
- let r = this.data.r;
- let lw = this.data.lw;
- this.progressContext.setLineWidth(lw+1);
- this.progressContext.setStrokeStyle(this.data.disabled?'#B6B3C1':'#21ADFF');
- this.progressContext.setLineCap('round');
- this.progressContext.beginPath();
- this.progressContext.arc(w, w, r, -Math.PI / 2, step * Math.PI - Math.PI / 2, false);
- this.progressContext.stroke();
- this.progressContext.draw(false, () => {});
- this.setData({
- progress_txt:this.data.progress + "%"
- })
- },
-
- }
- })
|