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

feat: getLocation add highAccuracyExpireTime、getUniverifyManager

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