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' VITE_WX_APPID = 'wxa2abb91f64032a2b'
# h5部署网站的base配置到 manifest.config.ts 里的 h5.router.base # 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'
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 # 是否开启sourcemap
VITE_SHOW_SOURCEMAP = false VITE_SHOW_SOURCEMAP = false
VITE_APP_PUBLIC_BASE = './' VITE_APP_PUBLIC_BASE = ./
VITE_SERVER_BASEURL = 'https://gateway.dev.cdlsxd.cn' VITE_SERVER_BASEURL = 'https://gateway.dev.cdlsxd.cn'
VITE_APP_PROXY = true VITE_APP_PROXY = true
VITE_APP_PROXY_PREFIX = 'https://gateway.dev.cdlsxd.cn' VITE_APP_PROXY_PREFIX = 'https://gateway.dev.cdlsxd.cn'

View File

@ -271,6 +271,9 @@ function backshow(e) {
onLoad(async () => { onLoad(async () => {
// activity_id // activity_id
Object.assign(query, getUrlParm()) Object.assign(query, getUrlParm())
if (query.token) {
useStore.setUserInfo({ token: query.token })
}
// if (useStore.userInfo.token) { // if (useStore.userInfo.token) {
getData() getData()
// } // }

View File

@ -28,8 +28,15 @@ defineOptions({
const { safeAreaInsets } = uni.getSystemInfoSync() const { safeAreaInsets } = uni.getSystemInfoSync()
const contentData = reactive<any>({}) const contentData = reactive<any>({})
const query = ref<string>('') const query = ref<string>('')
const activityCode = ref<string>('')
const useStore = useUserStore() const useStore = useUserStore()
let code = 'activity'
let timer = null let timer = null
const codeType = {
Interface: 'api_code',
lottery: 'lottery_code',
activity: 'activity_code',
}
interface SrcListType { interface SrcListType {
url?: string url?: string
@ -52,8 +59,17 @@ const getUrlPathName = () => {
return str.split('/')[0] return str.split('/')[0]
} }
} else { } else {
const strP = url.split('/') const str = url.split('/')
return strP[strP.length - 1] 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 initContent = async () => {
const params = { const params = {}
activity_code: query.value || '', params[codeType[code]] = activityCode.value || ''
}
const res: any = await getContent(params) const res: any = await getContent(params)
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) Object.assign(contentData, res.data)
if (res?.code === 200 && res.data.login_content_template.validate_login === 1) { if (loginValid.validate_login === 1) {
const timestamp = new Date().getTime() // activity_code
const url =
res.data.login_content_templates.source +
(res.data.login_content_templates.source.includes('?') ? '&timestamp=' : '?timestamp=') +
timestamp
Object.assign(srcList, { Object.assign(srcList, {
url, url: getTimesTamp(login.source),
title: res.data.login_content_templates.moduledesc, 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({ uni.setNavigationBarTitle({
title: srcList.title, title: srcList.title,
}) })
useStore.setUserInfo({ srcList, contentData, query: query.value })
} else { } else {
uni.showToast({ uni.showToast({
title: res.message, title: res.message,
icon: 'none', 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(() => { onLoad(() => {
activityCode.value = getUrlPathName()
timer = setInterval(async () => { timer = setInterval(async () => {
const params = { const params = {}
activity_code: query.value || '', params[codeType[code]] = activityCode.value || ''
}
const res: any = await getContent(params) const res: any = await getContent(params)
if (JSON.stringify(res.data) !== JSON.stringify(useStore.userInfo.contentData)) { if (JSON.stringify(res.data) !== JSON.stringify(useStore.userInfo.contentData)) {
uni.showToast({ uni.showToast({
title: '活动发生变更', title: '活动发生变更',
icon: 'none', icon: 'none',
}) })
initContent() initData(res)
} }
}, 60000) }, 60000)
// activity_id
query.value = getUrlPathName()
if (!useStore.userInfo.srcList.url || useStore.userInfo.query !== query.value) { if (!useStore.userInfo.srcList.url || useStore.userInfo.query !== query.value) {
initContent() initContent()
} else { } else {