export default { data() { return { minScrollTop: 100, // 设置回到顶端按钮显示要求,最小页面滚动距离 wechatQrcode: '', // 公众号二维码 diyRoute: '/pages/index/index', shopInfo: null // 店铺信息 }; }, onLoad(option) { // #ifdef H5 // H5地图选择位置回调数据 if (option.module && option.module == 'locationPicker') { option.name = ''; // 清空地址 } // #endif this.name = option.name || 'DIY_VIEW_INDEX'; // 根据店铺运营模式,打开平台(shop)或者连锁门店(stroe)页面,接口会自行判断 // 获取店铺信息 this.shopInfo = uni.getStorageSync('shopInfo'); }, onShow() { // 获取关注公众号二维码 this.getFollowQrcode(); // 重新获取店铺信息 this.shopInfo = uni.getStorageSync('shopInfo'); }, mounted() { // 监听图片、文字、商品列表等组件的点击事件 this.unsubscribe = this.$eventBus?.onMany([ 'rubik-cube-tap', 'picture-tap', 'text-tap', 'goods-list-tap', 'presale-tap', 'notes-tap', 'merch-list-tap', 'map-tap', 'img-ads-tap', 'many-goods-list-tap', 'search-tap', ], this._handleDiyGroupInteractionEvent); }, beforeDestroy() { // 移除图片点击事件监听 if (this.unsubscribe) this.unsubscribe(); }, methods: { // 关注公众号 getFollowQrcode() { if (!this.$util.isWeiXin()) return; this.$api.sendRequest({ url: '/wechat/api/wechat/followqrcode', success: res => { if (res.code >= 0 && res.data) { this.wechatQrcode = res.data.qrcode; } } }); }, officialAccountsOpen() { this.$refs.officialAccountsPopup.open(); }, officialAccountsClose() { this.$refs.officialAccountsPopup.close(); }, // 判断是否需要登录授权 _needLoginAuth() { // 检查 index_login_auth 都开启时才需要登录授权 return this.shopInfo?.index_login_auth == 1; }, // 统一处理点击及触摸事件 _handleDiyGroupInteractionEvent(payload) { // #ifdef H5 // 如果是 H5 环境,直接返回 true 继续传播 return true; // #endif // 如果不需要登录授权,直接返回 true 继续传播 if (!this._needLoginAuth()) { return true; } // 如果已登录,直接返回 true 继续传播 if (this.storeToken) { return true; } this.$refs.login?.open(); // 阻止事件继续传播 return false; }, /** * 标题连击 5 次显示构建版本信息(供测试人员使用) */ onTitleTap() { this._titleTapCount = (this._titleTapCount || 0) + 1; if (this._titleTapTimer) { clearTimeout(this._titleTapTimer); } if (this._titleTapCount >= 5) { this._titleTapCount = 0; this._showVersionInfo(); return; } // 2 秒内未达到 5 次则重置计数 this._titleTapTimer = setTimeout(() => { this._titleTapCount = 0; }, 2000); }, _showVersionInfo() { // #ifdef MP-WEIXIN try { const fs = uni.getFileSystemManager(); fs.readFile({ filePath: 'version.json', encoding: 'utf-8', success: (res) => { try { const v = JSON.parse(res.data); if (v && v.commitId) { uni.showModal({ title: '构建版本信息', content: `提交 ID: ${v.commitId}\n构建时间: ${v.buildTime}`, showCancel: false }); return; } } catch (e) {} uni.showModal({ title: '构建版本信息', content: '版本信息不可用', showCancel: false }); }, fail: () => this._showVersionFromGlobal() }); } catch (e) { this._showVersionFromGlobal(); } // #endif // #ifndef MP-WEIXIN this._showVersionFromGlobal(); // #endif }, _showVersionFromGlobal() { try { const v = typeof __app_version !== 'undefined' ? __app_version : null; if (v && v.commitId) { uni.showModal({ title: '构建版本信息', content: `提交 ID: ${v.commitId}\n构建时间: ${v.buildTime}`, showCancel: false }); return; } } catch (e) {} uni.showModal({ title: '构建版本信息', content: '版本信息不可用', showCancel: false }); } } }