activitCode 问题

This commit is contained in:
lf 2024-07-04 19:43:55 +08:00
parent bd3266779c
commit f6041a03f1
2 changed files with 26 additions and 20 deletions

View File

@ -27,7 +27,7 @@ defineOptions({
//
const { safeAreaInsets } = uni.getSystemInfoSync()
const contentData = reactive<any>({})
const query = ref<string>('')
const activityCode = ref<string>('')
const lottery = ref<string>('')
// const activityCode = ref<string>('')
const useStore = useUserStore()
@ -95,19 +95,19 @@ window.parent.addEventListener('message', function (event) {
switch (event.data.data.type) {
case 'login':
srcData = {
url: contentData.content_templates.source + `?activity_code=${query.value}`,
url: contentData.content_templates.source + `?activity_code=${activityCode.value}`,
title: contentData.content_templates.moduledesc,
}
break
case 'coupon':
srcData = {
url: contentData.user_content_templates.source + `?activity_code=${query.value}`,
url: contentData.user_content_templates.source + `?activity_code=${activityCode.value}`,
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=${query.value}`
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 = {
@ -117,7 +117,7 @@ window.parent.addEventListener('message', function (event) {
break
case 'couponBack':
srcData = {
url: contentData.content_templates.source + `?activity_code=${query.value}`,
url: contentData.content_templates.source + `?activity_code=${activityCode.value}`,
title: contentData.content_templates.moduledesc,
}
break
@ -126,16 +126,16 @@ window.parent.addEventListener('message', function (event) {
}
// if (event.data.data.type === 'login') {
// srcData = {
// url: contentData.content_templates.source + `?activity_code=${query.value}`,
// 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=${query.value}`,
// 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=${query.value}`
// 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}`,
@ -143,7 +143,7 @@ window.parent.addEventListener('message', function (event) {
// }
// } else if (event.data.data.type === 'couponBack') {
// srcData = {
// url: contentData.content_templates.source + `?activity_code=${query.value}`,
// url: contentData.content_templates.source + `?activity_code=${activityCode.value}`,
// title: contentData.content_templates.moduledesc,
// }
// } else if (event.data.data.type === 'logout') {
@ -164,15 +164,16 @@ window.parent.addEventListener('message', function (event) {
useStore.setUserInfo({
srcList,
contentData,
query: query.value,
activityCode: activityCode.value,
token: contentData.token,
lottery: lottery.value,
})
})
})
async function initContent() {
const params = {}
params[codeType[code]] = query.value || ''
params[codeType[code]] = activityCode.value || ''
useStore.reset()
const res: any = await getContent(params)
initData(res)
@ -186,18 +187,18 @@ function initData(res) {
content_templates: baseUrl,
token,
} = res.data
query.value = res.data.activity_code
activityCode.value = res.data.activity_code
Object.assign(contentData, res.data)
if (loginValid.validate_login === 1) {
// activity_code
Object.assign(srcList, {
url: getTimesTamp(login.source + `?activity_code=${query.value}`),
url: getTimesTamp(login.source + `?activity_code=${activityCode.value}`),
title: login.moduledesc,
})
} else if (loginValid.validate_login === 2) {
// api_code
Object.assign(srcList, {
url: getTimesTamp(baseUrl.source + `?activity_code=${query.value}&token=${token}`),
url: getTimesTamp(baseUrl.source + `?activity_code=${activityCode.value}&token=${token}`),
title: baseUrl.moduledesc,
})
}
@ -207,8 +208,9 @@ function initData(res) {
useStore.setUserInfo({
srcList,
contentData,
query: query.value,
activityCode: activityCode.value,
token,
lottery: lottery.value,
})
} else {
uni.showToast({
@ -239,9 +241,13 @@ const intervalData = () => {
}
onLoad(() => {
query.value = getUrlPathName()
lottery.value = query.value
if (!useStore.userInfo.srcList.url || useStore.userInfo.query !== query.value) {
activityCode.value = getUrlPathName()
lottery.value = activityCode.value
if (
!useStore.userInfo.srcList.url ||
(useStore.userInfo.lottery !== lottery.value &&
useStore.userInfo.activityCode !== activityCode.value)
) {
initContent()
} else {
Object.assign(srcList, useStore.userInfo.srcList, {

View File

@ -3,9 +3,9 @@ import { ref } from 'vue'
const initState = {
nickname: '',
query: '',
activityCode: '',
token: '',
href: '',
lottery: '',
srcList: { url: '' },
contentData: {},
}