mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
fix(Signature): fix checking if canvas is empty when backgoundColor is set (#12304)
* fix(Signature): fix checking if canvas is empty when set background color * fix(Signature): delete console and uncomment code * chore(Signature): reuse setCanvasBgColor function --------- Co-authored-by: Junyu Zhou <junyu@vivino.cn.com>
This commit is contained in:
parent
4abc67e4ac
commit
8eac20b9cb
@ -97,13 +97,19 @@ export default defineComponent({
|
|||||||
const empty = document.createElement('canvas');
|
const empty = document.createElement('canvas');
|
||||||
empty.width = canvas.width;
|
empty.width = canvas.width;
|
||||||
empty.height = canvas.height;
|
empty.height = canvas.height;
|
||||||
|
if (props.backgroundColor) {
|
||||||
|
const emptyCtx = empty.getContext('2d');
|
||||||
|
setCanvasBgColor(emptyCtx);
|
||||||
|
}
|
||||||
return canvas.toDataURL() === empty.toDataURL();
|
return canvas.toDataURL() === empty.toDataURL();
|
||||||
};
|
};
|
||||||
|
|
||||||
const setCanvasBgColor = () => {
|
const setCanvasBgColor = (
|
||||||
if (state.ctx && props.backgroundColor) {
|
ctx: CanvasRenderingContext2D | null | undefined,
|
||||||
state.ctx.fillStyle = props.backgroundColor;
|
) => {
|
||||||
state.ctx.fillRect(0, 0, state.width, state.height);
|
if (ctx && props.backgroundColor) {
|
||||||
|
ctx.fillStyle = props.backgroundColor;
|
||||||
|
ctx.fillRect(0, 0, state.width, state.height);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -134,7 +140,7 @@ export default defineComponent({
|
|||||||
if (state.ctx) {
|
if (state.ctx) {
|
||||||
state.ctx.clearRect(0, 0, state.width, state.height);
|
state.ctx.clearRect(0, 0, state.width, state.height);
|
||||||
state.ctx.closePath();
|
state.ctx.closePath();
|
||||||
setCanvasBgColor();
|
setCanvasBgColor(state.ctx);
|
||||||
}
|
}
|
||||||
emit('clear');
|
emit('clear');
|
||||||
};
|
};
|
||||||
@ -147,7 +153,7 @@ export default defineComponent({
|
|||||||
|
|
||||||
// ensure canvas is rendered
|
// ensure canvas is rendered
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
setCanvasBgColor();
|
setCanvasBgColor(state.ctx);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user