Commit 8058778e authored by raca's avatar raca
parents 9817ec8d 6bc9834a
......@@ -4,7 +4,7 @@
BUILD_MODE=development
# 微信小程序appid
WEAPP_ID=wx8f25def587982a19
WEAPP_ID=wx693fe3460124d84b
# 服务器接口地址
SERVER_ENDPOINT=http://172.10.61.170
......
......@@ -34,5 +34,21 @@
"错误.wav": {
"u": "https://cdn.jkwljy.com/pk-math/cqKDzvSN1Gh53GGfqkmURQiCSc6.wav",
"ossName": "/pk-math/cqKDzvSN1Gh53GGfqkmURQiCSc6.wav"
},
"引导页-A和B通关.wav": {
"u": "https://cdn.jkwljy.com/pk-math/39xS7n44dr7UfLvHkhAoTfkYVpgV.wav",
"ossName": "/pk-math/39xS7n44dr7UfLvHkhAoTfkYVpgV.wav"
},
"猫猫说话背景声.wav": {
"u": "https://cdn.jkwljy.com/pk-math/3BsHxobKFTM5jEHkSic2rKmwb5nU.wav",
"ossName": "/pk-math/3BsHxobKFTM5jEHkSic2rKmwb5nU.wav"
},
"打字音效.wav": {
"u": "https://cdn.jkwljy.com/pk-math/4153quBKosW4xvgWAM4EqTtZqjNM.wav",
"ossName": "/pk-math/4153quBKosW4xvgWAM4EqTtZqjNM.wav"
},
"打字声2.mp3": {
"u": "https://cdn.jkwljy.com/pk-math/v4SqPWo3mjH5SZaksSwfpRvVVbD.mp3",
"ossName": "/pk-math/v4SqPWo3mjH5SZaksSwfpRvVVbD.mp3"
}
}
......@@ -2,7 +2,7 @@
"miniprogramRoot": "dist/",
"projectname": "GeekLearnMathWeapp",
"description": "",
"appid": "wx8f25def587982a19",
"appid": "wx693fe3460124d84b",
"setting": {
"urlCheck": false,
"es6": false,
......
import { request, requestAfterSilentLogin } from '@/utils/request'
import { request as requesNative } from '@tarojs/taro'
import { getCurrentShareId } from '@/utils/share'
import type { UserInfo } from '@/types'
type LoginResult = UserInfo
......@@ -58,11 +59,18 @@ export function getSetting () {
}
export function updateUserPhone (code: string) {
return requestAfterSilentLogin<void, { code: string; userId?: number }>((userInfo) => ({
return requestAfterSilentLogin<void, { code: string; userId?: number }>((userInfo) => {
const shareId = getCurrentShareId()
return {
url: '/service-idea/stage/user/getUserPhone',
method: 'GET',
data: { code, userId: userInfo?.userId }
}))
data: shareId
? { code, userId: userInfo?.userId, shareId }
: ({
code, userId: userInfo?.userId
})
}
})
}
export type NickNameWord = {
......
export * from './auth'
export * from './game'
export * from './share'
import { requestAfterSilentLogin } from '@/utils/request'
type ShareDetail = {
shareParams: string;
id: number;
}
type GetShareDetailOptions = {
receiverId?: number;
userType?: 'INLET_USER';
shareId: string;
}
export function getShareAndRecord (shareId: string) {
return requestAfterSilentLogin<ShareDetail, GetShareDetailOptions>((userInfo) => ({
method: 'GET',
url: '/service-idea/share/getShareDetailAndRecordBrowse',
data: userInfo && userInfo.userId
? {
receiverId: userInfo.userId,
userType: 'INLET_USER',
shareId,
}
: { shareId },
}))
}
type SaveShareOption = {
/** 分享ID */
id?: number | string;
/** 父级分享ID */
parentId?: number | string | null;
/** 分享人ID */
sharerId: number;
/** 分享人类型 */
sharerType?: 'INLET_USER';
operatorId: number;
/** 分享类型 */
shareType: 'MINI_QR' | 'URL';
/** 分享路径 */
sharePath: string;
/** 分享参数 */
shareParams: string;
/** 分享ID */
bizId?: string;
/** 业务类型 */
bizType?: 'INLET_GROUP' | 'INLET_SHARE';
/** 分享渠道 */
channelType?: 'INLET_APPLET';
}
type SaveShareResult = SaveShareOption & {
shareUrl: string;
}
/** 保存分享 */
export function saveShare (option: SaveShareOption) {
return requestAfterSilentLogin<SaveShareResult, SaveShareOption>(_ => ({
method: 'POST',
url: '/service-idea/share/saveShare',
data: {
channelType: 'INLET_APPLET',
sharerType: 'INLET_USER',
...option,
},
}))
}
/**
* 预生成ShareId
*/
export function preCreateShareSeeds (seedsNum: number = 1) {
return requestAfterSilentLogin<number[], { num: number }>({
url: '/service-idea/share/preCreateShareIds',
method: 'GET',
data: { num: seedsNum },
})
}
......@@ -27,5 +27,17 @@ export default {
},
"错误.wav": {
"u": "https://cdn.jkwljy.com/pk-math/cqKDzvSN1Gh53GGfqkmURQiCSc6.wav"
},
"引导页-A和B通关.wav": {
"u": "https://cdn.jkwljy.com/pk-math/39xS7n44dr7UfLvHkhAoTfkYVpgV.wav"
},
"猫猫说话背景声.wav": {
"u": "https://cdn.jkwljy.com/pk-math/3BsHxobKFTM5jEHkSic2rKmwb5nU.wav"
},
"打字音效.wav": {
"u": "https://cdn.jkwljy.com/pk-math/4153quBKosW4xvgWAM4EqTtZqjNM.wav"
},
"打字声2.mp3": {
"u": "https://cdn.jkwljy.com/pk-math/v4SqPWo3mjH5SZaksSwfpRvVVbD.mp3"
}
} as const
......@@ -4,3 +4,4 @@ export * from './use-format-tick'
export * from './use-request'
export * from './use-toggle'
export * from './use-focus'
export * from './use-share'
import { useShareAppMessage, useRouter, type ShareAppMessageObject } from '@tarojs/taro'
import { useState, useEffect, useCallback } from 'react'
import { preCreateShareSeeds, saveShare } from '@/api'
import { getCurrentShareId, qs, getSharePath } from '@/utils/share'
import { getStorage, StorageKeys } from '@/utils/storage'
import { omit } from '@/utils'
type UseShareParams<T extends object = {}> = (arg: ShareAppMessageObject, id: number) => ({
pageParams?: T;
path?: string;
} & Taro.ShareAppMessageReturn)
const defaultParamsFn = <T extends object = {}>() => ({
pageParams: {} as T,
path: undefined,
})
const useShare = <T extends object = {}>(paramsFn?: UseShareParams<T>) => {
const [shareIds, setShareIds] = useState<number[]>([])
const router = useRouter<{ scene?: string; shareId?: string }>()
/**
* 获取分享种子
*/
const getSeeds = useCallback(() => {
const currentUser = getStorage(StorageKeys.userInfo)
if (!currentUser) return
preCreateShareSeeds(1)
.then(({ data }) => {
setShareIds(Array.isArray(data) ? data : [])
})
.catch((error) => {
console.log('get share seed occur error', error)
})
}, [])
useEffect(() => {
getSeeds()
}, [getSeeds])
useShareAppMessage((arg) => {
const defaultShareId = shareIds[0]
try {
const { pageParams, ...result } = (paramsFn ?? defaultParamsFn)(arg, defaultShareId) || {}
let sharePath = result.path ?? router.path
// 如果shareId已经生成,则生成url;
const userInfo = getStorage(StorageKeys.userInfo)
if (userInfo && userInfo.userId && defaultShareId > 0) {
const parentId = getCurrentShareId()
const safeParams = omit({ ...router.params, ...pageParams }, ['scene', 'shareId'])
// 调用记录接口
saveShare({
id: defaultShareId,
parentId,
sharerId: userInfo.userId,
sharerType: 'INLET_USER',
shareType: 'URL',
sharePath,
operatorId: userInfo.userId,
shareParams: JSON.stringify(safeParams),
}).catch((error) => {
console.log('save share occur error', error)
})
// failback
const queryString = qs(safeParams)
sharePath = `${sharePath}?scene=${encodeURIComponent(`shareId=${defaultShareId}`)}${queryString ? `&${queryString}` : ''}`
} else {
sharePath = getSharePath(sharePath, router.params)
}
console.log('generated share path:', sharePath)
return {
...result,
path: sharePath,
}
} catch (error) {
console.log('failback to main page')
return {
title: 'PKMATH',
path: '/pages/main/main',
}
}
})
return shareIds
}
export { useShare }
......@@ -47,6 +47,7 @@ Component({
},
attached () {
this._tickTime = Date.now()
this._tick = this.data.startValue
this.start()
console.log(this)
......@@ -59,15 +60,17 @@ Component({
}
},
getCount () {
const bias = +((Date.now() - this._tickTime) / 1000).toFixed(1)
if (this.data.isDown) {
return this.data.startValue - this._tick
return this.data.startValue - this._tick + bias
}
return this._tick
return this._tick + bias
},
start () {
this.stop()
this._timer = setInterval(() => {
this._tickTime = Date.now()
const isDown = this.data.isDown
if (isDown) {
this._tick -= 1
......
export default definePageConfig({
navigationBarTitleText: 'pk-math',
navigationStyle: 'custom',
navigationBarTextStyle: 'white'
navigationBarTextStyle: 'white',
enableShareAppMessage: true,
})
import { View, Image, Input, ScrollView, Text } from '@tarojs/components'
import { useDidShow, getCurrentInstance, getTabBar, getMenuButtonBoundingClientRect, showModal, useShareAppMessage } from '@tarojs/taro'
import { useDidShow, getCurrentInstance, getTabBar, getMenuButtonBoundingClientRect, showModal } from '@tarojs/taro'
import { useMemo, useState, useEffect, useRef, useCallback } from 'react'
import Modal from '@/components/Modal'
import Button from '@/components/Button'
import { useBoolean, useRequest } from '@/hooks'
import { useBoolean, useRequest, useShare } from '@/hooks'
import { createTribe } from '@/api/group'
import { useStoreActions, useStoreState } from '@/store/hooks'
import type { TabbarRef } from '@/custom-tab-bar/index'
......@@ -65,13 +65,24 @@ const Group = () => {
Promise.all([queryTribePoint(), fetchTribeInfo()])
})
useShareAppMessage(() => {
const getShareParams = useCallback(() => {
return {
pageParams: { groupId: tribeInfo?.id ?? '', shareUserId: userInfo.userId },
title: '邀请你来一起PKmath,快乐提升哦',
path: `pages/main/main?groupId=${tribeInfo?.id}&shareUserId=${userInfo.userId}`,
path: 'pages/main/main',
imageUrl: 'https://cdn.jkwljy.com/pk-math/4LHyu63hfeteRxAKNb2cj2uCrahf/420x336',
}
})
}, [tribeInfo, userInfo])
useShare(getShareParams)
// useShareAppMessage(() => {
// return {
// title: '邀请你来一起PKmath,快乐提升哦',
// path: `pages/main/main?groupId=${tribeInfo?.id}&shareUserId=${userInfo.userId}`,
// imageUrl: 'https://cdn.jkwljy.com/pk-math/4LHyu63hfeteRxAKNb2cj2uCrahf/420x336',
// }
// })
const { run, loading: spining } = useRequest(createTribe, {
immediate: false,
......
......@@ -7,7 +7,7 @@ const MainHeader = () => {
<View className={styles.chapter}>
<View className={styles.chapterContent}>
<View className={styles.chapterName}>
<Text>第 1 单元</Text>
<Text>第 1 部分</Text>
</View>
<View className={styles.chapterTips}><Text>二年级下·上半学期</Text></View>
</View>
......
......@@ -51,6 +51,22 @@ const Scene1 = ({ onNext }: Scene1Props) => {
}
}, [onNext, isActive])
const fn = useCallback(() => {
setIsActive(true)
}, [])
const fn1 = useCallback(() => {
handleEnd(1)
}, [handleEnd])
const fn2 = useCallback(() => {
handleEnd(2)
}, [handleEnd])
const fn3 = useCallback(() => {
handleEnd(3)
}, [handleEnd])
return (
<View className={cs.viewport}>
<View className={cs.viewport_body}>
......@@ -65,19 +81,19 @@ const Scene1 = ({ onNext }: Scene1Props) => {
<View className={styles.dialog}>
{current === 0 && (
<View className={styles.modal_1}>
<TextPrinter textList={Text1} onEnd={() => handleEnd(1)}></TextPrinter>
<TextPrinter textList={Text1} onEnd={fn1}></TextPrinter>
</View>
)}
{current === 1 && (
<View className={styles.modal_2}>
<TextPrinter textList={Text2} onEnd={() => handleEnd(2)} />
<TextPrinter textList={Text2} onEnd={fn2} />
</View>
)}
{current === 2 && (
<View className={styles.modal_2}>
<TextPrinter
textList={Text3}
onEnd={() => handleEnd(3)}
onEnd={fn3}
/>
</View>
)}
......@@ -85,7 +101,7 @@ const Scene1 = ({ onNext }: Scene1Props) => {
<View className={styles.modal_3}>
<TextPrinter
textList={Text4}
onEnd={() => setIsActive(true)}
onEnd={fn}
/>
</View>
)}
......
import { View, Text, Image, ScrollView } from '@tarojs/components'
import classNames from 'classnames'
import { useFormatTick } from '@/hooks'
import { useMemo } from 'react'
import { useMemo, useEffect } from 'react'
import { palyAudio } from '@/utils/play-audio'
import audio from '@/assets/oss/assets-audio'
import assets from '@/assets/oss/assets-guide'
import cs from './index.module.scss'
......@@ -53,6 +55,12 @@ const Scene4 = (props: Scene4Props) => {
const icons = useMemo(() => getIcon(level), [level])
useEffect(() => {
if (isCurrent) {
palyAudio(audio['引导页-A和B通关.wav'].u)
}
}, [isCurrent])
const isActive = true
const timeFmt = useFormatTick(time * 1000)
......
......@@ -24,6 +24,7 @@ const Scene6 = (props: Scene6Props) => {
const [name, setName] = useState('')
const dataRef = useRef<NickNameWord>({ noun: [], adj: [] })
const timerRef = useRef<NodeJS.Timer | null>(null)
const [loading, setLoading] = useState(false)
const [isGenerating, genActions] = useBoolean(false)
const genName = useCallback(() => {
......@@ -39,9 +40,14 @@ const Scene6 = (props: Scene6Props) => {
console.log(e.detail.errMsg)
return
}
setLoading(true)
updateNickNameAndPhone({ code: e.detail.code!, name })
.then(() => onNext())
.then(() => {
setLoading(false)
onNext()
})
.catch(err => {
setLoading(false)
console.log(err)
})
}, [updateNickNameAndPhone, onNext, name])
......@@ -107,6 +113,7 @@ const Scene6 = (props: Scene6Props) => {
openType="getPhoneNumber"
onGetPhoneNumber={handleGetPhone}
className={cs.btn}
loading={loading}
hoverClass={cs.is_hover}
>确定</Button>
)}
......
import { useState, useEffect, useRef } from 'react'
import { Text } from '@tarojs/components'
import { createInnerAudioContext } from '@tarojs/taro'
import audio from '@/assets/oss/assets-audio'
// @ts-ignore
const innerAudioContext = createInnerAudioContext({ useWebAudioImplement: true })
export function getAudio (src: string) {
innerAudioContext.src = src
innerAudioContext.loop = true
innerAudioContext.volume = 0.3
return innerAudioContext
}
type TextPrinterProps = {
textList: { text: string }[];
......@@ -18,6 +30,9 @@ const TextPrinter = (props: TextPrinterProps) => {
useEffect(() => {
let animationFrameId: number | null = null
let lastFrameTime: number | null = null
const audioPlayer = getAudio(audio['打字声2.mp3'].u)
audioPlayer.play()
const shouldDisplayNextChar = (timestamp: number, spd: number) => {
if (!lastFrameTime) {
......@@ -36,12 +51,16 @@ const TextPrinter = (props: TextPrinterProps) => {
const animateText = (timestamp) => {
let currentText = textList[currentTextIndex.current]
if (!currentText) return
if (!currentText) {
audioPlayer.stop()
return
}
if (charIndex.current >= currentText.text.length) {
charIndex.current = 0
currentTextIndex.current += 1
if (currentTextIndex.current >= textList.length) {
onEnd && onEnd()
audioPlayer.stop()
return
}
/** 停顿 */
......@@ -60,6 +79,7 @@ const TextPrinter = (props: TextPrinterProps) => {
animationFrameId = requestAnimationFrame(animateText)
return () => {
audioPlayer.stop()
if (animationFrameId) {
cancelAnimationFrame(animationFrameId)
}
......
......@@ -2,6 +2,7 @@ export default definePageConfig({
navigationBarTitleText: 'pk-math',
navigationStyle: 'custom',
navigationBarTextStyle: 'white',
enableShareAppMessage: true,
usingComponents: {
'count-up-time': '../../native-components/count-up/index'
}
......
......@@ -2,7 +2,9 @@ import { useEffect, useState, useCallback } from 'react'
import { View } from '@tarojs/components'
import { getStorage, StorageKeys } from '@/utils/storage'
import { silentLoginDeferred } from '@/utils/silent-login'
import { setNavigationBarColor } from '@tarojs/taro'
import { useShare } from '@/hooks'
import { setNavigationBarColor, useRouter } from '@tarojs/taro'
import { handleShare } from '@/utils/share'
import Loading from '@/components/Loading'
import styles from './main.module.scss'
import MainComponent from './components/main-component'
......@@ -11,6 +13,21 @@ import Guide from './guide'
const MainPage = () => {
const [isDone, setIsDone] = useState(false)
const [isReady, setIsReady] = useState(false)
const router = useRouter()
useEffect(() => {
handleShare(router.params)
}, [router.params])
const getShareParams = useCallback(() => {
return {
title: '邀请你来一起PKmath,快乐提升哦',
path: 'pages/main/main',
imageUrl: 'https://cdn.jkwljy.com/pk-math/4LHyu63hfeteRxAKNb2cj2uCrahf/420x336',
}
}, [])
useShare(getShareParams)
const handleDone = useCallback(() => {
setIsDone(true)
......
export default definePageConfig({
enableShareAppMessage: true,
navigationBarTitleText: 'pk-math',
navigationStyle: 'custom'
})
import { View, Text, Image } from '@tarojs/components'
import { useMemo, useState, useEffect, useCallback, useRef } from 'react'
import { useRouter, redirectTo, getMenuButtonBoundingClientRect, useShareAppMessage, navigateTo, showLoading, hideLoading, useDidShow } from '@tarojs/taro'
import { useRouter, redirectTo, getMenuButtonBoundingClientRect, navigateTo, showLoading, hideLoading, useDidShow } from '@tarojs/taro'
import classNames from 'classnames'
import Button from '@/components/Button'
import Loading from '@/components/Loading'
import ShareView from '@/pages/group/components/share-view'
import { useStoreState, useStoreActions } from '@/store/hooks'
import { useBoolean, useRequest } from '@/hooks'
import { useBoolean, useRequest, useShare } from '@/hooks'
import { pointToCard } from '@/api/account'
import assets from '@/assets/oss/assets-prepare'
import assetsGroup from '@/assets/oss/assets-group'
......@@ -77,13 +77,16 @@ const Prepare = () => {
}
}, [cardNum, getSetting])
useShareAppMessage(() => {
const getShareParams = useCallback(() => {
return {
pageParams: { groupId: tribeInfo?.id ?? '', shareUserId: userInfo.userId },
title: '邀请你来一起PKmath,快乐提升哦',
path: `pages/main/main?groupId=${tribeInfo?.id}&shareUserId=${userInfo.userId}`,
path: 'pages/main/main',
imageUrl: 'https://cdn.jkwljy.com/pk-math/4LHyu63hfeteRxAKNb2cj2uCrahf/420x336',
}
})
}, [tribeInfo, userInfo])
useShare(getShareParams)
const { run: exchange, loading: spinning } = useRequest(pointToCard, {
immediate: false,
......
type OmitObj<T, K extends (keyof T)[] = []> = {
[k in keyof T]: k extends (K extends (infer R)[] ? R : never) ? never : k;
}[keyof T];
function omit<T extends object, K extends (keyof T)[] = []>(value: T, keys: K): Pick<T, OmitObj<T, K>> {
const ret = {} as Pick<T, OmitObj<T, K>>
const objectKeys = Object.keys(value) as (keyof T)[]
objectKeys.forEach((key) => {
if (keys.indexOf(key) === -1) {
((ret as any)[key] as any) = value[key]
}
})
return ret
}
export { omit }
import type { RouteParamsWithShare } from '@/types'
import { getShareAndRecord } from '@/api'
let internalShareId: string | number | null = null
export function getCurrentShareId () {
return internalShareId
}
export function updateCurrentShareId (val?: string | number | null) {
if (val !== null && val !== undefined) {
internalShareId = val
}
}
export function parseQuery (queryString: string): Partial<Record<string, string>> {
if (!queryString) return {}
const query = decodeURIComponent(queryString)
const paramArr = query.split('&')
return paramArr.filter(Boolean).reduce((ret, item) => {
const index = item.indexOf('=')
if (index === 0) return ret
if (index === -1) {
ret[item] = true
return ret
}
const a = item.substring(0, index)
const b = item.substring(index + 1)
ret[a] = b
return ret
}, {})
}
export async function handleShare<T extends Partial<Record<string, string>>> (arg: RouteParamsWithShare<T>): Promise<T> {
const { scene, ...restParams } = arg
if (scene) {
const { shareId } = parseQuery(scene)
if (shareId) {
try {
const { data } = await getShareAndRecord(shareId)
const sharerParamsJson = data.shareParams || '{}'
const params = JSON.parse(sharerParamsJson)
updateCurrentShareId(data.id ?? null)
return { ...restParams, ...params } as T
} catch (error) {
console.log('parse share params error', error)
}
}
}
return restParams as T
}
export const qs = (params) => {
if (!params) return ''
const keys = Object.keys(params)
return keys.map((c) => `${c}=${encodeURIComponent(params[c]) || ''}`).join('&')
}
export function getSharePath (path, arg) {
return `${path}?${qs(arg)}`
}
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