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
780658d2
Commit
780658d2
authored
Apr 11, 2023
by
hewenhao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: update
parent
b83bac3f
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
300 additions
and
13 deletions
+300
-13
auth.ts
src/api/auth.ts
+2
-1
index.ts
src/api/index.ts
+1
-0
share.ts
src/api/share.ts
+79
-0
index.ts
src/hooks/index.ts
+1
-0
use-share.ts
src/hooks/use-share.ts
+89
-0
index.config.ts
src/pages/group/index.config.ts
+2
-1
index.tsx
src/pages/group/index.tsx
+16
-5
main.config.ts
src/pages/main/main.config.ts
+1
-0
main.tsx
src/pages/main/main.tsx
+18
-1
index.config.ts
src/pages/prepare/index.config.ts
+1
-0
index.tsx
src/pages/prepare/index.tsx
+8
-5
index.ts
src/utils/index.ts
+19
-0
share.ts
src/utils/share.ts
+63
-0
No files found.
src/api/auth.ts
View file @
780658d2
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
...
...
@@ -61,7 +62,7 @@ export function updateUserPhone (code: string) {
return
requestAfterSilentLogin
<
void
,
{
code
:
string
;
userId
?:
number
}
>
((
userInfo
)
=>
({
url
:
'/service-idea/stage/user/getUserPhone'
,
method
:
'GET'
,
data
:
{
code
,
userId
:
userInfo
?.
userId
}
data
:
{
code
,
userId
:
userInfo
?.
userId
,
shareId
:
getCurrentShareId
()
}
}))
}
...
...
src/api/index.ts
View file @
780658d2
export
*
from
'./auth'
export
*
from
'./game'
export
*
from
'./share'
src/api/share.ts
0 → 100644
View file @
780658d2
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
},
})
}
src/hooks/index.ts
View file @
780658d2
...
...
@@ -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'
src/hooks/use-share.ts
0 → 100644
View file @
780658d2
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
}
src/pages/group/index.config.ts
View file @
780658d2
export
default
definePageConfig
({
navigationBarTitleText
:
'pk-math'
,
navigationStyle
:
'custom'
,
navigationBarTextStyle
:
'white'
navigationBarTextStyle
:
'white'
,
enableShareAppMessage
:
true
,
})
src/pages/group/index.tsx
View file @
780658d2
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'
...
...
@@ -68,13 +68,24 @@ const Group = () => {
Promise
.
all
([
queryTribePoint
(),
fetchTribeInfo
()])
},
[
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
,
...
...
src/pages/main/main.config.ts
View file @
780658d2
...
...
@@ -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'
}
...
...
src/pages/main/main.tsx
View file @
780658d2
...
...
@@ -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
)
...
...
src/pages/prepare/index.config.ts
View file @
780658d2
export
default
definePageConfig
({
enableShareAppMessage
:
true
,
navigationBarTitleText
:
'pk-math'
,
navigationStyle
:
'custom'
})
src/pages/prepare/index.tsx
View file @
780658d2
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'
...
...
@@ -75,13 +75,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,
...
...
src/utils/index.ts
0 → 100644
View file @
780658d2
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
}
src/utils/share.ts
0 → 100644
View file @
780658d2
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
)}
`
}
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