feat: fix

This commit is contained in:
2025-11-30 22:59:30 +08:00
parent 15d5b05587
commit 8396b5b02a
13 changed files with 157 additions and 106 deletions

View File

@@ -13,6 +13,9 @@ import WechatLogo from "@/static/detail/wechat_icon.svg";
import LinkIcon from "@/static/detail/link.svg";
import CrossIcon from "@/static/detail/cross.svg";
import { genNTRPRequirementText, navto } from "@/utils/helper";
import { waitForAuthInit } from "@/utils/authInit";
import { useUserActions } from "@/store/userStore";
import { generatePosterImage, base64ToTempFilePath, delay } from "@/utils";
import { DayOfWeekMap } from "../../config";
import styles from "./index.module.scss";
@@ -22,6 +25,7 @@ dayjs.locale("zh-cn");
export default forwardRef(({ id, from, detail, userInfo }, ref) => {
const [visible, setVisible] = useState(false);
const [publishFlag, setPublishFlag] = useState(false);
const { fetchUserInfo } = useUserActions();
// const posterRef = useRef();
const { max_participants, participant_count } = detail || {};
@@ -92,8 +96,59 @@ export default forwardRef(({ id, from, detail, userInfo }, ref) => {
};
});
async function handleGenPoster() {
const {
id,
play_type,
skill_level_max,
skill_level_min,
start_time,
end_time,
location_name,
image_list,
title,
} = detail || {};
// 先等待静默登录完成
await waitForAuthInit();
const userInfo = await fetchUserInfo();
const { avatar_url, nickname } = userInfo;
const startTime = dayjs(start_time);
const endTime = dayjs(end_time);
const dayofWeek = DayOfWeekMap.get(startTime.day());
const gameLength = `${endTime.diff(startTime, "hour")}小时`;
Taro.showLoading({ title: "生成中..." });
const qrCodeUrlRes = await DetailService.getQrCodeUrl({
page: "game_pages/detail/index",
scene: `id=${id}`,
});
const qrCodeUrl = await base64ToTempFilePath(
qrCodeUrlRes.data.qr_code_base64
);
await delay(100);
const url = await generatePosterImage({
playType: play_type,
ntrp: `NTRP ${genNTRPRequirementText(skill_level_min, skill_level_max)}`,
mainCoursal:
image_list[0] && image_list[0].startsWith("http")
? image_list[0]
: "https://bimwe.oss-cn-shanghai.aliyuncs.com/front/ball/images/0621b8cf-f7d6-43ad-b852-7dc39f29a782.png",
nickname,
avatarUrl: avatar_url,
title,
locationName: location_name,
date: `${startTime.format("M月D日")} (${dayofWeek})`,
time: `${startTime.format("ah")}${gameLength}`,
qrCodeUrl,
});
Taro.hideLoading();
Taro.showShareImageMenu({
path: url,
});
}
async function handlePost() {
navto(`/game_pages/sharePoster/index?id=${detail.id}`);
// navto(`/game_pages/sharePoster/index?id=${detail.id}`);
handleGenPoster();
setVisible(false);
}