支付页面开发
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
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 Param = {
|
||||
scope: Scope,
|
||||
msg: string //检查不通过时警告
|
||||
}
|
||||
export default ({scope, msg}: Param) => {
|
||||
//检查授权
|
||||
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)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
}, [scope])
|
||||
|
||||
return {
|
||||
check,
|
||||
}
|
||||
|
||||
}
|
||||
+4
-4
@@ -32,7 +32,8 @@ type option = {
|
||||
data?: any,
|
||||
page?: number,
|
||||
pageSize?: number,
|
||||
pagination?: true|false
|
||||
pagination?: true|false,
|
||||
base_url?: string
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -99,9 +100,9 @@ export const useRequest = (options:option = {
|
||||
page: 1,
|
||||
pageSize: 24,
|
||||
pagination: false, // 是否分页
|
||||
base_url: ''
|
||||
}) => {
|
||||
|
||||
options.url = `${BASE_URL}${options.url}`
|
||||
options.url = `${options.base_url||BASE_URL}${options.url}`
|
||||
let params:Params = {
|
||||
code: null, // 业务码
|
||||
success: false, // 请求是否成功
|
||||
@@ -121,7 +122,6 @@ export const useRequest = (options:option = {
|
||||
const stateRef = useRef({...params})
|
||||
const [state, setState] = useState({...stateRef.current})
|
||||
const {removeToken, removeSessionKey} = useUserInfo()
|
||||
const router = useRouter()
|
||||
// 请求函数
|
||||
const fetchData = async (sub_options?:any) => {
|
||||
stateRef.current.loading = true
|
||||
|
||||
Reference in New Issue
Block a user