From a1427c12eef9a756ea58197eac314033ca27e799 Mon Sep 17 00:00:00 2001 From: zhenyuWang <13641039885@163.com> Date: Mon, 11 Jul 2022 16:53:02 +0800 Subject: [PATCH] =?UTF-8?q?fix(openLocation):=20=E6=A0=A1=E9=AA=8C=20latit?= =?UTF-8?q?ude=E3=80=81longitude=20=E6=95=B0=E6=8D=AE=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/protocols/location/openLocation.ts | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/packages/uni-api/src/protocols/location/openLocation.ts b/packages/uni-api/src/protocols/location/openLocation.ts index 8bbd7664e..6a99cb969 100644 --- a/packages/uni-api/src/protocols/location/openLocation.ts +++ b/packages/uni-api/src/protocols/location/openLocation.ts @@ -1,18 +1,36 @@ export const API_OPEN_LOCATION = 'openLocation' export type API_TYPE_OPEN_LOCATION = typeof uni.openLocation +const checkProps = (key: string, value: unknown): string | void => { + if (value === undefined) { + return `${key} should not be empty.` + } + + if (typeof value !== 'number') { + let receivedType: string = typeof value + receivedType = receivedType[0].toUpperCase() + receivedType.substring(1) + return `Expected Number, got ${receivedType} with value ${JSON.stringify( + value + )}.` + } +} + export const OpenLocationOptions: ApiOptions = { formatArgs: { latitude(value, params) { - if (value !== 0 && !value) { - return 'latitude should not be empty.' + const checkedInfo = checkProps('latitude', value) + if (checkedInfo) { + return checkedInfo } + params.latitude = value }, longitude(value, params) { - if (value !== 0 && !value) { - return 'longitude should not be empty.' + const checkedInfo = checkProps('longitude', value) + if (checkedInfo) { + return checkedInfo } + params.longitude = value }, scale(value, params) { -- GitLab