|
|
@@ -1,14 +1,14 @@
|
|
|
<template>
|
|
|
<view :class="classes" :style="{
|
|
|
zIndex,
|
|
|
- backgroundSize: `${gapX + width}px`
|
|
|
+ backgroundSize: `${gapX + width}px`,
|
|
|
+ backgroundImage: `url('${base64Url}')`
|
|
|
}">
|
|
|
</view>
|
|
|
</template>
|
|
|
<script lang="ts">
|
|
|
import { reactive, toRefs, computed, watch } from 'vue';
|
|
|
import Taro from '@tarojs/taro';
|
|
|
-import { log } from 'console';
|
|
|
export default {
|
|
|
props: {
|
|
|
name: {
|
|
|
@@ -111,10 +111,10 @@ export default {
|
|
|
ratio = res.pixelRatio;
|
|
|
}
|
|
|
});
|
|
|
- const canvasWidth = `${(gapX + width) * ratio}`;
|
|
|
- const canvasHeight = `${(gapY + height) * ratio}`;
|
|
|
- const markWidth = width * ratio;
|
|
|
- const markHeight = height * ratio;
|
|
|
+ const canvasWidth = `${(gapX.value + width.value) * ratio}`;
|
|
|
+ const canvasHeight = `${(gapY.value + height.value) * ratio}`;
|
|
|
+ const markWidth = width.value * ratio;
|
|
|
+ const markHeight = height.value * ratio;
|
|
|
const canvas: Taro.OffscreenCanvas = Taro.createOffscreenCanvas({
|
|
|
type: '2d',
|
|
|
width: Number(canvasWidth),
|
|
|
@@ -123,11 +123,11 @@ export default {
|
|
|
const ctx: any = canvas.getContext('2d');
|
|
|
|
|
|
if (ctx) {
|
|
|
- if (image) {
|
|
|
+ if (image.value) {
|
|
|
// 创建一个图片
|
|
|
const img = canvas.createImage() as HTMLImageElement;
|
|
|
dealWithImage(ctx, img, ratio, ctx.canvas, markWidth, markHeight);
|
|
|
- } else if (content) {
|
|
|
+ } else if (content.value) {
|
|
|
dealWithText(ctx, ratio, ctx.canvas, markWidth, markHeight);
|
|
|
}
|
|
|
} else {
|
|
|
@@ -138,10 +138,10 @@ export default {
|
|
|
const canvas = document.createElement('canvas');
|
|
|
const ratio = window.devicePixelRatio;
|
|
|
const ctx = canvas.getContext('2d');
|
|
|
- const canvasWidth = `${(gapX + width) * ratio}px`;
|
|
|
- const canvasHeight = `${(gapY + height) * ratio}px`;
|
|
|
- const markWidth = width * ratio;
|
|
|
- const markHeight = height * ratio;
|
|
|
+ const canvasWidth = `${(gapX.value + width.value) * ratio}px`;
|
|
|
+ const canvasHeight = `${(gapY.value + height.value) * ratio}px`;
|
|
|
+ const markWidth = width.value * ratio;
|
|
|
+ const markHeight = height.value * ratio;
|
|
|
canvas.setAttribute('width', canvasWidth);
|
|
|
canvas.setAttribute('height', canvasHeight);
|
|
|
|
|
|
@@ -168,14 +168,14 @@ export default {
|
|
|
ctx.rotate((Math.PI / 180) * Number(rotate));
|
|
|
img.crossOrigin = 'anonymous';
|
|
|
img.referrerPolicy = 'no-referrer';
|
|
|
- img.src = image; // 要加载的图片 url, 可以是base64
|
|
|
+ img.src = image.value; // 要加载的图片 url, 可以是base64
|
|
|
img.onload = () => {
|
|
|
ctx.drawImage(
|
|
|
img,
|
|
|
(-imageWidth * ratio) / 2,
|
|
|
(-imageHeight * ratio) / 2,
|
|
|
- imageWidth * ratio,
|
|
|
- imageHeight * ratio
|
|
|
+ imageWidth.value * ratio,
|
|
|
+ imageHeight.value * ratio
|
|
|
);
|
|
|
ctx.restore();
|
|
|
state.base64Url = canvas.toDataURL();
|
|
|
@@ -192,11 +192,11 @@ export default {
|
|
|
ctx.textAlign = 'center';
|
|
|
// 文字绕中间旋转
|
|
|
ctx.translate(markWidth / 2, markHeight / 2);
|
|
|
- ctx.rotate((Math.PI / 180) * Number(rotate));
|
|
|
- const markSize = Number(fontSize) * ratio;
|
|
|
- ctx.font = `${fontStyle} normal ${fontWeight} ${markSize}px/${markHeight}px ${fontFamily}`;
|
|
|
- ctx.fillStyle = fontColor;
|
|
|
- ctx.fillText(content, 0, 0);
|
|
|
+ ctx.rotate((Math.PI / 180) * Number(rotate.value));
|
|
|
+ const markSize = Number(fontSize.value) * ratio;
|
|
|
+ ctx.font = `${fontStyle.value} normal ${fontWeight.value} ${markSize}px/${markHeight}px ${fontFamily.value}`;
|
|
|
+ ctx.fillStyle = fontColor.value;
|
|
|
+ ctx.fillText(content.value, 0, 0);
|
|
|
ctx.restore();
|
|
|
state.base64Url = canvas.toDataURL();
|
|
|
};
|
|
|
@@ -208,21 +208,21 @@ export default {
|
|
|
|
|
|
watch(
|
|
|
() => [
|
|
|
- zIndex,
|
|
|
- gapX,
|
|
|
- gapY,
|
|
|
- width,
|
|
|
- height,
|
|
|
- rotate,
|
|
|
- image,
|
|
|
- imageWidth,
|
|
|
- imageHeight,
|
|
|
- content,
|
|
|
- fontStyle,
|
|
|
- fontWeight,
|
|
|
- fontColor,
|
|
|
- fontSize,
|
|
|
- fontFamily
|
|
|
+ zIndex.value,
|
|
|
+ gapX.value,
|
|
|
+ gapY.value,
|
|
|
+ width.value,
|
|
|
+ height.value,
|
|
|
+ rotate.value,
|
|
|
+ image.value,
|
|
|
+ imageWidth.value,
|
|
|
+ imageHeight.value,
|
|
|
+ content.value,
|
|
|
+ fontStyle.value,
|
|
|
+ fontWeight.value,
|
|
|
+ fontColor.value,
|
|
|
+ fontSize.value,
|
|
|
+ fontFamily.value
|
|
|
],
|
|
|
() => {
|
|
|
init();
|