Browse Source

canvas bug

es6
NieShichao 7 years ago
parent
commit
3caf7891af
  1. 33
      src/base/canvas/canvas.js

33
src/base/canvas/canvas.js

@ -29,6 +29,10 @@ BI.Canvas = BI.inherit(BI.Widget, {
this._queue = []; this._queue = [];
}, },
mounted: function () {
this.stroke();
},
_getContext: function () { _getContext: function () {
if (!this.ctx) { if (!this.ctx) {
this.ctx = this.canvas.getContext('2d'); this.ctx = this.canvas.getContext('2d');
@ -43,11 +47,11 @@ BI.Canvas = BI.inherit(BI.Widget, {
} }
if (BI.isObject(key)) { if (BI.isObject(key)) {
BI.each(key, function (k, v) { BI.each(key, function (k, v) {
self._queue.push({k: k, v: v}); self._queue.push({ k: k, v: v });
}); });
return; return;
} }
this._queue.push({k: key, v: value}); this._queue.push({ k: key, v: value });
}, },
_line: function (x0, y0) { _line: function (x0, y0) {
@ -113,20 +117,19 @@ BI.Canvas = BI.inherit(BI.Widget, {
this._getContext().clearRect(0, 0, this.canvas.width, this.canvas.height); this._getContext().clearRect(0, 0, this.canvas.width, this.canvas.height);
}, },
stroke: function (callback) { stroke: function () {
var self = this; var ctx = this._getContext();
BI.nextTick(function () { if(!ctx){
var ctx = self._getContext(); return false;
BI.each(self._queue, function (i, q) { }
if (BI.isFunction(ctx[q.k])) { BI.each(this._queue, function (i, q) {
ctx[q.k].apply(ctx, q.v); if (BI.isFunction(ctx[q.k])) {
} else { ctx[q.k].apply(ctx, q.v);
ctx[q.k] = q.v; } else {
} ctx[q.k] = q.v;
}); }
self._queue = [];
callback && callback();
}); });
this._queue = [];
} }
}); });
BI.shortcut("bi.canvas", BI.Canvas); BI.shortcut("bi.canvas", BI.Canvas);
Loading…
Cancel
Save