- 新增账号安全页面及支付密码验证组件 - 新增用户类型选择流程及商家资质管理 - 新增订单资质校验逻辑,师傅需满足订单证书要求 - 新增企业资质认证相关数据库表及接口 - 优化用户列表展示,区分个人与商家用户类型
143 行
11 KiB
Vue
143 行
11 KiB
Vue
<template>
|
||
<view class="page">
|
||
<YjyfNavBar theme="white" title="账号安全" :border="true" :showBack="returnOrder ? true : null" :customBack="!!returnOrder" @back="leaveSetup" />
|
||
<view v-if="loaded" class="card">
|
||
<view class="row" @tap="openPassword('login')"><text>登录密码</text><view class="value">{{ status.has_login_password ? '修改' : '设置' }} <image class="arrow" src="/static/icons/arrow-right.svg" mode="aspectFit" /></view></view>
|
||
<view class="row" @tap="openPassword('payment')"><text>支付密码</text><view class="value">{{ status.has_payment_password ? '修改' : '设置' }} <image class="arrow" src="/static/icons/arrow-right.svg" mode="aspectFit" /></view></view>
|
||
<view class="row" @tap="openCert"><text>企业资质认证</text><view class="value">{{ certText }} <image class="arrow" src="/static/icons/arrow-right.svg" mode="aspectFit" /></view></view>
|
||
</view>
|
||
<view v-if="mode" class="mask">
|
||
<view class="sheet">
|
||
<view class="sheet-head"><text class="title">{{ sheetTitle }}</text><text class="close" @tap="close">取消</text></view>
|
||
<template v-if="mode === 'login'">
|
||
<input v-if="status.has_login_password" v-model="oldPassword" class="input" password placeholder="请输入原登录密码" />
|
||
<input v-model="newPassword" class="input" password maxlength="30" placeholder="新登录密码(6至30位)" />
|
||
<input v-model="confirmPassword" class="input" password maxlength="30" placeholder="再次输入新登录密码" />
|
||
<text v-if="!status.has_login_password" class="hint">请使用绑定的微信手机号验证身份。</text>
|
||
<!-- #ifdef MP-WEIXIN -->
|
||
<button v-if="!status.has_login_password" class="primary" open-type="getPhoneNumber" :disabled="busy" @getphonenumber="onPhoneVerify">验证手机号并设置</button>
|
||
<!-- #endif -->
|
||
<!-- #ifndef MP-WEIXIN -->
|
||
<text v-if="!status.has_login_password" class="hint">请在微信小程序中完成手机号验证后设置。</text>
|
||
<!-- #endif -->
|
||
<button v-if="status.has_login_password" class="primary" :disabled="busy" @tap="savePassword">确认修改</button>
|
||
</template>
|
||
<template v-else-if="mode === 'payment'">
|
||
<input v-if="status.has_payment_password" v-model="oldPassword" class="input" type="number" password maxlength="6" placeholder="请输入原支付密码" />
|
||
<input v-else-if="!status.has_payment_password" v-model="oldPassword" class="input" password placeholder="请输入登录密码以验证身份" />
|
||
<input v-model="newPassword" class="input" type="number" password maxlength="6" placeholder="设置6位支付密码" />
|
||
<input v-model="confirmPassword" class="input" type="number" password maxlength="6" placeholder="再次输入支付密码" />
|
||
<button class="primary" :disabled="busy" @tap="savePassword">确认</button>
|
||
</template>
|
||
<template v-else>
|
||
<text v-if="cert && cert.verify_status === 'reject'" class="hint">审核未通过:{{ cert.audit_msg }}</text>
|
||
<text class="hint">上传后将通过腾讯云识别营业执照,请核对识别信息后提交。</text>
|
||
<input v-model="companyName" class="input" placeholder="请输入企业名称" />
|
||
<input v-model="licenseNo" class="input" placeholder="请输入营业执照号码" maxlength="18" />
|
||
<input v-model="legalPerson" class="input" placeholder="请输入法人姓名(选填)" />
|
||
<view class="upload" @tap="chooseLicense"><image v-if="imagePreview" :src="imagePreview" mode="aspectFit" class="license"/><text>{{ licenseImage ? '重新上传营业执照' : '上传营业执照' }}</text></view>
|
||
<button class="primary" :disabled="busy" @tap="submitCert">提交审核</button>
|
||
</template>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
</template>
|
||
<script setup>
|
||
import { ref, computed } from 'vue';
|
||
import { onLoad, onShow, onBackPress } from '@dcloudio/uni-app';
|
||
import YjyfNavBar from '@/components/YjyfNavBar.vue';
|
||
import api from '@/utils/api.js';
|
||
import { clearAuth } from '@/utils/request.js';
|
||
import { finishPaymentSetup } from '@/utils/payment-setup.mjs';
|
||
const loaded = ref(false), busy = ref(false), mode = ref('');
|
||
const returnOrder = ref('');
|
||
let setupFromPayment = false, setupOpened = false;
|
||
const status = ref({}), oldPassword = ref(''), newPassword = ref(''), confirmPassword = ref('');
|
||
const companyName = ref(''), licenseNo = ref(''), legalPerson = ref(''), licenseImage = ref(''), imagePreview = ref('');
|
||
const cert = computed(() => status.value.enterprise_cert || null);
|
||
const certText = computed(() => cert.value ? ({ pending: '审核中', pass: '已认证', reject: '未通过,可重提' }[cert.value.verify_status] || '') : '未认证');
|
||
const sheetTitle = computed(() => mode.value === 'login' ? '登录密码' : mode.value === 'payment' ? '支付密码' : '企业资质认证');
|
||
async function load() { try { status.value = await api.securityStatus(); loaded.value = true; } catch (e) {} }
|
||
function close() { if (busy.value) return; mode.value = ''; oldPassword.value = ''; newPassword.value = ''; confirmPassword.value = ''; }
|
||
function openPassword(which) { mode.value = which; }
|
||
function openCert() {
|
||
if (cert.value && cert.value.verify_status !== 'reject') { uni.showToast({ title: certText.value, icon: 'none' }); return; }
|
||
if (cert.value) { companyName.value = cert.value.company_name; licenseNo.value = cert.value.license_no; legalPerson.value = cert.value.legal_person; }
|
||
mode.value = 'cert';
|
||
}
|
||
function validPassword() {
|
||
const valid = mode.value === 'payment' ? /^\d{6}$/.test(newPassword.value) : /^\S{6,30}$/.test(newPassword.value);
|
||
if (!valid || newPassword.value !== confirmPassword.value) { uni.showToast({ title: '请检查两次输入的密码', icon: 'none' }); return false; }
|
||
return true;
|
||
}
|
||
async function onPhoneVerify(event) {
|
||
const code = event.detail && event.detail.code;
|
||
if (!code) { uni.showToast({ title: '未完成手机号验证', icon: 'none' }); return; }
|
||
await savePassword(code);
|
||
}
|
||
async function savePassword(phoneCode = '') {
|
||
if (typeof phoneCode !== 'string') phoneCode = '';
|
||
if (busy.value || !validPassword()) return;
|
||
busy.value = true;
|
||
try {
|
||
if (mode.value === 'login') {
|
||
await api.changeLoginPassword({ old_password: oldPassword.value, new_password: newPassword.value, phone_code: phoneCode });
|
||
clearAuth(); uni.showToast({ title: '请重新登录', icon: 'none' });
|
||
setTimeout(() => uni.reLaunch({ url: '/pages/login/login' }), 700); return;
|
||
}
|
||
const firstSetup = !status.value.has_payment_password;
|
||
if (!firstSetup) await api.changePaymentPassword({ old_password: oldPassword.value, new_password: newPassword.value });
|
||
else await api.setPaymentPassword({ login_password: oldPassword.value, new_password: newPassword.value });
|
||
busy.value = false; close(); uni.showToast({ title: '保存成功' });
|
||
if (setupFromPayment && firstSetup) {
|
||
try { await finishPaymentSetup(uni, returnOrder.value); } catch (e) { uni.showToast({ title: e.message, icon: 'none' }); }
|
||
} else await load();
|
||
} catch (e) {} finally { busy.value = false; }
|
||
}
|
||
function chooseLicense() { if (busy.value) return; uni.chooseImage({ count: 1, sizeType: ['compressed'], success: async res => {
|
||
busy.value = true; try {
|
||
const uploaded = await api.upload(res.tempFilePaths[0], 'cert'); licenseImage.value = uploaded.url; imagePreview.value = uploaded.fullurl || res.tempFilePaths[0];
|
||
try { const recognized = await api.recognizeEnterpriseLicense({ license_image: uploaded.url }); companyName.value = recognized.company_name; licenseNo.value = recognized.license_no; legalPerson.value = recognized.legal_person; }
|
||
catch (e) { /* Recognition errors are displayed by the request layer; manual entry remains available. */ }
|
||
} catch (e) {} finally { busy.value = false; }
|
||
} }); }
|
||
async function submitCert() {
|
||
if (busy.value) return;
|
||
if (!companyName.value.trim() || !licenseNo.value.trim() || !licenseImage.value) { uni.showToast({ title: '请填写企业信息并上传营业执照', icon: 'none' }); return; }
|
||
busy.value = true;
|
||
try { await api.submitEnterpriseCert({ company_name: companyName.value.trim(), license_no: licenseNo.value.trim(), legal_person: legalPerson.value.trim(), license_image: licenseImage.value }); busy.value = false; close(); await load(); uni.showToast({ title: '提交成功' }); } catch (e) {} finally { busy.value = false; }
|
||
}
|
||
async function leaveSetup() {
|
||
try { await finishPaymentSetup(uni, returnOrder.value); } catch (e) { uni.showToast({ title: e.message, icon: 'none' }); }
|
||
}
|
||
onLoad((options) => {
|
||
setupFromPayment = !!(options && options.setupPayment === '1');
|
||
const id = String((options && options.returnOrder) || '');
|
||
if (setupFromPayment && /^[1-9]\d*$/.test(id) && Number.isSafeInteger(Number(id))) returnOrder.value = id;
|
||
});
|
||
onBackPress(() => {
|
||
if (!returnOrder.value) return false;
|
||
leaveSetup();
|
||
return true;
|
||
});
|
||
onShow(async () => {
|
||
await load();
|
||
if (!loaded.value || !setupFromPayment || setupOpened) return;
|
||
setupOpened = true;
|
||
if (status.value.has_payment_password) await leaveSetup();
|
||
else openPassword('payment');
|
||
});
|
||
</script>
|
||
<style lang="scss" scoped>
|
||
@import '@/uni.scss';
|
||
.page { min-height: 100vh; background: $yjyf-bg-page; }
|
||
.card { margin: 24rpx; padding: 0 28rpx; background: $yjyf-bg-card; border-radius: 20rpx; }
|
||
.row { min-height: 100rpx; display: flex; align-items: center; justify-content: space-between; border-bottom: 1rpx solid $yjyf-border-color; color: $yjyf-text-main; font-size: 30rpx; }
|
||
.row:last-child { border-bottom: 0; }.value { color: $yjyf-text-secondary; font-size: 26rpx; display: flex; align-items: center; }.arrow { width: 26rpx; height: 26rpx; margin-left: 10rpx; }
|
||
.mask { position: fixed; inset: 0; z-index: 1000; background: rgba(0,0,0,.5); display: flex; align-items: flex-end; }
|
||
.sheet { width: 100%; max-height: 90vh; overflow-y: auto; padding: 30rpx 30rpx calc(30rpx + env(safe-area-inset-bottom)); border-radius: 24rpx 24rpx 0 0; background: $yjyf-bg-card; }
|
||
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24rpx; }.title { color: $yjyf-text-main; font-size: 32rpx; font-weight: 600; }.close { color: $yjyf-text-secondary; font-size: 28rpx; }
|
||
.input { height: 88rpx; padding: 0 20rpx; margin-bottom: 16rpx; background: $yjyf-bg-page; border-radius: 12rpx; font-size: 28rpx; }.hint { display: block; margin: 12rpx 0; color: $yjyf-text-secondary; font-size: 24rpx; }
|
||
.primary { margin-top: 22rpx; background: $yjyf-gradient-primary; color: $yjyf-bg-card; font-size: 30rpx; }.upload { display: flex; flex-direction: column; align-items: center; gap: 10rpx; padding: 24rpx; color: $yjyf-primary; border: 1rpx solid $yjyf-border-color; font-size: 26rpx; }.license { width: 300rpx; height: 180rpx; }
|
||
</style>
|