- 后端后台管理:在师傅管理模块新增 resetpwd 功能,支持重置登录密码、支付密码或全部重置,并联动清理锁定状态与在线令牌 - 视图与脚本:新增 resetpwd.html 弹窗视图并在 master.js 与 index.html 中注册操作按钮与表单联动逻辑 - 师傅端接口:MasterAuth::setPaymentPassword 简化流程,依托已有登录态直接设置6位数字支付密码,并在修改登录密码时自动重置锁定状态 - 师傅端小程序:security.vue 全面升级账号安全中心界面视觉与交互,展示账号信息、认证状态并提供标准弹窗;清理 wxlogin.js 中冗余代码
480 行
16 KiB
Vue
480 行
16 KiB
Vue
<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="security-body">
|
||
<!-- 安全状态概览 -->
|
||
<view class="hero-card">
|
||
<image class="hero-ico" :src="isAccountSafe ? '/static/icons/shield-green.svg' : '/static/icons/info-orange.svg'" mode="aspectFit" />
|
||
<view class="hero-info">
|
||
<text class="hero-title">{{ isAccountSafe ? '账号安全保护中' : '建议完善安全设置' }}</text>
|
||
<text class="hero-sub">登录账号:{{ status.mobile || '-' }}</text>
|
||
</view>
|
||
</view>
|
||
|
||
<!-- 账号基础信息 -->
|
||
<view class="card">
|
||
<view class="card-head">
|
||
<text class="card-title">账号信息</text>
|
||
</view>
|
||
<view class="row">
|
||
<text class="row-label">绑定手机号</text>
|
||
<view class="row-right">
|
||
<text class="row-val">{{ status.mobile || '-' }}</text>
|
||
<text v-if="status.mobile" class="tag tag-success">已绑定</text>
|
||
</view>
|
||
</view>
|
||
<view class="row clickable-hover" @tap="goVerifyStatus">
|
||
<text class="row-label">实名认证</text>
|
||
<view class="row-right">
|
||
<text class="tag" :class="verifyTagClass">{{ verifyStatusText }}</text>
|
||
<image v-if="status.verify_status !== 'pass'" class="arrow" src="/static/icons/arrow-right.svg" mode="aspectFit" />
|
||
</view>
|
||
</view>
|
||
</view>
|
||
|
||
<!-- 安全凭证管理 -->
|
||
<view class="card">
|
||
<view class="card-head">
|
||
<text class="card-title">安全凭证</text>
|
||
</view>
|
||
<view class="row clickable-hover" @tap="openPassword('login')">
|
||
<view class="row-left">
|
||
<text class="row-label">登录密码</text>
|
||
<text class="row-desc">用于 H5 网页端手机号密码登录</text>
|
||
</view>
|
||
<view class="row-right">
|
||
<text class="row-val" :class="{ unset: !status.has_login_password }">{{ status.has_login_password ? '已设置' : '未设置' }}</text>
|
||
<image class="arrow" src="/static/icons/arrow-right.svg" mode="aspectFit" />
|
||
</view>
|
||
</view>
|
||
<view class="row clickable-hover" @tap="openPassword('payment')">
|
||
<view class="row-left">
|
||
<text class="row-label">支付密码</text>
|
||
<text class="row-desc">用于余额提现安全确认</text>
|
||
</view>
|
||
<view class="row-right">
|
||
<text class="row-val" :class="{ unset: !status.has_payment_password }">{{ status.has_payment_password ? '已设置' : '未设置' }}</text>
|
||
<image class="arrow" src="/static/icons/arrow-right.svg" mode="aspectFit" />
|
||
</view>
|
||
</view>
|
||
</view>
|
||
|
||
<view class="logout clickable-hover" @tap="logout">
|
||
<text>退出登录</text>
|
||
</view>
|
||
</view>
|
||
</template>
|
||
|
||
<!-- 密码设置 / 修改底部弹窗 -->
|
||
<view v-if="mode" class="mask" @tap="cancelSheet">
|
||
<view class="sheet" @tap.stop>
|
||
<view class="sheet-head">
|
||
<text class="title">{{ sheetTitle }}</text>
|
||
<text class="close" @tap="cancelSheet">取消</text>
|
||
</view>
|
||
|
||
<!-- 登录密码表单 -->
|
||
<template v-if="mode === 'login'">
|
||
<view v-if="status.has_login_password" class="input-box">
|
||
<input
|
||
v-model="oldPassword"
|
||
class="input-field"
|
||
:password="!showOldPwd"
|
||
placeholder="请输入原登录密码"
|
||
/>
|
||
<view class="eye-btn" @tap="showOldPwd = !showOldPwd">
|
||
<image class="eye-ico" :src="showOldPwd ? '/static/icons/login-eye-open.svg' : '/static/icons/login-eye-close.svg'" mode="aspectFit" />
|
||
</view>
|
||
</view>
|
||
<view class="input-box">
|
||
<input
|
||
v-model="newPassword"
|
||
class="input-field"
|
||
:password="!showNewPwd"
|
||
maxlength="30"
|
||
placeholder="新登录密码(6至30位非空字符)"
|
||
/>
|
||
<view class="eye-btn" @tap="showNewPwd = !showNewPwd">
|
||
<image class="eye-ico" :src="showNewPwd ? '/static/icons/login-eye-open.svg' : '/static/icons/login-eye-close.svg'" mode="aspectFit" />
|
||
</view>
|
||
</view>
|
||
<view class="input-box">
|
||
<input
|
||
v-model="confirmPassword"
|
||
class="input-field"
|
||
:password="!showConfirmPwd"
|
||
maxlength="30"
|
||
placeholder="再次输入新登录密码"
|
||
/>
|
||
<view class="eye-btn" @tap="showConfirmPwd = !showConfirmPwd">
|
||
<image class="eye-ico" :src="showConfirmPwd ? '/static/icons/login-eye-open.svg' : '/static/icons/login-eye-close.svg'" mode="aspectFit" />
|
||
</view>
|
||
</view>
|
||
<button class="primary" :disabled="busy" @tap="savePassword">
|
||
{{ status.has_login_password ? '确认修改' : '确认设置' }}
|
||
</button>
|
||
<text v-if="status.has_login_password" class="hint center-hint">如忘记原密码,请联系平台管理员在后台重置</text>
|
||
</template>
|
||
|
||
<!-- 支付密码表单 -->
|
||
<template v-else-if="mode === 'payment'">
|
||
<view v-if="status.has_payment_password" class="input-box">
|
||
<input
|
||
v-model="oldPassword"
|
||
class="input-field"
|
||
type="number"
|
||
:password="!showOldPwd"
|
||
maxlength="6"
|
||
placeholder="请输入原6位数字支付密码"
|
||
/>
|
||
<view class="eye-btn" @tap="showOldPwd = !showOldPwd">
|
||
<image class="eye-ico" :src="showOldPwd ? '/static/icons/login-eye-open.svg' : '/static/icons/login-eye-close.svg'" mode="aspectFit" />
|
||
</view>
|
||
</view>
|
||
<view class="input-box">
|
||
<input
|
||
v-model="newPassword"
|
||
class="input-field"
|
||
type="number"
|
||
:password="!showNewPwd"
|
||
maxlength="6"
|
||
placeholder="请输入6位数字支付密码"
|
||
/>
|
||
<view class="eye-btn" @tap="showNewPwd = !showNewPwd">
|
||
<image class="eye-ico" :src="showNewPwd ? '/static/icons/login-eye-open.svg' : '/static/icons/login-eye-close.svg'" mode="aspectFit" />
|
||
</view>
|
||
</view>
|
||
<view class="input-box">
|
||
<input
|
||
v-model="confirmPassword"
|
||
class="input-field"
|
||
type="number"
|
||
:password="!showConfirmPwd"
|
||
maxlength="6"
|
||
placeholder="再次输入6位数字支付密码"
|
||
/>
|
||
<view class="eye-btn" @tap="showConfirmPwd = !showConfirmPwd">
|
||
<image class="eye-ico" :src="showConfirmPwd ? '/static/icons/login-eye-open.svg' : '/static/icons/login-eye-close.svg'" mode="aspectFit" />
|
||
</view>
|
||
</view>
|
||
<button class="primary" :disabled="busy" @tap="savePassword">
|
||
{{ status.has_payment_password ? '确认修改' : '确认设置' }}
|
||
</button>
|
||
<text v-if="status.has_payment_password" class="hint center-hint">如忘记原支付密码,请联系平台管理员在后台重置</text>
|
||
</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 showOldPwd = ref(false);
|
||
const showNewPwd = ref(false);
|
||
const showConfirmPwd = ref(false);
|
||
|
||
const isAccountSafe = computed(() => !!(status.value.mobile && status.value.has_payment_password));
|
||
|
||
const verifyStatusText = computed(() => {
|
||
const map = { pass: '已认证', pending: '审核中', reject: '未通过', draft: '未认证' };
|
||
return map[status.value.verify_status] || '未认证';
|
||
});
|
||
|
||
const verifyTagClass = computed(() => {
|
||
const st = status.value.verify_status;
|
||
if (st === 'pass') return 'tag-success';
|
||
if (st === 'pending') return 'tag-warning';
|
||
if (st === 'reject') return 'tag-danger';
|
||
return 'tag-muted';
|
||
});
|
||
|
||
const sheetTitle = computed(() => {
|
||
if (mode.value === 'login') {
|
||
return status.value.has_login_password ? '修改登录密码' : '设置登录密码';
|
||
}
|
||
return status.value.has_payment_password ? '修改支付密码' : '设置支付密码';
|
||
});
|
||
|
||
async function load() {
|
||
if (!isLogin()) {
|
||
toLogin('/pages/master/security');
|
||
return;
|
||
}
|
||
try {
|
||
status.value = await api.securityStatus();
|
||
loaded.value = true;
|
||
} catch (e) {}
|
||
}
|
||
|
||
function resetFormFields() {
|
||
oldPassword.value = '';
|
||
newPassword.value = '';
|
||
confirmPassword.value = '';
|
||
showOldPwd.value = false;
|
||
showNewPwd.value = false;
|
||
showConfirmPwd.value = false;
|
||
}
|
||
|
||
function close() {
|
||
if (busy.value) return;
|
||
mode.value = '';
|
||
resetFormFields();
|
||
}
|
||
|
||
function openPassword(which) {
|
||
resetFormFields();
|
||
mode.value = which;
|
||
}
|
||
|
||
function goVerifyStatus() {
|
||
if (status.value.verify_status === 'pass') return;
|
||
uni.navigateTo({ url: '/pages/master/apply' });
|
||
}
|
||
|
||
function validPassword() {
|
||
const isPayment = mode.value === 'payment';
|
||
const needOld = isPayment ? status.value.has_payment_password : status.value.has_login_password;
|
||
if (needOld && !oldPassword.value) {
|
||
uni.showToast({ title: '请输入原密码', icon: 'none' });
|
||
return false;
|
||
}
|
||
|
||
if (isPayment) {
|
||
if (!/^\d{6}$/.test(newPassword.value)) {
|
||
uni.showToast({ title: '支付密码须为6位数字', icon: 'none' });
|
||
return false;
|
||
}
|
||
} else {
|
||
if (!/^\S{6,30}$/.test(newPassword.value)) {
|
||
uni.showToast({ title: '登录密码须为6至30位非空字符', icon: 'none' });
|
||
return false;
|
||
}
|
||
}
|
||
|
||
if (newPassword.value !== confirmPassword.value) {
|
||
uni.showToast({ title: '两次输入的新密码不一致', icon: 'none' });
|
||
return false;
|
||
}
|
||
return true;
|
||
}
|
||
|
||
async function savePassword() {
|
||
if (busy.value || !validPassword()) 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' }), 800);
|
||
return;
|
||
}
|
||
|
||
const firstSetup = !status.value.has_payment_password;
|
||
if (firstSetup) {
|
||
await api.setPaymentPassword({ new_password: newPassword.value });
|
||
} else {
|
||
await api.changePaymentPassword({
|
||
old_password: oldPassword.value,
|
||
new_password: newPassword.value
|
||
});
|
||
}
|
||
|
||
busy.value = false;
|
||
close();
|
||
uni.showToast({ title: firstSetup ? '设置成功' : '修改成功', icon: 'success' });
|
||
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: async (result) => {
|
||
if (result.confirm) {
|
||
try { await api.logout(); } catch (e) {}
|
||
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; padding-bottom: calc(48rpx + env(safe-area-inset-bottom)); }
|
||
.security-body { padding-top: 20rpx; }
|
||
|
||
.hero-card {
|
||
margin: 0 $yjyf-space-md 20rpx;
|
||
padding: 28rpx 32rpx;
|
||
background: $yjyf-bg-card;
|
||
border-radius: $yjyf-radius-md;
|
||
box-shadow: $yjyf-shadow-card;
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 20rpx;
|
||
}
|
||
.hero-ico { width: 52rpx; height: 52rpx; flex-shrink: 0; }
|
||
.hero-info { display: flex; flex-direction: column; gap: 6rpx; min-width: 0; }
|
||
.hero-title { font-size: $yjyf-font-title; font-weight: 700; color: $yjyf-text-main; }
|
||
.hero-sub { font-size: $yjyf-font-sub; color: $yjyf-text-secondary; }
|
||
|
||
.card {
|
||
margin: 0 $yjyf-space-md 20rpx;
|
||
padding: 0 32rpx;
|
||
background: $yjyf-bg-card;
|
||
border-radius: $yjyf-radius-md;
|
||
box-shadow: $yjyf-shadow-card;
|
||
}
|
||
.card-head { padding: 26rpx 0 12rpx; }
|
||
.card-title { font-size: $yjyf-font-sub; color: $yjyf-text-secondary; font-weight: 600; }
|
||
|
||
.row {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
gap: 16rpx;
|
||
min-height: 108rpx;
|
||
border-top: 1rpx solid $yjyf-border-color;
|
||
}
|
||
.row-left { display: flex; flex-direction: column; gap: 4rpx; }
|
||
.row-label { font-size: $yjyf-font-body; color: $yjyf-text-main; }
|
||
.row-desc { font-size: $yjyf-font-micro; color: $yjyf-text-muted; }
|
||
.row-right { display: flex; align-items: center; gap: 12rpx; flex-shrink: 0; }
|
||
.row-val { font-size: $yjyf-font-sub; color: $yjyf-text-secondary; }
|
||
.row-val.unset { color: $yjyf-warning; font-weight: 500; }
|
||
.arrow { width: 24rpx; height: 24rpx; }
|
||
|
||
.tag {
|
||
padding: 6rpx 16rpx;
|
||
border-radius: $yjyf-radius-pill;
|
||
font-size: $yjyf-font-micro;
|
||
font-weight: 600;
|
||
line-height: 1;
|
||
}
|
||
.tag-success { background: rgba(47, 168, 79, 0.1); color: $yjyf-success; }
|
||
.tag-warning { background: rgba(249, 141, 37, 0.12); color: $yjyf-warning; }
|
||
.tag-danger { background: rgba(232, 51, 27, 0.1); color: $yjyf-danger; }
|
||
.tag-muted { background: $yjyf-bg-page; color: $yjyf-text-secondary; }
|
||
|
||
.logout {
|
||
margin: 40rpx $yjyf-space-md 0;
|
||
height: 92rpx;
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
border-radius: $yjyf-radius-pill;
|
||
background: $yjyf-bg-card;
|
||
box-shadow: $yjyf-shadow-card;
|
||
color: $yjyf-danger;
|
||
font-size: $yjyf-font-body;
|
||
font-weight: 600;
|
||
}
|
||
|
||
.mask { position: fixed; inset: 0; z-index: 999; display: flex; align-items: flex-end; background: rgba(0, 0, 0, 0.45); }
|
||
.sheet {
|
||
width: 100%;
|
||
padding: 32rpx 32rpx calc(40rpx + env(safe-area-inset-bottom));
|
||
border-radius: $yjyf-radius-lg $yjyf-radius-lg 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: 4rpx; }
|
||
.title { font-size: $yjyf-font-title; font-weight: 700; color: $yjyf-text-main; }
|
||
.close { font-size: $yjyf-font-sub; color: $yjyf-text-secondary; padding: 8rpx 0 8rpx 16rpx; }
|
||
|
||
.input-box {
|
||
height: 92rpx;
|
||
padding: 0 20rpx 0 24rpx;
|
||
border-radius: $yjyf-radius-sm;
|
||
background: $yjyf-bg-page;
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 12rpx;
|
||
}
|
||
.input-field { flex: 1; min-width: 0; height: 92rpx; font-size: $yjyf-font-body; color: $yjyf-text-main; }
|
||
.eye-btn { width: 56rpx; height: 56rpx; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
|
||
.eye-ico { width: 34rpx; height: 34rpx; }
|
||
|
||
.hint { font-size: $yjyf-font-micro; color: $yjyf-text-muted; line-height: 1.5; }
|
||
.center-hint { text-align: center; }
|
||
.primary {
|
||
width: 100%;
|
||
height: 90rpx;
|
||
line-height: 90rpx;
|
||
border-radius: $yjyf-radius-pill;
|
||
background: $yjyf-gradient-primary;
|
||
box-shadow: $yjyf-shadow-button;
|
||
color: $yjyf-text-inverse;
|
||
font-size: $yjyf-font-body;
|
||
font-weight: 700;
|
||
border: none;
|
||
}
|
||
.primary::after { border: none; }
|
||
</style>
|