|
|
@@ -9,19 +9,30 @@
|
|
|
<script>
|
|
|
import ActivityHost from "@/components/activity-host.vue";
|
|
|
import PolicyConsentHost from "@/components/policy-consent-host.vue";
|
|
|
+import tabbarBlockMixin from "@/utils/tabbar-block-mixin.js";
|
|
|
+import { eventBus } from "@/utils/event-bus";
|
|
|
+import { consumeHomeRefreshAfterPolicy } from "@/utils/policy-consent-manager.js";
|
|
|
|
|
|
export default {
|
|
|
+ mixins: [tabbarBlockMixin],
|
|
|
components: {
|
|
|
ActivityHost,
|
|
|
PolicyConsentHost,
|
|
|
},
|
|
|
data() {
|
|
|
return {
|
|
|
- pendingActivityOptions: {}
|
|
|
+ pendingActivityOptions: {},
|
|
|
+ pendingPolicyRefresh: false,
|
|
|
+ policyAcceptedHandler: null,
|
|
|
+ loginSuccessHandler: null,
|
|
|
}
|
|
|
},
|
|
|
onLoad(options) {
|
|
|
this.pendingActivityOptions = options || {};
|
|
|
+ this.bindPolicyRefreshListeners();
|
|
|
+ },
|
|
|
+ onUnload() {
|
|
|
+ this.unbindPolicyRefreshListeners();
|
|
|
},
|
|
|
onReady() {
|
|
|
this.$nextTick(() => {
|
|
|
@@ -33,6 +44,10 @@ export default {
|
|
|
},
|
|
|
onShow() {
|
|
|
this.$updateCartBadge();
|
|
|
+ // 在其他 Tab 同意协议后切回首页时补刷数据
|
|
|
+ if (consumeHomeRefreshAfterPolicy() && uni.getStorageSync("token")) {
|
|
|
+ this.refreshHomePageData();
|
|
|
+ }
|
|
|
},
|
|
|
onShareAppMessage(res) {
|
|
|
return this.$refs.activityHost?.getShareAppMessage(res) || {
|
|
|
@@ -61,6 +76,38 @@ export default {
|
|
|
comp.scrollTop = e.scrollTop;
|
|
|
},
|
|
|
methods: {
|
|
|
+ bindPolicyRefreshListeners() {
|
|
|
+ if (!this.policyAcceptedHandler) {
|
|
|
+ this.policyAcceptedHandler = () => {
|
|
|
+ this.pendingPolicyRefresh = true;
|
|
|
+ };
|
|
|
+ eventBus.on("policyAccepted", this.policyAcceptedHandler);
|
|
|
+ }
|
|
|
+ if (!this.loginSuccessHandler) {
|
|
|
+ this.loginSuccessHandler = () => {
|
|
|
+ if (!this.pendingPolicyRefresh) return;
|
|
|
+ this.pendingPolicyRefresh = false;
|
|
|
+ consumeHomeRefreshAfterPolicy();
|
|
|
+ this.refreshHomePageData();
|
|
|
+ };
|
|
|
+ eventBus.on("loginSuccess", this.loginSuccessHandler);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ unbindPolicyRefreshListeners() {
|
|
|
+ if (this.policyAcceptedHandler) {
|
|
|
+ eventBus.off("policyAccepted", this.policyAcceptedHandler);
|
|
|
+ this.policyAcceptedHandler = null;
|
|
|
+ }
|
|
|
+ if (this.loginSuccessHandler) {
|
|
|
+ eventBus.off("loginSuccess", this.loginSuccessHandler);
|
|
|
+ this.loginSuccessHandler = null;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ refreshHomePageData() {
|
|
|
+ this.$nextTick(() => {
|
|
|
+ this.$refs.sellContainer?.refreshPageData?.();
|
|
|
+ });
|
|
|
+ },
|
|
|
hasActivityEntryOptions(options = {}) {
|
|
|
return !!(options.scene || options.reduceCode || options.upsellCode);
|
|
|
}
|