优化流程
This commit is contained in:
parent
67058f7997
commit
fc86eeb33f
29
lib/pen.js
29
lib/pen.js
@ -81,34 +81,29 @@ export default class Painter {
|
||||
}
|
||||
}
|
||||
|
||||
_border({ borderRadius = '0', width, height, borderWidth = '0', borderStyle = 'solid' }) {
|
||||
_border({ borderRadius = 0, width, height, borderWidth = 0, borderStyle = 'solid' }) {
|
||||
let r1 = 0,
|
||||
r2 = 0,
|
||||
r3 = 0,
|
||||
r4 = 0
|
||||
if (borderRadius) {
|
||||
const border = borderRadius.split(' ')
|
||||
if (border.length === 1) {
|
||||
r1 = r2 = r3 = r4 = Math.min(borderRadius === '0' ? 0 : borderRadius.toPx(), width / 2, height / 2);
|
||||
} else if (border.length === 4) {
|
||||
r1 = Math.min(border[0] === '0' ? 0 : border[0].toPx(), width / 2, height / 2);
|
||||
r2 = Math.min(border[1] === '0' ? 0 : border[1].toPx(), width / 2, height / 2);
|
||||
r3 = Math.min(border[2] === '0' ? 0 : border[2].toPx(), width / 2, height / 2);
|
||||
r4 = Math.min(border[3] === '0' ? 0 : border[3].toPx(), width / 2, height / 2);
|
||||
const border = borderRadius.split(/\s+/)
|
||||
if (border.length === 4) {
|
||||
r1 = Math.min(border[0].toPx(), width / 2, height / 2);
|
||||
r2 = Math.min(border[1].toPx(), width / 2, height / 2);
|
||||
r3 = Math.min(border[2].toPx(), width / 2, height / 2);
|
||||
r4 = Math.min(border[3].toPx(), width / 2, height / 2);
|
||||
} else {
|
||||
r1 = r2 = r3 = r4 = Math.min(borderRadius && borderRadius.toPx(), width / 2, height / 2);
|
||||
}
|
||||
}
|
||||
const lineWidth = borderWidth === '0' ? 0 : borderWidth.toPx();
|
||||
const lineWidth = borderWidth && borderWidth.toPx();
|
||||
this.ctx.lineWidth = lineWidth;
|
||||
if (borderStyle === 'dashed') {
|
||||
this.ctx.setLineDash([2 * lineWidth, 2 * lineWidth]);
|
||||
this.ctx.setLineDash([lineWidth * 4 / 3, lineWidth * 4 / 3]);
|
||||
// this.ctx.lineDashOffset = 2 * lineWidth
|
||||
} else if (borderStyle === 'dotted') {
|
||||
this.ctx.setLineDash([lineWidth, lineWidth]);
|
||||
} else if (borderStyle !== 'solid') {
|
||||
const segments = borderStyle.split(/\s+/)
|
||||
if (segments.length === 2) {
|
||||
this.ctx.setLineDash([segments[0].toPx(), segments[1].toPx()])
|
||||
}
|
||||
}
|
||||
const notSolid = borderStyle !== 'solid'
|
||||
this.ctx.beginPath();
|
||||
@ -641,7 +636,7 @@ export default class Painter {
|
||||
if (!view.css || !view.css.shadow) {
|
||||
return;
|
||||
}
|
||||
const box = view.css.shadow.replace(/,\s+/g, ',').split(' ');
|
||||
const box = view.css.shadow.replace(/,\s+/g, ',').split(/\s+/);
|
||||
if (box.length > 4) {
|
||||
console.error('shadow don\'t spread option');
|
||||
return;
|
||||
|
||||
15
painter.js
15
painter.js
@ -27,7 +27,7 @@ Component({
|
||||
},
|
||||
palette: {
|
||||
type: Object,
|
||||
observer: function (newVal, oldVal) {
|
||||
observer: function(newVal, oldVal) {
|
||||
if (this.isNeedRefresh(newVal, oldVal)) {
|
||||
this.paintCount = 0;
|
||||
this.startPaint();
|
||||
@ -36,7 +36,7 @@ Component({
|
||||
},
|
||||
dancePalette: {
|
||||
type: Object,
|
||||
observer: function (newVal, oldVal) {
|
||||
observer: function(newVal, oldVal) {
|
||||
if (!this.isEmpty(newVal)) {
|
||||
this.initDancePalette(newVal);
|
||||
}
|
||||
@ -53,7 +53,7 @@ Component({
|
||||
},
|
||||
action: {
|
||||
type: Object,
|
||||
observer: function (newVal, oldVal) {
|
||||
observer: function(newVal, oldVal) {
|
||||
if (newVal) {
|
||||
this.doAction(newVal)
|
||||
}
|
||||
@ -624,10 +624,10 @@ Component({
|
||||
setTimeout(() => {
|
||||
wx.canvasToTempFilePath({
|
||||
canvasId: 'photo',
|
||||
success: function (res) {
|
||||
success: function(res) {
|
||||
that.getImageInfo(res.tempFilePath);
|
||||
},
|
||||
fail: function (error) {
|
||||
fail: function(error) {
|
||||
console.error(`canvasToTempFilePath failed, ${JSON.stringify(error)}`);
|
||||
that.triggerEvent('imgErr', {
|
||||
error: error
|
||||
@ -679,6 +679,9 @@ function setStringPrototype(screenK, scale) {
|
||||
* @param {Boolean} minus 是否支持负数
|
||||
*/
|
||||
String.prototype.toPx = function toPx(minus) {
|
||||
if (this === '0') {
|
||||
return 0
|
||||
}
|
||||
let reg;
|
||||
if (minus) {
|
||||
reg = /^-?[0-9]+([.]{1}[0-9]+){0,1}(rpx|px)$/g;
|
||||
@ -701,4 +704,4 @@ function setStringPrototype(screenK, scale) {
|
||||
}
|
||||
return res;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user