更新记录
1.0.0(2026-11-27)
- 提供
parseAddress、parseAddressCandidates,离线拆分收货地址 - 支持 Web、微信小程序、Android、iOS、鸿蒙
- App 端街道需原文包含「街道」「镇」或「乡」
- 标准基座即可运行
平台兼容性
uni-app(4.61)
| Vue2 | Vue3 | Chrome | Safari | app-vue | app-nvue | Android | iOS | 鸿蒙 |
|---|---|---|---|---|---|---|---|---|
| - | √ | √ | √ | - | - | √ | √ | √ |
| 微信小程序 | 支付宝小程序 | 抖音小程序 | 百度小程序 | 快手小程序 | 京东小程序 | 鸿蒙元服务 | QQ小程序 | 飞书小程序 | 小红书小程序 | 快应用-华为 | 快应用-联盟 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| √ | - | - | - | - | - | - | - | - | - | - | - |
uni-app x(4.61)
| Chrome | Safari | Android | iOS | 鸿蒙 | 微信小程序 | 支付宝小程序 |
|---|---|---|---|---|---|---|
| √ | √ | √ | √ | √ | √ | - |
其他
| 多语言 | 暗黑模式 | 宽屏模式 | 蒸汽模式 |
|---|---|---|---|
| × | × | √ | × |
ba-address-parse
离线解析收货地址。把一段文字拆成省、市、区县、街道、详细地址、姓名、手机号、邮编。不联网,不上传内容。
不用自定义基座。iOS 本地运行需要安装 Xcode。
Web 和微信小程序可以识别街道。Android、iOS、鸿蒙只有原文里写了「街道」「镇」或「乡」时,街道才有内容。
接入
把 uni_modules/ba-address-parse 放到项目的 uni_modules 下。
import { parseAddress, parseAddressCandidates } from '@/uni_modules/ba-address-parse'
const r = parseAddress('郑州市管城回族区航海东路与明理路交叉口往南100米紫荆花园,刘一刀,电话***')
// province 省,city 市,county 区县,street 街道
// address 详细地址,name 姓名,phone 电话,zipCode 邮编
const list = parseAddressCandidates('广东省深圳市南山区科技园腾讯大厦18楼 张三 ***')
const first = list[0]
console.log(first.name, first.phone, first.province.name, first.confidence)
parseAddress 返回第一条结果。parseAddressCandidates 返回候选列表。Web 和微信小程序可能有多条;Android、iOS、鸿蒙目前返回一条。
parseAddressCandidates 的第二个参数可以不传。
| 字段 | 类型 | 必填 | 默认 | 说明 |
|---|---|---|---|---|
minScore |
number |
否 | Web、微信小程序 0.18;App 0 |
最低置信度,范围 0 到 1。低于该值不返回 |
limit |
number |
否 | 20 |
最多返回几条,范围 1 到 100。仅 Web、微信小程序 |
idCard |
boolean |
否 | true |
是否提取身份证号。仅 Web、微信小程序 |
withRaw |
boolean |
否 | false |
为 true 时,每条候选带上原文 raw |
withClean |
boolean |
否 | false |
为 true 时,每条候选带上收拢空白后的原文 clean |
返回
parseAddress:
| 字段 | 说明 |
|---|---|
province city county street |
行政区名称,没有则为空字符串 |
address |
详细地址 |
name phone zipCode |
姓名、手机号或固话、邮编 |
parseAddressCandidates 的每条候选还包括 confidence、warnings、scoreReasons,以及带 code、name 的 province、city、county、street。传入 withRaw 或 withClean 时,还会带上 raw、clean。
错别字、口语化地址建议再用地图接口核对。
示例
<template>
<view>
<input v-model="raw" placeholder="粘贴收货信息" />
<button @click="onParse">智能识别</button>
<text>{{ name }} {{ phone }}</text>
<text>{{ province }}{{ city }}{{ county }}{{ street }}</text>
<text>{{ address }}</text>
</view>
</template>
<script>
import { parseAddress } from '@/uni_modules/ba-address-parse'
export default {
data() {
return {
raw: '',
province: '',
city: '',
county: '',
street: '',
address: '',
name: '',
phone: ''
}
},
methods: {
onParse() {
const r = parseAddress(this.raw)
this.province = r.province
this.city = r.city
this.county = r.county
this.street = r.street
this.address = r.address
this.name = r.name
this.phone = r.phone
}
}
}
</script>
uni-app x 在 script setup 里按同样的路径导入。

收藏人数:
购买源码授权版(
试用
使用 HBuilderX 导入示例项目
赞赏(0)
下载 14516
赞赏 6
下载 12789483
赞赏 1960
赞赏
京公网安备:11010802035340号