继续完善购物逻辑闭环,consumer模块完成度75%

This commit is contained in:
2026-01-26 17:15:51 +08:00
parent be90f1213b
commit f2f208f258
21 changed files with 2516 additions and 217 deletions

View File

@@ -20,6 +20,11 @@
</view>
<view class="form-group">
<view class="form-item">
<text class="label">智能填写</text>
<textarea class="smart-textarea" v-model="smartInput" placeholder="粘贴姓名+电话+地址,自动识别填充" @input="parseSmartInput" maxlength="200"></textarea>
<text class="smart-tip">示例:张三 13800138000 北京市朝阳区三里屯SOHO A座</text>
</view>
<view class="form-item">
<text class="label">标签</text>
<view class="tags-container">
@@ -65,6 +70,7 @@ const isEdit = ref(false)
const addressId = ref('')
const regionString = ref('')
const tags = ['家', '公司', '学校']
const smartInput = ref('')
const formData = reactive({
name: '',
@@ -203,6 +209,41 @@ const saveAddress = () => {
}, 1500)
}
const parseSmartInput = () => {
const input = smartInput.value.trim()
if (!input) return
// 提取手机号
const phoneRegex = /(1[3-9]\d{9})/
const phoneMatch = input.match(phoneRegex)
if (phoneMatch) {
formData.phone = phoneMatch[0]
}
// 提取姓名取第一个2-4位中文
const nameRegex = /([\u4e00-\u9fa5]{2,4})/
const nameMatch = input.match(nameRegex)
if (nameMatch) {
formData.name = nameMatch[0]
}
// 去掉姓名和电话后剩余作为地址
let addrText = input
if (formData.name) addrText = addrText.replace(formData.name, '')
if (formData.phone) addrText = addrText.replace(formData.phone, '')
addrText = addrText.replace(/[,;\s]+/g, ' ').trim()
// 解析省市区
const pattern1 = /^(.*?省)?(.*?市)?(.*?[区县])?(.*)$/
const m = addrText.match(pattern1)
if (m) {
const [, province, city, district, detail] = m
regionString.value = `${(province||'').trim()} ${(city||'').trim()} ${(district||'').trim()}`.trim()
formData.detail = (detail||'').trim()
} else {
formData.detail = addrText
}
}
const deleteAddress = () => {
uni.showModal({
title: '提示',
@@ -316,4 +357,4 @@ const deleteAddress = () => {
line-height: 44px;
border: 1px solid #ddd;
}
</style>
</style>