1
This commit is contained in:
@@ -4,7 +4,11 @@ export default {
|
|||||||
quiet: false,
|
quiet: false,
|
||||||
stats: true
|
stats: true
|
||||||
},
|
},
|
||||||
mini: {},
|
mini: {
|
||||||
|
webpackChain(chain) {
|
||||||
|
chain.devtool('source-map')
|
||||||
|
}
|
||||||
|
},
|
||||||
h5: {},
|
h5: {},
|
||||||
// 添加这个配置来显示完整错误信息
|
// 添加这个配置来显示完整错误信息
|
||||||
compiler: {
|
compiler: {
|
||||||
|
|||||||
@@ -145,6 +145,7 @@ export default forwardRef(({ id, from, detail, userInfo }, ref) => {
|
|||||||
const qrCodeUrl = qrCodeUrlRes.data.ossPath;
|
const qrCodeUrl = qrCodeUrlRes.data.ossPath;
|
||||||
await delay(100);
|
await delay(100);
|
||||||
// Taro.showLoading({ title: "生成中..." });
|
// Taro.showLoading({ title: "生成中..." });
|
||||||
|
console.log('url', qrCodeUrl)
|
||||||
const url = await generatePosterImage({
|
const url = await generatePosterImage({
|
||||||
playType: play_type,
|
playType: play_type,
|
||||||
ntrp: `NTRP ${genNTRPRequirementText(skill_level_min, skill_level_max)}`,
|
ntrp: `NTRP ${genNTRPRequirementText(skill_level_min, skill_level_max)}`,
|
||||||
@@ -160,6 +161,8 @@ export default forwardRef(({ id, from, detail, userInfo }, ref) => {
|
|||||||
time: `${startTime.format("ah")}点 ${gameLength}`,
|
time: `${startTime.format("ah")}点 ${gameLength}`,
|
||||||
qrCodeUrl,
|
qrCodeUrl,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log('urlend', url)
|
||||||
// Taro.hideLoading();
|
// Taro.hideLoading();
|
||||||
Taro.showShareImageMenu({
|
Taro.showShareImageMenu({
|
||||||
path: url,
|
path: url,
|
||||||
|
|||||||
@@ -169,7 +169,7 @@ class GameDetailService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getLinkUrl(req: { path: string, query: string }): Promise<ApiResponse<{ url_link: string, path: string, query: string }>> {
|
async getLinkUrl(req: { path: string, query: string }): Promise<ApiResponse<{ url_link: string, path: string, query: string }>> {
|
||||||
return httpService.post('/user/generate_url_link', req, { showLoading: true })
|
return httpService.post('/user/generate_url_link', req, { showLoading: false })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -56,9 +56,27 @@ function getImageWh(src: string): Promise<{ width: number; height: number }> {
|
|||||||
|
|
||||||
/** 加载图片 */
|
/** 加载图片 */
|
||||||
function loadImage(canvas: any, src: string): Promise<any> {
|
function loadImage(canvas: any, src: string): Promise<any> {
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
|
||||||
|
let timer: any;
|
||||||
const img = canvas.createImage();
|
const img = canvas.createImage();
|
||||||
img.onload = () => resolve(img);
|
|
||||||
|
img.crossOrigin = "anonymous"
|
||||||
|
|
||||||
|
img.onload = () => {
|
||||||
|
clearTimeout(timer);
|
||||||
|
resolve(img);
|
||||||
|
};
|
||||||
|
img.onerror = () => {
|
||||||
|
clearTimeout(timer);
|
||||||
|
console.log('img error', src)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
timer = setTimeout(() => {
|
||||||
|
reject(new Error(`Image load timeout: ${src}`));
|
||||||
|
}, 8000);
|
||||||
|
|
||||||
img.src = src;
|
img.src = src;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -146,6 +164,7 @@ async function drawRotateCoverImage(
|
|||||||
rotate = 0 // 旋转角度(弧度)
|
rotate = 0 // 旋转角度(弧度)
|
||||||
) {
|
) {
|
||||||
const { width, height } = await getImageWh(src);
|
const { width, height } = await getImageWh(src);
|
||||||
|
console.log('width', width, 'height', height)
|
||||||
const scale = Math.max(w / width, h / height);
|
const scale = Math.max(w / width, h / height);
|
||||||
const newW = width * scale;
|
const newW = width * scale;
|
||||||
const newH = height * scale;
|
const newH = height * scale;
|
||||||
@@ -179,6 +198,7 @@ async function drawRotateCoverImage(
|
|||||||
|
|
||||||
// 绘制 cover
|
// 绘制 cover
|
||||||
ctx.drawImage(img, offsetX, offsetY, newW, newH);
|
ctx.drawImage(img, offsetX, offsetY, newW, newH);
|
||||||
|
console.log('drawImage', offsetX, offsetY, newW, newH)
|
||||||
|
|
||||||
ctx.restore();
|
ctx.restore();
|
||||||
}
|
}
|
||||||
@@ -290,6 +310,8 @@ function drawTextWrap(
|
|||||||
|
|
||||||
/** 核心纯函数:生成海报图片 */
|
/** 核心纯函数:生成海报图片 */
|
||||||
export async function generatePosterImage(data: any): Promise<string> {
|
export async function generatePosterImage(data: any): Promise<string> {
|
||||||
|
|
||||||
|
|
||||||
console.log("start !!!!");
|
console.log("start !!!!");
|
||||||
// const dpr = Taro.getWindowInfo().pixelRatio;
|
// const dpr = Taro.getWindowInfo().pixelRatio;
|
||||||
const dpr = 1;
|
const dpr = 1;
|
||||||
@@ -297,19 +319,30 @@ export async function generatePosterImage(data: any): Promise<string> {
|
|||||||
const width = 600;
|
const width = 600;
|
||||||
const height = 1000;
|
const height = 1000;
|
||||||
|
|
||||||
|
console.log('width', width, 'height', height)
|
||||||
const canvas = Taro.createOffscreenCanvas({ type: "2d", width: width * dpr, height: height * dpr });
|
const canvas = Taro.createOffscreenCanvas({ type: "2d", width: width * dpr, height: height * dpr });
|
||||||
const ctx = canvas.getContext("2d");
|
const ctx = canvas.getContext("2d");
|
||||||
ctx.scale(dpr, dpr);
|
ctx.scale(dpr, dpr);
|
||||||
|
|
||||||
|
|
||||||
|
console.log('ctx', ctx)
|
||||||
|
|
||||||
|
|
||||||
// 背景渐变
|
// 背景渐变
|
||||||
roundRectGradient(ctx, 0, 0, width, height, 24, "#BFFFEF", "#F2FFFC");
|
roundRectGradient(ctx, 0, 0, width, height, 24, "#BFFFEF", "#F2FFFC");
|
||||||
|
|
||||||
|
console.log('bgUrl', bgUrl)
|
||||||
const bgImg = await loadImage(canvas, bgUrl);
|
const bgImg = await loadImage(canvas, bgUrl);
|
||||||
ctx.drawImage(bgImg, 0, 0, width, height);
|
ctx.drawImage(bgImg, 0, 0, width, height);
|
||||||
|
console.log('bgUrlend', )
|
||||||
|
|
||||||
|
|
||||||
roundRotateRect(ctx, 70, 100, width - 140, width - 140, 20, '#fff', deg2rad(-6));
|
roundRotateRect(ctx, 70, 100, width - 140, width - 140, 20, '#fff', deg2rad(-6));
|
||||||
|
|
||||||
|
|
||||||
// 顶部图片
|
// 顶部图片
|
||||||
const mainImg = await loadImage(canvas, data.mainCoursal);
|
const mainImg = await loadImage(canvas, data.mainCoursal);
|
||||||
|
console.log('mainCoursal', data.mainCoursal)
|
||||||
await drawRotateCoverImage(
|
await drawRotateCoverImage(
|
||||||
ctx,
|
ctx,
|
||||||
canvas,
|
canvas,
|
||||||
@@ -378,6 +411,8 @@ export async function generatePosterImage(data: any): Promise<string> {
|
|||||||
left = 20;
|
left = 20;
|
||||||
|
|
||||||
const dateImg = await loadImage(canvas, dateIcon);
|
const dateImg = await loadImage(canvas, dateIcon);
|
||||||
|
|
||||||
|
console.log('dateIcon', dateIcon)
|
||||||
await drawCoverImage(
|
await drawCoverImage(
|
||||||
ctx,
|
ctx,
|
||||||
canvas,
|
canvas,
|
||||||
@@ -404,6 +439,7 @@ export async function generatePosterImage(data: any): Promise<string> {
|
|||||||
left = 20;
|
left = 20;
|
||||||
top += 24;
|
top += 24;
|
||||||
|
|
||||||
|
|
||||||
const mapImg = await loadImage(canvas, mapIcon);
|
const mapImg = await loadImage(canvas, mapIcon);
|
||||||
await drawCoverImage(ctx, canvas, mapIcon, mapImg, left, top, 40, 40, 12);
|
await drawCoverImage(ctx, canvas, mapIcon, mapImg, left, top, 40, 40, 12);
|
||||||
|
|
||||||
@@ -440,11 +476,13 @@ export async function generatePosterImage(data: any): Promise<string> {
|
|||||||
ctx.font = "400 20px sans-serif";
|
ctx.font = "400 20px sans-serif";
|
||||||
ctx.fillText("长按识别二维码,快来加入,有你就有场!", left, height - 30/* top */);
|
ctx.fillText("长按识别二维码,快来加入,有你就有场!", left, height - 30/* top */);
|
||||||
|
|
||||||
|
console.log('canvas', canvas)
|
||||||
// 导出图片
|
// 导出图片
|
||||||
const { tempFilePath } = await Taro.canvasToTempFilePath({
|
const { tempFilePath } = await Taro.canvasToTempFilePath({
|
||||||
canvas,
|
canvas,
|
||||||
fileType: 'png',
|
fileType: 'png',
|
||||||
quality: 0.7,
|
quality: 0.7,
|
||||||
});
|
});
|
||||||
|
console.log('tempFilePath', tempFilePath)
|
||||||
return tempFilePath;
|
return tempFilePath;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -533,7 +533,6 @@ const drawShareCard = async (ctx: any, data: ShareCardData, offscreen: any): Pro
|
|||||||
const locationPath = await loadImage(`${OSS_BASE}/front/ball/images/adc9a167-2ea9-4e3b-b963-6a894a1fd91b.jpg`)
|
const locationPath = await loadImage(`${OSS_BASE}/front/ball/images/adc9a167-2ea9-4e3b-b963-6a894a1fd91b.jpg`)
|
||||||
ctx.drawImage(locationPath, iconX, locationInfoY, iconSize, iconSize)
|
ctx.drawImage(locationPath, iconX, locationInfoY, iconSize, iconSize)
|
||||||
drawBoldText(ctx, data.venueName, danDaX, locationInfoY + 10, locationFontSize, '#000000')
|
drawBoldText(ctx, data.venueName, danDaX, locationInfoY + 10, locationFontSize, '#000000')
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const wxAny: any = (typeof (globalThis as any) !== 'undefined' && (globalThis as any).wx) ? (globalThis as any).wx : null
|
const wxAny: any = (typeof (globalThis as any) !== 'undefined' && (globalThis as any).wx) ? (globalThis as any).wx : null
|
||||||
if (wxAny && typeof wxAny.canvasToTempFilePath === 'function') {
|
if (wxAny && typeof wxAny.canvasToTempFilePath === 'function') {
|
||||||
|
|||||||
Reference in New Issue
Block a user