文件
yjyf/yjyf-master-app/pages/master/security.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

222 行
9.3 KiB
Vue

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

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

<template>
<view class="page">
<YjyfNavBar theme="white" :title="setupFromPayment ? '设置支付密码' : '账号安全'" :border="true" :showBack="setupFromPayment ? true : null" :customBack="setupFromPayment" @back="handleBack" />
<template v-if="!setupFromPayment">
<view v-if="loaded" class="card">
<view class="row clickable-hover" @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 clickable-hover" @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 clickable-hover" @tap="logout">退出登录</view>
</template>
<view v-if="mode" 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="再次输入新登录密码" />
<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="onPhoneVerifyLogin">验证手机号并设置</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_login_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="再次输入支付密码" />
<template v-if="!status.has_payment_password && !status.has_login_password">
<text class="hint">当前尚未设置登录密码,请通过绑定微信手机号验证后设置支付密码。</text>
<!-- #ifdef MP-WEIXIN -->
<button class="primary" open-type="getPhoneNumber" :disabled="busy" @getphonenumber="onPhoneVerifyPayment">验证手机号并设置</button>
<!-- #endif -->
<!-- #ifndef MP-WEIXIN -->
<text class="hint">请在微信小程序内完成手机号验证,或先设置登录密码。</text>
<!-- #endif -->
</template>
<button v-else class="primary" :disabled="busy" @tap="savePassword">确认</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, isLogin, toLogin } from '@/utils/request.js';
import { finishPaymentSetup } from '@/utils/payment-setup.mjs';
const loaded = ref(false);
const busy = ref(false);
const mode = ref('');
const setupFromPayment = ref(false);
let setupOpened = false;
const status = ref({});
const oldPassword = ref('');
const newPassword = ref('');
const confirmPassword = ref('');
const sheetTitle = computed(() => mode.value === 'login' ? '登录密码' : '支付密码');
async function load() {
if (!isLogin()) {
toLogin('/pages/master/security');
return;
}
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 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 onPhoneVerifyLogin(event) {
const code = event.detail && event.detail.code;
if (!code) { uni.showToast({ title: '未完成手机号验证', icon: 'none' }); return; }
await savePassword(code);
}
async function onPhoneVerifyPayment(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,
phone_code: phoneCode,
new_password: newPassword.value
});
}
busy.value = false;
close();
uni.showToast({ title: '保存成功' });
if (setupFromPayment.value && firstSetup) {
try { await finishPaymentSetup(uni); } catch (e) { uni.showToast({ title: e.message, icon: 'none' }); }
} else {
await load();
}
} catch (e) {
} finally {
busy.value = false;
}
}
function handleBack() {
if (!busy.value) leaveSetup();
}
function cancelSheet() {
if (busy.value) return;
if (setupFromPayment.value) leaveSetup();
else close();
}
function logout() {
uni.showModal({
title: '退出登录',
content: '确认退出当前师傅账号?',
confirmColor: '#F0710D',
success: (result) => {
if (result.confirm) {
clearAuth();
uni.reLaunch({ url: '/pages/login/login' });
}
}
});
}
async function leaveSetup() {
try { await finishPaymentSetup(uni); } catch (e) { uni.showToast({ title: e.message, icon: 'none' }); }
}
onLoad((options) => {
setupFromPayment.value = !!(options && options.setupPayment === '1');
});
onBackPress(() => {
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: 20rpx; }
.row { display: flex; align-items: center; justify-content: space-between; min-height: 104rpx; border-bottom: 1rpx solid $yjyf-border-color; font-size: 28rpx; color: $yjyf-text-main; }
.row:last-child { border-bottom: 0; }
.value { display: flex; align-items: center; gap: 12rpx; color: $yjyf-text-secondary; font-size: 26rpx; }
.arrow { width: 28rpx; height: 28rpx; }
.logout { margin: 40rpx 24rpx; height: 92rpx; line-height: 92rpx; text-align: center; border-radius: 16rpx; background: $yjyf-bg-card; color: $yjyf-danger; font-size: 28rpx; font-weight: 600; }
.mask { position: fixed; inset: 0; z-index: 999; display: flex; align-items: flex-end; background: rgba(0,0,0,.45); }
.sheet { width: 100%; padding: 32rpx 28rpx 48rpx; border-radius: 24rpx 24rpx 0 0; background: $yjyf-bg-card; display: flex; flex-direction: column; gap: 20rpx; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8rpx; }
.title { font-size: 32rpx; font-weight: 700; color: $yjyf-text-main; }
.close { font-size: 26rpx; color: $yjyf-text-secondary; }
.input { height: 88rpx; padding: 0 24rpx; border-radius: 12rpx; background: $yjyf-bg-page; font-size: 28rpx; color: $yjyf-text-main; }
.hint { font-size: 24rpx; color: $yjyf-text-secondary; line-height: 1.5; }
.primary { width: 100%; height: 90rpx; line-height: 90rpx; border-radius: 45rpx; background: $yjyf-gradient-primary; color: #fff; font-size: 30rpx; font-weight: 600; border: none; }
.primary::after { border: none; }
</style>