From e5b33085bd556be76734ec9d8ef6516636968d46 Mon Sep 17 00:00:00 2001 From: zpc Date: Sun, 23 Mar 2025 13:21:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.vue | 8 +- components/buy-notice/buy-notice.vue | 332 +++++++++------- .../detail-preview-popup.vue | 30 +- components/detail-preview-popup/index.js | 73 ++++ package/index/leitai.vue | 2 +- package/index/lian-ji.vue | 2 +- pages/shouye/detail.vue | 354 ++++++------------ pages/shouye/detail_wuxian.vue | 2 +- 8 files changed, 414 insertions(+), 389 deletions(-) create mode 100644 components/detail-preview-popup/index.js diff --git a/App.vue b/App.vue index 8600157..df138ce 100644 --- a/App.vue +++ b/App.vue @@ -1,5 +1,8 @@ + \ No newline at end of file diff --git a/components/detail-preview-popup/detail-preview-popup.vue b/components/detail-preview-popup/detail-preview-popup.vue index 2e36608..0fc720a 100644 --- a/components/detail-preview-popup/detail-preview-popup.vue +++ b/components/detail-preview-popup/detail-preview-popup.vue @@ -103,10 +103,24 @@ export default { this.innerProductType = this.productType; this.innerProbability = this.probability; this.innerExtraInfo = this.extraInfo; + + // 监听全局预览事件 + uni.$on('global-preview-event', this.handleGlobalEvent); + }, + beforeDestroy() { + // 组件销毁前移除事件监听 + uni.$off('global-preview-event', this.handleGlobalEvent); }, methods: { + // 处理全局预览事件 + handleGlobalEvent(options) { + console.log('收到全局预览事件', options); + this.setPreviewData(options); + }, + // 设置预览数据并打开弹窗 setPreviewData(data) { + console.log('设置预览数据', data); if (!data) return; // 更新内部数据 @@ -123,17 +137,27 @@ export default { // 打开弹窗 open() { - console.log('尝试打开弹窗'); + console.log('尝试打开弹窗', this.$refs.popup); this.visible = true; // 使用nextTick确保DOM更新后再打开弹窗 this.$nextTick(() => { console.log('DOM已更新,准备打开弹窗'); if (this.$refs.popup) { - this.$refs.popup.open(); - console.log('弹窗已打开'); + // 小程序环境下需要额外延迟 + setTimeout(() => { + this.$refs.popup.open(); + console.log('弹窗已打开'); + }, 50); } else { console.error('popup ref不存在,请检查组件是否正确挂载'); + // 延迟后再次尝试 + setTimeout(() => { + if (this.$refs.popup) { + this.$refs.popup.open(); + console.log('弹窗已打开(延迟尝试)'); + } + }, 300); } }); }, diff --git a/components/detail-preview-popup/index.js b/components/detail-preview-popup/index.js new file mode 100644 index 0000000..4737d19 --- /dev/null +++ b/components/detail-preview-popup/index.js @@ -0,0 +1,73 @@ +import Vue from 'vue' + +/** + * 全局商品预览弹窗方法 + * @param {Object} options 预览参数 + * @param {String} options.title 商品标题 + * @param {String} options.imgUrl 商品图片地址 + * @param {String} options.tipTitle 商品标签 + * @param {String} options.productType 商品类型 + * @param {String} options.probability 商品概率 + * @param {Array} options.extraInfo 额外信息 + * @returns {Promise} 返回Promise + */ +const preview = function(options = {}) { + return new Promise((resolve) => { + // 获取当前页面 + const pages = getCurrentPages(); + const currentPage = pages[pages.length - 1]; + + // 尝试获取全局预览组件 + let previewComponent = null; + + // 尝试在App.vue中找到全局组件 + try { + const app = getApp(); + if (app.$vm && app.$vm.$children) { + // 在App.vue的子组件中查找 + for (const child of app.$vm.$children) { + if (child.$options.name === 'DetailPreviewPopup') { + previewComponent = child; + break; + } + } + } + } catch (e) { + console.error('获取全局组件失败', e); + } + + // 如果没找到全局组件,尝试在当前页面找 + if (!previewComponent && currentPage && currentPage.$vm) { + try { + // 查找页面中的预览组件 + const pageVm = currentPage.$vm; + for (const child of pageVm.$children) { + if (child.$options.name === 'DetailPreviewPopup') { + previewComponent = child; + break; + } + } + } catch (e) { + console.error('获取页面组件失败', e); + } + } + + // 如果还是没找到组件,发送全局事件 + if (!previewComponent) { + console.log('未找到组件实例,发送全局事件'); + uni.$emit('global-preview-event', options); + setTimeout(() => resolve(), 500); + return; + } + + // 使用找到的组件 + console.log('找到预览组件,直接调用'); + previewComponent.setPreviewData(options); + setTimeout(() => resolve(previewComponent), 300); + }); +}; + +// 挂载到Vue原型上 +Vue.prototype.$preview = preview; + +export default preview; \ No newline at end of file diff --git a/package/index/leitai.vue b/package/index/leitai.vue index 2972fe5..2157341 100644 --- a/package/index/leitai.vue +++ b/package/index/leitai.vue @@ -699,7 +699,7 @@ export default { if (type == 1) { url = "orderbuy"; - if (!uni.getStorageSync("_agree_buy_notice") && !fromNotice) { + if (this.$refs.buyNotice.getIsShow()&& !fromNotice) { this.$refs.buyNotice.getRule(6); return; } diff --git a/package/index/lian-ji.vue b/package/index/lian-ji.vue index d630918..b99c89a 100644 --- a/package/index/lian-ji.vue +++ b/package/index/lian-ji.vue @@ -757,7 +757,7 @@ } } - if (!uni.getStorageSync('_agree_buy_notice') && !fromNotice) { + if (this.$refs.buyNotice.getIsShow() && !fromNotice) { this.$refs.buyNotice.getRule(6) return } diff --git a/pages/shouye/detail.vue b/pages/shouye/detail.vue index 827c242..d8521db 100644 --- a/pages/shouye/detail.vue +++ b/pages/shouye/detail.vue @@ -3,62 +3,37 @@ -->