|
|
|
@ -106,10 +106,13 @@ |
|
|
|
<script> |
|
|
|
import config from '@/utils/config'; |
|
|
|
import { getOpenId } from '@/utils/storage'; |
|
|
|
import { FetchSessionKey, FetchDecryptPhone } from '@/api/user.js'; |
|
|
|
|
|
|
|
export default { |
|
|
|
data() { |
|
|
|
return { |
|
|
|
sessionKey: '', |
|
|
|
openid: '', |
|
|
|
formData: { |
|
|
|
name: '', |
|
|
|
idCard: '', |
|
|
|
@ -123,43 +126,59 @@ export default { |
|
|
|
}; |
|
|
|
}, |
|
|
|
|
|
|
|
onLoad() {}, |
|
|
|
onLoad() { |
|
|
|
this.getSessionKey(); |
|
|
|
}, |
|
|
|
|
|
|
|
methods: { |
|
|
|
async getSessionKey() { |
|
|
|
try { |
|
|
|
uni.login({ |
|
|
|
success: async (loginRes) => { |
|
|
|
console.log('loginRes',loginRes) |
|
|
|
if (loginRes.code) { |
|
|
|
const res = await FetchSessionKey({ |
|
|
|
libcode: config.LIB_CODE, |
|
|
|
code: loginRes.code |
|
|
|
}); |
|
|
|
if (res.code === 200) { |
|
|
|
this.sessionKey = res.data.session_key; |
|
|
|
this.openid = res.data.openid; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
} catch (error) { |
|
|
|
console.error('获取sessionKey失败:', error); |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
getPhoneNumber(e) { |
|
|
|
if (e.detail.errMsg !== 'getPhoneNumber:ok') { |
|
|
|
uni.showToast({ title: '取消授权', icon: 'none' }); |
|
|
|
return; |
|
|
|
} |
|
|
|
// #ifdef MP-WEIXIN |
|
|
|
uni.login({ |
|
|
|
success: (loginRes) => { |
|
|
|
uni.request({ |
|
|
|
url: config.baseUrl + '/api/wx/decryptPhone', |
|
|
|
method: 'POST', |
|
|
|
data: { |
|
|
|
code: loginRes.code, |
|
|
|
encryptedData: e.detail.encryptedData, |
|
|
|
iv: e.detail.iv |
|
|
|
}, |
|
|
|
success: (res) => { |
|
|
|
if (res.data?.code === 200) { |
|
|
|
this.formData.phone = res.data.data.phoneNumber || ''; |
|
|
|
} else { |
|
|
|
uni.showToast({ title: res.data?.message || '获取失败', icon: 'none' }); |
|
|
|
} |
|
|
|
}, |
|
|
|
fail: () => uni.showToast({ title: '获取手机号失败', icon: 'none' }) |
|
|
|
}); |
|
|
|
}, |
|
|
|
fail: () => uni.showToast({ title: '登录失败', icon: 'none' }) |
|
|
|
|
|
|
|
if (!this.sessionKey) { |
|
|
|
uni.showToast({ title: '请稍后再试', icon: 'none' }); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
FetchDecryptPhone({ |
|
|
|
sessionKey: this.sessionKey, |
|
|
|
encryptedData: e.detail.encryptedData, |
|
|
|
iv: e.detail.iv |
|
|
|
}).then(res => { |
|
|
|
if (res.code === 200) { |
|
|
|
this.formData.phone = res.data.phoneNumber || ''; |
|
|
|
uni.showToast({ title: '获取成功', icon: 'success' }); |
|
|
|
} else { |
|
|
|
uni.showToast({ title: res.message || '获取失败', icon: 'none' }); |
|
|
|
} |
|
|
|
}).catch(() => { |
|
|
|
uni.showToast({ title: '获取手机号失败', icon: 'none' }); |
|
|
|
}); |
|
|
|
// #endif |
|
|
|
// #ifndef MP-WEIXIN |
|
|
|
uni.showToast({ title: '仅支持微信小程序', icon: 'none' }); |
|
|
|
// #endif |
|
|
|
}, |
|
|
|
|
|
|
|
togglePwd() { |
|
|
|
this.showPwd = !this.showPwd; |
|
|
|
}, |
|
|
|
@ -170,26 +189,20 @@ export default { |
|
|
|
// 身份证验证(支持15位和18位,自动去除空格和连字符) |
|
|
|
validateIdCard(idCard) { |
|
|
|
if (!idCard) return false; |
|
|
|
|
|
|
|
// 去除空格和连字符 |
|
|
|
idCard = idCard.replace(/[\s-]/g, ''); |
|
|
|
|
|
|
|
// 15位身份证格式验证 |
|
|
|
const idCard15Reg = /^[1-9]\d{5}\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}$/; |
|
|
|
|
|
|
|
// 18位身份证格式验证 |
|
|
|
const idCard18Reg = /^[1-9]\d{5}(18|19|20)\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}[\dXx]$/; |
|
|
|
|
|
|
|
// 15位身份证直接验证格式 |
|
|
|
if (idCard.length === 15) { |
|
|
|
return idCard15Reg.test(idCard); |
|
|
|
} |
|
|
|
|
|
|
|
// 18位身份证需要验证格式、日期和校验码 |
|
|
|
if (idCard.length !== 18 || !idCard18Reg.test(idCard)) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
// 验证日期有效性(宽松模式:跳过校验码验证) |
|
|
|
const year = +idCard.substring(6, 10); |
|
|
|
const month = +idCard.substring(10, 12); |
|
|
|
@ -197,7 +210,6 @@ export default { |
|
|
|
const date = new Date(year, month - 1, day); |
|
|
|
return date.getFullYear() === year && date.getMonth() === month - 1 && date.getDate() === day; |
|
|
|
}, |
|
|
|
|
|
|
|
// 手机号验证 |
|
|
|
validatePhone(phone) { |
|
|
|
return /^1[3-9]\d{9}$/.test(phone); |
|
|
|
|