文件
yjyf/yjyf-master-app/pages/master/auth.vue
MiAn 14533eadb7 feat: 用户端与师傅端双小程序架构解耦,新增师傅独立认证及超时自动关单机制
1. 账号体系与数据库解耦:
   - 师傅表 fa_master 解除对 fa_user.id 的外键依赖,升级为独立认证账号主表;
   - 新增师傅端独立支撑表:fa_master_security、fa_master_token、fa_master_wechat、fa_master_agreement_read;
   - 新增工单超时未接单自动关闭与原路退款配置(order_unaccepted_close_days)。

2. 服务端(Server):
   - 新增师傅端独立 API 控制器与认证库(MasterAuth, MasterBase, MasterMessage, MasterSecurity, MasterToken);
   - WxLogin 支持双小程序端(user/master)独立换取 session_key、openid 与 access_token;
   - 新增控制台调度命令 php think order:autoclose,支持订单超时自动关闭与售后退款闭环;
   - 修复 PHP 8.5 兼容性问题(Request.php 的 (bool) 强制转换);
   - 系统业务配置全面收敛至数据库 fa_config 及 site.php。

3. 小程序端:
   - yjyf-app(用户端):彻底剥离师傅端路由、组件及静态资源,增加隐私授权弹窗与评价模块;
   - yjyf-master-app(师傅端):全新独立微信小程序工程(wx140d90ceda786107),实现工作台、接单大厅、资质认证、工单协同与钱包提现完整闭环。
2026-11-23 15:10:30 +08:00

778 行
21 KiB
Vue

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

