diff --git a/components.d.ts b/components.d.ts index ef24a60..19a5e08 100644 --- a/components.d.ts +++ b/components.d.ts @@ -22,6 +22,7 @@ declare module '@vue/runtime-core' { Tensorflow: typeof import('./src/components/arFrame/tensorflow.vue')['default'] VanActionSheet: typeof import('vant/es')['ActionSheet'] VanAddressEdit: typeof import('vant/es')['AddressEdit'] + VanButton: typeof import('vant/es')['Button'] VanDivider: typeof import('vant/es')['Divider'] VanField: typeof import('vant/es')['Field'] VanIcon: typeof import('vant/es')['Icon'] diff --git a/src/views/badge/preview.vue b/src/views/badge/preview.vue index 36bff6b..3c6fa7d 100644 --- a/src/views/badge/preview.vue +++ b/src/views/badge/preview.vue @@ -113,11 +113,35 @@ --> +
+
地址识别
+
+ + + +
+
+
识别结果
+
+ {{ contact_name }} {{ contact_mobile }} {{ province_name }} {{ city_name }} {{ county_name }} {{ address }} +
+
+
收货地址
{ 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 loading = ref(false) const confirm = () => { @@ -401,6 +507,8 @@ const confirm = () => { parms.addr_id = 0 parms.country_id = 45 } + console.log('parms', parms) + return false; badgeApi.creatOrder(parms).then((res: any) => { console.log('creatOrder', res) showSuccessToast({