Browse Source

达人地址识别

lzm_web
Linzm 6 months ago
parent
commit
241cb53eea
  1. 1
      components.d.ts
  2. 108
      src/views/badge/preview.vue

1
components.d.ts vendored

@ -22,6 +22,7 @@ declare module '@vue/runtime-core' {
Tensorflow: typeof import('./src/components/arFrame/tensorflow.vue')['default'] Tensorflow: typeof import('./src/components/arFrame/tensorflow.vue')['default']
VanActionSheet: typeof import('vant/es')['ActionSheet'] VanActionSheet: typeof import('vant/es')['ActionSheet']
VanAddressEdit: typeof import('vant/es')['AddressEdit'] VanAddressEdit: typeof import('vant/es')['AddressEdit']
VanButton: typeof import('vant/es')['Button']
VanDivider: typeof import('vant/es')['Divider'] VanDivider: typeof import('vant/es')['Divider']
VanField: typeof import('vant/es')['Field'] VanField: typeof import('vant/es')['Field']
VanIcon: typeof import('vant/es')['Icon'] VanIcon: typeof import('vant/es')['Icon']

108
src/views/badge/preview.vue

@ -113,11 +113,35 @@
</block> --> </block> -->
</block> </block>
</div> </div>
<div class="address-box" v-if="orderStat.use_type == 2 && imageUrl && code == 'ACAYOAAC3PFCPO3CD6DVM1'">
<div class="order-title" style="padding: 0 16px;">地址识别</div>
<div class="address-item">
<van-field
v-model="addressInput"
label=""
placeholder="请输入姓名、手机号、详细地址(如:张三 13800138000 广东省深圳市南山区科技园1号)"
clearable
right-icon="search"
>
<template #button>
<van-button size="small" type="primary" @click="handleAddressInput" style="margin-left: 8px;">自动识别</van-button>
</template>
</van-field>
</div>
<div class="address-item" style="padding: 0px 16px 16px 16px;" v-if="contact_name && contact_mobile && province_name && city_name && county_name && address">
<div style="font-size: 16px;color: #387aff;text-align: left;margin-bottom: 8px;">识别结果</div>
<div style="font-size: 14px;text-align: left;">
{{ contact_name }} {{ contact_mobile }} {{ province_name }} {{ city_name }} {{ county_name }} {{ address }}
</div>
</div>
</div>
<div class="address-box" v-if="orderStat.use_type == 2 && imageUrl"> <div class="address-box" v-if="orderStat.use_type == 2 && imageUrl">
<div class="order-title" style="padding: 0 16px;">收货地址</div> <div class="order-title" style="padding: 0 16px;">收货地址</div>
<div class="address-item"> <div class="address-item">
<van-address-edit <van-address-edit
:area-list="areaList" :area-list="areaList"
:tel-validator="true"
tel-maxlength="11"
show-delete show-delete
show-search-result show-search-result
:search-result="searchResult" :search-result="searchResult"
@ -184,6 +208,9 @@ const showBgCompare = ref(false)
const currentIndex = ref(0) const currentIndex = ref(0)
const imageList = ref([]) const imageList = ref([])
const imageWater = ref('') const imageWater = ref('')
const code = localStorage.get('code')
function compare() { function compare() {
showCompare.value = true showCompare.value = true
} }
@ -346,6 +373,85 @@ const changeValue = (value: number) => {
payAmount.value = value payAmount.value = value
} }
const addressInput = ref('')
const handleAddressInput = () => {
console.log('handleAddressInput', addressInput.value)
const text = addressInput.value;
if (!text) return;
//
const phoneRegex = /(1[3-9]\d{9})/g;
const phoneMatch = phoneRegex.exec(text);
if (phoneMatch) {
contact_mobile.value = phoneMatch[0];
}
// 2-4
const nameRegex = /([\u4e00-\u9fa5]{2,4})/g;
const nameMatches = text.match(nameRegex);
if (nameMatches && nameMatches.length > 0) {
//
contact_name.value = nameMatches[0];
}
console.log('contact_name', contact_name.value)
console.log('contact_mobile', contact_mobile.value)
//
let provinceFound = '';
for (const [provinceId, provinceName] of Object.entries(areaList.province_list)) {
if (text.includes(provinceName)) {
provinceFound = provinceName;
console.log('识别到省份ID:', provinceId);
province_id.value = provinceId;
break;
}
}
console.log('province_id', province_id.value)
console.log('provinceFound', provinceFound)
province_name.value = provinceFound;
//
let cityFound = '';
for (const [cityId, cityName] of Object.entries(areaList.city_list)) {
if (text.includes(cityName) && cityId !== province_id.value) {
cityFound = cityName;
city_id.value = cityId;
break;
}
}
console.log('cityFound', cityFound)
city_name.value = cityFound;
//
let detail = text
.replace(contact_name.value, '')
.replace(contact_mobile.value, '')
.replace(province_name.value, '')
.replace(city_name.value, '')
.trim();
//
if (detail.includes('区') || detail.includes('县')) {
const districtMatch = detail.match(/(.+?(区|县))/);
if (districtMatch) {
// id
let foundCountyId = '';
for (const [cid, cname] of Object.entries(areaList.county_list)) {
if (districtMatch[0].includes(cname)) {
foundCountyId = cid;
county_id.value = cid;
county_name.value = cname;
break;
}
}
//
if (!foundCountyId) {
county_id.value = 0;
county_name.value = '';
}
detail = detail.replace(county_name.value, '').trim();
}
}
console.log('county_id', county_id.value)
console.log('county_name', county_name.value)
console.log('detail', detail)
address.value = detail;
}
const key = ref(0) const key = ref(0)
const loading = ref(false) const loading = ref(false)
const confirm = () => { const confirm = () => {
@ -401,6 +507,8 @@ const confirm = () => {
parms.addr_id = 0 parms.addr_id = 0
parms.country_id = 45 parms.country_id = 45
} }
console.log('parms', parms)
return false;
badgeApi.creatOrder(parms).then((res: any) => { badgeApi.creatOrder(parms).then((res: any) => {
console.log('creatOrder', res) console.log('creatOrder', res)
showSuccessToast({ showSuccessToast({

Loading…
Cancel
Save