<template>
<view class="auth-page">
<!-- 1. 白底简约顶部导航栏(对标奇兵到家) -->
<YjyfNavBar theme="white" title="实名认证" :border="true" />
<!-- 2. 国家电子商务法合规提示横幅(对标奇兵到家米黄浅底 + 绿色盾牌) -->
<view class="policy-banner">
<image class="policy-ico" src="/static/icons/shield-green.svg" mode="aspectFit" />
<text class="policy-txt">按国家电子商务法要求,上门服务需实名。实名信息仅用于身份验证,平台将严格保障您的信息安全。</text>
</view>
<view class="content-body">
<!-- 3. 上传身份证照片(置顶核心卡片,对标奇兵到家) -->
<view class="upload-card">
<view class="upload-title">上传身份证照片</view>
<view class="upload-warn">以下实名信息必须与您银行卡、支付宝的实名信息一致,避免无法收到工钱。</view>
<!-- 身份证人像面 -->
<view class="idcard-uploader-item">
<view class="idcard-box clickable-hover" @tap="uploadCert('front')">
<!-- 识别中动效遮罩 -->
<view class="loading-overlay" v-if="uploadingSide === 'front'">
<view class="loading-spinner"></view>
<text class="loading-overlay-txt">正在识别证件信息...</text>
</view>
<template v-else-if="form.idcard_front">
<image class="idcard-preview-img" :src="getWatermarkUrl(form.idcard_front)" mode="aspectFit" />
<!-- 平台安全防伪水印(对标奇兵到家:白色贯穿细斜线 + 居中文案,无暗色遮罩) -->
<view class="watermark-wrap">
<view class="watermark-diagonal-line"></view>
<text class="watermark-txt">仅用于身份信息认证</text>
</view>
<view class="reupload-tag">
<text class="reupload-txt">点击更换</text>
</view>
</template>
<template v-else>
<view class="uploader-ph">
<image class="uploader-cam-ico" src="/static/icons/camera.svg" mode="aspectFit" />
<text class="uploader-tip">点击拍摄 / 上传人像面</text>
<text class="uploader-sub">上传后自动提取姓名与身份证号</text>
</view>
</template>
</view>
<text class="idcard-sublabel">身份证人像面</text>
</view>
<!-- 身份证国徽面 -->
<view class="idcard-uploader-item">
<view class="idcard-box clickable-hover" @tap="uploadCert('back')">
<!-- 校验中动效遮罩 -->
<view class="loading-overlay" v-if="uploadingSide === 'back'">
<view class="loading-spinner"></view>
<text class="loading-overlay-txt">正在核验证件有效期限...</text>
</view>
<template v-else-if="form.idcard_back">
<image class="idcard-preview-img" :src="getWatermarkUrl(form.idcard_back)" mode="aspectFit" />
<view class="watermark-wrap">
<view class="watermark-diagonal-line"></view>
<text class="watermark-txt">仅用于身份信息认证</text>
</view>
<view class="reupload-tag">
<text class="reupload-txt">点击更换</text>
</view>
</template>
<template v-else>
<view class="uploader-ph">
<image class="uploader-cam-ico" src="/static/icons/camera.svg" mode="aspectFit" />
<text class="uploader-tip">点击拍摄 / 上传国徽面</text>
<text class="uploader-sub">上传后自动核验证件有效期限</text>
</view>
</template>
</view>
<view class="sublabel-wrap">
<text class="idcard-sublabel">身份证国徽面</text>
<view class="expired-tag-badge" v-if="backOcrSuccess && isExpired">
<image class="expired-tag-ico" src="/static/icons/alert-circle-red.svg" mode="aspectFit" />
<text class="expired-tag-txt">证件已过期</text>
</view>
</view>
</view>
<!-- 过期醒目警示条(仅当检测到过期时才展示) -->
<view class="expired-banner" v-if="isExpired">
<image class="expired-ico" src="/static/icons/alert-circle-red.svg" mode="aspectFit" />
<view class="expired-content">
<text class="expired-title">身份证已超过有效期限</text>
<text class="expired-desc">有效截止日期:{{ backOcrValidDate }}。根据国家法规要求,已过期证件无法通过实名认证,请更换有效身份证重新上传。</text>
</view>
</view>
</view>
<!-- 4. 身份信息核对卡片(自动填写,支持手动核对与修改) -->
<view class="form-card">
<view class="form-row">
<text class="row-label">真实姓名</text>
<input
class="row-input"
v-model="form.realname"
placeholder="上传人像面后自动填写"
placeholder-style="color: #BBBBBB;"
/>
</view>
<view class="form-divider"></view>
<view class="form-row">
<text class="row-label">身份证号码</text>
<input
class="row-input"
v-model="form.idcard_no"
maxlength="18"
placeholder="上传人像面后自动填写"
placeholder-style="color: #BBBBBB;"
/>
</view>
<!-- 国徽面识别出有效期限后,仅在单处清晰呈现 -->
<template v-if="backOcrSuccess && backOcrValidDate">
<view class="form-divider"></view>
<view class="form-row">
<text class="row-label">有效期限</text>
<text class="row-val" :class="{ 'text-danger': isExpired }">
{{ backOcrValidDate }}
</text>
<text class="expire-badge" :class="isExpired ? 'danger' : 'success'">
{{ isExpired ? '已过期' : '有效' }}
</text>
</view>
</template>
</view>
</view>
<!-- 5. 底部全宽主橙大按钮(对标奇兵到家,过期直接禁用) -->
<view class="bottom-bar">
<view
class="submit-btn clickable-hover"
:class="{ disabled: isSubmitDisabled }"
@tap="submit"
>
<text class="submit-txt">{{ submitButtonText }}</text>
</view>
</view>
<YjyfPrivacyPopup />
</view>
</template>
<script setup>
import { ref, reactive, computed, onMounted } from 'vue';
import { onShow } from '@dcloudio/uni-app';
import YjyfNavBar from '@/components/YjyfNavBar.vue';
import YjyfPrivacyPopup from '@/components/YjyfPrivacyPopup.vue';
import api from '@/utils/api.js';
import { isLogin, toLogin, getUser } from '@/utils/request.js';
const submitting = ref(false);
const uploadingSide = ref(''); // 'front' | 'back' | '' 互不干扰独立状态
const isSelectingImage = ref(false); // 正在选择图片保护锁,防止 onShow 冲刷表单
const hasInitialLoaded = ref(false); // 是否已完成首屏初始化
const frontOcrSuccess = ref(false);
const backOcrSuccess = ref(false);
const backOcrValidDate = ref('');
const isExpired = ref(false); // 是否已过期
const form = reactive({
realname: '',
mobile: '',
idcard_no: '',
idcard_front: '',
idcard_back: '',
valid_date: '',
city: '',
skills: []
});
// 方案1:腾讯云数据万象动态防伪水印(不破坏原图,边缘节点实时渲染)
function getWatermarkUrl(url) {
if (!url) return '';
if ((url.includes('myqcloud.com') || url.includes('cos.')) && !url.includes('watermark')) {
const b64Text = '5LuF55So5LqO6Lqr5Lu95L-h5oGv6K6k6K-B'; // "仅用于身份信息认证"
const b64Color = 'I0ZGRkZGRg'; // "#FFFFFF"
const delim = url.includes('?') ? '&' : '?';
return `${url}${delim}watermark/2/text/${b64Text}/fill/${b64Color}/fontsize/40/dissolve/85/shadow/60/gravity/center/degree/340`;
}
return url;
}
// 智能解析并检测有效期是否过期
function checkExpired(validDateStr) {
const str = (validDateStr || '').trim();
if (!str) {
return { is_expired: false, desc: '' };
}
if (str.includes('长期')) {
return { is_expired: false, desc: '长期有效' };
}
const matches = str.match(/\d{4}[\.\-\/年]\d{2}[\.\-\/月]\d{2}/g);
if (matches && matches.length > 0) {
const lastDateStr = matches[matches.length - 1].replace(/[年\/]/g, '-').replace(/[月日\.]/g, '-');
const parts = lastDateStr.split('-').filter(Boolean);
if (parts.length >= 3) {
const y = parseInt(parts[0], 10);
const m = parseInt(parts[1], 10) - 1;
const d = parseInt(parts[2], 10);
const expireDate = new Date(y, m, d, 23, 59, 59);
const now = new Date();
const expired = expireDate.getTime() < now.getTime();
const formatted = `${parts[0]}.${parts[1]}.${parts[2]}`;
return {
is_expired: expired,
desc: expired ? `已于 ${formatted} 过期` : `有效期至 ${formatted}`
};
}
}
return { is_expired: false, desc: str };
}
// 独立上传证件照并自动识别回填
function uploadCert(side) {
if (!isLogin()) { toLogin(); return; }
if (uploadingSide.value || submitting.value) return;
// 加上防冲刷锁
isSelectingImage.value = true;
uni.chooseImage({
count: 1,
sizeType: ['compressed'],
sourceType: ['album', 'camera'],
success: async (res) => {
const temp = res.tempFilePaths[0];
uploadingSide.value = side;
try {
// 1. 上传图片至服务器/COS
const up = await api.upload(temp, 'cert');
const imgUrl = up.fullurl || up.url;
if (side === 'front') {
form.idcard_front = imgUrl;
// 2. 调用识别接口提取姓名与身份证号,直接自动填入表单
try {
const ocrRes = await api.masterOcrIdCard({ image: imgUrl, side: 'front' });
if (ocrRes && (ocrRes.name || ocrRes.idcard_no)) {
if (ocrRes.name) form.realname = ocrRes.name;
if (ocrRes.idcard_no) form.idcard_no = ocrRes.idcard_no;
frontOcrSuccess.value = true;
uni.showToast({ title: '人像面识别成功', icon: 'success', duration: 1500 });
} else {
uni.showToast({ title: '人像面已上传,请核对姓名与证件号', icon: 'none' });
}
} catch (ocrErr) {
const errMsg = ocrErr?.message || ocrErr?.msg || '未能清晰识别,请手动核对姓名与证件号';
uni.showToast({ title: errMsg, icon: 'none', duration: 2500 });
}
} else {
form.idcard_back = imgUrl;
// 校验国徽面与有效期限
try {
const ocrBack = await api.masterOcrIdCard({ image: imgUrl, side: 'back' });
const rawValidDate = ocrBack?.valid_date || '';
form.valid_date = rawValidDate;
backOcrValidDate.value = rawValidDate;
backOcrSuccess.value = true;
let expired = false;
if (ocrBack?.is_expired !== undefined) {
expired = !!ocrBack.is_expired;
} else {
const chk = checkExpired(rawValidDate);
expired = chk.is_expired;
}
isExpired.value = expired;
if (expired) {
uni.showModal({
title: '身份证已过期提醒',
content: `检测到该身份证有效截止日期为【${rawValidDate}】,已过有效期限,无法通过实名认证,请更换有效身份证重新上传。`,
showCancel: false,
confirmText: '我知道了',
confirmColor: '#E8331B'
});
} else {
uni.showToast({ title: '国徽面核验通过', icon: 'success', duration: 1500 });
}
} catch (e) {
backOcrSuccess.value = true;
uni.showToast({ title: '国徽面已上传,请确保照片清晰', icon: 'none' });
}
}
} catch (e) {
uni.showToast({ title: '证件上传失败,请重试', icon: 'none' });
} finally {
uploadingSide.value = '';
isSelectingImage.value = false;
}
},
fail: () => {
isSelectingImage.value = false;
}
});
}
async function load() {
if (!isLogin()) { toLogin(); return; }
try {
const res = await api.masterInfo();
if (res && res.applied && res.master) {
if (!form.realname && res.master.realname) form.realname = res.master.realname;
if (!form.mobile && res.master.mobile) form.mobile = res.master.mobile;
if (!form.idcard_no && res.master.idcard_no) form.idcard_no = res.master.idcard_no;
if (!form.idcard_front && res.master.idcard_front) form.idcard_front = res.master.idcard_front;
if (!form.idcard_back && res.master.idcard_back) form.idcard_back = res.master.idcard_back;
if (!form.city && res.master.city) form.city = res.master.city;
if (!form.skills.length && res.skills) {
form.skills = res.skills.map(s => s.cat_id).filter(Boolean);
}
} else {
const u = getUser();
if (u && !form.mobile) form.mobile = u.mobile || '';
}
} catch (e) {
uni.showToast({ title: (e && (e.message || e.msg)) || '获取认证信息失败', icon: 'none' });
} finally {
hasInitialLoaded.value = true;
}
}
// 提交按钮禁用状态
const isSubmitDisabled = computed(() => {
if (submitting.value || !!uploadingSide.value) return true;
if (isExpired.value) return true;
return false;
});
// 提交按钮文案
const submitButtonText = computed(() => {
if (submitting.value) return '公安二要素实名核验中...';
if (uploadingSide.value) return '证件上传识别中...';
if (isExpired.value) return '身份证已过期,无法提交';
return '提交';
});
async function submit() {
if (!isLogin()) { toLogin(); return; }
if (isSubmitDisabled.value) {
if (isExpired.value) {
uni.showToast({ title: '身份证已过期,请上传最新有效证件', icon: 'none', duration: 2500 });
}
return;
}
if (!form.idcard_front || !form.idcard_back) {
uni.showToast({ title: '请先完整上传身份证人像面和国徽面', icon: 'none' });
return;
}
const realname = (form.realname || '').trim();
const idcard = (form.idcard_no || '').trim();
if (!realname) {
uni.showToast({ title: '请填写真实姓名', icon: 'none' });
return;
}
if (!idcard) {
uni.showToast({ title: '请填写18位二代身份证号', icon: 'none' });
return;
}
if (!/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(idcard)) {
uni.showToast({ title: '身份证号码格式不正确', icon: 'none' });
return;
}
const normalizedCity = (form.city || '').trim();
const skillsPayload = Array.isArray(form.skills)
? form.skills.map(id => Number(id)).filter(id => id > 0)
: [];
if (!normalizedCity || skillsPayload.length === 0) {
uni.showModal({
title: '请先完善入驻信息',
content: '尚未选择服务城市或技能类目,请先在师傅入驻页面完善后再进行实名认证。',
confirmText: '去完善',
cancelText: '取消',
success: (modalRes) => {
if (modalRes.confirm) {
uni.redirectTo({ url: '/pages/master/apply' });
}
}
});
return;
}
submitting.value = true;
uni.showLoading({ title: '公安二要素实名核验中...', mask: true });
try {
const payload = {
realname: realname,
mobile: form.mobile || (getUser() ? getUser().mobile : ''),
idcard_no: idcard,
idcard_front: form.idcard_front,
idcard_back: form.idcard_back,
valid_date: form.valid_date || backOcrValidDate.value || '',
city: normalizedCity
};
skillsPayload.forEach((id, i) => { payload['skills[' + i + ']'] = id; });
await api.masterApply(payload);
uni.hideLoading();
uni.showToast({ title: '提交成功,等待审核', icon: 'success' });
setTimeout(() => {
uni.navigateBack({
fail: () => uni.reLaunch({ url: '/pages/master/hall?tab=3' })
});
}, 1200);
} catch (e) {
uni.hideLoading();
} finally {
submitting.value = false;
}
}
onMounted(() => {
if (!hasInitialLoaded.value) {
load();
}
});
onShow(() => {
if (isSelectingImage.value) {
return;
}
if (!hasInitialLoaded.value) {
load();
}
});
</script>
<style lang="scss" scoped>
@import '@/uni.scss';
.auth-page {
min-height: 100vh;
background: #F5F6F8;
padding-bottom: calc(160rpx + env(safe-area-inset-bottom));
}
/* 顶部合规提示栏(对标奇兵到家米黄浅底) */
.policy-banner {
display: flex;
align-items: flex-start;
gap: 16rpx;
background: #FFF7EC;
padding: 22rpx 32rpx;
border-bottom: 1rpx solid #FFE9D3;
}
.policy-ico {
width: 32rpx;
height: 32rpx;
flex-shrink: 0;
margin-top: 4rpx;
}
.policy-txt {
font-size: 24rpx;
line-height: 1.55;
color: #8C5320;
}
.content-body {
padding: 24rpx;
}
/* 1. 证件上传卡片(置顶,对标奇兵到家) */
.upload-card {
background: #FFFFFF;
border-radius: 20rpx;
padding: 32rpx;
margin-bottom: 24rpx;
box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.03);
}
.upload-title {
font-size: 32rpx;
font-weight: 700;
color: #1F1F1F;
margin-bottom: 12rpx;
}
.upload-warn {
font-size: 24rpx;
line-height: 1.5;
color: #F0710D;
margin-bottom: 32rpx;
}
.idcard-uploader-item {
margin-bottom: 32rpx;
display: flex;
flex-direction: column;
align-items: center;
}
.idcard-box {
width: 100%;
height: 330rpx;
background: #111111; // 对标奇兵到家深色承托底
border-radius: 16rpx;
display: flex;
align-items: center;
justify-content: center;
position: relative;
overflow: hidden;
}
.idcard-preview-img {
width: 100%;
height: 100%;
}
/* 识别中的动效遮罩 */
.loading-overlay {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0, 0, 0, 0.65);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
z-index: 20;
}
.loading-spinner {
width: 52rpx;
height: 52rpx;
border: 4rpx solid #FFFFFF;
border-top-color: #F0710D;
border-radius: 50%;
animation: spin 0.8s linear infinite;
margin-bottom: 16rpx;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.loading-overlay-txt {
font-size: 26rpx;
color: #FFFFFF;
}
/*
* 平台安全防伪水印(1:1 对标奇兵到家):
* 无全屏暗黑遮罩,采用白色贯穿细斜线 + 居中文本,字迹清爽透亮,不遮盖证件关键信息
*/
.watermark-wrap {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
display: flex;
align-items: center;
justify-content: center;
pointer-events: none;
overflow: hidden;
}
.watermark-diagonal-line {
position: absolute;
top: 50%;
left: -20%;
width: 140%;
height: 2rpx;
background: rgba(255, 255, 255, 0.75);
transform: rotate(-24deg);
box-shadow: 0 1rpx 4rpx rgba(0, 0, 0, 0.4);
}
.watermark-txt {
position: relative;
z-index: 2;
color: #FFFFFF;
font-size: 30rpx;
font-weight: 500;
letter-spacing: 2rpx;
text-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.8);
}
.reupload-tag {
position: absolute;
bottom: 14rpx;
right: 14rpx;
background: rgba(0, 0, 0, 0.6);
border-radius: 8rpx;
padding: 6rpx 14rpx;
z-index: 10;
}
.reupload-txt {
color: #FFFFFF;
font-size: 22rpx;
}
.uploader-ph {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 20rpx;
background: #F7F8FA;
width: 100%;
height: 100%;
border: 2rpx dashed #CFD5DE;
box-sizing: border-box;
}
.uploader-cam-ico {
width: 68rpx;
height: 68rpx;
margin-bottom: 16rpx;
opacity: 0.75;
}
.uploader-tip {
font-size: 28rpx;
font-weight: 600;
color: #444444;
margin-bottom: 8rpx;
}
.uploader-sub {
font-size: 22rpx;
color: #999999;
}
.idcard-sublabel {
font-size: 28rpx;
color: #444444;
margin-top: 18rpx;
}
.sublabel-wrap {
display: flex;
align-items: center;
justify-content: center;
gap: 12rpx;
margin-top: 18rpx;
}
.expired-tag-badge {
display: flex;
align-items: center;
gap: 6rpx;
}
.expired-tag-ico {
width: 26rpx;
height: 26rpx;
}
.expired-tag-txt {
font-size: 24rpx;
font-weight: 600;
color: #E8331B;
}
/* 过期警示横幅 */
.expired-banner {
display: flex;
align-items: flex-start;
gap: 16rpx;
background: #FFF2F0;
border: 1rpx solid #FFCCC7;
border-radius: 12rpx;
padding: 20rpx;
margin-top: 10rpx;
}
.expired-ico {
width: 36rpx;
height: 36rpx;
flex-shrink: 0;
margin-top: 4rpx;
}
.expired-content {
flex: 1;
display: flex;
flex-direction: column;
gap: 6rpx;
}
.expired-title {
font-size: 26rpx;
font-weight: 700;
color: #E8331B;
}
.expired-desc {
font-size: 22rpx;
line-height: 1.5;
color: #A8071A;
}
/* 2. 身份信息核对卡片(次置,纯净表单,对标奇兵到家) */
.form-card {
background: #FFFFFF;
border-radius: 20rpx;
padding: 0 32rpx;
margin-bottom: 24rpx;
box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.03);
}
.form-row {
display: flex;
align-items: center;
height: 110rpx;
}
.row-label {
width: 190rpx;
font-size: 30rpx;
color: #333333;
flex-shrink: 0;
}
.row-input {
flex: 1;
font-size: 30rpx;
font-weight: 500;
color: #1F1F1F;
}
.row-val {
flex: 1;
font-size: 28rpx;
font-weight: 500;
color: #333333;
&.text-danger {
color: #E8331B;
}
}
.expire-badge {
font-size: 22rpx;
border-radius: 6rpx;
padding: 2rpx 10rpx;
&.success {
color: #2FA84F;
background: #E8F7EC;
}
&.danger {
color: #E8331B;
background: #FFF2F0;
}
}
.form-divider {
height: 1rpx;
background: #F0F0F2;
}
/* 3. 底部固定提交大按钮(对标奇兵到家橙色大圆角) */
.bottom-bar {
position: fixed;
bottom: 0;
left: 0;
right: 0;
background: #FFFFFF;
padding: 20rpx 32rpx calc(20rpx + env(safe-area-inset-bottom));
box-shadow: 0 -4rpx 16rpx rgba(0, 0, 0, 0.04);
z-index: 100;
}
.submit-btn {
width: 100%;
height: 92rpx;
background: $yjyf-gradient-primary;
border-radius: 46rpx;
display: flex;
align-items: center;
justify-content: center;
box-shadow: 0 8rpx 20rpx rgba(240, 113, 13, 0.28);
&.disabled {
background: #D8D8D8;
box-shadow: none;
opacity: 0.8;
}
}
.submit-txt {
font-size: 32rpx;
font-weight: 700;
color: #FFFFFF;
letter-spacing: 2rpx;
}
</style>