fix: wteail detail
This commit is contained in:
@@ -54,9 +54,14 @@
|
||||
>
|
||||
<text class="icon">↓</text>
|
||||
</view>
|
||||
<view class="action-btn share" @tap.stop="shareWallpaper(item)">
|
||||
<button
|
||||
class="action-btn share"
|
||||
open-type="share"
|
||||
:data-item="item"
|
||||
@tap.stop="shareWallpaper(item)"
|
||||
>
|
||||
<text class="icon">➦</text>
|
||||
</view>
|
||||
</button>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -75,13 +80,28 @@
|
||||
<text>没有更多了</text>
|
||||
</view>
|
||||
</scroll-view>
|
||||
|
||||
<LoginPopup ref="loginPopupRef" @logind="handleLogind" />
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, onMounted } from "vue";
|
||||
import { ref, onMounted, computed } from "vue";
|
||||
import { getBavBarHeight } from "@/utils/system";
|
||||
import { getWallpaperList, getWallpaperCategoryList } from "@/api/wallpaper.js";
|
||||
import {
|
||||
saveRemoteImageToLocal,
|
||||
saveRecordRequest,
|
||||
getShareToken,
|
||||
} from "@/utils/common.js";
|
||||
import { onShareAppMessage } from "@dcloudio/uni-app";
|
||||
import { getShareReward, abilityCheck } from "@/api/system.js";
|
||||
import { useUserStore } from "@/stores/user";
|
||||
|
||||
const userStore = useUserStore();
|
||||
const loginPopupRef = ref(null);
|
||||
|
||||
const isLoggedIn = computed(() => !!userStore.userInfo.nickName);
|
||||
|
||||
const categories = ref([]);
|
||||
const currentCategoryId = ref(null);
|
||||
@@ -91,6 +111,26 @@ const loading = ref(false);
|
||||
const hasMore = ref(true);
|
||||
const isRefreshing = ref(false);
|
||||
|
||||
onShareAppMessage(async (options) => {
|
||||
getShareReward({ scene: "wallpaper_download" });
|
||||
if (options.from === "button") {
|
||||
const shareTokenRes = await getShareToken(
|
||||
"wallpaper_download",
|
||||
options?.target?.dataset?.item?.id,
|
||||
);
|
||||
return {
|
||||
title: "分享精美壁纸",
|
||||
path: `/pages/wallpaper/detail?shareToken=${shareTokenRes.shareToken}`,
|
||||
};
|
||||
} else {
|
||||
const shareTokenRes = await getShareToken("wallpaper_download", "");
|
||||
return {
|
||||
title: "新春祝福",
|
||||
path: `/pages/index/index?shareToken=${shareTokenRes.shareToken}`,
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
onMounted(async () => {
|
||||
await fetchCategories();
|
||||
});
|
||||
@@ -157,6 +197,10 @@ const loadMore = () => {
|
||||
loadWallpapers();
|
||||
};
|
||||
|
||||
const handleLogind = async () => {
|
||||
// Logic after successful login if needed
|
||||
};
|
||||
|
||||
const onRefresh = () => {
|
||||
isRefreshing.value = true;
|
||||
loadWallpapers(true);
|
||||
@@ -170,46 +214,37 @@ const previewImage = (index) => {
|
||||
});
|
||||
};
|
||||
|
||||
const downloadWallpaper = (item) => {
|
||||
const downloadWallpaper = async (item) => {
|
||||
if (!isLoggedIn.value) {
|
||||
loginPopupRef.value.open();
|
||||
return;
|
||||
}
|
||||
|
||||
const abilityRes = await abilityCheck("wallpaper_download");
|
||||
if (!abilityRes.canUse) {
|
||||
if (
|
||||
abilityRes?.blockType === "need_share" &&
|
||||
abilityRes?.message === "分享可继续"
|
||||
) {
|
||||
uni.showToast({
|
||||
title: "分享给好友即可下载",
|
||||
icon: "none",
|
||||
});
|
||||
return;
|
||||
}
|
||||
uni.showToast({
|
||||
title: "您今日壁纸下载次数已用完,明日再试",
|
||||
icon: "none",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
uni.showLoading({ title: "下载中..." });
|
||||
uni.downloadFile({
|
||||
url: item.url,
|
||||
success: (res) => {
|
||||
if (res.statusCode === 200) {
|
||||
uni.saveImageToPhotosAlbum({
|
||||
filePath: res.tempFilePath,
|
||||
success: () => {
|
||||
uni.hideLoading();
|
||||
uni.showToast({ title: "保存成功", icon: "success" });
|
||||
},
|
||||
fail: (err) => {
|
||||
uni.hideLoading();
|
||||
console.error(err);
|
||||
uni.showToast({ title: "保存失败", icon: "none" });
|
||||
},
|
||||
});
|
||||
} else {
|
||||
uni.hideLoading();
|
||||
uni.showToast({ title: "下载失败", icon: "none" });
|
||||
}
|
||||
},
|
||||
fail: () => {
|
||||
uni.hideLoading();
|
||||
uni.showToast({ title: "下载失败", icon: "none" });
|
||||
},
|
||||
});
|
||||
await saveRemoteImageToLocal(item.imageUrl);
|
||||
saveRecordRequest("", item.id, "wallpaper_download", item.imageUrl);
|
||||
};
|
||||
|
||||
const shareWallpaper = (item) => {
|
||||
// uni.share is for App, specific provider.
|
||||
// For general sharing, we might just preview it or use button open-type="share" if it was a button component.
|
||||
// Since this is a custom UI, we can guide user to preview and long press, or just preview.
|
||||
// Or if on MP-Weixin, show share menu.
|
||||
uni.previewImage({
|
||||
urls: [item.url],
|
||||
});
|
||||
// uni.showToast({ title: '长按图片发送给朋友', icon: 'none' });
|
||||
};
|
||||
const shareWallpaper = (item) => {};
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
||||
Reference in New Issue
Block a user