fix: 修改分享初始化逻辑、去除小猫图

This commit is contained in:
2026-02-08 23:58:37 +08:00
parent 70a66fabdc
commit 28955e9da1
3 changed files with 38 additions and 27 deletions

View File

@@ -25,9 +25,10 @@ dayjs.locale("zh-cn");
// 分享弹窗 // 分享弹窗
export default forwardRef(({ id, from, detail, userInfo }, ref) => { export default forwardRef(({ id, from, detail, userInfo }, ref) => {
const [visible, setVisible] = useState(false); const [visible, setVisible] = useState(false);
const [publishFlag, setPublishFlag] = useState(false);
const [shareImageUrl, setShareImageUrl] = useState(""); const [shareImageUrl, setShareImageUrl] = useState("");
const { fetchUserInfo } = useUserActions(); const { fetchUserInfo } = useUserActions();
const publishFlag = from === "publish";
// const posterRef = useRef(); // const posterRef = useRef();
const { max_participants, participant_count } = detail || {}; const { max_participants, participant_count } = detail || {};
@@ -57,18 +58,20 @@ export default forwardRef(({ id, from, detail, userInfo }, ref) => {
} }
useImperativeHandle(ref, () => ({ useImperativeHandle(ref, () => ({
show: async (publish_flag = false) => { show: async () => {
setPublishFlag(publish_flag);
if (publish_flag) {
try {
const url = await generateShareImageUrl();
setShareImageUrl(url);
} catch (e) {}
}
setVisible(true); setVisible(true);
}, },
})); }));
useEffect(() => {
if (from === "publish") {
generateShareImageUrl().then((url) => {
setShareImageUrl(url);
setVisible(true);
});
}
}, [from]);
async function generateShareImageUrl() { async function generateShareImageUrl() {
const { const {
play_type, play_type,
@@ -183,7 +186,6 @@ export default forwardRef(({ id, from, detail, userInfo }, ref) => {
function onClose() { function onClose() {
setVisible(false); setVisible(false);
setPublishFlag(false);
} }
return ( return (

View File

@@ -54,12 +54,6 @@ function Index() {
await waitForAuthInit(); await waitForAuthInit();
// 然后再获取用户信息 // 然后再获取用户信息
await fetchUserInfo(); await fetchUserInfo();
await delay(1000);
if (from === "publish") {
handleShare(true);
}
}; };
init(); init();
}, []); }, []);
@@ -126,8 +120,12 @@ function Index() {
} }
} }
function handleShare(flag = false) { function handleShare() {
sharePopupRef.current.show(flag); if (!detail.id) {
toast("球局未加载完成,请稍后再试");
return false;
}
sharePopupRef.current.show();
} }
const handleJoinGame = async () => { const handleJoinGame = async () => {
@@ -293,6 +291,7 @@ function Index() {
currentUserInfo={myInfo} currentUserInfo={myInfo}
/> />
{/* share popup */} {/* share popup */}
{detail.id && myInfo.id && (
<SharePopup <SharePopup
ref={sharePopupRef} ref={sharePopupRef}
id={id as string} id={id as string}
@@ -300,6 +299,7 @@ function Index() {
detail={detail} detail={detail}
userInfo={myInfo} userInfo={myInfo}
/> />
)}
</View> </View>
</ScrollView> </ScrollView>
); );

View File

@@ -35,12 +35,21 @@ export function base64ToTempFilePath(base64Data: string): Promise<string> {
} }
interface TaroGetImageInfo {
getImageInfo(option: {
src: string;
success?: (res: { width: number; height: number }) => void;
fail?: (err: unknown) => void;
}): void;
}
/** 获取图片宽高 */ /** 获取图片宽高 */
function getImageWh(src: string): Promise<{ width: number; height: number }> { function getImageWh(src: string): Promise<{ width: number; height: number }> {
return new Promise((resolve) => { return new Promise((resolve, reject) => {
Taro.getImageInfo({ (Taro as TaroGetImageInfo).getImageInfo({
src, src,
success: ({ width, height }) => resolve({ width, height }), success: ({ width, height }) => resolve({ width, height }),
fail: (e) => reject(e),
}); });
}); });
} }