import Vue from 'vue' import teenagePopUpWindow from '@/components/teenagePopUpWindow/teenagePopUpWindow.vue' const app = getApp(); // 创建全局弹窗容器 function createPopupContainer() { const container = document.createElement('div'); container.id = 'teenage-popup-container'; document.body.appendChild(container); return container; } export function createTeenagePopUpWindow(options = {}) { const { title, content, confirmText, imageSrc } = options; // 确保弹窗容器存在 let container = document.getElementById('teenage-popup-container'); if (!container) { container = createPopupContainer(); } // 创建 Vue 实例 const PopupConstructor = Vue.extend({ render(h) { return h(teenagePopUpWindow, { props: { text: content || '截图至相册,微信扫一扫', confirmText: confirmText || '知道了', imageSrc: imageSrc || '../../static/me/qingshaonianmoshi.png' }, on: { close: this.closePopup } }); }, methods: { closePopup() { this.$destroy(); this.$el.remove(); } } }); // 创建并挂载实例 const instance = new PopupConstructor().$mount(container); return { show: () => { // 在 uni-app 中使用 uni.createAnimation 或 $refs 来触发显示 if (instance.$children && instance.$children[0] && instance.$children[0].open) { instance.$children[0].open(); } }, hide: () => { // 在 uni-app 中使用 uni.createAnimation 或 $refs 来触发隐藏 if (instance.$children && instance.$children[0] && instance.$children[0].close) { instance.$children[0].close(); } } }; } // 全局定时弹窗方法 export async function setupTeenagePopupTimer() { function showTeenagePopUpWindow() { const teenagePopup = createTeenagePopUpWindow({ title: '青少年模式提醒', content: '为保护未成年人健康成长,建议合理控制使用时间', confirmText: '我知道了' }); // 显示弹窗 teenagePopup.show(); } showTeenagePopUpWindow(); }