181 行
13 KiB
Vue
181 行
13 KiB
Vue
<template>
|
||
<view class="page">
|
||
<YjyfNavBar theme="white" :title="setupFromPayment ? '设置支付密码' : mode === 'cert' ? '企业资质认证' : '账号安全'" :border="true" :showBack="mode === 'cert' || setupFromPayment ? true : null" :customBack="mode === 'cert' || setupFromPayment" @back="handleBack" />
|
||
<template v-if="mode !== 'cert' && !setupFromPayment">
|
||
<view v-if="loaded" class="card">
|
||
<view class="row" @tap="openCert"><text>企业资质认证</text><view class="value"><text :class="{ attention: !cert || cert.verify_status === 'reject' }">{{ certText }}</text><image class="arrow" src="/static/icons/arrow-right.svg" mode="aspectFit" /></view></view>
|
||
<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>
|
||
<view v-if="loaded" class="logout" @tap="logout">退出登录</view>
|
||
</template>
|
||
<view v-else-if="mode === 'cert'" class="cert-page">
|
||
<view class="cert-accent"></view>
|
||
<view class="cert-card">
|
||
<view class="cert-notice">为保障账号和交易安全,请上传真实有效的营业执照进行企业资质认证。<text>企业信息仅用于资质审核。</text></view>
|
||
<view class="cert-content">
|
||
<view class="cert-heading"><text class="required">*</text>上传营业执照照片</view>
|
||
<view class="cert-description">上传后将自动识别企业信息,请核对识别结果。若识别有误或识别失败,可手动修改;请确保照片清晰完整。</view>
|
||
<text v-if="cert && cert.verify_status === 'reject'" class="reject">审核未通过:{{ cert.audit_msg }}</text>
|
||
<view class="upload" @tap="chooseLicense">
|
||
<image v-if="imagePreview" :src="imagePreview" mode="aspectFit" class="license" />
|
||
<image v-else src="/static/icons/enterprise-license.svg" mode="aspectFit" class="license-illustration" />
|
||
<text>{{ busy ? '处理中...' : licenseImage ? '重新上传营业执照' : '上传营业执照' }}</text>
|
||
</view>
|
||
<view v-if="licenseImage" class="cert-fields">
|
||
<view class="field"><text>企业名称</text><input v-model="companyName" placeholder="请输入企业名称" /></view>
|
||
<view class="field"><text>营业执照号码</text><input v-model="licenseNo" placeholder="请输入营业执照号码" maxlength="18" /></view>
|
||
<view class="field"><text>法人姓名</text><input v-model="legalPerson" placeholder="请输入法人姓名(选填)" /></view>
|
||
<button class="primary" :disabled="busy" @tap="submitCert">提交审核</button>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
</view>
|
||
<view v-if="mode && mode !== 'cert'" class="mask">
|
||
<view class="sheet">
|
||
<view class="sheet-head"><text class="title">{{ sheetTitle }}</text><text class="close" @tap="cancelSheet">取消</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="再次输入新登录密码" />
|
||
<button class="primary" :disabled="busy" @tap="savePassword">{{ status.has_login_password ? '确认修改' : '确认设置' }}</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-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">{{ status.has_payment_password ? '确认修改' : '确认设置' }}</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('');
|
||
const setupFromPayment = ref(false);
|
||
let 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' ? '登录密码' : '支付密码');
|
||
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 savePassword() {
|
||
if (busy.value || !validPassword()) return;
|
||
if (mode.value === 'login' && status.value.has_login_password && !oldPassword.value) {
|
||
uni.showToast({ title: '请输入原登录密码', icon: 'none' });
|
||
return;
|
||
}
|
||
if (mode.value === 'payment' && status.value.has_payment_password && !/^\d{6}$/.test(oldPassword.value)) {
|
||
uni.showToast({ title: '请输入6位原支付密码', icon: 'none' });
|
||
return;
|
||
}
|
||
busy.value = true;
|
||
try {
|
||
if (mode.value === 'login') {
|
||
await api.changeLoginPassword({ old_password: oldPassword.value, new_password: newPassword.value });
|
||
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({ new_password: newPassword.value });
|
||
busy.value = false; close(); uni.showToast({ title: '保存成功' });
|
||
if (setupFromPayment.value && 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];
|
||
companyName.value = ''; licenseNo.value = ''; legalPerson.value = '';
|
||
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; }
|
||
}
|
||
function handleBack() { if (mode.value === 'cert') { close(); return; } if (!busy.value) leaveSetup(); }
|
||
function cancelSheet() { if (busy.value) return; if (setupFromPayment.value) leaveSetup(); else close(); }
|
||
function logout() { uni.showModal({ title: '退出登录', content: '确认退出当前登录账号?', success: (result) => { if (result.confirm) { clearAuth(); uni.reLaunch({ url: '/pages/login/login' }); } } }); }
|
||
async function leaveSetup() {
|
||
try { await finishPaymentSetup(uni, returnOrder.value); } catch (e) { uni.showToast({ title: e.message, icon: 'none' }); }
|
||
}
|
||
onLoad((options) => {
|
||
setupFromPayment.value = !!(options && options.setupPayment === '1');
|
||
const id = String((options && options.returnOrder) || '');
|
||
if (setupFromPayment.value && /^[1-9]\d*$/.test(id) && Number.isSafeInteger(Number(id))) returnOrder.value = id;
|
||
});
|
||
onBackPress(() => {
|
||
if (mode.value === 'cert') { if (!busy.value) close(); return true; }
|
||
if (!setupFromPayment.value) return false;
|
||
if (!busy.value) leaveSetup();
|
||
return true;
|
||
});
|
||
onShow(async () => {
|
||
await load();
|
||
if (!loaded.value || !setupFromPayment.value || 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: 16rpx; }
|
||
.row { min-height: 104rpx; display: flex; align-items: center; justify-content: space-between; border-bottom: 1rpx solid $yjyf-border-color; color: $yjyf-text-regular; font-size: 30rpx; }
|
||
.row:last-child { border-bottom: 0; }
|
||
.value { color: $yjyf-text-secondary; font-size: 28rpx; display: flex; align-items: center; }
|
||
.attention { color: $yjyf-primary; }
|
||
.arrow { width: 26rpx; height: 26rpx; margin-left: 10rpx; }
|
||
.logout { margin: 56rpx 24rpx 0; padding: 30rpx; border-radius: 16rpx; background: $yjyf-bg-card; text-align: center; color: $yjyf-primary; font-size: 30rpx; }
|
||
.cert-page { position: relative; padding: 64rpx 24rpx 48rpx; }
|
||
.cert-accent { position: absolute; top: 0; left: 0; right: 0; height: 200rpx; background: $yjyf-gradient-primary; }
|
||
.cert-card { position: relative; overflow: hidden; border-radius: 16rpx; background: $yjyf-bg-card; }
|
||
.cert-notice { padding: 28rpx; background: $yjyf-primary-bg; color: $yjyf-text-regular; font-size: 27rpx; line-height: 1.7; }
|
||
.cert-notice text { color: $yjyf-danger; }
|
||
.cert-content { padding: 32rpx 28rpx 40rpx; }
|
||
.cert-heading { color: $yjyf-text-main; font-size: 32rpx; font-weight: 600; }
|
||
.required, .reject { color: $yjyf-danger; }
|
||
.cert-description { margin-top: 16rpx; color: $yjyf-text-regular; font-size: 27rpx; line-height: 1.65; }
|
||
.reject { display: block; margin-top: 20rpx; font-size: 26rpx; }
|
||
.upload { width: 300rpx; min-height: 260rpx; box-sizing: border-box; margin: 32rpx auto 0; padding: 24rpx; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16rpx; color: $yjyf-primary; background: $yjyf-primary-bg; border: 2rpx dashed $yjyf-primary; font-size: 28rpx; font-weight: 600; }
|
||
.license-illustration { width: 200rpx; height: 140rpx; }
|
||
.license { width: 240rpx; height: 160rpx; }
|
||
.cert-fields { margin-top: 32rpx; }
|
||
.field { display: flex; align-items: center; min-height: 92rpx; border-bottom: 1rpx solid $yjyf-border-color; color: $yjyf-text-regular; font-size: 27rpx; }
|
||
.field text { width: 200rpx; flex-shrink: 0; }
|
||
.field input { flex: 1; min-width: 0; font-size: 27rpx; }
|
||
.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: 32rpx; background: $yjyf-gradient-primary; color: $yjyf-bg-card; font-size: 30rpx; }
|
||
</style>
|