商城测试版v8_1
This commit is contained in:
@@ -1,51 +1,62 @@
|
||||
import { alert } from "@/common/common";
|
||||
import Taro from "@tarojs/taro";
|
||||
import { memo, useCallback, useState } from "react";
|
||||
import { alert } from '@/common/common'
|
||||
import Taro from '@tarojs/taro'
|
||||
import { memo, useCallback, useState } from 'react'
|
||||
|
||||
type Scope = 'scope.userLocation'|'scope.userLocation'|'scope.record'|'scope.camera'|'scope.bluetooth'|'scope.writePhotosAlbum'|'scope.addPhoneContact'|'scope.addPhoneCalendar'|'scope.werun'|'scope.address'|'scope.invoiceTitle'|'scope.invoice'|'scope.userInfo'
|
||||
type Scope =
|
||||
| 'scope.userLocation'
|
||||
| 'scope.userLocation'
|
||||
| 'scope.record'
|
||||
| 'scope.camera'
|
||||
| 'scope.bluetooth'
|
||||
| 'scope.writePhotosAlbum'
|
||||
| 'scope.addPhoneContact'
|
||||
| 'scope.addPhoneCalendar'
|
||||
| 'scope.werun'
|
||||
| 'scope.address'
|
||||
| 'scope.invoiceTitle'
|
||||
| 'scope.invoice'
|
||||
| 'scope.userInfo'
|
||||
type Param = {
|
||||
scope: Scope,
|
||||
msg: string //检查不通过时警告
|
||||
scope: Scope
|
||||
msg: string //检查不通过时警告
|
||||
}
|
||||
export default ({scope, msg}: Param) => {
|
||||
//这个hook微信授权检查授权
|
||||
const check = useCallback(() => {
|
||||
return new Promise((reslove, reject) => {
|
||||
Taro.getSetting({
|
||||
success: (res) => {
|
||||
if(res.authSetting[scope]) {
|
||||
reslove(true)
|
||||
} else if (res.authSetting[scope] === undefined) {
|
||||
Taro.authorize({
|
||||
scope: scope,
|
||||
success() {
|
||||
reslove(true)
|
||||
},
|
||||
fail() {
|
||||
alert.none(msg)
|
||||
reject(false)
|
||||
}
|
||||
})
|
||||
} else {
|
||||
Taro.openSetting({
|
||||
success(res) {
|
||||
if(res.authSetting[scope]) {
|
||||
reslove(true)
|
||||
} else {
|
||||
alert.none(msg)
|
||||
reject(false)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
export default ({ scope, msg }: Param) => {
|
||||
//这个hook微信授权检查授权
|
||||
const check = useCallback(() => {
|
||||
return new Promise((reslove, reject) => {
|
||||
Taro.getSetting({
|
||||
success: (res) => {
|
||||
if (res.authSetting[scope]) {
|
||||
reslove(true)
|
||||
} else if (res.authSetting[scope] === undefined) {
|
||||
Taro.authorize({
|
||||
scope: scope,
|
||||
success() {
|
||||
reslove(true)
|
||||
},
|
||||
fail() {
|
||||
alert.none(msg)
|
||||
reject(false)
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
}, [scope])
|
||||
} else {
|
||||
Taro.openSetting({
|
||||
success(res) {
|
||||
if (res.authSetting[scope]) {
|
||||
reslove(true)
|
||||
} else {
|
||||
alert.none(msg)
|
||||
reject(false)
|
||||
}
|
||||
},
|
||||
})
|
||||
}
|
||||
},
|
||||
})
|
||||
})
|
||||
}, [scope])
|
||||
|
||||
return {
|
||||
check,
|
||||
}
|
||||
|
||||
}
|
||||
return {
|
||||
check,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user