From 612e279193a19c0c301958754b45fe38125e9ebe Mon Sep 17 00:00:00 2001
From: VK <370725567@qq.com>
Date: Tue, 10 Dec 2024 14:44:33 +0800
Subject: [PATCH] =?UTF-8?q?App=E7=AB=AF=E6=96=B0=E5=A2=9Euni.openLocation?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Info.plist | 3 +
pages.json | 14 +-
pages/API/open-location/open-location.uvue | 26 +-
uni_modules/uni-openLocation/changelog.md | 6 +
uni_modules/uni-openLocation/package.json | 98 ++++
.../pages/openLocation/openLocation.uvue | 527 ++++++++++++++++++
uni_modules/uni-openLocation/readme.md | 11 +
.../uni-openLocation/static/target.png | Bin 0 -> 1201 bytes
.../utssdk/app-android/index.uts | 36 ++
.../utssdk/app-ios/Info.plist | 14 +
.../uni-openLocation/utssdk/app-ios/index.uts | 36 ++
.../uni-openLocation/utssdk/interface.uts | 418 ++++++++++++++
.../uni-openLocation/utssdk/unierror.uts | 30 +
.../uni-openLocation/utssdk/web/index.uts | 36 ++
14 files changed, 1241 insertions(+), 14 deletions(-)
create mode 100644 uni_modules/uni-openLocation/changelog.md
create mode 100644 uni_modules/uni-openLocation/package.json
create mode 100644 uni_modules/uni-openLocation/pages/openLocation/openLocation.uvue
create mode 100644 uni_modules/uni-openLocation/readme.md
create mode 100644 uni_modules/uni-openLocation/static/target.png
create mode 100644 uni_modules/uni-openLocation/utssdk/app-android/index.uts
create mode 100644 uni_modules/uni-openLocation/utssdk/app-ios/Info.plist
create mode 100644 uni_modules/uni-openLocation/utssdk/app-ios/index.uts
create mode 100644 uni_modules/uni-openLocation/utssdk/interface.uts
create mode 100644 uni_modules/uni-openLocation/utssdk/unierror.uts
create mode 100644 uni_modules/uni-openLocation/utssdk/web/index.uts
diff --git a/Info.plist b/Info.plist
index 5ae92142..a6513623 100644
--- a/Info.plist
+++ b/Info.plist
@@ -31,6 +31,9 @@
alipay
safepay
weixin
+ qqmap
+ iosamap
+ baidumap
diff --git a/pages.json b/pages.json
index ed18fa53..978dfec3 100644
--- a/pages.json
+++ b/pages.json
@@ -893,7 +893,7 @@
}
},
// #endif
- // #ifdef WEB || MP-WEIXIN
+ // #ifdef APP-ANDROID || APP-IOS || WEB || MP-WEIXIN
{
"path": "pages/API/open-location/open-location",
"group": "1,9,1",
@@ -902,6 +902,16 @@
}
},
// #endif
+ // #ifdef APP-ANDROID || APP-IOS || WEB
+ {
+ "path": "uni_modules/uni-openLocation/pages/openLocation/openLocation",
+ "style": {
+ "navigationBarTitleText": " ",
+ "navigationStyle": "custom",
+ "disableSwipeBack": false
+ }
+ },
+ // #endif
// #ifdef APP-ANDROID || APP-IOS || WEB || MP-WEIXIN
{
"path": "pages/API/choose-location/choose-location",
@@ -2397,7 +2407,7 @@
}
}
// #endif
- ],
+],
"globalStyle": {
"pageOrientation": "portrait",
"navigationBarTitleText": "Hello uniapp x",
diff --git a/pages/API/open-location/open-location.uvue b/pages/API/open-location/open-location.uvue
index 1fb7386f..bd9d1dc7 100644
--- a/pages/API/open-location/open-location.uvue
+++ b/pages/API/open-location/open-location.uvue
@@ -9,7 +9,7 @@
经度
-
+
@@ -17,7 +17,7 @@
纬度
-
+
@@ -25,7 +25,7 @@
位置名称
-
+
@@ -33,7 +33,7 @@
详细位置
-
+
@@ -51,21 +51,23 @@
export default {
data() {
return {
- title: 'openLocation'
+ title: 'openLocation',
+ longitude: 116.39747,
+ latitude: 39.9085,
+ name: '天安门',
+ address: '北京市东城区东长安街'
}
},
onHide() {
console.log("Page Hide");
},
methods: {
- openLocation: function (e) {
- console.log(e)
- var value = e.detail.value
+ openLocation: function () {
uni.openLocation({
- longitude: Number(value.longitude),
- latitude: Number(value.latitude),
- name: value.name,
- address: value.address
+ longitude: this.longitude,
+ latitude: this.latitude,
+ name: this.name,
+ address: this.address
})
}
}
diff --git a/uni_modules/uni-openLocation/changelog.md b/uni_modules/uni-openLocation/changelog.md
new file mode 100644
index 00000000..e296ac6e
--- /dev/null
+++ b/uni_modules/uni-openLocation/changelog.md
@@ -0,0 +1,6 @@
+## 1.0.2(2024-12-10)
+ios端支持侧滑关闭
+## 1.0.1(2024-12-10)
+插件新增文件pages_init.json,方便注册页面
+## 1.0.0(2024-12-09)
+发布API uni.openLocation 需 HBuilderX 4.41+
diff --git a/uni_modules/uni-openLocation/package.json b/uni_modules/uni-openLocation/package.json
new file mode 100644
index 00000000..4f0a0d4c
--- /dev/null
+++ b/uni_modules/uni-openLocation/package.json
@@ -0,0 +1,98 @@
+{
+ "id": "uni-openLocation",
+ "displayName": "uni-openLocation",
+ "version": "1.0.2",
+ "description": "实现APP端的 uni.openLocation",
+ "keywords": [
+ "uni-openLocation"
+],
+ "repository": "",
+ "engines": {
+ "HBuilderX": "^3.6.8"
+ },
+ "dcloudext": {
+ "type": "uts",
+ "sale": {
+ "regular": {
+ "price": "0.00"
+ },
+ "sourcecode": {
+ "price": "0.00"
+ }
+ },
+ "contact": {
+ "qq": ""
+ },
+ "declaration": {
+ "ads": "无",
+ "data": "插件不采集任何数据",
+ "permissions": "无"
+ },
+ "npmurl": ""
+ },
+ "uni_modules": {
+ "dependencies": [
+ "uts-openSchema"
+ ],
+ "uni-ext-api": {
+ "uni": {
+ "openLocation": {
+ "name": "openLocation",
+ "app": {
+ "js": false,
+ "kotlin": true,
+ "swift": true,
+ "arkts": false
+ }
+ }
+ }
+ },
+ "encrypt": [],
+ "platforms": {
+ "cloud": {
+ "tcb": "y",
+ "aliyun": "y",
+ "alipay": "y"
+ },
+ "client": {
+ "Vue": {
+ "vue2": "u",
+ "vue3": "y"
+ },
+ "App": {
+ "app-android": "y",
+ "app-ios": "y",
+ "app-harmony": "u"
+ },
+ "H5-mobile": {
+ "Safari": "y",
+ "Android Browser": "y",
+ "微信浏览器(Android)": "y",
+ "QQ浏览器(Android)": "y"
+ },
+ "H5-pc": {
+ "Chrome": "y",
+ "IE": "u",
+ "Edge": "y",
+ "Firefox": "y",
+ "Safari": "y"
+ },
+ "小程序": {
+ "微信": "u",
+ "阿里": "u",
+ "百度": "u",
+ "字节跳动": "u",
+ "QQ": "u",
+ "钉钉": "u",
+ "快手": "u",
+ "飞书": "u",
+ "京东": "u"
+ },
+ "快应用": {
+ "华为": "u",
+ "联盟": "u"
+ }
+ }
+ }
+ }
+}
diff --git a/uni_modules/uni-openLocation/pages/openLocation/openLocation.uvue b/uni_modules/uni-openLocation/pages/openLocation/openLocation.uvue
new file mode 100644
index 00000000..48f9bee2
--- /dev/null
+++ b/uni_modules/uni-openLocation/pages/openLocation/openLocation.uvue
@@ -0,0 +1,527 @@
+
+
+
+
+
+ {{ icon.position }}
+
+
+
+ {{ icon.back }}
+
+
+
+
+
+
+
+
diff --git a/uni_modules/uni-openLocation/readme.md b/uni_modules/uni-openLocation/readme.md
new file mode 100644
index 00000000..9382356a
--- /dev/null
+++ b/uni_modules/uni-openLocation/readme.md
@@ -0,0 +1,11 @@
+# uni-openLocation
+
+> 需 HBuilderX 4.41+
+
+[使用文档](https://doc.dcloud.net.cn/uni-app-x/api/open-location.html)
+
+### 开发文档
+[UTS 语法](https://uniapp.dcloud.net.cn/tutorial/syntax-uts.html)
+[UTS API插件](https://uniapp.dcloud.net.cn/plugin/uts-plugin.html)
+[UTS 组件插件](https://uniapp.dcloud.net.cn/plugin/uts-component.html)
+[Hello UTS](https://gitcode.net/dcloud/hello-uts)
\ No newline at end of file
diff --git a/uni_modules/uni-openLocation/static/target.png b/uni_modules/uni-openLocation/static/target.png
new file mode 100644
index 0000000000000000000000000000000000000000..8c138822dadc02bf6bde61ca020e30c39fda35b7
GIT binary patch
literal 1201
zcmV;i1Wx;jP)Px(Ye_^wRCr$Pn@dj=K@i8ghj+lhUc|(M%MD2&V#MeHSfVBi9{_?}c0Yk0xdAtB
z#!s-z0g*4jVvJ#dgC-asL<2YWVuXu8kjQgdYiF0&&P=~*1`>M`LN-$~)Aj4>e^vMN
zP!i&?8IMJYWhX2`Z!u;^ok!CsAuLC!m4jclO(!C=*=$(NqCr2X=rm
z7=Zx*$0F@O2#5H3!_{^Ndr^>SiSD!Lyj@4
zCo-GO>jlPv2EcLNo+E@5#0{f)uJ=HNfCgZzw{uQ+yh|XPOypudB
zP1n!NCv_oc15g#b$|t=iZMQdm5_@Ak|0i=`2%|QDt==vs+GudP>S=;ljW=8`Ia>Zq
z4&S{Y@Lv#ywjO8!*zW62F~$-+0Of6W@{X6cwew8#=K;W<7vn+@bccd6fP(6;@jL?O
zYsX*m%v{d{goC#k-n9?~N!9XM13+hjQkwE>osRRx`|czMxRIcv1b_4+H<_~
zy0v&7v|xAm83zK(He?oiMDKalP6L3y_*D-jN!1Wn9)#MwKbaGTo)(-*o^bT
zzkX(3$T<-s5XIf$=f0+e5?Oj09S8tOa}fTR2TuzaW68+uVp{f@Y5+L1JgHe
zszRs)fS3P+0Kn4$)p|e)0I&SL3;>}$z#IGUaMdbM3xG%zfQ=3WUh(6QSDy%J0}z=L
z6d_bRj!O*(k)C&YU#$c#hOP1tfE&oX2Y}RA@hF~O74p*sSOD37mFBJiVD!Fr1e`+f
zPl*>r0$`N4wi9~2@#NI;x34m5fllx%roOZ7(TafLjYNlnsPc>0=?EV>fP5qb@IKHB
zgzmTx1VC62Fr7!yfQ!9U7!I%(0Q()G*6OcUG@)ofDFkOH2;M7ly~6RU^Jj~Z;=r}
zBZ4>^A7wSlWC2-X81^O$m@HtjK*<(clLk#1G-(j!0|?nHW$FM~Vi@-SbsaGEpgDTC
zw*Gx%W!1UQMm7%i*FWuUKOFq9iuOsINN0sU1YUQvq+09h5;v=>&$aKz-X8h>dnen!
zw4$`_UBuZd@m^rMV*Wn@j&J8TBpnMJ|3MBLhn7-dK`fp#0>xa~o
zuw?(zs`QR;QD?721VAIE?ls5CC>>#iH^_|8EMxY>;Kx {
+ uni.$emit(optionsEventName, JSON.parse(JSON.stringify(options)))
+ })
+ const successEventId = uni.$on(successEventName, () => {
+ const res = new OpenLocationSuccessImpl()
+ options.success?.(res)
+ options.complete?.(res)
+ })
+ const failEventId = uni.$on(failEventName, (errCode : OpenLocationErrorCode) => {
+ const res = new OpenLocationFailImpl(errCode)
+ options.fail?.(res)
+ options.complete?.(res)
+ })
+ uni.openDialogPage({
+ url: `/uni_modules/uni-openLocation/pages/openLocation/openLocation?readyEventName=${readyEventName}&optionsEventName=${optionsEventName}&successEventName=${successEventName}&failEventName=${failEventName}`,
+ fail(err) {
+ const res = new OpenLocationFailImpl(4)
+ options.fail?.(res)
+ options.complete?.(res)
+ uni.$off(readyEventName, readyEventId)
+ uni.$off(successEventName, successEventId)
+ uni.$off(failEventName, failEventId)
+ }
+ })
+};
diff --git a/uni_modules/uni-openLocation/utssdk/app-ios/Info.plist b/uni_modules/uni-openLocation/utssdk/app-ios/Info.plist
new file mode 100644
index 00000000..0ac85128
--- /dev/null
+++ b/uni_modules/uni-openLocation/utssdk/app-ios/Info.plist
@@ -0,0 +1,14 @@
+
+
+
+
+
+ LSApplicationQueriesSchemes
+
+ qqmap
+ iosamap
+ baidumap
+
+
+
+
diff --git a/uni_modules/uni-openLocation/utssdk/app-ios/index.uts b/uni_modules/uni-openLocation/utssdk/app-ios/index.uts
new file mode 100644
index 00000000..781339cb
--- /dev/null
+++ b/uni_modules/uni-openLocation/utssdk/app-ios/index.uts
@@ -0,0 +1,36 @@
+import { OpenLocation, OpenLocationOptions, OpenLocationSuccessImpl } from "../interface.uts"
+import { OpenLocationFailImpl } from "../unierror.uts"
+
+export const openLocation : OpenLocation = function (options : OpenLocationOptions) {
+ const uuid = `${Date.now()}${Math.floor(Math.random() * 1e7)}`
+ const baseEventName = `uni_open_location_${uuid}`
+ const readyEventName = `${baseEventName}_ready`
+ const optionsEventName = `${baseEventName}_options`
+ const successEventName = `${baseEventName}_success`
+ const failEventName = `${baseEventName}_fail`
+
+ uni.$on(readyEventName, (..._ : any) => {
+ uni.$emit(optionsEventName, JSON.parse(JSON.stringify(options)!))
+ })
+ uni.$on(successEventName, (..._ : any) => {
+ const res = new OpenLocationSuccessImpl()
+ options.success?.(res)
+ options.complete?.(res)
+ })
+ uni.$on(failEventName, (..._ : any) => {
+ const res = new OpenLocationFailImpl(4)
+ options.fail?.(res)
+ options.complete?.(res)
+ })
+ uni.openDialogPage({
+ url: `/uni_modules/uni-openLocation/pages/openLocation/openLocation?readyEventName=${readyEventName}&optionsEventName=${optionsEventName}&successEventName=${successEventName}&failEventName=${failEventName}`,
+ fail(err) {
+ const res = new OpenLocationFailImpl(4)
+ options.fail?.(res)
+ options.complete?.(res)
+ uni.$off(readyEventName)
+ uni.$off(successEventName)
+ uni.$off(failEventName)
+ }
+ })
+};
diff --git a/uni_modules/uni-openLocation/utssdk/interface.uts b/uni_modules/uni-openLocation/utssdk/interface.uts
new file mode 100644
index 00000000..ec285dfb
--- /dev/null
+++ b/uni_modules/uni-openLocation/utssdk/interface.uts
@@ -0,0 +1,418 @@
+/**
+ * 错误码
+ */
+export type OpenLocationErrorCode =
+/**
+ * 框架内部错误
+ * @uniPlatform {
+ * "app": {
+ * "android": {
+ * "osVer": "5.0",
+ * "uniVer": "√",
+ * "unixVer": "4.41"
+ * },
+ * "ios": {
+ * "osVer": "12.0",
+ * "uniVer": "√",
+ * "unixVer": "4.41"
+ * },
+ * "harmony": {
+ * "osVer": "3.0",
+ * "uniVer": "4.23",
+ * "unixVer": "x"
+ * }
+ * },
+ * "web": {
+ * "uniVer": "√",
+ * "unixVer": "4.0"
+ * },
+ * "mp": {
+ * "weixin": {
+ * "uniVer": "x",
+ * "unixVer": "x"
+ * }
+ * }
+ * }
+ */
+4;
+
+export interface OpenLocationSuccess {
+ errMsg: string
+}
+
+type OpenLocationSuccessCallback = (result : OpenLocationSuccess) => void
+
+export interface OpenLocationFail extends IUniError {
+ errCode : OpenLocationErrorCode
+}
+type OpenLocationFailCallback = (result : OpenLocationFail) => void
+
+export type OpenLocationComplete = any
+type OpenLocationCompleteCallback = (result : OpenLocationComplete) => void
+
+/**
+ * uni.openLocation函数参数定义
+ */
+export type OpenLocationOptions = {
+ /**
+ * 纬度,范围为-90~90,负数表示南纬,使用 gcj02 国测局坐标系
+ * @uniPlatform {
+ * "app": {
+ * "android": {
+ * "osVer": "5.0",
+ * "uniVer": "√",
+ * "unixVer": "4.41"
+ * },
+ * "ios": {
+ * "osVer": "12.0",
+ * "uniVer": "√",
+ * "unixVer": "4.41"
+ * },
+ * "harmony": {
+ * "osVer": "3.0",
+ * "uniVer": "4.23",
+ * "unixVer": "x"
+ * }
+ * },
+ * "web": {
+ * "uniVer": "√",
+ * "unixVer": "4.0"
+ * },
+ * "mp": {
+ * "weixin": {
+ * "uniVer": "√",
+ * "unixVer": "4.41"
+ * }
+ * }
+ * }
+ */
+ latitude : number,
+ /**
+ * 经度,范围为-180~180,负数表示西经,使用 gcj02 国测局坐标系
+ * @uniPlatform {
+ * "app": {
+ * "android": {
+ * "osVer": "5.0",
+ * "uniVer": "√",
+ * "unixVer": "4.41"
+ * },
+ * "ios": {
+ * "osVer": "12.0",
+ * "uniVer": "√",
+ * "unixVer": "4.41"
+ * },
+ * "harmony": {
+ * "osVer": "3.0",
+ * "uniVer": "4.23",
+ * "unixVer": "x"
+ * }
+ * },
+ * "web": {
+ * "uniVer": "√",
+ * "unixVer": "4.0"
+ * },
+ * "mp": {
+ * "weixin": {
+ * "uniVer": "√",
+ * "unixVer": "4.41"
+ * }
+ * }
+ * }
+ */
+ longitude : number,
+ /**
+ * 缩放比例,范围5~18,默认为18(微信小程序)
+ * @uniPlatform {
+ * "app": {
+ * "android": {
+ * "osVer": "5.0",
+ * "uniVer": "√",
+ * "unixVer": "4.41"
+ * },
+ * "ios": {
+ * "osVer": "12.0",
+ * "uniVer": "√",
+ * "unixVer": "4.41"
+ * },
+ * "harmony": {
+ * "osVer": "3.0",
+ * "uniVer": "4.23",
+ * "unixVer": "x"
+ * }
+ * },
+ * "web": {
+ * "uniVer": "√",
+ * "unixVer": "4.0"
+ * },
+ * "mp": {
+ * "weixin": {
+ * "uniVer": "√",
+ * "unixVer": "4.41"
+ * }
+ * }
+ * }
+ */
+ scale ?: number | null,
+ /**
+ * 位置名
+ * @uniPlatform {
+ * "app": {
+ * "android": {
+ * "osVer": "5.0",
+ * "uniVer": "√",
+ * "unixVer": "4.41"
+ * },
+ * "ios": {
+ * "osVer": "12.0",
+ * "uniVer": "√",
+ * "unixVer": "4.41"
+ * },
+ * "harmony": {
+ * "osVer": "3.0",
+ * "uniVer": "4.23",
+ * "unixVer": "x"
+ * }
+ * },
+ * "web": {
+ * "uniVer": "√",
+ * "unixVer": "4.0"
+ * },
+ * "mp": {
+ * "weixin": {
+ * "uniVer": "√",
+ * "unixVer": "4.41"
+ * }
+ * }
+ * }
+ */
+ name ?: string | null,
+ /**
+ * 地址的详细说明
+ * @uniPlatform {
+ * "app": {
+ * "android": {
+ * "osVer": "5.0",
+ * "uniVer": "√",
+ * "unixVer": "4.41"
+ * },
+ * "ios": {
+ * "osVer": "12.0",
+ * "uniVer": "√",
+ * "unixVer": "4.41"
+ * },
+ * "harmony": {
+ * "osVer": "3.0",
+ * "uniVer": "4.23",
+ * "unixVer": "x"
+ * }
+ * },
+ * "web": {
+ * "uniVer": "√",
+ * "unixVer": "4.0"
+ * },
+ * "mp": {
+ * "weixin": {
+ * "uniVer": "√",
+ * "unixVer": "4.41"
+ * }
+ * }
+ * }
+ */
+ address ?: string | null,
+ /**
+ * 接口调用成功的回调函数
+ * @uniPlatform {
+ * "app": {
+ * "android": {
+ * "osVer": "5.0",
+ * "uniVer": "√",
+ * "unixVer": "4.41"
+ * },
+ * "ios": {
+ * "osVer": "12.0",
+ * "uniVer": "√",
+ * "unixVer": "4.41"
+ * },
+ * "harmony": {
+ * "osVer": "3.0",
+ * "uniVer": "4.23",
+ * "unixVer": "x"
+ * }
+ * },
+ * "web": {
+ * "uniVer": "√",
+ * "unixVer": "4.0"
+ * },
+ * "mp": {
+ * "weixin": {
+ * "uniVer": "√",
+ * "unixVer": "4.41"
+ * }
+ * }
+ * }
+ */
+ success ?: OpenLocationSuccessCallback | null,
+ /**
+ * 接口调用失败的回调函数
+ * @uniPlatform {
+ * "app": {
+ * "android": {
+ * "osVer": "5.0",
+ * "uniVer": "√",
+ * "unixVer": "4.41"
+ * },
+ * "ios": {
+ * "osVer": "12.0",
+ * "uniVer": "√",
+ * "unixVer": "4.41"
+ * },
+ * "harmony": {
+ * "osVer": "3.0",
+ * "uniVer": "4.23",
+ * "unixVer": "x"
+ * }
+ * },
+ * "web": {
+ * "uniVer": "√",
+ * "unixVer": "4.0"
+ * },
+ * "mp": {
+ * "weixin": {
+ * "uniVer": "√",
+ * "unixVer": "4.41"
+ * }
+ * }
+ * }
+ */
+ fail ?: OpenLocationFailCallback | null,
+ /**
+ * 接口调用结束的回调函数(调用成功、失败都会执行)
+ * @uniPlatform {
+ * "app": {
+ * "android": {
+ * "osVer": "5.0",
+ * "uniVer": "√",
+ * "unixVer": "4.41"
+ * },
+ * "ios": {
+ * "osVer": "12.0",
+ * "uniVer": "√",
+ * "unixVer": "4.41"
+ * },
+ * "harmony": {
+ * "osVer": "3.0",
+ * "uniVer": "4.23",
+ * "unixVer": "x"
+ * }
+ * },
+ * "web": {
+ * "uniVer": "√",
+ * "unixVer": "4.0"
+ * },
+ * "mp": {
+ * "weixin": {
+ * "uniVer": "√",
+ * "unixVer": "4.41"
+ * }
+ * }
+ * }
+ */
+ complete ?: OpenLocationCompleteCallback | null
+};
+
+/**
+ * 使用应用内置地图查看位置
+ *
+ * @param {OpenLocationOptions} options
+ * @tutorial https://doc.dcloud.net.cn/uni-app-x/api/prompt.html#openLocation
+ * @uniPlatform {
+ * "app": {
+ * "android": {
+ * "osVer": "5.0",
+ * "uniVer": "√",
+ * "unixVer": "4.41"
+ * },
+ * "ios": {
+ * "osVer": "12.0",
+ * "uniVer": "√",
+ * "unixVer": "4.41"
+ * },
+ * "harmony": {
+ * "osVer": "3.0",
+ * "uniVer": "4.23",
+ * "unixVer": "x"
+ * }
+ * },
+ * "web": {
+ * "uniVer": "√",
+ * "unixVer": "4.0"
+ * },
+ * "mp": {
+ * "weixin": {
+ * "uniVer": "√",
+ * "unixVer": "4.41"
+ * }
+ * }
+ * }
+ */
+export type OpenLocation = (options : OpenLocationOptions) => void;
+
+export interface Uni {
+ /**
+ * @description 使用应用内置地图查看位置
+ * @example
+ * ```typescript
+ uni.openLocation({
+ latitude: 39.908823,
+ longitude: 116.39747,
+ success: (res) => {
+ console.log('res: ', res)
+ },
+ fail: (err) => {
+ console.log('err: ', err)
+ },
+ complete: (res) => {
+ console.log('complete: ', res)
+ }
+ });
+ * ```
+ * @tutorial https://doc.dcloud.net.cn/uni-app-x/api/prompt.html#openLocation
+ * @uniPlatform {
+ * "app": {
+ * "android": {
+ * "osVer": "5.0",
+ * "uniVer": "√",
+ * "unixVer": "4.41"
+ * },
+ * "ios": {
+ * "osVer": "12.0",
+ * "uniVer": "√",
+ * "unixVer": "4.41"
+ * },
+ * "harmony": {
+ * "osVer": "3.0",
+ * "uniVer": "4.23",
+ * "unixVer": "x"
+ * }
+ * },
+ * "web": {
+ * "uniVer": "√",
+ * "unixVer": "4.0"
+ * },
+ * "mp": {
+ * "weixin": {
+ * "uniVer": "√",
+ * "unixVer": "4.41"
+ * }
+ * }
+ * }
+ */
+ openLocation(options : OpenLocationOptions) : void;
+}
+
+export class OpenLocationSuccessImpl implements OpenLocationSuccess {
+ errMsg : string
+ constructor(errMsg : string = 'chooseLocation:ok') {
+ this.errMsg = errMsg
+ }
+}
diff --git a/uni_modules/uni-openLocation/utssdk/unierror.uts b/uni_modules/uni-openLocation/utssdk/unierror.uts
new file mode 100644
index 00000000..e1882813
--- /dev/null
+++ b/uni_modules/uni-openLocation/utssdk/unierror.uts
@@ -0,0 +1,30 @@
+import { OpenLocationErrorCode, OpenLocationFail } from "./interface.uts"
+
+/**
+ * 错误主题
+ */
+
+export const UniErrorSubject = 'uni-openLocation';
+
+/**
+ * 错误码
+ * @UniError
+ */
+export const UniErrors : Map = new Map([
+ /**
+ * 框架内部错误
+ */
+ [4, 'internal error']
+]);
+
+export class OpenLocationFailImpl extends UniError implements OpenLocationFail {
+ // #ifndef APP-IOS
+ override errCode : OpenLocationErrorCode;
+ // #endif
+ constructor(errCode : OpenLocationErrorCode) {
+ super();
+ this.errSubject = UniErrorSubject;
+ this.errCode = errCode;
+ this.errMsg = UniErrors.get(errCode) ?? "";
+ }
+}
diff --git a/uni_modules/uni-openLocation/utssdk/web/index.uts b/uni_modules/uni-openLocation/utssdk/web/index.uts
new file mode 100644
index 00000000..7694f651
--- /dev/null
+++ b/uni_modules/uni-openLocation/utssdk/web/index.uts
@@ -0,0 +1,36 @@
+import { OpenLocation, OpenLocationOptions, OpenLocationSuccessImpl, OpenLocationErrorCode } from "../interface.uts"
+import { OpenLocationFailImpl } from "../unierror.uts"
+
+export const openLocation : OpenLocation = function (options : OpenLocationOptions) {
+ const uuid = `${Date.now()}${Math.floor(Math.random() * 1e7)}`
+ const baseEventName = `uni_open_location_${uuid}`
+ const readyEventName = `${baseEventName}_ready`
+ const optionsEventName = `${baseEventName}_options`
+ const successEventName = `${baseEventName}_success`
+ const failEventName = `${baseEventName}_fail`
+
+ const readyEventId = uni.$on(readyEventName, () => {
+ uni.$emit(optionsEventName, JSON.parse(JSON.stringify(options)))
+ })
+ const successEventId = uni.$on(successEventName, () => {
+ const res = new OpenLocationSuccessImpl()
+ options.success?.(res)
+ options.complete?.(res)
+ })
+ const failEventId = uni.$on(failEventName, (errCode : OpenLocationErrorCode) => {
+ const res = new OpenLocationFailImpl(errCode)
+ options.fail?.(res)
+ options.complete?.(res)
+ })
+ uni.openDialogPage({
+ url: `/uni_modules/uni-openLocation/pages/openLocation/openLocation?readyEventName=${readyEventName}&optionsEventName=${optionsEventName}&successEventName=${successEventName}&failEventName=${failEventName}`,
+ fail(err) {
+ const res = new OpenLocationFailImpl(4)
+ options.fail?.(res)
+ options.complete?.(res)
+ uni.$off(readyEventName, readyEventId)
+ uni.$off(successEventName, successEventId)
+ uni.$off(failEventName, failEventId)
+ }
+ })
+};
--
GitLab