提交 758c0f91 编写于 作者: D DCloud_LXH

feat: getLocation add highAccuracyExpireTime、getUniverifyManager

上级 fc3280ba
......@@ -52,3 +52,6 @@ export type API_TYPE_CLOSE_AUTH_VIEW = typeof uni.closeAuthView
export const API_GET_CHECK_BOX_STATE = 'getCheckBoxState'
export type API_TYPE_GET_CHECK_BOX_STATE = typeof uni.getCheckBoxState
export const API_GET_UNIVERIFY_MANAGER = 'getUniverifyManager'
export type API_TYPE_GET_UNIVERIFY_MANAGER = typeof uni.getUniverifyManager
......@@ -42,7 +42,12 @@ function getLocationSuccess(
export const getLocation = <API_TYPE_GET_LOCATION>defineAsyncApi(
API_GET_LOCATION,
(
{ type = 'wgs84', geocode = false, altitude = false },
{
type = 'wgs84',
geocode = false,
altitude = false,
highAccuracyExpireTime,
},
{ resolve, reject }
) => {
plus.geolocation.getCurrentPosition(
......@@ -61,6 +66,7 @@ export const getLocation = <API_TYPE_GET_LOCATION>defineAsyncApi(
{
geocode: geocode,
enableHighAccuracy: altitude,
timeout: highAccuracyExpireTime,
}
)
},
......
......@@ -16,10 +16,12 @@ import {
API_TYPE_CLOSE_AUTH_VIEW,
API_GET_CHECK_BOX_STATE,
API_TYPE_GET_CHECK_BOX_STATE,
API_GET_UNIVERIFY_MANAGER,
API_TYPE_GET_UNIVERIFY_MANAGER,
defineAsyncApi,
defineSyncApi,
} from '@dcloudio/uni-api'
import { isPlainObject, toTypeString } from '@vue/shared'
import { isPlainObject, toTypeString, extend } from '@vue/shared'
import {
warpPlusSuccessCallback,
warpPlusErrorCallback,
......@@ -28,9 +30,11 @@ import {
type Provider = PlusOauthAuthService
type CallBack = {
resolve: (res: any) => void
reject: (errMsg: string) => void
reject: (errMsg: string, errRes?: any) => void
}
let univerifyManager: UniverifyManager
function getService(provider: string): Promise<Provider> {
return new Promise((resolve, reject) => {
plus.oauth.getServices((services) => {
......@@ -230,22 +234,69 @@ function univerifyButtonsClickHandling(
) {
if (
isPlainObject(univerifyStyle) &&
univerifyStyle.buttons &&
toTypeString(univerifyStyle.buttons.list) === '[object Array]' &&
univerifyStyle.buttons.list!.length > 0
isPlainObject(univerifyStyle.buttons) &&
toTypeString(univerifyStyle.buttons.list) === '[object Array]'
) {
univerifyStyle.buttons.list!.forEach((button, index) => {
univerifyStyle.buttons!.list![index].onclick = function () {
_closeAuthView().then(() => {
errorCallback({
code: '30008',
message: '用户点击了自定义按钮',
index,
provider: button.provider,
})
})
const res = {
code: '30008',
message: '用户点击了自定义按钮',
index,
provider: button.provider,
}
isPlainObject(univerifyManager)
? univerifyManager._triggerUniverifyButtonsClick(res)
: _closeAuthView().then(() => {
errorCallback(res)
})
}
})
}
return univerifyStyle
}
class UniverifyManager implements UniApp.UniverifyManager {
provider: string = 'univerify'
eventName: string = 'api.univerifyButtonsClick'
close() {
closeAuthView()
}
login(options: UniApp.UniverifyLoginOptions) {
login(this._getOptions(options))
}
getCheckBoxState(options: UniApp.GetCheckBoxStateOptions) {
getCheckBoxState(options)
}
preLogin(options?: UniApp.CallBackOptions) {
preLogin(this._getOptions(options))
}
onButtonsClick(callback: UniApp.CallbackFunction) {
UniServiceJSBridge.on(this.eventName, callback)
}
offButtonsClick(callback: UniApp.CallbackFunction) {
UniServiceJSBridge.off(this.eventName, callback)
}
_triggerUniverifyButtonsClick(res: any) {
UniServiceJSBridge.emit(this.eventName, res)
}
_getOptions(options: any = {}) {
return extend({}, options, { provider: this.provider })
}
}
export const getUniverifyManager =
defineSyncApi<API_TYPE_GET_UNIVERIFY_MANAGER>(
API_GET_UNIVERIFY_MANAGER,
() => {
return univerifyManager || (univerifyManager = new UniverifyManager())
}
)
......@@ -14,7 +14,7 @@ type GeoRes = (coords: GeolocationCoordinates, skip?: boolean) => void
export const getLocation = <API_TYPE_GET_LOCATION>defineAsyncApi(
API_GET_LOCATION,
({ type, altitude }, { resolve, reject }) => {
({ type, altitude, highAccuracyExpireTime }, { resolve, reject }) => {
const mapInfo = getMapInfo()
new Promise((resolve: GeoRes, reject) => {
......@@ -24,7 +24,7 @@ export const getLocation = <API_TYPE_GET_LOCATION>defineAsyncApi(
reject,
{
enableHighAccuracy: altitude,
timeout: 1000 * 100,
timeout: highAccuracyExpireTime || 1000 * 100,
}
)
} else {
......
......@@ -922,10 +922,10 @@
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==
"@dcloudio/types@2.5.10":
version "2.5.10"
resolved "https://registry.yarnpkg.com/@dcloudio/types/-/types-2.5.10.tgz#fb5ced15061dabcb3410efafeee188576dd3f20b"
integrity sha512-wrZVZIsF9xmOCKVZjXhtv8PBRcOahZVuNhfyf3xKhqs4zj6pHwegAzxIPTFvLNtUxKqEpG9azVPcfFZCOGIjYA==
"@dcloudio/types@2.5.11":
version "2.5.11"
resolved "https://registry.yarnpkg.com/@dcloudio/types/-/types-2.5.11.tgz#12bacd800807965e3d0002022efebba38c243b71"
integrity sha512-dgAI1fNAhOhQumxO3P901VOYlfnXGJCDljFsZ3EqGGKitf5FB0HSZEutnam2O1zrHwqmHkSSJ+5jiYOED0B8kA==
"@eslint/eslintrc@^0.4.3":
version "0.4.3"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册