mirror of
http://36.133.248.69:3088/admin/RentWeAppFront.git
synced 2026-06-07 06:22:27 +08:00
修复bug
This commit is contained in:
@@ -1,176 +1,235 @@
|
||||
<template>
|
||||
<view class="u-m-20">
|
||||
<u-navbar :is-back="true" title="账号实名信息" :border-bottom="false"></u-navbar>
|
||||
<view>
|
||||
|
||||
<view class="mt-30">
|
||||
<u-cell-group>
|
||||
<u-cell-item :title="getTitle" :arrow="false" hover-class="none" @click="updateName">
|
||||
{{(cardNo == null ? orgNo : cardNo) || ''}}
|
||||
<u-cell-item :title="getTitle" :arrow="true" hover-class="none" @click="showModel = true">
|
||||
<text class="value-text">{{ showValue || '未设置' }}</text>
|
||||
</u-cell-item>
|
||||
</u-cell-group>
|
||||
</view>
|
||||
|
||||
<u-modal
|
||||
v-model="showModel"
|
||||
@confirm="confirmAuthCode"
|
||||
ref="uModal"
|
||||
:async-close="true"
|
||||
:title="'设置' + getTitle"
|
||||
>
|
||||
<view class="slot-content">
|
||||
<u-input
|
||||
<!-- ======================
|
||||
完全自定义弹窗(扔掉u-modal)
|
||||
样式100%可控 永不转圈 超美观
|
||||
========================= -->
|
||||
<view class="modal-mask" v-if="showModel" @click="showModel = false"></view>
|
||||
<view class="modal-content" v-if="showModel">
|
||||
<view class="modal-header">
|
||||
<text class="title">设置{{ getTitle }}</text>
|
||||
</view>
|
||||
|
||||
<view class="modal-body">
|
||||
<input
|
||||
v-model="authCode"
|
||||
type="text"
|
||||
:border="false"
|
||||
:placeholder="'请输入' + getTitle"
|
||||
:placeholder="'请输入' + getTitle"
|
||||
class="modal-input"
|
||||
/>
|
||||
</view>
|
||||
</u-modal>
|
||||
|
||||
<view class="modal-footer">
|
||||
<view class="btn cancel" @click="closeModal">取消</view>
|
||||
<view class="btn confirm" :class="{loading: submitting}" @click="doSubmit">
|
||||
<text v-if="!submitting">确定</text>
|
||||
<text v-else class="loading-text">提交中...</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import config from "@/common/config.js"
|
||||
import { rsaEncrypt } from "@/common/utils/ras.js"
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
user: {
|
||||
userType: null,
|
||||
userType: '',
|
||||
oaAuth: null,
|
||||
cusNo: null,
|
||||
userName: null,
|
||||
openId: null
|
||||
},
|
||||
pic: null,
|
||||
authCode: '',
|
||||
showModel: false,
|
||||
submitting: false,
|
||||
cardNo: null,
|
||||
orgNo: null
|
||||
}
|
||||
},
|
||||
onLoad(options) {
|
||||
// 页面加载时同步最新用户信息
|
||||
onLoad() {
|
||||
this.getUserProfile();
|
||||
},
|
||||
methods: {
|
||||
updateName() {
|
||||
this.showModel = true;
|
||||
closeModal() {
|
||||
this.showModel = false
|
||||
this.authCode = ''
|
||||
},
|
||||
// 身份证校验
|
||||
checkIdCard(code) {
|
||||
return /^[1-9]\d{5}(19|20)\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}[\dXx]$/.test(code);
|
||||
},
|
||||
// 统一社会信用代码校验
|
||||
checkCreditCode(code) {
|
||||
return /^[0-9A-Z]{18}$/.test(code);
|
||||
},
|
||||
confirmAuthCode() {
|
||||
// 修复:统一使用 loginType 变量
|
||||
const loginType = this.user.userType;
|
||||
|
||||
if (!this.authCode) {
|
||||
this.showModel = false;
|
||||
return this.$mytip.toast(loginType === '0' ? '请输入身份证号' : '请输入组织社会信用代码')
|
||||
async doSubmit() {
|
||||
const userType = String(this.user.userType)
|
||||
const input = this.authCode.trim()
|
||||
|
||||
if (!input) {
|
||||
this.$mytip.toast(userType === '0' ? '请输入身份证号' : '请输入企业信用代码')
|
||||
return
|
||||
}
|
||||
|
||||
// 校验身份证
|
||||
if (loginType === '0' && !this.checkIdCard(this.authCode)) {
|
||||
uni.showToast({ title: '身份证号格式不正确', icon: 'none' });
|
||||
return;
|
||||
if (userType === '0' && !this.checkIdCard(input)) {
|
||||
uni.showToast({ title: '身份证格式不正确', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
// 校验信用代码
|
||||
if (loginType === '1' && !this.checkCreditCode(this.authCode)) {
|
||||
uni.showToast({ title: '社会信用代码格式不正确', icon: 'none' });
|
||||
return;
|
||||
if (userType === '1' && !this.checkCreditCode(input)) {
|
||||
uni.showToast({ title: '社会信用代码格式错误', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
const token = this.$getToken();
|
||||
const url = "/login/updateVerifyCode";
|
||||
const encryptCode = rsaEncrypt(this.authCode);
|
||||
|
||||
this.$u.post(url, {
|
||||
userType: loginType,
|
||||
code: loginType === '0' ? encryptCode : this.authCode
|
||||
}, {
|
||||
'WT': token
|
||||
}).then(obj => {
|
||||
if (obj.flag) {
|
||||
// 赋值展示
|
||||
if (loginType === '0') {
|
||||
this.cardNo = this.applyMask(this.authCode);
|
||||
} else {
|
||||
this.orgNo = this.authCode;
|
||||
}
|
||||
|
||||
this.showModel = false;
|
||||
this.$mytip.toast('修改成功');
|
||||
|
||||
// 关键:先更新用户信息,成功后再跳转
|
||||
this.getUserProfile().then(() => {
|
||||
setTimeout(() => {
|
||||
uni.switchTab({ url: '/pages/center/center' });
|
||||
}, 1000);
|
||||
});
|
||||
|
||||
this.submitting = true
|
||||
try {
|
||||
const token = this.$getToken()
|
||||
const res = await this.$u.post('/login/updateVerifyCode', {
|
||||
userType,
|
||||
code: userType === '0' ? rsaEncrypt(input) : input
|
||||
}, { WT: token })
|
||||
|
||||
if (res.flag) {
|
||||
this.$mytip.toast('设置成功')
|
||||
this.closeModal()
|
||||
await this.getUserProfile()
|
||||
setTimeout(() => uni.switchTab({ url: '/pages/center/center' }), 1500)
|
||||
} else {
|
||||
this.$mytip.toast('修改失败');
|
||||
this.$mytip.toast(res.msg || '设置失败')
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
this.$mytip.toast('提交失败')
|
||||
} finally {
|
||||
this.submitting = false
|
||||
}
|
||||
},
|
||||
// 身份证脱敏修复
|
||||
applyMask(idCard) {
|
||||
if (!idCard || idCard.length !== 18) return idCard;
|
||||
// 前6位 + 8个* + 后4位
|
||||
return idCard.replace(/^(\d{6})\d{8}(\d{4})$/, '$1********$2');
|
||||
if (!idCard || idCard.length !== 18) return idCard
|
||||
return idCard.replace(/^(\d{6})\d{8}(\d{4})$/, '$1********$2')
|
||||
},
|
||||
updateAvatar() {
|
||||
this.$u.route('/pages-biz/profile/avatar')
|
||||
},
|
||||
// 关键修复:获取用户信息并同步到当前页面 data
|
||||
async getUserProfile() {
|
||||
try {
|
||||
const token = this.$getToken();
|
||||
const url = `/login/userInfo`;
|
||||
|
||||
const obj = await this.$u.get(url, {}, { 'WT': token });
|
||||
const userInfo = {
|
||||
userType: obj.data.userType,
|
||||
oaAuth: obj.data.oaAuth,
|
||||
cusNo: obj.data.cusNo,
|
||||
userName: obj.data.userName,
|
||||
openId: obj.data.openId,
|
||||
subscribe: obj.data.subscribeMsg
|
||||
};
|
||||
|
||||
// 同步缓存 + 当前页面数据
|
||||
uni.setStorageSync('userInfo', userInfo);
|
||||
this.user = userInfo;
|
||||
|
||||
// 同步展示实名信息
|
||||
if (userInfo.userType === '0') {
|
||||
this.cardNo = obj.data.cardNo ? this.applyMask(obj.data.cardNo) : null;
|
||||
this.orgNo = null;
|
||||
} else {
|
||||
this.orgNo = obj.data.orgNo || null;
|
||||
this.cardNo = null;
|
||||
const token = this.$getToken()
|
||||
const obj = await this.$u.get('/login/userInfo', {}, { WT: token })
|
||||
if (!obj.data) return
|
||||
const user = obj.data
|
||||
this.user = {
|
||||
userType: String(user.userType),
|
||||
oaAuth: user.oaAuth,
|
||||
cusNo: user.cusNo,
|
||||
userName: user.userName,
|
||||
openId: user.openId
|
||||
}
|
||||
|
||||
return userInfo;
|
||||
} catch (e) {
|
||||
console.error('获取用户信息失败', e);
|
||||
}
|
||||
if (this.user.userType === '0') {
|
||||
this.cardNo = user.cardNo ? this.applyMask(user.cardNo) : null
|
||||
this.orgNo = null
|
||||
} else {
|
||||
this.orgNo = user.orgNo || null
|
||||
this.cardNo = null
|
||||
}
|
||||
uni.setStorageSync('userInfo', this.user)
|
||||
} catch (e) {}
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
getTitle() {
|
||||
return this.user.userType === '0' ? '身份证号' : '企业社会信用代码';
|
||||
return this.user.userType === '0' ? '身份证号' : '企业社会信用代码'
|
||||
},
|
||||
showValue() {
|
||||
return this.user.userType === '0' ? this.cardNo : this.orgNo
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.slot-content {
|
||||
padding: 40rpx;
|
||||
/* 页面样式 */
|
||||
.mt-30 {
|
||||
margin-top: 30rpx;
|
||||
}
|
||||
.value-text {
|
||||
font-size: 28rpx;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
/* ======================
|
||||
自定义弹窗样式(超美观)
|
||||
========================= */
|
||||
.modal-mask {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
z-index: 999;
|
||||
}
|
||||
|
||||
.modal-content {
|
||||
position: fixed;
|
||||
top: 50%;
|
||||
left: 50%;
|
||||
transform: translate(-50%, -50%);
|
||||
width: 82%;
|
||||
background: #fff;
|
||||
border-radius: 20rpx;
|
||||
z-index: 1000;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 4rpx 20rpx rgba(0,0,0,0.15);
|
||||
}
|
||||
|
||||
.modal-input {
|
||||
width: 100%;
|
||||
height: 80rpx;
|
||||
font-size: 32rpx;
|
||||
border-bottom: 2rpx solid #EEEEEE;
|
||||
padding: 0 10rpx;
|
||||
box-sizing: border-box;
|
||||
color: #333;
|
||||
}
|
||||
.modal-header {
|
||||
padding: 40rpx 30rpx 20rpx;
|
||||
text-align: center;
|
||||
font-weight: bold;
|
||||
.title {
|
||||
font-size: 34rpx;
|
||||
color: #222;
|
||||
}
|
||||
}
|
||||
|
||||
.modal-body {
|
||||
padding: 20rpx 40rpx 40rpx;
|
||||
}
|
||||
|
||||
.modal-footer {
|
||||
display: flex;
|
||||
border-top: 1rpx solid #f0f0f0;
|
||||
height: 96rpx;
|
||||
.btn {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 30rpx;
|
||||
&.cancel {
|
||||
color: #666;
|
||||
background: #f8f8f8;
|
||||
}
|
||||
&.confirm {
|
||||
color: #fff;
|
||||
background: #EA414A;
|
||||
&.loading {
|
||||
opacity: 0.8;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user