细节优化

This commit is contained in:
kron
2025-07-14 13:39:10 +08:00
parent d73d52f752
commit cde905c680
15 changed files with 106 additions and 90 deletions

View File

@@ -180,70 +180,74 @@ export const drawRoundImage = async (
};
export async function generateCanvasImage(canvasId, type, user, data) {
var ctx = uni.createCanvasContext(canvasId);
const width = 300;
const height = 534;
ctx.drawImage("../static/share-bg.png", 0, 0, width, height);
drawRoundImage(ctx, user.avatar, 17, 20, 32, 32, 20);
ctx.drawImage(user.lvlImage, 12, 15, 42, 42);
renderText(ctx, user.nickName, 13, "#fff", 58, 34);
renderRankTitle(ctx, user.lvlName);
try {
var ctx = uni.createCanvasContext(canvasId);
const width = 300;
const height = 534;
ctx.drawImage("../static/share-bg.png", 0, 0, width, height);
drawRoundImage(ctx, user.avatar, 17, 20, 32, 32, 20);
ctx.drawImage(user.lvlImage, 12, 15, 42, 42);
renderText(ctx, user.nickName, 13, "#fff", 58, 34);
renderRankTitle(ctx, user.lvlName);
let titleImage = "../static/first-try-title.png";
let subTitle = "正式开启弓箭手之路";
if (type > 1) {
subTitle = `今日弓箭练习打卡 ${data.createdAt
.split(" ")[0]
.replaceAll("-", ".")}`;
let titleImage = "../static/first-try-title.png";
let subTitle = "正式开启弓箭手之路";
if (type > 1) {
subTitle = `今日弓箭练习打卡 ${data.createdAt
.split(" ")[0]
.replaceAll("-", ".")}`;
}
if (type == 2) {
titleImage = "../static/practise-one-title.png";
} else if (type == 3) {
titleImage = "../static/practise-two-title.png";
}
ctx.drawImage(titleImage, (width - 160) / 2, 160, 160, 40);
const subTitleWidth = ctx.measureText(subTitle).width;
renderText(
ctx,
subTitle,
18,
"#fff",
width / 2 - subTitleWidth - (type > 1 ? 15 : 9),
220
);
renderText(ctx, "共", 14, "#fff", 122, 300);
const totalRing = data.arrows.reduce((last, next) => last + next.ring, 0);
renderText(ctx, totalRing, 14, "#fed847", 148, 300, "center");
renderText(ctx, "环", 14, "#fff", 161, 300);
renderLine(ctx, 77);
renderLine(ctx, 185);
renderScores(ctx, data.arrows);
ctx.drawImage(
"../static/device-icon.png",
width * 0.06,
height * 0.87,
48,
48
);
renderText(ctx, "射灵平台", 14, "#fff", width * 0.25, height * 0.9);
renderText(
ctx,
"快加入我们一起玩吧~",
10,
"rgba(255, 255, 255, 0.5)",
width * 0.25,
height * 0.93
);
renderText(
ctx,
"后羿就是这样练成的",
10,
"rgba(255, 255, 255, 0.5)",
width * 0.25,
height * 0.955
);
ctx.drawImage("../static/qr-code.png", width * 0.75, height * 0.86, 56, 56);
ctx.draw();
} catch (err) {
console.log(err);
}
if (type == 2) {
titleImage = "../static/practise-one-title.png";
} else if (type == 3) {
titleImage = "../static/practise-two-title.png";
}
ctx.drawImage(titleImage, (width - 160) / 2, 160, 160, 40);
const subTitleWidth = ctx.measureText(subTitle).width;
renderText(
ctx,
subTitle,
18,
"#fff",
width / 2 - subTitleWidth - (type > 1 ? 15 : 9),
220
);
renderText(ctx, "共", 14, "#fff", 122, 300);
const totalRing = data.arrows.reduce((last, next) => last + next.ring, 0);
renderText(ctx, totalRing, 14, "#fed847", 148, 300, "center");
renderText(ctx, "环", 14, "#fff", 161, 300);
renderLine(ctx, 77);
renderLine(ctx, 185);
renderScores(ctx, data.arrows);
ctx.drawImage(
"../static/device-icon.png",
width * 0.06,
height * 0.87,
48,
48
);
renderText(ctx, "射灵平台", 14, "#fff", width * 0.25, height * 0.9);
renderText(
ctx,
"快加入我们一起玩吧~",
10,
"rgba(255, 255, 255, 0.5)",
width * 0.25,
height * 0.93
);
renderText(
ctx,
"后羿就是这样练成的",
10,
"rgba(255, 255, 255, 0.5)",
width * 0.25,
height * 0.955
);
ctx.drawImage("../static/qr-code.png", width * 0.75, height * 0.86, 56, 56);
ctx.draw();
}
export const wxShare = async () => {