fix: 修改分享初始化逻辑、去除小猫图
This commit is contained in:
@@ -25,9 +25,10 @@ dayjs.locale("zh-cn");
|
||||
// 分享弹窗
|
||||
export default forwardRef(({ id, from, detail, userInfo }, ref) => {
|
||||
const [visible, setVisible] = useState(false);
|
||||
const [publishFlag, setPublishFlag] = useState(false);
|
||||
const [shareImageUrl, setShareImageUrl] = useState("");
|
||||
const { fetchUserInfo } = useUserActions();
|
||||
|
||||
const publishFlag = from === "publish";
|
||||
// const posterRef = useRef();
|
||||
const { max_participants, participant_count } = detail || {};
|
||||
|
||||
@@ -57,18 +58,20 @@ export default forwardRef(({ id, from, detail, userInfo }, ref) => {
|
||||
}
|
||||
|
||||
useImperativeHandle(ref, () => ({
|
||||
show: async (publish_flag = false) => {
|
||||
setPublishFlag(publish_flag);
|
||||
if (publish_flag) {
|
||||
try {
|
||||
const url = await generateShareImageUrl();
|
||||
setShareImageUrl(url);
|
||||
} catch (e) {}
|
||||
}
|
||||
show: async () => {
|
||||
setVisible(true);
|
||||
},
|
||||
}));
|
||||
|
||||
useEffect(() => {
|
||||
if (from === "publish") {
|
||||
generateShareImageUrl().then((url) => {
|
||||
setShareImageUrl(url);
|
||||
setVisible(true);
|
||||
});
|
||||
}
|
||||
}, [from]);
|
||||
|
||||
async function generateShareImageUrl() {
|
||||
const {
|
||||
play_type,
|
||||
@@ -183,7 +186,6 @@ export default forwardRef(({ id, from, detail, userInfo }, ref) => {
|
||||
|
||||
function onClose() {
|
||||
setVisible(false);
|
||||
setPublishFlag(false);
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
@@ -54,12 +54,6 @@ function Index() {
|
||||
await waitForAuthInit();
|
||||
// 然后再获取用户信息
|
||||
await fetchUserInfo();
|
||||
|
||||
await delay(1000);
|
||||
|
||||
if (from === "publish") {
|
||||
handleShare(true);
|
||||
}
|
||||
};
|
||||
init();
|
||||
}, []);
|
||||
@@ -126,8 +120,12 @@ function Index() {
|
||||
}
|
||||
}
|
||||
|
||||
function handleShare(flag = false) {
|
||||
sharePopupRef.current.show(flag);
|
||||
function handleShare() {
|
||||
if (!detail.id) {
|
||||
toast("球局未加载完成,请稍后再试");
|
||||
return false;
|
||||
}
|
||||
sharePopupRef.current.show();
|
||||
}
|
||||
|
||||
const handleJoinGame = async () => {
|
||||
@@ -293,6 +291,7 @@ function Index() {
|
||||
currentUserInfo={myInfo}
|
||||
/>
|
||||
{/* share popup */}
|
||||
{detail.id && myInfo.id && (
|
||||
<SharePopup
|
||||
ref={sharePopupRef}
|
||||
id={id as string}
|
||||
@@ -300,6 +299,7 @@ function Index() {
|
||||
detail={detail}
|
||||
userInfo={myInfo}
|
||||
/>
|
||||
)}
|
||||
</View>
|
||||
</ScrollView>
|
||||
);
|
||||
|
||||
@@ -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 }> {
|
||||
return new Promise((resolve) => {
|
||||
Taro.getImageInfo({
|
||||
return new Promise((resolve, reject) => {
|
||||
(Taro as TaroGetImageInfo).getImageInfo({
|
||||
src,
|
||||
success: ({ width, height }) => resolve({ width, height }),
|
||||
fail: (e) => reject(e),
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user