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
6a11fa6f
Commit
6a11fa6f
authored
Apr 02, 2023
by
hewenhao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: update
parent
be06f06c
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
30 additions
and
30 deletions
+30
-30
auth.ts
src/api/auth.ts
+3
-4
game.ts
src/api/game.ts
+12
-13
index.tsx
src/custom-tab-bar/index.tsx
+8
-6
main.tsx
src/pages/main/main.tsx
+3
-1
request.ts
src/utils/request.ts
+4
-6
No files found.
src/api/auth.ts
View file @
6a11fa6f
import
{
request
,
requestAfterSilentLogin
}
from
'@/utils/request'
import
{
request
,
requestAfterSilentLogin
}
from
'@/utils/request'
import
{
getStorage
,
StorageKeys
}
from
'@/utils/storage'
type
LoginResult
=
{
type
LoginResult
=
{
phone
?:
string
|
null
;
phone
?:
string
|
null
;
...
@@ -42,11 +41,11 @@ export type AccountOut = {
...
@@ -42,11 +41,11 @@ export type AccountOut = {
}
}
export
function
getAccountInfo
()
{
export
function
getAccountInfo
()
{
return
requestAfterSilentLogin
<
AccountOut
[],
AccountIn
>
({
return
requestAfterSilentLogin
<
AccountOut
[],
AccountIn
>
(
(
userInfo
)
=>
(
{
method
:
'POST'
,
method
:
'POST'
,
url
:
'/service-idea/account/selectAccounts'
,
url
:
'/service-idea/account/selectAccounts'
,
data
:
{
data
:
{
userId
:
getStorage
(
StorageKeys
.
userInfo
)
?.
userId
,
userId
:
userInfo
?.
userId
,
}
}
})
})
)
}
}
src/api/game.ts
View file @
6a11fa6f
import
{
requestAfterSilentLogin
}
from
'@/utils/request'
import
{
requestAfterSilentLogin
}
from
'@/utils/request'
import
{
getStorage
,
StorageKeys
}
from
'@/utils/storage'
import
{
QuestionItem
,
type
QuestionType
}
from
'@/pages/game/play/types'
import
{
QuestionItem
,
type
QuestionType
}
from
'@/pages/game/play/types'
export
const
getQuestionList
=
(
stageId
:
number
)
=>
{
export
const
getQuestionList
=
(
stageId
:
number
)
=>
{
return
requestAfterSilentLogin
<
QuestionType
[],
{
stageId
:
number
,
userId
?:
number
}
>
({
return
requestAfterSilentLogin
<
QuestionType
[],
{
stageId
:
number
,
userId
?:
number
}
>
(
userInfo
=>
(
{
url
:
'/service-idea/stage/startStage'
,
url
:
'/service-idea/stage/startStage'
,
method
:
'GET'
,
method
:
'GET'
,
data
:
{
stageId
,
userId
:
getStorage
(
StorageKeys
.
userInfo
)
?.
userId
}
data
:
{
stageId
,
userId
:
userInfo
?.
userId
}
})
})
)
}
}
export
const
enum
StageStatus
{
export
const
enum
StageStatus
{
...
@@ -65,20 +64,20 @@ export interface StageDetail extends Stage {
...
@@ -65,20 +64,20 @@ export interface StageDetail extends Stage {
/** 获取关卡详情 */
/** 获取关卡详情 */
export
function
getStageDetail
(
stageId
:
number
)
{
export
function
getStageDetail
(
stageId
:
number
)
{
return
requestAfterSilentLogin
<
StageDetail
,
{
stageId
:
number
,
userId
?:
number
}
>
({
return
requestAfterSilentLogin
<
StageDetail
,
{
stageId
:
number
,
userId
?:
number
}
>
(
userInfo
=>
(
{
method
:
'GET'
,
method
:
'GET'
,
url
:
'/service-idea/stage/stageDetail'
,
url
:
'/service-idea/stage/stageDetail'
,
data
:
{
stageId
,
userId
:
getStorage
(
StorageKeys
.
userInfo
)
?.
userId
}
data
:
{
stageId
,
userId
:
userInfo
?.
userId
}
})
})
)
}
}
/** 获取关卡列表 */
/** 获取关卡列表 */
export
function
getStageList
()
{
export
function
getStageList
()
{
return
requestAfterSilentLogin
<
Stage
[],
{
chapter
:
number
;
userId
?:
number
}
>
({
return
requestAfterSilentLogin
<
Stage
[],
{
chapter
:
number
;
userId
?:
number
}
>
(
userInfo
=>
(
{
method
:
'GET'
,
method
:
'GET'
,
url
:
'/service-idea/stage/listStages'
,
url
:
'/service-idea/stage/listStages'
,
data
:
{
chapter
:
1
,
userId
:
getStorage
(
StorageKeys
.
userInfo
)
?.
userId
}
data
:
{
chapter
:
1
,
userId
:
userInfo
?.
userId
}
})
})
)
}
}
export
interface
CompleteQuestion
extends
QuestionItem
{
export
interface
CompleteQuestion
extends
QuestionItem
{
...
@@ -115,12 +114,12 @@ export interface CompleteStageOut {
...
@@ -115,12 +114,12 @@ export interface CompleteStageOut {
/** 完成 */
/** 完成 */
export
function
completeStage
(
arg
:
CompleteStageParam
)
{
export
function
completeStage
(
arg
:
CompleteStageParam
)
{
return
requestAfterSilentLogin
<
CompleteStageOut
,
CompleteStageParamIn
>
({
return
requestAfterSilentLogin
<
CompleteStageOut
,
CompleteStageParamIn
>
(
userInfo
=>
(
{
method
:
'POST'
,
method
:
'POST'
,
url
:
'/service-idea/stage/completeStage'
,
url
:
'/service-idea/stage/completeStage'
,
data
:
{
data
:
{
...
arg
,
...
arg
,
userId
:
getStorage
(
StorageKeys
.
userInfo
)
?.
userId
userId
:
userInfo
?.
userId
}
}
})
})
)
}
}
src/custom-tab-bar/index.tsx
View file @
6a11fa6f
import
{
useState
,
useImperativeHandle
,
forwardRef
,
useCallback
}
from
'react'
import
{
useState
,
useImperativeHandle
,
forwardRef
,
useCallback
,
type
ForwardRefRenderFunction
}
from
'react'
import
{
View
,
Image
}
from
'@tarojs/components'
import
{
View
,
Image
}
from
'@tarojs/components'
import
{
switchTab
}
from
'@tarojs/taro'
import
{
switchTab
}
from
'@tarojs/taro'
import
styles
from
'./index.module.scss'
import
styles
from
'./index.module.scss'
type
REfType
=
{
type
TabbarRef
=
{
switchTab
:
(
index
:
number
,
url
:
string
)
=>
void
;
switchTab
:
(
index
:
number
,
url
:
string
)
=>
void
;
setSelected
:
(
index
:
number
)
=>
void
setSelected
:
(
index
:
number
)
=>
void
;
}
}
const
Tabbar
=
forwardRef
<
unknown
,
REfType
>
(
(
_
,
ref
)
=>
{
const
Tabbar
:
ForwardRefRenderFunction
<
TabbarRef
,
{}
>
=
(
_
,
ref
)
=>
{
const
[
selected
,
setSelected
]
=
useState
(
0
)
const
[
selected
,
setSelected
]
=
useState
(
0
)
const
_switchTab
=
useCallback
((
index
:
number
,
url
:
string
)
=>
{
const
_switchTab
=
useCallback
((
index
:
number
,
url
:
string
)
=>
{
...
@@ -41,6 +41,8 @@ const Tabbar = forwardRef<unknown, REfType>((_, ref) => {
...
@@ -41,6 +41,8 @@ const Tabbar = forwardRef<unknown, REfType>((_, ref) => {
</
View
>
</
View
>
</
View
>
</
View
>
)
)
})
}
export
{
TabbarRef
}
export
default
Tabbar
export
default
forwardRef
(
Tabbar
)
src/pages/main/main.tsx
View file @
6a11fa6f
...
@@ -2,6 +2,8 @@ import { View } from '@tarojs/components'
...
@@ -2,6 +2,8 @@ import { View } from '@tarojs/components'
import
{
getMenuButtonBoundingClientRect
,
useDidShow
,
getCurrentInstance
,
getTabBar
,
pageScrollTo
,
getSystemInfoSync
}
from
'@tarojs/taro'
import
{
getMenuButtonBoundingClientRect
,
useDidShow
,
getCurrentInstance
,
getTabBar
,
pageScrollTo
,
getSystemInfoSync
}
from
'@tarojs/taro'
import
{
useState
,
useMemo
,
useEffect
,
useCallback
}
from
'react'
import
{
useState
,
useMemo
,
useEffect
,
useCallback
}
from
'react'
import
{
useStoreActions
,
useStoreState
}
from
'@/store/hooks'
import
{
useStoreActions
,
useStoreState
}
from
'@/store/hooks'
import
type
{
TabbarRef
}
from
'../../custom-tab-bar/index'
import
{
CurrentRoundId
,
SceneContext
}
from
'./components/scene/constants'
import
{
CurrentRoundId
,
SceneContext
}
from
'./components/scene/constants'
import
MainHeader
from
'./components/header'
import
MainHeader
from
'./components/header'
import
MainChapter
from
'./components/chapter'
import
MainChapter
from
'./components/chapter'
...
@@ -19,7 +21,7 @@ const MainPage = () => {
...
@@ -19,7 +21,7 @@ const MainPage = () => {
useDidShow
(()
=>
{
useDidShow
(()
=>
{
fetchAccount
()
fetchAccount
()
const
tabbar
=
getTabBar
(
page
)
as
any
const
tabbar
=
getTabBar
<
TabbarRef
>
(
page
)
tabbar
?.
setSelected
(
0
)
tabbar
?.
setSelected
(
0
)
})
})
...
...
src/utils/request.ts
View file @
6a11fa6f
...
@@ -66,14 +66,14 @@ async function request<T = unknown, P = unknown> (options: RequestOption<T, P>):
...
@@ -66,14 +66,14 @@ async function request<T = unknown, P = unknown> (options: RequestOption<T, P>):
const
token
=
getStorage
(
StorageKeys
.
token
)
const
token
=
getStorage
(
StorageKeys
.
token
)
const
userId
=
getStorage
(
StorageKeys
.
userInfo
)?.
userId
//
const userId = getStorage(StorageKeys.userInfo)?.userId
if
(
token
)
{
if
(
token
)
{
header
.
Authorization
=
`Bearer
${
token
}
`
header
.
Authorization
=
`Bearer
${
token
}
`
}
}
if
(
userId
)
{
//
if (userId) {
header
.
STUDENTUSERID
=
`
${
userId
}
`
//
header.STUDENTUSERID = `${userId}`
}
//
}
const
doRequest
=
(
baseUrl
)
=>
{
const
doRequest
=
(
baseUrl
)
=>
{
const
base
=
options
.
baseUrl
||
baseUrl
const
base
=
options
.
baseUrl
||
baseUrl
...
@@ -143,11 +143,9 @@ export async function requestAfterSilentLogin<T, P = void> (arg: RequestAfterSil
...
@@ -143,11 +143,9 @@ export async function requestAfterSilentLogin<T, P = void> (arg: RequestAfterSil
const
userInfo
=
getStorage
(
StorageKeys
.
userInfo
)
const
userInfo
=
getStorage
(
StorageKeys
.
userInfo
)
if
(
typeof
arg
===
'function'
)
{
if
(
typeof
arg
===
'function'
)
{
// eslint-disable-next-line no-return-await
return
await
request
<
T
,
P
>
(
arg
(
userInfo
))
return
await
request
<
T
,
P
>
(
arg
(
userInfo
))
}
}
// eslint-disable-next-line no-return-await
return
await
request
<
T
,
P
>
(
arg
)
return
await
request
<
T
,
P
>
(
arg
)
}
}
...
...
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