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 @@
export default {
pages: [
'pages/market/index',
'pages/main/main',
'pages/market/index',
'pages/accept-pk/index',
'pages/battles/index',
'pages/prepare/index',
......
......@@ -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
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) {
return requestAfterSilentLogin<void, { nickName: string, userId?: number }>(userInfo => ({
method: 'GET',
......
......@@ -54,14 +54,17 @@ export type PkRecords = {
} & Pick<PkDetails, 'allPkNum' | 'userRanks' | 'winPkNum'>
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',
url: '/service-idea/pk/personal/stage/records',
data: {
stageId: data.stageId,
userId: data.userId || userInfo?.userId,
data
}
}))
})
}
export type SubmitPkResultParams = {
......
......@@ -3,6 +3,7 @@ import { View, Text, Image, ScrollView } from '@tarojs/components'
import classNames from 'classnames'
import Modal from '@/components/Modal'
import { useStoreState, useStoreActions } from '@/store/hooks'
import { convertDateTime } from '@/utils/day'
import assets from '@/assets/oss/assets-pk'
import { badgeImages } from '../const'
import { UserInfo, GameResultProps } from './game-result'
......@@ -97,7 +98,7 @@ const GameResult = ({ record }: GameResultProps) => {
src={record.result ? assets['win.png'].u : assets['lose.png'].u}
className={gameResultStyles.levelResult}
/>
<Text className={gameResultStyles.levelDate}>{record.createTime}</Text>
<Text className={gameResultStyles.levelDate}>{convertDateTime(record.createTime)}</Text>
</View>
<View className={styles.gameBody}>
......
import { CSSProperties } from 'react'
import { View, Text, Image } from '@tarojs/components'
import classNames from 'classnames'
import { convertDateTime } from '@/utils/day'
import assets from '@/assets/oss/assets-pk'
import assets2 from '@/assets/oss/assets-prepare'
import { PkRecord } from '@/api/pk'
......@@ -27,7 +28,7 @@ const GameResult = ({ record }: GameResultProps) => {
src={assets[record.result ? 'win.png' : 'lose.png'].u}
className={styles.levelResult}
/>
<Text className={styles.levelDate}>{record.createTime}</Text>
<Text className={styles.levelDate}>{convertDateTime(record.createTime)}</Text>
</View>
<View className={styles.gameBody}>
......
......@@ -11,10 +11,9 @@ import styles from './exchange-item.module.scss'
import styles2 from './exchange-rename-card.module.scss'
type ExchangeItemProps = {
title: string;
stepValue: number;
// onConfirm: (arg: number) => void;
onCancel: () => void;
title: string
stepValue: number
onCancel: () => void
}
const randomPick = (arr: string[]) => {
......@@ -25,13 +24,17 @@ const randomPick = (arr: string[]) => {
const ExchangeRenameCard = (props: ExchangeItemProps) => {
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 [generating, { setTrue, setFalse }] = useBoolean(false)
const dataRef = useRef<NickNameWord>({ noun: [], adj: [] })
const timerRef = useRef<NodeJS.Timer | null>(null)
const accountExchange = useStoreActions(actions => actions.userModel.accountExchange)
const changeNickName = useStoreActions(actions => actions.userModel.changeNickName)
const accountExchange = useStoreActions(
(actions) => actions.userModel.accountExchange
)
const changeNickName = useStoreActions(
(actions) => actions.userModel.changeNickName
)
const generateName = useCallback(() => {
const { noun, adj } = dataRef.current
......@@ -73,21 +76,25 @@ const ExchangeRenameCard = (props: ExchangeItemProps) => {
num: 1,
accountTo: 'NAME_CARD',
accountFrom: 'POINT',
}).then(() => {
})
.then(() => {
changeNickName(name).then(() => {
showToast({ title: '操作成功', icon: 'success' })
onCancel && onCancel()
})
}).catch(() => {
})
.catch(() => {})
}
return (
<>
<View className={styles2.description}>
请输入您的角色名(7字以内)
</View>
<View className={styles2.description}>请输入您的角色名(7字以内)</View>
<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
src={assetsGuide['touzi.png'].u}
className={classNames(
......@@ -97,10 +104,22 @@ const ExchangeRenameCard = (props: ExchangeItemProps) => {
onClick={handleGenerate}
></Image>
</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.cancel} onClick={() => onCancel()} id="market_exchange_cancel">取消</View>
<View className={styles.confirm} onClick={handleConfirm} data-name="兑换改名卡">
<View
className={styles.cancel}
onClick={() => onCancel()}
id="market_exchange_cancel"
>
取消
</View>
<View
className={styles.confirm}
onClick={handleConfirm}
data-name="兑换改名卡"
>
确定
</View>
</View>
......
......@@ -245,7 +245,7 @@ const StudyMarket = () => {
bodyClassName={styles.moal_body}
onClose={setFalse}
maskClosable={false}
tilte={`兑换${currentGoods?.subTitle ?? currentGoods?.title ?? ''}`}
tilte={`兑换${currentGoods?.subTitle ?? ''}`}
>
{currentGoods?.subTitle === '改名卡' ? (
<ExchangeRenameCard
......
import {
action, Action, Thunk, thunk, State
} 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 { pointToCard } from '@/api/account'
import { ExchangeParams, accountExchange, pointToCard } from '@/api/account'
import { showModal, showToast, showLoading, hideLoading } from '@tarojs/taro'
import { getStorage, StorageKeys, updateStorage } from '@/utils/storage'
import { Deferred } from '@/utils/deferred'
......@@ -176,8 +176,9 @@ const userModel: UserModel = {
accountExchange: thunk(async (actions, payload) => {
try {
showLoading({ mask: true, title: '操作中...' })
const { data } = await accountExchange(payload)
console.log(data)
const { data: list } = await accountExchange(payload)
const point = list.find(c => c.accountType === 'POINT')?.amount ?? 0
actions.updateState({ point })
hideLoading()
} catch (err) {
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