重构:移除身份证自动填充地区功能

This commit is contained in:
2026-01-30 13:48:53 +08:00
parent 027db84a25
commit cdda12afaa
2 changed files with 14 additions and 90 deletions

View File

@@ -27,9 +27,6 @@ export class BasicInfoPage {
this.isSavingDraft = false; this.isSavingDraft = false;
this.autoSaveTimer = null; this.autoSaveTimer = null;
// 身份证自动填充标记
this.lastFilledAreaCode = null;
// 组件实例 // 组件实例
this.cityPicker = null; this.cityPicker = null;
this.agreementModal = null; this.agreementModal = null;
@@ -336,34 +333,15 @@ export class BasicInfoPage {
const input = infoItem.querySelector(`#basic-input-${item.id}`); const input = infoItem.querySelector(`#basic-input-${item.id}`);
const errorEl = infoItem.querySelector(`#error-${item.id}`); const errorEl = infoItem.querySelector(`#error-${item.id}`);
input.addEventListener('input', async () => { input.addEventListener('input', () => {
this.basicInfoValues[item.id] = input.value.trim(); this.basicInfoValues[item.id] = input.value.trim();
this.updateBasicInfoProgress(); this.updateBasicInfoProgress();
this.checkSubmitButton(); this.checkSubmitButton();
// 清除错误提示
input.classList.remove('error');
if (errorEl) { if (errorEl) {
input.classList.remove('error');
errorEl.style.display = 'none'; errorEl.style.display = 'none';
} }
// 身份证输入到6位时自动填充地区
if (item.id === 'idCard' && input.value.trim().length >= 6) {
const areaCode = Validator.extractAreaCode(input.value);
console.log('[BasicInfoPage] 身份证输入,提取地区代码:', areaCode);
if (areaCode && areaCode !== this.lastFilledAreaCode) {
console.log('[BasicInfoPage] 查询地区信息...');
const areaInfo = await AreaService.getAreaByCode(areaCode);
console.log('[BasicInfoPage] 查询结果:', areaInfo);
if (areaInfo) {
this.handleCityConfirm(areaInfo);
this.lastFilledAreaCode = areaCode;
console.log('[BasicInfoPage] 地区自动填充成功');
}
}
}
}); });
} }
}); });
@@ -636,18 +614,12 @@ export class BasicInfoPage {
// 清除草稿 // 清除草稿
DraftManager.clearDraft(); DraftManager.clearDraft();
// 提交成功,显示结果 // 提交成功:有返回数据则进入成功页(含无 H5 时的成功+5秒倒计时/回首页)
const h5Urls = response.data?.h5Urls || response.data?.h5urls; if (response.data) {
if (response.data && h5Urls && h5Urls.length > 0) {
// 如果有返回的 H5 URL显示跳转选项
this.showSubmitSuccessDialog(response.data); this.showSubmitSuccessDialog(response.data);
} else { } else {
// 普通成功提示
showToast('信息提交成功!'); showToast('信息提交成功!');
// 延迟跳转或刷新 setTimeout(() => window.location.reload(), 2000);
setTimeout(() => {
window.location.reload();
}, 2000);
} }
} else { } else {
throw new Error(response.message || '提交失败'); throw new Error(response.message || '提交失败');
@@ -850,29 +822,25 @@ export class BasicInfoPage {
iframeSection.style.display = 'none'; iframeSection.style.display = 'none';
} }
// 创建完成提示 // 有 redirectUrl 跳转直推页,否则 5 秒后回首页(与无 h5Urls 分支一致)
const finalUrl = redirectUrl || window.location.href.split('?')[0];
const btnText = redirectUrl ? '立即跳转' : '返回首页';
const completeSection = document.createElement('div'); const completeSection = document.createElement('div');
completeSection.className = 'auth-complete-section'; completeSection.className = 'auth-complete-section';
completeSection.innerHTML = ` completeSection.innerHTML = `
<div class="auth-complete-icon">✓</div> <div class="auth-complete-icon">✓</div>
<div class="auth-complete-title">全部授权完成</div> <div class="auth-complete-title">全部授权完成</div>
<div class="auth-complete-desc">您的申请已全部提交成功!</div> <div class="auth-complete-desc">您的申请已全部提交成功!</div>
${redirectUrl ? ` <div class="auth-countdown">
<div class="auth-countdown"> <span id="countdownSeconds">5</span> 秒后自动跳转...
<span id="countdownSeconds">5</span> 秒后自动跳转... </div>
</div> <button class="auth-redirect-btn" id="redirectNowBtn">${btnText}</button>
<button class="auth-redirect-btn" id="redirectNowBtn">立即跳转</button>
` : `
<button class="auth-redirect-btn" onclick="window.location.reload()">返回首页</button>
`}
`; `;
container.appendChild(completeSection); container.appendChild(completeSection);
// 启动倒计时 this.startFinalCountdown(finalUrl);
if (redirectUrl) {
this.startFinalCountdown(redirectUrl);
}
} }
/** /**

View File

@@ -116,50 +116,6 @@ export class AreaService {
.filter(key => key.startsWith(CACHE_KEY_PREFIX)) .filter(key => key.startsWith(CACHE_KEY_PREFIX))
.forEach(key => localStorage.removeItem(key)); .forEach(key => localStorage.removeItem(key));
} }
/**
* 根据地区代码身份证前6位查询地区信息
* @param {string} areaCode - 地区代码6位
* @returns {Promise<Object|null>} - 地区信息 {province, city, district, value},如果未找到则返回 null
*/
static async getAreaByCode(areaCode) {
if (!areaCode || areaCode.length < 6) {
return null;
}
try {
const provincecode = areaCode.substring(0, 2);
// 并行查询省列表和该省的市区列表
const [provinces, areas] = await Promise.all([
this.getProvinces(),
this.getAreaList(provincecode)
]);
// 查找省、市、区
const province = provinces.find(p => p.code === provincecode);
const city = areas.find(a => a.code === areaCode.substring(0, 4));
const district = areas.find(a => a.code === areaCode);
// 至少要有省份才返回
if (province) {
return {
province: province.name,
city: city ? city.name : '',
district: district ? district.name : '',
provinceCode: province.code,
cityCode: city ? city.code : '',
districtCode: district ? district.code : '',
value: city ? city.name : province.name // 只返回市名或省名
};
}
return null;
} catch (error) {
console.error('[AreaService] 根据代码查询地区失败:', error);
return null;
}
}
} }
export default AreaService; export default AreaService;