Commit 591317ef authored by hewenhao's avatar hewenhao

feat(main): 从配置文件获取群聊二维码

- 新增 config.json 文件,包含二维码 URL - 更新 package.json 版本号至 1.1.11 - 修改 chapter.tsx 文件,实现从配置文件获取二维码并展示
parent 6b33e39c
{
"qrUrl": "https://frontend-bkt-1257124244.cos.ap-chengdu.myqcloud.com/pk-math/qrcode-expire-in-7-2.png"
}
\ No newline at end of file
{ {
"name": "learn-math-weapp", "name": "learn-math-weapp",
"version": "1.1.10", "version": "1.1.11",
"private": true, "private": true,
"description": "", "description": "",
"scripts": { "scripts": {
......
import { View, Image } from '@tarojs/components' import { View, Image } from '@tarojs/components'
import assetsMainNext from '@/assets/oss/assets-main-next' import assetsMainNext from '@/assets/oss/assets-main-next'
import { getMenuButtonBoundingClientRect, getSystemInfoSync, navigateTo, previewImage } from '@tarojs/taro' import { getMenuButtonBoundingClientRect, getSystemInfoSync, navigateTo, previewImage, request } from '@tarojs/taro'
import { useStoreActions, useStoreState } from '@/store/hooks' import { useStoreActions, useStoreState } from '@/store/hooks'
import { useMemo } from 'react' import { useEffect, useMemo, useState } from 'react'
import styles from './chapter.module.scss' import styles from './chapter.module.scss'
const qrCodeUrl = 'https://frontend-bkt-1257124244.cos.ap-chengdu.myqcloud.com/pk-math/qrcode-expire-in-7.png?v=1' const configUrl = 'https://cdn.jkwljy.com/pk-math/config.json'
const showGroupQrcode = (config: MiniConfig) => {
if (config.qrUrl) {
previewImage({
current: config.qrUrl,
urls: [config.qrUrl]
})
}
}
type MiniConfig = {
qrUrl: string
}
const showGroupQrcode = () => { const getConfig = async () => {
previewImage({ const result = await request<MiniConfig>({
current: qrCodeUrl, method: 'GET',
urls: [qrCodeUrl] url: `${configUrl}?v=${Date.now()}`,
header: { 'Cache-Control': 'no-cache' },
timeout: 10000
}) })
return result.data
} }
const MainHeader = () => { const MainHeader = () => {
...@@ -33,6 +49,14 @@ const MainHeader = () => { ...@@ -33,6 +49,14 @@ const MainHeader = () => {
} }
}, [nav]) }, [nav])
const [miniConfig, setMiniConfig] = useState<MiniConfig | null>(null)
useEffect(() => {
getConfig().then(config => {
setMiniConfig(config)
})
}, [])
return ( return (
<> <>
<View className={styles.bgTopWrap}> <View className={styles.bgTopWrap}>
...@@ -60,10 +84,12 @@ const MainHeader = () => { ...@@ -60,10 +84,12 @@ const MainHeader = () => {
{/* <View className={styles.dot}></View> */} {/* <View className={styles.dot}></View> */}
<Image src={assetsMainNext['pk-btn.png'].u} className={styles.pkIcon}></Image> <Image src={assetsMainNext['pk-btn.png'].u} className={styles.pkIcon}></Image>
</View> </View>
<View className={styles.joinGroup} onClick={showGroupQrcode}> {miniConfig && (
{/* <View className={styles.dot}></View> */} <View className={styles.joinGroup} onClick={() => showGroupQrcode(miniConfig)}>
<Image src={assetsMainNext['join-group.png'].u} className={styles.pkIcon}></Image> {/* <View className={styles.dot}></View> */}
</View> <Image src={assetsMainNext['join-group.png'].u} className={styles.pkIcon}></Image>
</View>
)}
</View> </View>
</> </>
) )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment