Commit a7b3a1d6 authored by hewenhao's avatar hewenhao

Merge branch 'feature/2023-06-12-v1.1' of…

Merge branch 'feature/2023-06-12-v1.1' of dev.jiuaoedu.com:hewenhao/GeekLearnMathWeapp into feature/2023-06-12-v1.1
parents 8b42a4a1 1118e50d
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
export default { export default {
pages: [ pages: [
'pages/market/index',
'pages/main/main', 'pages/main/main',
'pages/market/index',
'pages/accept-pk/index', 'pages/accept-pk/index',
'pages/battles/index', 'pages/battles/index',
'pages/prepare/index', 'pages/prepare/index',
......
...@@ -13,3 +13,21 @@ export const pointToCard = ({ num }: { num: number }) => { ...@@ -13,3 +13,21 @@ export const pointToCard = ({ num }: { num: number }) => {
}) })
) )
} }
export type ExchangeParams = {
accountTo: 'POINT' | 'NAME_CARD' | 'CARD',
accountFrom: 'POINT' | 'NAME_CARD' | 'CARD',
num: number;
userId?: number;
}
export function accountExchange (data: ExchangeParams) {
return requestAfterSilentLogin<AccountOut[], ExchangeParams>(userInfo => ({
method: 'POST',
url: '/service-idea/account/accountExchange',
data: {
...data,
userId: userInfo?.userId
}
}))
}
...@@ -120,24 +120,6 @@ export const receivePoint = () => requestAfterSilentLogin<void, { userId?: numbe ...@@ -120,24 +120,6 @@ export const receivePoint = () => requestAfterSilentLogin<void, { userId?: numbe
data: { userId: user?.userId } data: { userId: user?.userId }
})) }))
export type ExchangeParams = {
accountTo: 'POINT' | 'NAME_CARD' | 'CARD',
accountFrom: 'POINT' | 'NAME_CARD' | 'CARD',
num: number;
userId?: number;
}
export function accountExchange (data: ExchangeParams) {
return requestAfterSilentLogin<void, ExchangeParams>(userInfo => ({
method: 'POST',
url: '/service-idea/stage/user/accountExchange',
data: {
...data,
userId: userInfo?.userId
}
}))
}
export function changeNickName (nickName: string) { export function changeNickName (nickName: string) {
return requestAfterSilentLogin<void, { nickName: string, userId?: number }>(userInfo => ({ return requestAfterSilentLogin<void, { nickName: string, userId?: number }>(userInfo => ({
method: 'GET', method: 'GET',
......
...@@ -54,14 +54,17 @@ export type PkRecords = { ...@@ -54,14 +54,17 @@ export type PkRecords = {
} & Pick<PkDetails, 'allPkNum' | 'userRanks' | 'winPkNum'> } & Pick<PkDetails, 'allPkNum' | 'userRanks' | 'winPkNum'>
export function fetchUserRecords (data: PkParams) { export function fetchUserRecords (data: PkParams) {
return requestAfterSilentLogin<PkRecords, PkParams>((userInfo) => ({ if (!data.stageId) {
delete data.stageId
}
return requestAfterSilentLogin<PkRecords, PkParams>((userInfo) => {
data.userId = data.userId || userInfo?.userId
return {
method: 'GET', method: 'GET',
url: '/service-idea/pk/personal/stage/records', url: '/service-idea/pk/personal/stage/records',
data: { data
stageId: data.stageId,
userId: data.userId || userInfo?.userId,
} }
})) })
} }
export type SubmitPkResultParams = { export type SubmitPkResultParams = {
......
...@@ -3,6 +3,7 @@ import { View, Text, Image, ScrollView } from '@tarojs/components' ...@@ -3,6 +3,7 @@ import { View, Text, Image, ScrollView } from '@tarojs/components'
import classNames from 'classnames' import classNames from 'classnames'
import Modal from '@/components/Modal' import Modal from '@/components/Modal'
import { useStoreState, useStoreActions } from '@/store/hooks' import { useStoreState, useStoreActions } from '@/store/hooks'
import { convertDateTime } from '@/utils/day'
import assets from '@/assets/oss/assets-pk' import assets from '@/assets/oss/assets-pk'
import { badgeImages } from '../const' import { badgeImages } from '../const'
import { UserInfo, GameResultProps } from './game-result' import { UserInfo, GameResultProps } from './game-result'
...@@ -97,7 +98,7 @@ const GameResult = ({ record }: GameResultProps) => { ...@@ -97,7 +98,7 @@ const GameResult = ({ record }: GameResultProps) => {
src={record.result ? assets['win.png'].u : assets['lose.png'].u} src={record.result ? assets['win.png'].u : assets['lose.png'].u}
className={gameResultStyles.levelResult} className={gameResultStyles.levelResult}
/> />
<Text className={gameResultStyles.levelDate}>{record.createTime}</Text> <Text className={gameResultStyles.levelDate}>{convertDateTime(record.createTime)}</Text>
</View> </View>
<View className={styles.gameBody}> <View className={styles.gameBody}>
......
import { CSSProperties } from 'react' import { CSSProperties } from 'react'
import { View, Text, Image } from '@tarojs/components' import { View, Text, Image } from '@tarojs/components'
import classNames from 'classnames' import classNames from 'classnames'
import { convertDateTime } from '@/utils/day'
import assets from '@/assets/oss/assets-pk' import assets from '@/assets/oss/assets-pk'
import assets2 from '@/assets/oss/assets-prepare' import assets2 from '@/assets/oss/assets-prepare'
import { PkRecord } from '@/api/pk' import { PkRecord } from '@/api/pk'
...@@ -27,7 +28,7 @@ const GameResult = ({ record }: GameResultProps) => { ...@@ -27,7 +28,7 @@ const GameResult = ({ record }: GameResultProps) => {
src={assets[record.result ? 'win.png' : 'lose.png'].u} src={assets[record.result ? 'win.png' : 'lose.png'].u}
className={styles.levelResult} className={styles.levelResult}
/> />
<Text className={styles.levelDate}>{record.createTime}</Text> <Text className={styles.levelDate}>{convertDateTime(record.createTime)}</Text>
</View> </View>
<View className={styles.gameBody}> <View className={styles.gameBody}>
......
...@@ -11,10 +11,9 @@ import styles from './exchange-item.module.scss' ...@@ -11,10 +11,9 @@ import styles from './exchange-item.module.scss'
import styles2 from './exchange-rename-card.module.scss' import styles2 from './exchange-rename-card.module.scss'
type ExchangeItemProps = { type ExchangeItemProps = {
title: string; title: string
stepValue: number; stepValue: number
// onConfirm: (arg: number) => void; onCancel: () => void
onCancel: () => void;
} }
const randomPick = (arr: string[]) => { const randomPick = (arr: string[]) => {
...@@ -25,13 +24,17 @@ const randomPick = (arr: string[]) => { ...@@ -25,13 +24,17 @@ const randomPick = (arr: string[]) => {
const ExchangeRenameCard = (props: ExchangeItemProps) => { const ExchangeRenameCard = (props: ExchangeItemProps) => {
const { onCancel, stepValue } = props const { onCancel, stepValue } = props
const userInfo = useStoreState(state => state.userModel.userInfo) const userInfo = useStoreState((state) => state.userModel.userInfo)
const [name, setName] = useState(userInfo.nickName) const [name, setName] = useState(userInfo.nickName)
const [generating, { setTrue, setFalse }] = useBoolean(false) const [generating, { setTrue, setFalse }] = useBoolean(false)
const dataRef = useRef<NickNameWord>({ noun: [], adj: [] }) const dataRef = useRef<NickNameWord>({ noun: [], adj: [] })
const timerRef = useRef<NodeJS.Timer | null>(null) const timerRef = useRef<NodeJS.Timer | null>(null)
const accountExchange = useStoreActions(actions => actions.userModel.accountExchange) const accountExchange = useStoreActions(
const changeNickName = useStoreActions(actions => actions.userModel.changeNickName) (actions) => actions.userModel.accountExchange
)
const changeNickName = useStoreActions(
(actions) => actions.userModel.changeNickName
)
const generateName = useCallback(() => { const generateName = useCallback(() => {
const { noun, adj } = dataRef.current const { noun, adj } = dataRef.current
...@@ -73,21 +76,25 @@ const ExchangeRenameCard = (props: ExchangeItemProps) => { ...@@ -73,21 +76,25 @@ const ExchangeRenameCard = (props: ExchangeItemProps) => {
num: 1, num: 1,
accountTo: 'NAME_CARD', accountTo: 'NAME_CARD',
accountFrom: 'POINT', accountFrom: 'POINT',
}).then(() => { })
.then(() => {
changeNickName(name).then(() => { changeNickName(name).then(() => {
showToast({ title: '操作成功', icon: 'success' }) showToast({ title: '操作成功', icon: 'success' })
onCancel && onCancel()
}) })
}).catch(() => {
}) })
.catch(() => {})
} }
return ( return (
<> <>
<View className={styles2.description}> <View className={styles2.description}>请输入您的角色名(7字以内)</View>
请输入您的角色名(7字以内)
</View>
<View className={styles2.input}> <View className={styles2.input}>
<Input className={styles2.inputName} value={name as string} onInput={e => setName(e.detail.value)} /> <Input
className={styles2.inputName}
value={name as string}
onInput={(e) => setName(e.detail.value)}
/>
<Image <Image
src={assetsGuide['touzi.png'].u} src={assetsGuide['touzi.png'].u}
className={classNames( className={classNames(
...@@ -97,10 +104,22 @@ const ExchangeRenameCard = (props: ExchangeItemProps) => { ...@@ -97,10 +104,22 @@ const ExchangeRenameCard = (props: ExchangeItemProps) => {
onClick={handleGenerate} onClick={handleGenerate}
></Image> ></Image>
</View> </View>
<View className={styles2.tips}>将消耗 <Text className={styles2.tips_val}>{stepValue}</Text> 水晶</View> <View className={styles2.tips}>
将消耗 <Text className={styles2.tips_val}>{stepValue}</Text> 水晶
</View>
<View className={styles.footer}> <View className={styles.footer}>
<View className={styles.cancel} onClick={() => onCancel()} id="market_exchange_cancel">取消</View> <View
<View className={styles.confirm} onClick={handleConfirm} data-name="兑换改名卡"> className={styles.cancel}
onClick={() => onCancel()}
id="market_exchange_cancel"
>
取消
</View>
<View
className={styles.confirm}
onClick={handleConfirm}
data-name="兑换改名卡"
>
确定 确定
</View> </View>
</View> </View>
......
...@@ -245,7 +245,7 @@ const StudyMarket = () => { ...@@ -245,7 +245,7 @@ const StudyMarket = () => {
bodyClassName={styles.moal_body} bodyClassName={styles.moal_body}
onClose={setFalse} onClose={setFalse}
maskClosable={false} maskClosable={false}
tilte={`兑换${currentGoods?.subTitle ?? currentGoods?.title ?? ''}`} tilte={`兑换${currentGoods?.subTitle ?? ''}`}
> >
{currentGoods?.subTitle === '改名卡' ? ( {currentGoods?.subTitle === '改名卡' ? (
<ExchangeRenameCard <ExchangeRenameCard
......
import { import {
action, Action, Thunk, thunk, State action, Action, Thunk, thunk, State
} from 'easy-peasy' } from 'easy-peasy'
import { getAccountInfo, getSetting, accountExchange, changeNickName, type ExchangeParams, type SettintType, updateUserInfo, type UpdateUserInfoIn, updateUserPhone } from '@/api' import { getAccountInfo, getSetting, type SettintType, updateUserInfo, type UpdateUserInfoIn, updateUserPhone, changeNickName } from '@/api'
import type { UserInfo } from '@/types' import type { UserInfo } from '@/types'
import { pointToCard } from '@/api/account' import { ExchangeParams, accountExchange, pointToCard } from '@/api/account'
import { showModal, showToast, showLoading, hideLoading } from '@tarojs/taro' import { showModal, showToast, showLoading, hideLoading } from '@tarojs/taro'
import { getStorage, StorageKeys, updateStorage } from '@/utils/storage' import { getStorage, StorageKeys, updateStorage } from '@/utils/storage'
import { Deferred } from '@/utils/deferred' import { Deferred } from '@/utils/deferred'
...@@ -176,8 +176,9 @@ const userModel: UserModel = { ...@@ -176,8 +176,9 @@ const userModel: UserModel = {
accountExchange: thunk(async (actions, payload) => { accountExchange: thunk(async (actions, payload) => {
try { try {
showLoading({ mask: true, title: '操作中...' }) showLoading({ mask: true, title: '操作中...' })
const { data } = await accountExchange(payload) const { data: list } = await accountExchange(payload)
console.log(data) const point = list.find(c => c.accountType === 'POINT')?.amount ?? 0
actions.updateState({ point })
hideLoading() hideLoading()
} catch (err) { } catch (err) {
hideLoading() hideLoading()
......
// 返回月和日,例如:6月16日
function formatMonthDay (date: Date): string {
const month = date.getMonth() + 1
const day = date.getDate()
return `${month}月${day}日`
}
// 返回时间,例如:18:00:00
function formatTime (date: Date): string {
const hours = date.getHours()
const minutes = date.getMinutes()
const seconds = date.getSeconds()
return `${hours.toString().padStart(2, '0')}:${minutes
.toString()
.padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`
}
export function convertDateTime (input: string): string {
const date = new Date(input)
const monthDay = formatMonthDay(date)
const time = formatTime(date)
return `${monthDay} ${time}`
}
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