From 883b2cb611392c18945749730f477a03c1ae29e4 Mon Sep 17 00:00:00 2001 From: lf <1534621107@qq.com> Date: Thu, 20 Jun 2024 18:51:39 +0800 Subject: [PATCH] index api --- env/.env | 2 +- env/.env.production | 2 +- src/pages/activity/index.vue | 3 ++ src/pages/index/index.vue | 83 ++++++++++++++++++++++++++---------- 4 files changed, 65 insertions(+), 25 deletions(-) diff --git a/env/.env b/env/.env index 09a6096..a43a47a 100644 --- a/env/.env +++ b/env/.env @@ -5,7 +5,7 @@ VITE_UNI_APPID = 'H57F2ACE4' VITE_WX_APPID = 'wxa2abb91f64032a2b' # h5部署网站的base,配置到 manifest.config.ts 里的 h5.router.base -VITE_APP_PUBLIC_BASE = 'test' +VITE_APP_PUBLIC_BASE = ./ # VITE_SERVER_BASEURL = 'https://gateway.dev.cdlsxd.cn' VITE_SERVER_BASEURL = 'https://gateway.dev.cdlsxd.cn' diff --git a/env/.env.production b/env/.env.production index dbddac0..6b0a741 100644 --- a/env/.env.production +++ b/env/.env.production @@ -5,7 +5,7 @@ VITE_DELETE_CONSOLE = true # 是否开启sourcemap VITE_SHOW_SOURCEMAP = false -VITE_APP_PUBLIC_BASE = './' +VITE_APP_PUBLIC_BASE = ./ VITE_SERVER_BASEURL = 'https://gateway.dev.cdlsxd.cn' VITE_APP_PROXY = true VITE_APP_PROXY_PREFIX = 'https://gateway.dev.cdlsxd.cn' \ No newline at end of file diff --git a/src/pages/activity/index.vue b/src/pages/activity/index.vue index 9d9ce6b..b27c72d 100644 --- a/src/pages/activity/index.vue +++ b/src/pages/activity/index.vue @@ -271,6 +271,9 @@ function backshow(e) { onLoad(async () => { // activity_id 方式 Object.assign(query, getUrlParm()) + if (query.token) { + useStore.setUserInfo({ token: query.token }) + } // if (useStore.userInfo.token) { getData() // } diff --git a/src/pages/index/index.vue b/src/pages/index/index.vue index 6eabc68..aff27cf 100644 --- a/src/pages/index/index.vue +++ b/src/pages/index/index.vue @@ -28,8 +28,15 @@ defineOptions({ const { safeAreaInsets } = uni.getSystemInfoSync() const contentData = reactive({}) const query = ref('') +const activityCode = ref('') const useStore = useUserStore() +let code = 'activity' let timer = null +const codeType = { + Interface: 'api_code', + lottery: 'lottery_code', + activity: 'activity_code', +} interface SrcListType { url?: string @@ -52,8 +59,17 @@ const getUrlPathName = () => { return str.split('/')[0] } } else { - const strP = url.split('/') - return strP[strP.length - 1] + const str = url.split('/') + const strP = str[str.length - 1] + let strR = '' + if (strP.indexOf('-') === -1) { + strR = strP + code = 'activity' + } else { + code = strP.split('-')[0] + strR = strP.split('-')[1] + } + return strR } } @@ -100,49 +116,70 @@ window.parent.addEventListener('message', function (event) { }) const initContent = async () => { - const params = { - activity_code: query.value || '', - } + const params = {} + params[codeType[code]] = activityCode.value || '' const res: any = await getContent(params) - Object.assign(contentData, res.data) - if (res?.code === 200 && res.data.login_content_template.validate_login === 1) { - const timestamp = new Date().getTime() - const url = - res.data.login_content_templates.source + - (res.data.login_content_templates.source.includes('?') ? '×tamp=' : '?timestamp=') + - timestamp - Object.assign(srcList, { - url, - title: res.data.login_content_templates.moduledesc, - }) + initData(res) +} + +const initData = (res) => { + if (res.code === 200) { + const { + login_content_template: loginValid, + login_content_templates: login, + content_templates: baseUrl, + // eslint-disable-next-line camelcase + activity_code, + } = res.data + // eslint-disable-next-line camelcase + query.value = activity_code + Object.assign(contentData, res.data) + if (loginValid.validate_login === 1) { + // activity_code 方式 + Object.assign(srcList, { + url: getTimesTamp(login.source), + title: login.moduledesc, + }) + } else if (loginValid.validate_login === 2) { + // api_code 方式 + Object.assign(srcList, { + url: getTimesTamp( + baseUrl.source + `?activity_code=${query.value}&token=${loginValid.token}`, + ), + title: baseUrl.moduledesc, + }) + } uni.setNavigationBarTitle({ title: srcList.title, }) + useStore.setUserInfo({ srcList, contentData, query: query.value }) } else { uni.showToast({ title: res.message, icon: 'none', }) } - useStore.setUserInfo({ srcList, contentData, query: query.value }) +} + +function getTimesTamp(url) { + const timestamp = new Date().getTime() + return url + (url.includes('?') ? '×tamp=' : '?timestamp=') + timestamp } onLoad(() => { + activityCode.value = getUrlPathName() timer = setInterval(async () => { - const params = { - activity_code: query.value || '', - } + const params = {} + params[codeType[code]] = activityCode.value || '' const res: any = await getContent(params) if (JSON.stringify(res.data) !== JSON.stringify(useStore.userInfo.contentData)) { uni.showToast({ title: '活动发生变更', icon: 'none', }) - initContent() + initData(res) } }, 60000) - // activity_id 方式 - query.value = getUrlPathName() if (!useStore.userInfo.srcList.url || useStore.userInfo.query !== query.value) { initContent() } else {