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

View File

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