index api

This commit is contained in:
lf 2024-06-20 18:51:39 +08:00
parent 70f8c0fff9
commit 883b2cb611
4 changed files with 65 additions and 25 deletions

2
env/.env vendored
View File

@ -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'

2
env/.env.production vendored
View File

@ -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'

View File

@ -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()
// }

View File

@ -28,8 +28,15 @@ defineOptions({
const { safeAreaInsets } = uni.getSystemInfoSync()
const contentData = reactive<any>({})
const query = ref<string>('')
const activityCode = ref<string>('')
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('?') ? '&timestamp=' : '?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('?') ? '&timestamp=' : '?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 {