Commit cd7b58a5 authored by spc's avatar spc

this.hasShownPopu

parent f5d8e817
......@@ -9,6 +9,7 @@ export const useHomeStore = defineStore("homeInfo", {
homeInfo: null,
isLogin: false,
babyExistence: false,
hasShownPopup: false, // 记录是否已经显示过弹窗(全局状态)
};
},
actions: {
......@@ -30,6 +31,20 @@ export const useHomeStore = defineStore("homeInfo", {
this.babyExistence = !babyExistence;
},
/**
* 标记弹窗已显示
*/
markPopupAsShown() {
this.hasShownPopup = true;
},
/**
* 重置弹窗状态(用于测试或特殊需求)
*/
resetPopupState() {
this.hasShownPopup = false;
},
/**
* 获取首页信息
*/
......@@ -38,8 +53,9 @@ export const useHomeStore = defineStore("homeInfo", {
console.log("loadHomeInfo", data);
if (data) {
this.setHomeInfo(data);
// 通过参数传入的方式使用 $sensors
// 通过参数传入的方式使用 $sensors
this.hasShownPopup = false
const userStore = useUserStore();
const mdData = {
......
......@@ -398,7 +398,6 @@ export default {
channelTabListMianTitle: '',
popupImageUrl: '',
popupImageObj: {},
showPop1: false,
}
},
components: {
......@@ -421,18 +420,7 @@ export default {
this.showRegisterLayer = this.isClickPhoneAuth && newVal.isLogin && !newVal.babyExistence;
if (newVal.homeInfo !== null) {
this.initHomeInfo();
// 处理 showPop1 弹窗逻辑(来自 fetchHomeInfo)
console.warn("showPop1", newVal, this.showPop1)
if (newVal.homeInfo.showPop1 && !this.showPop1) {
this.showPop1 = true;
// 延迟显示弹窗,确保页面渲染完成
this.$nextTick(() => {
setTimeout(() => {
this.showImagePopup();
}, 500);
});
}
this.checkAndShowPopup();
}
},
deep: true,
......@@ -462,6 +450,10 @@ export default {
this.checkExposure(this.scrollTop);
});
},
unmounted() {
// 组件销毁时清理弹窗状态(可选,根据业务需求决定是否保留状态)
// 如果需要重置弹窗状态,可以在这里调用 this.resetPopupState()
},
methods: {
async initHomeInfo() {
const { data } = await fetchHomeJSON();
......@@ -754,6 +746,24 @@ export default {
},
closePop1() {
this.$refs.imagePopup.close();
},
// 重置弹窗状态(可在需要时调用)
resetPopupState() {
this.homeStore.resetPopupState(); // 重置 store 中的弹窗状态
},
// 检查并显示弹窗(使用 store 全局状态管理)
checkAndShowPopup() {
// 使用 store 中的 hasShownPopup 来记录是否已经显示过弹窗
if (!this.homeStore.hasShownPopup && this.homeStore.homeInfo?.showPop1) {
this.homeStore.markPopupAsShown(); // 标记已显示过弹窗(全局状态)
this.$nextTick(() => {
setTimeout(() => {
this.showImagePopup();
}, 500);
});
}
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment