From 879190c956702ea9aad18bd3456415cbf06b7e04 Mon Sep 17 00:00:00 2001 From: WindowBird <13870814+windows-bird@user.noreply.gitee.com> Date: Tue, 19 Aug 2025 09:51:32 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E4=BD=8D=E7=BD=AE=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=E5=B0=81=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/map-location/README.md | 182 ++++++++++ components/map-location/map-location.vue | 431 +++++++++++++++++++++++ pages/lease/lease.vue | 417 ++-------------------- 3 files changed, 639 insertions(+), 391 deletions(-) create mode 100644 components/map-location/README.md create mode 100644 components/map-location/map-location.vue diff --git a/components/map-location/README.md b/components/map-location/README.md new file mode 100644 index 0000000..0b8099d --- /dev/null +++ b/components/map-location/README.md @@ -0,0 +1,182 @@ +# MapLocation 地图定位组件 + +一个可复用的地图定位组件,集成了地址输入、位置获取、地图打开等功能。 + +## 功能特性 + +- 📍 自动获取当前位置 +- 🗺️ 一键打开系统地图 +- 📝 支持手动输入地址 +- 📱 跨平台支持(APP、微信小程序、H5) +- 🎨 美观的UI设计 +- 🔧 高度可配置 + +## 使用方法 + +### 基础用法 + +```vue + + + +``` + +### 完整用法 + +```vue + + + +``` + +## Props 属性 + +| 属性名 | 类型 | 默认值 | 说明 | +|--------|------|--------|------| +| label | String | '地址' | 表单标签 | +| placeholder | String | '请输入或选择收货地址' | 输入框占位符 | +| value | String | '' | 地址值(支持v-model) | +| showLocationCard | Boolean | true | 是否显示位置建议卡片 | + +## Events 事件 + +| 事件名 | 参数 | 说明 | +|--------|------|------| +| input | String | 地址值变化时触发 | +| location-success | Object | 位置获取成功时触发 | +| location-error | Error | 位置获取失败时触发 | +| use-location | Object | 点击使用位置时触发 | +| map-opened | - | 地图打开成功时触发 | +| address-focus | - | 地址输入框获得焦点时触发 | +| address-input | String | 地址输入时触发 | + +## 位置对象结构 + +```javascript +{ + address: "纬度: 39.123456, 经度: 116.123456", + latitude: 39.123456, + longitude: 116.123456 +} +``` + +## 方法 + +组件提供了以下方法供外部调用: + +### setLocation(location) +手动设置位置信息 + +```javascript +// 在父组件中调用 +this.$refs.mapLocation.setLocation({ + address: '北京市朝阳区', + latitude: 39.123456, + longitude: 116.123456 +}) +``` + +### clearLocation() +清空位置信息 + +```javascript +// 在父组件中调用 +this.$refs.mapLocation.clearLocation() +``` + +## 平台支持 + +- ✅ APP-PLUS:使用系统地图应用 +- ✅ MP-WEIXIN:使用微信小程序地图 +- ✅ H5:使用高德地图在线版 + +## 依赖 + +- `@/utils/permission.js`:权限处理工具 +- uni-app 定位API +- uni-app 地图API + +## 注意事项 + +1. 首次使用需要用户授权定位权限 +2. 不同平台的权限处理可能略有差异 +3. H5环境下需要网络连接才能使用地图功能 +4. 建议在真机上测试定位功能 \ No newline at end of file diff --git a/components/map-location/map-location.vue b/components/map-location/map-location.vue new file mode 100644 index 0000000..f16282f --- /dev/null +++ b/components/map-location/map-location.vue @@ -0,0 +1,431 @@ + + + + + \ No newline at end of file diff --git a/pages/lease/lease.vue b/pages/lease/lease.vue index 1dbe23e..b7e150d 100644 --- a/pages/lease/lease.vue +++ b/pages/lease/lease.vue @@ -38,47 +38,15 @@ - - 地址 - - - - 🗺️ - - - - - - - - - - 当前定位 - - {{ currentLocation.address }} - - - - - - - 获取位置 - 点击获取当前位置 - - 需要定位权限 - - - - + @@ -134,10 +102,13 @@