| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- <template>
- <view>
- <sell-container ref="sellContainer"></sell-container>
- <ActivityHost ref="activityHost" :enable-upsell="false"></ActivityHost>
- <policy-consent-host />
- </view>
- </template>
- <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: {},
- pendingPolicyRefresh: false,
- policyAcceptedHandler: null,
- loginSuccessHandler: null,
- }
- },
- onLoad(options) {
- this.pendingActivityOptions = options || {};
- this.bindPolicyRefreshListeners();
- },
- onUnload() {
- this.unbindPolicyRefreshListeners();
- },
- onReady() {
- this.$nextTick(() => {
- if (this.hasActivityEntryOptions(this.pendingActivityOptions)) {
- this.$refs.activityHost?.handlePageOptions(this.pendingActivityOptions);
- }
- this.pendingActivityOptions = {};
- });
- },
- onShow() {
- this.$updateCartBadge();
- // 在其他 Tab 同意协议后切回首页时补刷数据
- if (consumeHomeRefreshAfterPolicy() && uni.getStorageSync("token")) {
- this.refreshHomePageData();
- }
- },
- onShareAppMessage(res) {
- return this.$refs.activityHost?.getShareAppMessage(res) || {
- title: "书嗨",
- path: "/pages/sell/index",
- };
- },
- onShareTimeline(res) {
- return this.$refs.activityHost?.getShareTimeline(res) || {
- title: "书嗨",
- path: "/pages/sell/index",
- };
- },
- onPullDownRefresh() {
- if (this.$refs.sellContainer) {
- this.$refs.sellContainer.hasShareList();
- this.$refs.sellContainer.getIndexCateInfo();
- }
- setTimeout(() => {
- uni.stopPullDownRefresh();
- }, 1000);
- },
- onPageScroll(e) {
- const comp = this.$refs.sellContainer;
- if (!comp) return;
- 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);
- }
- }
- }
- </script>
- <style>
- /* Empty style as content is in the component */
- </style>
|