|
@@ -21,131 +21,111 @@ export const CertLayout: FC<CertLayoutProps> = ({ name, date, ...props }) => {
|
|
if (props.isOpened && !loaded.current) init();
|
|
if (props.isOpened && !loaded.current) init();
|
|
}, [props.isOpened]);
|
|
}, [props.isOpened]);
|
|
|
|
|
|
- const loadFont = (url: string, family: string) => {
|
|
|
|
- return new Promise((res, rej) => {
|
|
|
|
- Taro.loadFontFace({
|
|
|
|
- family,
|
|
|
|
- source: `url('${url}')`,
|
|
|
|
- // @ts-ignore
|
|
|
|
- scopes: ["native"],
|
|
|
|
- success: res,
|
|
|
|
- fail: rej,
|
|
|
|
- });
|
|
|
|
- });
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
const init = async () => {
|
|
const init = async () => {
|
|
try {
|
|
try {
|
|
Taro.showLoading({
|
|
Taro.showLoading({
|
|
title: "绘制中",
|
|
title: "绘制中",
|
|
});
|
|
});
|
|
|
|
|
|
- if (!loaded.current) {
|
|
|
|
- await loadFont(
|
|
|
|
- "https://houseoss.4dkankan.com/project/wx-csbwg-public/fonts/SourceHanSansSCBold.otf",
|
|
|
|
- "SourceHanSansCN-Bold"
|
|
|
|
- );
|
|
|
|
- await loadFont(
|
|
|
|
- "https://houseoss.4dkankan.com/project/wx-csbwg-public/fonts/SourceHanSerifCN-SemiBold.otf",
|
|
|
|
- "SourceHanSerifCN-Bold"
|
|
|
|
- );
|
|
|
|
- await loadFont(
|
|
|
|
- "https://houseoss.4dkankan.com/project/wx-csbwg-public/fonts/SourceHanSansSCRegular.otf",
|
|
|
|
- "SourceHanSansSCRegular"
|
|
|
|
- );
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- Taro.createSelectorQuery()
|
|
|
|
- .select("#certCanvas")
|
|
|
|
- .fields({ node: true, size: true }, async (res) => {
|
|
|
|
- const canvas = res.node;
|
|
|
|
- const ctx = canvas.getContext("2d") as CanvasRenderingContext2D;
|
|
|
|
-
|
|
|
|
- canvas.width = res.width * system.pixelRatio;
|
|
|
|
- canvas.height = res.height * system.pixelRatio;
|
|
|
|
-
|
|
|
|
- const bgInfo = await getTempImgPath(
|
|
|
|
- "https://houseoss.4dkankan.com/project/wx-csbwg-public/images/cert-min.png"
|
|
|
|
- );
|
|
|
|
- const ratio = bgInfo.width / canvas.width;
|
|
|
|
-
|
|
|
|
- const bgSource = await loadImg(canvas, bgInfo.path);
|
|
|
|
-
|
|
|
|
- ctx.drawImage(bgSource, 0, 0, canvas.width, canvas.height);
|
|
|
|
-
|
|
|
|
- ctxText(
|
|
|
|
- ctx,
|
|
|
|
- "特此授予锡善云城·热心市民".split("").join(" "),
|
|
|
|
- `${7 * system.pixelRatio}px SourceHanSansSCRegular`,
|
|
|
|
- "center",
|
|
|
|
- "#424A4A",
|
|
|
|
- canvas.width / 2,
|
|
|
|
- 800 / ratio
|
|
|
|
- );
|
|
|
|
-
|
|
|
|
- ctxText(
|
|
|
|
- ctx,
|
|
|
|
- name.split("").join(" "),
|
|
|
|
- `${15 * system.pixelRatio}px SourceHanSansCN-Bold`,
|
|
|
|
- "center",
|
|
|
|
- "#CFC49E",
|
|
|
|
- canvas.width / 2,
|
|
|
|
- 1020 / ratio
|
|
|
|
- );
|
|
|
|
-
|
|
|
|
- ctxTextWrap(
|
|
|
|
- ctx,
|
|
|
|
- "特此证明,感谢您的热情参与与慷慨支持。您的善举为社区带来了无限的温暖与希望。因您的无私奉献,特授予您热心市民称号,以表彰您对慈善事业的贡献。您的善行将永远激励着我们,为构建更美好的社会贡献一份力量。",
|
|
|
|
- `${7 * system.pixelRatio}px SourceHanSansSCRegular`,
|
|
|
|
- "center",
|
|
|
|
- "#424A4A",
|
|
|
|
- canvas.width / 2,
|
|
|
|
- 1200 / ratio,
|
|
|
|
- 460 * system.pixelRatio
|
|
|
|
- );
|
|
|
|
-
|
|
|
|
- ctxText(
|
|
|
|
- ctx,
|
|
|
|
- date,
|
|
|
|
- `${6 * system.pixelRatio}px SourceHanSerifCN-Bold`,
|
|
|
|
- "left",
|
|
|
|
- "#424A4A",
|
|
|
|
- 740 / ratio,
|
|
|
|
- 1660 / ratio
|
|
|
|
- );
|
|
|
|
-
|
|
|
|
- ctxText(
|
|
|
|
- ctx,
|
|
|
|
- "锡善云城",
|
|
|
|
- `${6 * system.pixelRatio}px SourceHanSerifCN-Bold`,
|
|
|
|
- "left",
|
|
|
|
- "#424A4A",
|
|
|
|
- 1880 / ratio,
|
|
|
|
- 1660 / ratio
|
|
|
|
- );
|
|
|
|
-
|
|
|
|
- await new Promise((resolve, reject) => {
|
|
|
|
- Taro.canvasToTempFilePath({
|
|
|
|
- canvas,
|
|
|
|
- fileType: "jpg",
|
|
|
|
- success(res2) {
|
|
|
|
- setImgPath(res2.tempFilePath);
|
|
|
|
-
|
|
|
|
- loaded.current = true;
|
|
|
|
- resolve(true);
|
|
|
|
- },
|
|
|
|
- fail(err) {
|
|
|
|
- Taro.showToast({
|
|
|
|
- title: err.errMsg,
|
|
|
|
- icon: "none",
|
|
|
|
- duration: 4000,
|
|
|
|
|
|
+ await new Promise((resolve, reject) => {
|
|
|
|
+ Taro.createSelectorQuery()
|
|
|
|
+ .select("#certCanvas")
|
|
|
|
+ .fields({ node: true, size: true }, async (res) => {
|
|
|
|
+ const canvas = res.node;
|
|
|
|
+ const ctx = canvas.getContext("2d") as CanvasRenderingContext2D;
|
|
|
|
+
|
|
|
|
+ canvas.width = res.width * system.pixelRatio;
|
|
|
|
+ canvas.height = res.height * system.pixelRatio;
|
|
|
|
+
|
|
|
|
+ try {
|
|
|
|
+ const bgInfo = await getTempImgPath(
|
|
|
|
+ "https://houseoss.4dkankan.com/project/wx-csbwg-public/images/cert-min.png"
|
|
|
|
+ );
|
|
|
|
+ const ratio = bgInfo.width / canvas.width;
|
|
|
|
+
|
|
|
|
+ const bgSource = await loadImg(canvas, bgInfo.path);
|
|
|
|
+
|
|
|
|
+ ctx.drawImage(bgSource, 0, 0, canvas.width, canvas.height);
|
|
|
|
+
|
|
|
|
+ ctxText(
|
|
|
|
+ ctx,
|
|
|
|
+ "特此授予锡善云城·热心市民".split("").join(" "),
|
|
|
|
+ `${7 * system.pixelRatio}px SourceHanSansSCRegular`,
|
|
|
|
+ "center",
|
|
|
|
+ "#424A4A",
|
|
|
|
+ canvas.width / 2,
|
|
|
|
+ 800 / ratio
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ ctxText(
|
|
|
|
+ ctx,
|
|
|
|
+ name.split("").join(" "),
|
|
|
|
+ `${15 * system.pixelRatio}px SourceHanSansCN-Bold`,
|
|
|
|
+ "center",
|
|
|
|
+ "#CFC49E",
|
|
|
|
+ canvas.width / 2,
|
|
|
|
+ 1020 / ratio
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ ctxTextWrap(
|
|
|
|
+ ctx,
|
|
|
|
+ "特此证明,感谢您的热情参与与慷慨支持。您的善举为社区带来了无限的温暖与希望。因您的无私奉献,特授予您热心市民称号,以表彰您对慈善事业的贡献。您的善行将永远激励着我们,为构建更美好的社会贡献一份力量。",
|
|
|
|
+ `${7 * system.pixelRatio}px SourceHanSansSCRegular`,
|
|
|
|
+ "center",
|
|
|
|
+ "#424A4A",
|
|
|
|
+ canvas.width / 2,
|
|
|
|
+ 1200 / ratio,
|
|
|
|
+ 460 * system.pixelRatio
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ ctxText(
|
|
|
|
+ ctx,
|
|
|
|
+ date,
|
|
|
|
+ `${6 * system.pixelRatio}px SourceHanSerifCN-Bold`,
|
|
|
|
+ "left",
|
|
|
|
+ "#424A4A",
|
|
|
|
+ 740 / ratio,
|
|
|
|
+ 1660 / ratio
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ ctxText(
|
|
|
|
+ ctx,
|
|
|
|
+ "锡善云城",
|
|
|
|
+ `${6 * system.pixelRatio}px SourceHanSerifCN-Bold`,
|
|
|
|
+ "left",
|
|
|
|
+ "#424A4A",
|
|
|
|
+ 1880 / ratio,
|
|
|
|
+ 1660 / ratio
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ await new Promise((resolve, reject) => {
|
|
|
|
+ Taro.canvasToTempFilePath({
|
|
|
|
+ canvas,
|
|
|
|
+ fileType: "jpg",
|
|
|
|
+ success(res2) {
|
|
|
|
+ setImgPath(res2.tempFilePath);
|
|
|
|
+
|
|
|
|
+ loaded.current = true;
|
|
|
|
+ resolve(true);
|
|
|
|
+ },
|
|
|
|
+ fail(err) {
|
|
|
|
+ Taro.showToast({
|
|
|
|
+ title: err.errMsg,
|
|
|
|
+ icon: "none",
|
|
|
|
+ duration: 4000,
|
|
|
|
+ });
|
|
|
|
+ reject(err);
|
|
|
|
+ },
|
|
});
|
|
});
|
|
- reject(err);
|
|
|
|
- },
|
|
|
|
- });
|
|
|
|
- });
|
|
|
|
- })
|
|
|
|
- .exec();
|
|
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ resolve(true);
|
|
|
|
+ } catch (err) {
|
|
|
|
+ reject(false);
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+ .exec();
|
|
|
|
+ });
|
|
} finally {
|
|
} finally {
|
|
Taro.hideLoading();
|
|
Taro.hideLoading();
|
|
}
|
|
}
|