Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
taobao-mini-template
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
2
Issues
2
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
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
qinhaitao
taobao-mini-template
Commits
1cc32d85
Commit
1cc32d85
authored
Oct 28, 2021
by
王能飞
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'c_client_taro-pack' into 'c_client_taro'
授权优化 See merge request
!51
parents
4321834f
7d71d83f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
6 deletions
+17
-6
app.config.js
c_client/src/app.config.js
+5
-1
canvasComp.js
...ient/src/components/_miniprogram/canvasComp/canvasComp.js
+1
-1
useAuth.js
c_client/src/hooks/useAuth.js
+11
-4
No files found.
c_client/src/app.config.js
View file @
1cc32d85
...
@@ -42,5 +42,9 @@ export default {
...
@@ -42,5 +42,9 @@ export default {
version
:
'*'
,
version
:
'*'
,
provider
:
'3000000026642582'
provider
:
'3000000026642582'
}
}
},
memberBenefit
:
{
version
:
'*'
,
provider
:
'3000000043103783'
}
}
}
}
\ No newline at end of file
c_client/src/components/_miniprogram/canvasComp/canvasComp.js
View file @
1cc32d85
...
@@ -17,7 +17,7 @@ Component({
...
@@ -17,7 +17,7 @@ Component({
this
.
postMessage
(
data
.
type
,
data
)
this
.
postMessage
(
data
.
type
,
data
)
}
}
},
},
didUn
M
ount
()
{
didUn
m
ount
()
{
// 页面被关闭
// 页面被关闭
this
.
main
&&
this
.
main
.
destroy
();
this
.
main
&&
this
.
main
.
destroy
();
},
},
...
...
c_client/src/hooks/useAuth.js
View file @
1cc32d85
import
{
useEffect
,
useRef
,
useState
}
from
'react'
import
{
useEffect
,
useRef
,
useState
}
from
'react'
import
Taro
,
{
useDidShow
,
showToast
}
from
'@tarojs/taro'
import
Taro
,
{
useDidShow
,
showToast
}
from
'@tarojs/taro'
import
{
getSetting
,
openSetting
,
authorize
,
getAuthUserInfo
}
from
'tbcc-sdk-ts/lib/core/tb'
import
{
getSetting
,
openSetting
,
authorize
,
getAuthUserInfo
}
from
'tbcc-sdk-ts/lib/core/tb'
import
{
useThrottle
}
from
'@/hooks/useThrottle'
// 授权
// 授权
export
function
useAuth
(
authSuccess
=
()
=>
{})
{
export
function
useAuth
(
authSuccess
=
()
=>
{})
{
const
[
visible
,
setVisible
]
=
useState
(
false
)
const
[
visible
,
setVisible
]
=
useState
(
false
)
const
goToOpenSetting
=
useRef
(
false
)
const
goToOpenSetting
=
useRef
(
false
)
// 授权信息调用是否完成 防止用户调用了授权API 未弹出再次点击
const
completeHandle
=
useRef
(
true
)
// 获取授权信息
// 获取授权信息
const
onHandleSetting
=
async
()
=>
{
const
onHandleSetting
=
useThrottle
(
async
()
=>
{
const
res
=
await
getSetting
()
const
res
=
await
getSetting
()
if
(
!
res
.
authSetting
?.
userInfo
)
{
if
(
!
res
.
authSetting
?.
userInfo
)
{
const
authResult
=
await
authorize
().
catch
(
err
=>
{
const
authResult
=
await
authorize
().
catch
(
err
=>
{
setVisible
(
true
)
setVisible
(
true
)
showToast
({
title
:
'请先授权,授权成功后才可参与活动'
})
showToast
({
title
:
'请先授权,授权成功后才可参与活动'
})
completeHandle
.
current
=
true
})
})
if
(
authResult
)
{
if
(
authResult
)
{
authUserInfo
()
authUserInfo
()
...
@@ -20,14 +24,16 @@ export function useAuth(authSuccess = () => {}) {
...
@@ -20,14 +24,16 @@ export function useAuth(authSuccess = () => {}) {
}
else
{
}
else
{
authUserInfo
()
authUserInfo
()
}
}
}
}
)
// 打开授权设置
// 打开授权设置
const
onOpenSetting
=
async
()
=>
{
const
onOpenSetting
=
useThrottle
(
async
()
=>
{
if
(
!
completeHandle
.
current
)
return
;
goToOpenSetting
.
current
=
true
goToOpenSetting
.
current
=
true
showToast
({
title
:
'打开授权开关,授权成功后才可参与活动'
,
duration
:
1000
,
success
:
()
=>
openSetting
()
})
showToast
({
title
:
'打开授权开关,授权成功后才可参与活动'
,
duration
:
1000
,
success
:
()
=>
openSetting
()
})
}
}
)
// 获取用户授权信息
// 获取用户授权信息
const
authUserInfo
=
async
()
=>
{
const
authUserInfo
=
async
()
=>
{
completeHandle
.
current
=
true
const
info
=
await
getAuthUserInfo
()
const
info
=
await
getAuthUserInfo
()
if
(
info
)
{
if
(
info
)
{
authSuccess
(
info
)
authSuccess
(
info
)
...
@@ -42,6 +48,7 @@ export function useAuth(authSuccess = () => {}) {
...
@@ -42,6 +48,7 @@ export function useAuth(authSuccess = () => {}) {
if
(
goToOpenSetting
.
current
)
{
if
(
goToOpenSetting
.
current
)
{
// 重新授权
// 重新授权
onHandleSetting
()
onHandleSetting
()
completeHandle
.
current
=
false
goToOpenSetting
.
current
=
false
goToOpenSetting
.
current
=
false
}
}
})
})
...
...
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