Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
GeekLearnMathWeapp
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
frontend
GeekLearnMathWeapp
Commits
c004c329
Commit
c004c329
authored
Mar 29, 2023
by
m
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: update
parent
cf07f2a1
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
209 additions
and
41 deletions
+209
-41
app.config.ts.tpl
scripts/app.config.ts.tpl
+1
-1
useModal.ts
src/hooks/useModal.ts
+0
-27
useRequest.ts
src/hooks/useRequest.ts
+131
-0
useToggle.ts
src/hooks/useToggle.ts
+39
-0
index.tsx
src/pages/prepare/components/overview/index.tsx
+21
-3
launch-quest.tsx
src/pages/prepare/components/overview/launch-quest.tsx
+6
-6
index.tsx
src/pages/prepare/index.tsx
+11
-4
No files found.
scripts/app.config.ts.tpl
View file @
c004c329
...
@@ -6,10 +6,10 @@
...
@@ -6,10 +6,10 @@
export default {
export default {
pages: [
pages: [
'pages/prepare/index',
'pages/main/main',
'pages/main/main',
'pages/group/index',
'pages/group/index',
'pages/game/play/index',
'pages/game/play/index',
'pages/prepare/index',
],
],
subPackages: {
{
packages
}
},
subPackages: {
{
packages
}
},
resizable: true,
resizable: true,
...
...
src/hooks/useModal.ts
deleted
100644 → 0
View file @
cf07f2a1
import
{
useState
}
from
'react'
interface
UseModalResult
{
isVisible
:
boolean
;
showModal
:
()
=>
void
;
closeModal
:
()
=>
void
;
}
const
useModal
=
():
UseModalResult
=>
{
const
[
isVisible
,
setIsVisible
]
=
useState
(
false
)
const
showModal
=
()
=>
{
setIsVisible
(
true
)
}
const
closeModal
=
()
=>
{
setIsVisible
(
false
)
}
return
{
isVisible
,
showModal
,
closeModal
,
}
}
export
default
useModal
src/hooks/useRequest.ts
0 → 100644
View file @
c004c329
import
{
useCallback
,
useEffect
,
useRef
,
useState
}
from
'react'
import
Taro
from
'@tarojs/taro'
import
type
{
RequestResult
}
from
'@/types'
interface
Options
<
T
,
P
>
{
immediate
?:
boolean
;
params
?:
P
;
pollInterval
?:
number
;
pollRetryCount
?:
number
;
trigger
?:
unknown
[];
debounceDelay
?:
number
;
throttleDelay
?:
number
;
retryCount
?:
number
;
onError
?:
(
error
:
Error
&
RequestResult
<
T
>
)
=>
void
;
onSuccess
?:
(
result
:
T
)
=>
void
;
onComplete
?:
()
=>
void
;
}
interface
Result
<
T
,
P
>
{
data
:
T
|
null
;
loading
:
boolean
;
error
:
Error
&
RequestResult
<
T
>
|
null
;
run
:
(
params
?:
P
)
=>
Promise
<
void
>
;
refresh
:
()
=>
Promise
<
void
>
;
cancel
:
()
=>
void
;
updateData
:
(
newData
:
T
)
=>
void
;
}
export
default
function
useRequest
<
T
=
unknown
,
P
=
unknown
>
(
service
:
(
params
?:
P
)
=>
Promise
<
T
>
,
options
:
Options
<
T
,
P
>
):
Result
<
T
,
P
>
{
const
[
data
,
updateData
]
=
useState
<
T
|
null
>
(
null
)
const
[
error
,
setError
]
=
useState
<
Error
&
RequestResult
<
T
>
|
null
>
(
null
)
const
[
loading
,
setLoading
]
=
useState
<
boolean
>
(
false
)
const
paramsRef
=
useRef
<
P
|
undefined
>
(
options
.
params
)
const
pollRetryCountRef
=
useRef
<
number
>
(
0
)
const
debounceTimerRef
=
useRef
<
NodeJS
.
Timeout
|
null
>
(
null
)
const
throttleTimerRef
=
useRef
<
NodeJS
.
Timeout
|
null
>
(
null
)
const
cancelSourceRef
=
useRef
<
Taro
.
RequestTask
<
RequestResult
<
T
>>
|
null
>
(
null
)
const
run
=
useCallback
(
async
(
params
?:
P
)
=>
{
if
(
params
!==
undefined
)
{
paramsRef
.
current
=
{
...
paramsRef
.
current
,
...
params
}
}
runConfig
(
paramsRef
.
current
)
},
[
service
,
options
])
const
refresh
=
useCallback
(
async
()
=>
run
(
paramsRef
.
current
),
[
run
])
const
cancel
=
useCallback
(()
=>
cancelSourceRef
.
current
?.
abort
(),
[])
useEffect
(()
=>
{
if
(
options
.
immediate
!==
false
)
{
run
(
paramsRef
.
current
)
}
},
[])
useEffect
(()
=>
{
if
(
options
.
trigger
!==
undefined
)
{
run
(
paramsRef
.
current
)
}
},
[
JSON
.
stringify
(
options
.
trigger
)])
const
runService
=
async
(
params
?:
P
,
retryCount
:
number
=
options
.
retryCount
||
0
)
=>
{
try
{
cancelSourceRef
.
current
?.
abort
()
paramsRef
.
current
=
params
const
res
=
await
service
(
params
)
updateData
(
res
)
options
.
onSuccess
?.(
res
)
}
catch
(
err
)
{
if
(
retryCount
>
0
)
{
runService
(
params
,
retryCount
-
1
)
}
else
{
setError
(
err
)
options
.
onError
?.(
err
)
}
}
finally
{
setLoading
(
false
)
options
.
onComplete
?.()
}
}
const
executeWithPolling
=
(
params
?:
P
)
=>
{
runService
(
params
)
if
(
options
.
pollInterval
&&
(
!
options
.
pollRetryCount
||
pollRetryCountRef
.
current
<
options
.
pollRetryCount
))
{
setTimeout
(()
=>
runConfig
(
params
),
options
.
pollInterval
)
pollRetryCountRef
.
current
+=
1
}
}
const
executeWithDebounce
=
(
params
?:
P
)
=>
{
if
(
debounceTimerRef
.
current
)
{
clearTimeout
(
debounceTimerRef
.
current
)
}
debounceTimerRef
.
current
=
setTimeout
(()
=>
{
executeWithPolling
(
params
)
},
options
.
debounceDelay
)
}
const
executeWithThrottle
=
(
params
?:
P
)
=>
{
if
(
!
throttleTimerRef
.
current
)
{
throttleTimerRef
.
current
=
setTimeout
(()
=>
{
throttleTimerRef
.
current
=
null
},
options
.
throttleDelay
)
executeWithPolling
(
params
)
}
}
const
runConfig
=
(
params
?:
P
)
=>
{
if
(
options
.
debounceDelay
)
{
executeWithDebounce
(
params
)
}
else
if
(
options
.
throttleDelay
)
{
executeWithThrottle
(
params
)
}
else
{
executeWithPolling
(
params
)
}
}
return
{
data
,
error
,
loading
,
run
,
refresh
,
cancel
,
updateData
,
}
}
src/hooks/useToggle.ts
0 → 100644
View file @
c004c329
import
{
useState
,
useCallback
,
useRef
}
from
'react'
export
type
ToggleValue
=
boolean
|
string
|
number
interface
UseToggleOptions
{
initialValue
?:
ToggleValue
;
reverseValue
?:
ToggleValue
;
}
export
default
function
useToggle
({
initialValue
=
false
,
reverseValue
=
!
initialValue
,
}:
UseToggleOptions
=
{})
{
const
[
value
,
setValue
]
=
useState
<
ToggleValue
>
(
initialValue
)
const
initialValueRef
=
useRef
(
initialValue
)
const
reverseValueRef
=
useRef
(
reverseValue
)
const
toggle
=
useCallback
((
newInitialValue
?:
ToggleValue
,
newReverseValue
?:
ToggleValue
)
=>
{
if
(
newInitialValue
!==
undefined
)
{
initialValueRef
.
current
=
newInitialValue
}
if
(
newReverseValue
!==
undefined
)
{
reverseValueRef
.
current
=
newReverseValue
}
if
(
reverseValue
===
undefined
)
{
setValue
((
prevValue
)
=>
typeof
prevValue
===
'boolean'
?
!
prevValue
:
initialValue
)
}
else
{
setValue
((
prevValue
)
=>
prevValue
===
initialValueRef
.
current
?
reverseValueRef
.
current
:
initialValueRef
.
current
)
}
},
[
initialValue
,
reverseValue
])
return
[
value
,
toggle
]
as
const
}
src/pages/prepare/components/overview/index.tsx
View file @
c004c329
import
{
memo
}
from
'react'
import
{
View
,
Text
}
from
'@tarojs/components'
import
{
View
,
Text
}
from
'@tarojs/components'
// import { useStoreState } from '@/store/hooks';
import
Taro
from
'@tarojs/taro'
import
useRequest
from
'@/hooks/useRequest'
import
TopLeftInfo
from
'./top-left-info'
import
TopLeftInfo
from
'./top-left-info'
import
LaunchQuest
from
'./launch-quest'
import
LaunchQuest
from
'./launch-quest'
import
GloryBadge
from
'./glory-badge'
import
GloryBadge
from
'./glory-badge'
...
@@ -8,14 +12,28 @@ import { formatTime } from '../../utils'
...
@@ -8,14 +12,28 @@ import { formatTime } from '../../utils'
import
styles
from
'./index.module.scss'
import
styles
from
'./index.module.scss'
const
getUserInfo
=
async
({
uid
}:
{
uid
:
number
})
=>
{
const
response
=
await
Taro
.
request
({
url
:
`https://api.example.com/users/
${
uid
}
`
,
method
:
'GET'
,
})
return
response
.
data
}
const
Overview
:
React
.
FC
=
()
=>
{
const
Overview
:
React
.
FC
=
()
=>
{
// const levelInfo = useStoreState((state) => state.prepareModel.levelInfo)
const
levelInfo
=
{
const
levelInfo
=
{
title
:
'表内除法'
,
title
:
'表内除法'
,
totalQuestions
:
10
,
totalQuestions
:
10
,
duration
:
80
,
duration
:
80
,
}
}
const
{
data
,
error
}
=
useRequest
(
getUserInfo
,
{
params
:
{
uid
:
100
},
})
console
.
log
(
'error'
,
error
)
console
.
log
(
'data'
,
data
)
return
(
return
(
<>
<>
<
TopLeftInfo
/>
<
TopLeftInfo
/>
...
@@ -41,4 +59,4 @@ const Overview: React.FC = () => {
...
@@ -41,4 +59,4 @@ const Overview: React.FC = () => {
)
)
}
}
export
default
Overview
export
default
memo
(
Overview
)
src/pages/prepare/components/overview/launch-quest.tsx
View file @
c004c329
import
React
from
'react'
import
React
from
'react'
import
{
View
,
Text
,
Button
}
from
'@tarojs/components'
import
{
View
,
Text
,
Button
}
from
'@tarojs/components'
import
Modal
from
'@/components/Modal'
import
Modal
from
'@/components/Modal'
import
use
Modal
from
'@/hooks/useModal
'
import
use
Toggle
from
'@/hooks/useToggle
'
import
styles
from
'./index.module.scss'
import
styles
from
'./index.module.scss'
const
LaunchQuest
:
React
.
FC
=
()
=>
{
const
LaunchQuest
:
React
.
FC
=
()
=>
{
const
{
isVisible
,
showModal
,
closeModal
}
=
useModal
()
const
[
isVisible
,
toggleModal
]
=
useToggle
()
return
(
return
(
<>
<>
<
View
className=
{
styles
.
launchQuest
}
>
<
View
className=
{
styles
.
launchQuest
}
>
<
Button
onClick=
{
showModal
}
>
开始闯关
</
Button
>
<
Button
onClick=
{
()
=>
toggleModal
(
true
)
}
>
开始闯关
</
Button
>
<
Text
className=
{
styles
.
tip
}
>
<
Text
className=
{
styles
.
tip
}
>
首次免答题卡
首次免答题卡
{
/* {hasFreePass ? '首次免答题卡' : '-1答题卡'} */
}
{
/* {hasFreePass ? '首次免答题卡' : '-1答题卡'} */
}
</
Text
>
</
Text
>
</
View
>
</
View
>
<
Modal
isVisible=
{
isVisible
}
onClose=
{
closeModal
}
>
<
Modal
isVisible=
{
isVisible
as
boolean
}
onClose=
{
()
=>
toggleModal
(
false
)
}
>
<
View
>
<
View
>
<
Text
>
你的答题卡已经用完了
</
Text
>
<
Text
>
你的答题卡已经用完了
</
Text
>
<
Button
onClick=
{
closeModal
}
>
建设学习部落得更多答题卡
</
Button
>
<
Button
onClick=
{
()
=>
toggleModal
(
false
)
}
>
建设学习部落得更多答题卡
</
Button
>
<
Button
onClick=
{
closeModal
}
>
购买
</
Button
>
<
Button
onClick=
{
()
=>
toggleModal
(
false
)
}
>
购买
</
Button
>
</
View
>
</
View
>
</
Modal
>
</
Modal
>
</>
</>
...
...
src/pages/prepare/index.tsx
View file @
c004c329
import
{
useEffect
,
memo
}
from
'react'
import
{
View
,
Text
}
from
'@tarojs/components'
import
{
View
,
Text
}
from
'@tarojs/components'
import
{
useEffect
}
from
'react'
import
Tabs
,
{
type
TabItem
}
from
'@/components/Tabs'
import
Tabs
,
{
type
TabItem
}
from
'@/components/Tabs'
import
{
useStoreState
,
useStoreActions
}
from
'@/store/hooks'
import
{
useStoreState
,
useStoreActions
}
from
'@/store/hooks'
import
Overview
from
'./components/overview/index'
import
Overview
from
'./components/overview/index'
import
RankList
from
'./components/rank-list/index'
import
RankList
from
'./components/rank-list/index'
...
@@ -11,10 +13,15 @@ const Prepare: React.FC = () => {
...
@@ -11,10 +13,15 @@ const Prepare: React.FC = () => {
useEffect
(()
=>
{
useEffect
(()
=>
{
refresh
()
refresh
()
},
[
currentUser
])
},
[])
console
.
log
(
'list'
)
const
tabs
:
TabItem
[]
=
[
const
tabs
:
TabItem
[]
=
[
{
label
:
'成都排行榜'
,
children
:
<
RankList
users=
{
list
}
currentUser=
{
currentUser
}
/>
},
{
label
:
'成都排行榜'
,
children
:
<
RankList
users=
{
list
}
currentUser=
{
currentUser
}
/>
},
{
{
label
:
'学习部落排行榜'
,
label
:
'学习部落排行榜'
,
children
:
(
children
:
(
...
@@ -34,4 +41,4 @@ const Prepare: React.FC = () => {
...
@@ -34,4 +41,4 @@ const Prepare: React.FC = () => {
)
)
}
}
export
default
Prepare
export
default
memo
(
Prepare
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment