|
|
@@ -678,6 +678,7 @@
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
import { ref, onMounted, onUnmounted, computed, watch } from "vue";
|
|
|
+import { storeToRefs } from "pinia";
|
|
|
import { useRoute, useRouter } from "vue-router";
|
|
|
import {
|
|
|
searchVideoByTags,
|
|
|
@@ -699,7 +700,7 @@ const router = useRouter();
|
|
|
|
|
|
// 用户信息
|
|
|
const userStore = useUserStore();
|
|
|
-const { isLoginUser, isVipUser } = userStore;
|
|
|
+const { isLoginUser, isVipUser } = storeToRefs(userStore);
|
|
|
|
|
|
// 价格配置
|
|
|
const priceStore = usePriceStore();
|
|
|
@@ -728,10 +729,10 @@ const videoInfo = ref<any>({
|
|
|
// 相关视频
|
|
|
const relatedVideos = ref<any[]>([]);
|
|
|
|
|
|
-// 开通会员,购买单片栏
|
|
|
-const showPurchaseButtonArea = ref(true);
|
|
|
-// 购买提示弹窗
|
|
|
-const showPurchasePrompt = ref(true);
|
|
|
+// 开通会员,购买单片栏(避免初始闪现,默认不显示)
|
|
|
+const showPurchaseButtonArea = ref(false);
|
|
|
+// 购买提示弹窗(避免初始闪现,默认不显示)
|
|
|
+const showPurchasePrompt = ref(false);
|
|
|
// 会员购买弹窗
|
|
|
const showMembershipPurchaseModal = ref(false);
|
|
|
// 单片购买弹窗
|
|
|
@@ -764,6 +765,9 @@ const showSinglePaymentWaitingDialog = ref(false);
|
|
|
const showShareLinkDialog = ref(false);
|
|
|
const singleCurrentOrderNo = ref("");
|
|
|
|
|
|
+// 用户信息是否已同步完成(用于避免初次刷新时过早进行购买判断)
|
|
|
+const isUserSynced = ref(false);
|
|
|
+
|
|
|
// 会员购买按钮点击
|
|
|
const handleMembershipClick = () => {
|
|
|
// 特殊游览器滚动
|
|
|
@@ -774,10 +778,21 @@ const handleMembershipClick = () => {
|
|
|
};
|
|
|
|
|
|
// 单片购买按钮点击
|
|
|
-const handleSinglePurchaseClick = () => {
|
|
|
+const handleSinglePurchaseClick = async () => {
|
|
|
// 特殊游览器滚动
|
|
|
specialBrowserScroll();
|
|
|
|
|
|
+ // 确保价格配置已加载(团队相关价格可能不同)
|
|
|
+ if (isLoginUser.value && !priceStore.isPriceConfigLoaded) {
|
|
|
+ try {
|
|
|
+ await priceStore.fetchPriceConfig();
|
|
|
+ } catch (error) {
|
|
|
+ console.error("价格配置加载失败:", error);
|
|
|
+ showError("价格配置加载失败,请重试");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// 已登录,显示购买弹窗
|
|
|
showSinglePurchaseModal.value = true;
|
|
|
};
|
|
|
@@ -792,7 +807,7 @@ const handleMembershipPurchase = async () => {
|
|
|
isPaymentLoading.value = true;
|
|
|
|
|
|
// 未登录用户先创建游客账户
|
|
|
- if (!isLoginUser) {
|
|
|
+ if (!isLoginUser.value) {
|
|
|
try {
|
|
|
const guestResponse = await userStore.createGuest();
|
|
|
if (!guestResponse) {
|
|
|
@@ -850,7 +865,7 @@ const handleSinglePurchase = async () => {
|
|
|
}
|
|
|
|
|
|
// 未登录用户先创建游客账户
|
|
|
- if (!isLoginUser) {
|
|
|
+ if (!isLoginUser.value) {
|
|
|
try {
|
|
|
const guestResponse = await userStore.createGuest();
|
|
|
if (!guestResponse) {
|
|
|
@@ -1277,7 +1292,7 @@ const playVideo = (video: any) => {
|
|
|
}
|
|
|
|
|
|
// 判断是否需要通过URL参数传递视频数据
|
|
|
- const shouldIncludeVideoData = !isVipUser;
|
|
|
+ const shouldIncludeVideoData = !isVipUser.value;
|
|
|
|
|
|
// 构建路由参数
|
|
|
const routeParams = {
|
|
|
@@ -1302,13 +1317,12 @@ const checkVideoPurchaseStatus = async () => {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- if (!isLoginUser) {
|
|
|
+ if (!isLoginUser.value) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
await loadVideoInfo();
|
|
|
-
|
|
|
console.log("showPurchasePrompt:", showPurchasePrompt.value);
|
|
|
} catch (error) {
|
|
|
console.error("检查视频购买状态失败:", error);
|
|
|
@@ -1323,6 +1337,7 @@ const loadVideoInfo = async () => {
|
|
|
if (isFreeVideo.value) {
|
|
|
console.log("isFreeVideo");
|
|
|
showPurchaseButtonArea.value = false;
|
|
|
+ showPurchasePrompt.value = false;
|
|
|
|
|
|
const { name, cover, m3u8 } = route.query;
|
|
|
videoInfo.value = {
|
|
|
@@ -1336,10 +1351,10 @@ const loadVideoInfo = async () => {
|
|
|
time: 0,
|
|
|
taginfo: [],
|
|
|
};
|
|
|
- } else if (!isVipUser) {
|
|
|
+ } else if (!isVipUser.value) {
|
|
|
// 未登录
|
|
|
console.log("isNotLogin");
|
|
|
- if (!isLoginUser) {
|
|
|
+ if (!isLoginUser.value) {
|
|
|
showPurchasePrompt.value = true;
|
|
|
showPurchaseButtonArea.value = true;
|
|
|
const { name, cover, duration, view, like } = route.query;
|
|
|
@@ -1403,7 +1418,7 @@ const loadVideoInfo = async () => {
|
|
|
};
|
|
|
}
|
|
|
}
|
|
|
- } else if (isVipUser) {
|
|
|
+ } else if (isVipUser.value) {
|
|
|
// 付费用户,从详情接口获取视频信息
|
|
|
const response = await getVideoDetail(device, String(videoId));
|
|
|
console.log("isVipUser");
|
|
|
@@ -1438,6 +1453,9 @@ const loadVideoInfo = async () => {
|
|
|
taginfo: [],
|
|
|
};
|
|
|
}
|
|
|
+ // 会员用户不显示购买提示/按钮
|
|
|
+ showPurchaseButtonArea.value = false;
|
|
|
+ showPurchasePrompt.value = false;
|
|
|
}
|
|
|
};
|
|
|
|
|
|
@@ -1499,6 +1517,10 @@ const loadRecommendedVideoList = async () => {
|
|
|
watch(
|
|
|
[() => route.params.id, () => route.query],
|
|
|
async ([newId, newQuery], [oldId, oldQuery]) => {
|
|
|
+ // 用户信息未同步完成时,跳过首次触发
|
|
|
+ if (!isUserSynced.value) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
// 检查路由是否真的变化了
|
|
|
const idChanged = newId !== oldId;
|
|
|
const queryChanged = JSON.stringify(newQuery) !== JSON.stringify(oldQuery);
|
|
|
@@ -1521,19 +1543,24 @@ watch(
|
|
|
);
|
|
|
|
|
|
onMounted(async () => {
|
|
|
- // 确保用户信息已同步
|
|
|
- if (!userStore.userInfo) {
|
|
|
+ // 确保用户信息已同步(基于 token 判断是否需要拉取)
|
|
|
+ if (userStore.token) {
|
|
|
await userStore.sync();
|
|
|
}
|
|
|
|
|
|
// 加载价格配置
|
|
|
- if (!priceStore.isPriceConfigLoaded) {
|
|
|
+ if (isLoginUser.value && !priceStore.isPriceConfigLoaded) {
|
|
|
await priceStore.fetchPriceConfig();
|
|
|
}
|
|
|
|
|
|
- // 单片是否购买
|
|
|
+ // 标记用户信息已同步完成,允许路由监听逻辑运行
|
|
|
+ isUserSynced.value = true;
|
|
|
+
|
|
|
+ // 初次进入页面时,按顺序执行:购买判断 -> 加载视频 -> 加载相关推荐
|
|
|
await checkVideoPurchaseStatus();
|
|
|
-
|
|
|
+ await loadVideoInfo();
|
|
|
+ await loadRecommendedVideoList();
|
|
|
+
|
|
|
// 处理分享链接访问
|
|
|
await handleShareLinkVisit();
|
|
|
});
|