From 75a8a4d5fc7b98ab4dba1399b0083ee7cbd9bea9 Mon Sep 17 00:00:00 2001 From: lf <1534621107@qq.com> Date: Fri, 12 Jul 2024 10:12:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96index=20=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/index/index.vue | 102 +++++++++++--------------------------- 1 file changed, 28 insertions(+), 74 deletions(-) diff --git a/src/pages/index/index.vue b/src/pages/index/index.vue index d14fdee..8b204ef 100644 --- a/src/pages/index/index.vue +++ b/src/pages/index/index.vue @@ -88,76 +88,30 @@ const getUrlPathName = () => { } window.parent.addEventListener('message', function (event) { - let srcData = { - url: '', - title: '', - } switch (event.data.data.type) { case 'login': - srcData = { - url: contentData.content_templates.source + `?activity_code=${activityCode.value}`, - title: contentData.content_templates.moduledesc, - } + case 'couponBack': + srcList.url = contentData.content_templates.source + `?activity_code=${activityCode.value}` + srcList.title = contentData.content_templates.moduledesc break case 'coupon': - srcData = { - url: contentData.user_content_templates.source + `?activity_code=${activityCode.value}`, - title: contentData.user_content_templates.moduledesc, - } + srcList.url = + contentData.user_content_templates.source + `?activity_code=${activityCode.value}` + srcList.title = contentData.user_content_templates.moduledesc break case 'product': // eslint-disable-next-line no-case-declarations const url = `product_id=${event.data.data.product_id}&id=${event.data.data.id}&activity_code=${activityCode.value}` - // eslint-disable-next-line no-case-declarations - const newUrl = encodeURIComponent(url) - srcData = { - url: contentData.user_content_templates.source + `#/pages/coupon/product?url=${newUrl}`, - title: contentData.user_content_templates.moduledesc, - } - break - case 'couponBack': - srcData = { - url: contentData.content_templates.source + `?activity_code=${activityCode.value}`, - title: contentData.content_templates.moduledesc, - } + srcList.url = + contentData.user_content_templates.source + + `#/pages/coupon/product?url=${encodeURIComponent(url)}` + srcList.title = contentData.user_content_templates.moduledesc break case 'logout': return initContent() } - // if (event.data.data.type === 'login') { - // srcData = { - // url: contentData.content_templates.source + `?activity_code=${activityCode.value}`, - // title: contentData.content_templates.moduledesc, - // } - // } else if (event.data.data.type === 'coupon') { - // srcData = { - // url: contentData.user_content_templates.source + `?activity_code=${activityCode.value}`, - // title: contentData.user_content_templates.moduledesc, - // } - // } else if (event.data.data.type === 'product') { - // const url = `product_id=${event.data.data.product_id}&id=${event.data.data.id}&activity_code=${activityCode.value}` - // const newUrl = encodeURIComponent(url) - // srcData = { - // url: contentData.user_content_templates.source + `#/pages/coupon/product?url=${newUrl}`, - // title: contentData.user_content_templates.moduledesc, - // } - // } else if (event.data.data.type === 'couponBack') { - // srcData = { - // url: contentData.content_templates.source + `?activity_code=${activityCode.value}`, - // title: contentData.content_templates.moduledesc, - // } - // } else if (event.data.data.type === 'logout') { - // return initContent() - // // srcData = { - // // url: contentData.login_content_templates.source, - // // title: contentData.login_content_templates.moduledesc, - // // } - // } nextTick(() => { - Object.assign(srcList, { - url: getTimesTamp(srcData.url), - title: srcData.title, - }) + srcList.url = getTimesTamp(srcList.url) uni.setNavigationBarTitle({ title: srcList.title, }) @@ -191,16 +145,14 @@ function initData(res) { Object.assign(contentData, res.data) if (loginValid.validate_login === 1) { // activity_code 方式 - Object.assign(srcList, { - url: getTimesTamp(login.source + `?activity_code=${activityCode.value}`), - title: login.moduledesc, - }) + srcList.url = getTimesTamp(login.source + `?activity_code=${activityCode.value}`) + srcList.title = login.moduledesc } else if (loginValid.validate_login === 2) { // api_code 方式 - Object.assign(srcList, { - url: getTimesTamp(baseUrl.source + `?activity_code=${activityCode.value}&token=${token}`), - title: baseUrl.moduledesc, - }) + srcList.url = getTimesTamp( + baseUrl.source + `?activity_code=${activityCode.value}&token=${token}`, + ) + srcList.title = baseUrl.moduledesc } uni.setNavigationBarTitle({ title: srcList.title, @@ -241,20 +193,22 @@ const intervalData = () => { } onLoad(() => { + const { + srcList: srcListU, + lottery: lotteryU, + activityCode: activityCodeU, + contentData: contentDataU, + } = useStore.userInfo activityCode.value = getUrlPathName() lottery.value = activityCode.value - if ( - !useStore.userInfo.srcList.url || - (useStore.userInfo.lottery !== lottery.value && - useStore.userInfo.activityCode !== activityCode.value) - ) { + if (!srcListU.url || (lotteryU !== lottery.value && activityCodeU !== activityCode.value)) { initContent() } else { - activityCode.value = useStore.userInfo.activityCode - Object.assign(srcList, useStore.userInfo.srcList, { - url: getTimesTamp(useStore.userInfo.srcList.url), + activityCode.value = activityCodeU + Object.assign(srcList, srcListU, { + url: getTimesTamp(srcListU.url), }) - Object.assign(contentData, useStore.userInfo.contentData) + Object.assign(contentData, contentDataU) uni.setNavigationBarTitle({ title: srcList.title, })