Files
RentWeAppFront/pages-biz/profile/profile.vue

176 lines
4.4 KiB
Vue
Raw Normal View History

2026-01-15 17:18:24 +08:00
<template>
<view class="u-m-20">
<u-navbar :is-back="true" title="账号实名信息" :border-bottom="false"></u-navbar>
<view>
<u-cell-group>
<u-cell-item :title="getTitle" :arrow="false" hover-class="none" @click="updateName">
{{(cardNo == null ? orgNo : cardNo) || ''}}
</u-cell-item>
</u-cell-group>
</view>
2026-05-14 14:42:51 +08:00
<u-modal
v-model="showModel"
@confirm="confirmAuthCode"
ref="uModal"
:async-close="true"
:title="'设置' + getTitle"
>
2026-01-15 17:18:24 +08:00
<view class="slot-content">
2026-05-14 14:42:51 +08:00
<u-input
v-model="authCode"
type="text"
:border="false"
:placeholder="'请输入' + getTitle"
/>
2026-01-15 17:18:24 +08:00
</view>
</u-modal>
</view>
</template>
<script>
2026-05-14 14:42:51 +08:00
import config from "@/common/config.js"
import { rsaEncrypt } from "@/common/utils/ras.js"
2026-01-15 17:18:24 +08:00
export default {
data() {
return {
user: {
userType: null,
oaAuth: null,
cusNo: null,
userName: null,
openId: null
},
pic: null,
authCode: '',
showModel: false,
cardNo: null,
orgNo: null
}
},
onLoad(options) {
2026-05-14 14:42:51 +08:00
// 页面加载时同步最新用户信息
this.getUserProfile();
2026-01-15 17:18:24 +08:00
},
methods: {
updateName() {
this.showModel = true;
},
2026-05-14 14:42:51 +08:00
// 身份证校验
2026-01-15 17:18:24 +08:00
checkIdCard(code) {
2026-05-14 14:42:51 +08:00
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);
2026-01-15 17:18:24 +08:00
},
2026-05-14 14:42:51 +08:00
// 统一社会信用代码校验
2026-01-15 17:18:24 +08:00
checkCreditCode(code) {
return /^[0-9A-Z]{18}$/.test(code);
},
confirmAuthCode() {
2026-05-14 14:42:51 +08:00
// 修复:统一使用 loginType 变量
const loginType = this.user.userType;
2026-01-15 17:18:24 +08:00
if (!this.authCode) {
this.showModel = false;
return this.$mytip.toast(loginType === '0' ? '请输入身份证号' : '请输入组织社会信用代码')
}
2026-05-14 14:42:51 +08:00
// 校验身份证
if (loginType === '0' && !this.checkIdCard(this.authCode)) {
uni.showToast({ title: '身份证号格式不正确', icon: 'none' });
2026-01-15 17:18:24 +08:00
return;
}
2026-05-14 14:42:51 +08:00
// 校验信用代码
if (loginType === '1' && !this.checkCreditCode(this.authCode)) {
uni.showToast({ title: '社会信用代码格式不正确', icon: 'none' });
2026-01-15 17:18:24 +08:00
return;
}
2026-05-14 14:42:51 +08:00
const token = this.$getToken();
const url = "/login/updateVerifyCode";
const encryptCode = rsaEncrypt(this.authCode);
2026-01-15 17:18:24 +08:00
this.$u.post(url, {
userType: loginType,
code: loginType === '0' ? encryptCode : this.authCode
}, {
'WT': token
}).then(obj => {
if (obj.flag) {
2026-05-14 14:42:51 +08:00
// 赋值展示
2026-01-15 17:18:24 +08:00
if (loginType === '0') {
2026-05-14 14:42:51 +08:00
this.cardNo = this.applyMask(this.authCode);
2026-01-15 17:18:24 +08:00
} else {
2026-05-14 14:42:51 +08:00
this.orgNo = this.authCode;
2026-01-15 17:18:24 +08:00
}
2026-05-14 14:42:51 +08:00
2026-01-15 17:18:24 +08:00
this.showModel = false;
this.$mytip.toast('修改成功');
2026-05-14 14:42:51 +08:00
// 关键:先更新用户信息,成功后再跳转
this.getUserProfile().then(() => {
setTimeout(() => {
uni.switchTab({ url: '/pages/center/center' });
}, 1000);
});
2026-01-15 17:18:24 +08:00
} else {
this.$mytip.toast('修改失败');
}
});
},
2026-05-14 14:42:51 +08:00
// 身份证脱敏修复
2026-01-15 17:18:24 +08:00
applyMask(idCard) {
2026-05-14 14:42:51 +08:00
if (!idCard || idCard.length !== 18) return idCard;
// 前6位 + 8个* + 后4位
return idCard.replace(/^(\d{6})\d{8}(\d{4})$/, '$1********$2');
2026-01-15 17:18:24 +08:00
},
updateAvatar() {
this.$u.route('/pages-biz/profile/avatar')
},
2026-05-14 14:42:51 +08:00
// 关键修复:获取用户信息并同步到当前页面 data
async getUserProfile() {
try {
const token = this.$getToken();
const url = `/login/userInfo`;
const obj = await this.$u.get(url, {}, { 'WT': token });
const userInfo = {
2026-01-15 17:18:24 +08:00
userType: obj.data.userType,
oaAuth: obj.data.oaAuth,
cusNo: obj.data.cusNo,
userName: obj.data.userName,
2026-01-30 09:01:38 +08:00
openId: obj.data.openId,
subscribe: obj.data.subscribeMsg
2026-05-14 14:42:51 +08:00
};
// 同步缓存 + 当前页面数据
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;
}
return userInfo;
} catch (e) {
console.error('获取用户信息失败', e);
}
2026-01-15 17:18:24 +08:00
}
},
computed: {
getTitle() {
2026-05-14 14:42:51 +08:00
return this.user.userType === '0' ? '身份证号' : '企业社会信用代码';
2026-01-15 17:18:24 +08:00
}
}
}
</script>
<style lang="scss" scoped>
.slot-content {
padding: 40rpx;
}
</style>