feat(master): 后台增加师傅密码重置功能并优化师傅端账号安全页面
- 后端后台管理:在师傅管理模块新增 resetpwd 功能,支持重置登录密码、支付密码或全部重置,并联动清理锁定状态与在线令牌 - 视图与脚本:新增 resetpwd.html 弹窗视图并在 master.js 与 index.html 中注册操作按钮与表单联动逻辑 - 师傅端接口:MasterAuth::setPaymentPassword 简化流程,依托已有登录态直接设置6位数字支付密码,并在修改登录密码时自动重置锁定状态 - 师傅端小程序:security.vue 全面升级账号安全中心界面视觉与交互,展示账号信息、认证状态并提供标准弹窗;清理 wxlogin.js 中冗余代码
这个提交包含在:
@@ -841,4 +841,80 @@ class Master extends Backend
|
||||
}
|
||||
$this->success($target === 'disabled' ? '已停用该师傅账号并强制下线' : '已恢复启用该师傅账号');
|
||||
}
|
||||
|
||||
/**
|
||||
* 后台重置师傅登录密码或支付密码
|
||||
*/
|
||||
public function resetpwd($ids = null)
|
||||
{
|
||||
$id = (int)($ids ?: $this->request->param('ids'));
|
||||
$row = $this->model->find($id);
|
||||
if (!$row) {
|
||||
$this->error(__('No Results were found'));
|
||||
}
|
||||
$mid = (int)$row['id'];
|
||||
$security = Db::name('master_security')->where('master_id', $mid)->find();
|
||||
|
||||
if ($this->request->isPost()) {
|
||||
$this->token();
|
||||
$params = $this->request->post('row/a', []);
|
||||
$type = trim((string)($params['type'] ?? ''));
|
||||
$newPassword = (string)($params['new_password'] ?? '');
|
||||
|
||||
if (!in_array($type, ['login', 'payment', 'both'], true)) {
|
||||
$this->error('请选择有效的重置类型');
|
||||
}
|
||||
if ($type === 'login' && $newPassword !== '' && !preg_match('/^\S{6,30}$/', $newPassword)) {
|
||||
$this->error('新登录密码须为6至30位非空字符');
|
||||
}
|
||||
if ($type === 'payment' && $newPassword !== '' && !preg_match('/^\d{6}$/', $newPassword)) {
|
||||
$this->error('新支付密码须为6位数字');
|
||||
}
|
||||
|
||||
Db::startTrans();
|
||||
try {
|
||||
\app\common\library\MasterSecurity::ensure($mid);
|
||||
|
||||
if ($type === 'login' || $type === 'both') {
|
||||
if ($type === 'login' && $newPassword !== '') {
|
||||
$salt = \fast\Random::alnum();
|
||||
$encrypted = \app\common\library\MasterAuth::instance()->getEncryptPassword($newPassword, $salt);
|
||||
Db::name('master')->where('id', $mid)->update(['password' => $encrypted, 'salt' => $salt, 'updatetime' => time()]);
|
||||
} else {
|
||||
Db::name('master')->where('id', $mid)->update(['password' => '', 'salt' => '', 'updatetime' => time()]);
|
||||
}
|
||||
Db::name('master_security')->where('master_id', $mid)->update([
|
||||
'failed_attempts' => 0,
|
||||
'locked_until' => 0,
|
||||
]);
|
||||
}
|
||||
|
||||
if ($type === 'payment' || $type === 'both') {
|
||||
$payHash = ($type === 'payment' && $newPassword !== '') ? password_hash($newPassword, PASSWORD_DEFAULT) : '';
|
||||
Db::name('master_security')->where('master_id', $mid)->update([
|
||||
'payment_password_hash' => $payHash,
|
||||
'payment_failed_attempts' => 0,
|
||||
'payment_locked_until' => 0,
|
||||
]);
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
$this->error('重置失败:' . $e->getMessage());
|
||||
}
|
||||
|
||||
if ($type === 'login' || $type === 'both') {
|
||||
\app\common\library\MasterToken::clear($mid);
|
||||
}
|
||||
$this->success('密码重置成功');
|
||||
}
|
||||
|
||||
$this->view->assign([
|
||||
'row' => $row,
|
||||
'hasLoginPassword' => !empty($row['password']),
|
||||
'hasPaymentPassword' => $security && (string)$security['payment_password_hash'] !== '',
|
||||
]);
|
||||
return $this->view->fetch();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
</div>
|
||||
<table id="table" class="table table-striped table-bordered table-hover table-nowrap"
|
||||
data-operate-detail="{:$auth->check('master/detail')}"
|
||||
data-operate-resetpwd="{:$auth->check('master/resetpwd')}"
|
||||
data-operate-edit="{:$auth->check('master/edit')}"
|
||||
data-operate-del="{:$auth->check('master/del')}"
|
||||
width="100%">
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
<form id="resetpwd-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
|
||||
{:token()}
|
||||
<div class="panel panel-default panel-form-section">
|
||||
<div class="panel-heading"><h4 class="panel-title">重置师傅密码</h4></div>
|
||||
<div class="panel-body">
|
||||
<div class="form-group">
|
||||
<label class="control-label col-sm-3">目标师傅:</label>
|
||||
<div class="col-sm-8">
|
||||
<p class="form-control-static">{$row.realname|default=$row.nickname|htmlentities}(ID:{$row.id},手机:{$row.mobile|default='未绑定'|htmlentities})</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="control-label col-sm-3">当前状态:</label>
|
||||
<div class="col-sm-8">
|
||||
<p class="form-control-static">
|
||||
登录密码:
|
||||
{if $hasLoginPassword}<span class="label label-success">已设置</span>{else /}<span class="label label-default">未设置</span>{/if}
|
||||
|
||||
支付密码:
|
||||
{if $hasPaymentPassword}<span class="label label-success">已设置</span>{else /}<span class="label label-default">未设置</span>{/if}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="control-label col-sm-3">重置项目:</label>
|
||||
<div class="col-sm-8">
|
||||
<div class="radio">
|
||||
<label><input type="radio" name="row[type]" value="login" checked> 仅重置登录密码</label>
|
||||
</div>
|
||||
<div class="radio">
|
||||
<label><input type="radio" name="row[type]" value="payment"> 仅重置支付密码</label>
|
||||
</div>
|
||||
<div class="radio">
|
||||
<label><input type="radio" name="row[type]" value="both"> 同时清空登录密码与支付密码</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group" id="new-password-group">
|
||||
<label class="control-label col-sm-3" for="c-new-password">新密码(选填):</label>
|
||||
<div class="col-sm-8">
|
||||
<input id="c-new-password" name="row[new_password]" class="form-control" type="password" autocomplete="new-password" placeholder="留空则清空密码,由师傅在小程序端自行重新设置">
|
||||
<p class="help-block" id="new-password-help">留空将清空原密码并解除锁定,师傅可在“账号安全”中直接重设;若填写,登录密码须6-30位,支付密码须6位数字。</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel-footer normal-footer text-center">
|
||||
<button type="submit" class="btn btn-warning btn-embossed disabled">确认重置</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
@@ -12,7 +12,7 @@ use think\Db;
|
||||
*/
|
||||
class MasterAuth extends MasterBase
|
||||
{
|
||||
protected $noNeedLogin = ['login', 'wxlogin', 'wxPhoneLogin'];
|
||||
protected $noNeedLogin = ['login', 'wxPhoneLogin'];
|
||||
|
||||
/**
|
||||
* 师傅手机号 + 密码登录(H5调试/账号密码通道)
|
||||
@@ -71,40 +71,12 @@ class MasterAuth extends MasterBase
|
||||
}
|
||||
|
||||
/**
|
||||
* 师傅端微信小程序 OpenID 静默/授权登录
|
||||
* 师傅端微信小程序 OpenID 静默登录(已下线,统一走微信手机号授权登录)
|
||||
* @ApiMethod (POST)
|
||||
*/
|
||||
public function wxlogin()
|
||||
{
|
||||
$code = trim((string)$this->request->post('code'));
|
||||
$nickname = trim((string)$this->request->post('nickname'));
|
||||
$avatar = trim((string)$this->request->post('avatar'));
|
||||
if ($code === '') {
|
||||
$this->error('缺少微信登录凭证 code');
|
||||
}
|
||||
|
||||
$wx = WxLogin::jscode2session($code, 'master');
|
||||
if (isset($wx['error'])) {
|
||||
$this->error($wx['error'], ['wx_errcode' => isset($wx['errcode']) ? (int)$wx['errcode'] : 0]);
|
||||
}
|
||||
|
||||
$ret = WxLogin::provisionMaster(
|
||||
$wx['openid'],
|
||||
isset($wx['unionid']) ? $wx['unionid'] : '',
|
||||
isset($wx['session_key']) ? $wx['session_key'] : '',
|
||||
$nickname,
|
||||
$avatar
|
||||
);
|
||||
if (!$this->masterAuth->direct($ret['master_id'])) {
|
||||
$this->error($this->masterAuth->getError() ?: '登录失败');
|
||||
}
|
||||
|
||||
$this->success('登录成功', [
|
||||
'token' => $this->masterAuth->getToken(),
|
||||
'expires' => 2592000,
|
||||
'masterinfo' => $this->profileData(),
|
||||
'is_new' => $ret['is_new'],
|
||||
]);
|
||||
$this->error('师傅端已取消静默登录,请使用微信手机号授权登录');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -144,6 +116,10 @@ class MasterAuth extends MasterBase
|
||||
}
|
||||
|
||||
$ret = WxLogin::provisionMasterWithMobile($mobile, $openid, $unionid, $sessionKey);
|
||||
$masterRow = Db::name('master')->field('status')->where('id', $ret['master_id'])->find();
|
||||
if ($masterRow && isset($masterRow['status']) && $masterRow['status'] !== 'normal') {
|
||||
$this->error('师傅账号已被禁用');
|
||||
}
|
||||
if (!$this->masterAuth->direct($ret['master_id'])) {
|
||||
$this->error($this->masterAuth->getError() ?: '登录失败');
|
||||
}
|
||||
@@ -176,21 +152,28 @@ class MasterAuth extends MasterBase
|
||||
}
|
||||
|
||||
/**
|
||||
* 安全状态查询(登录密码 / 支付密码)
|
||||
* 安全状态查询(登录密码 / 支付密码 / 绑定手机号 / 实名状态)
|
||||
*/
|
||||
public function securityStatus()
|
||||
{
|
||||
$mid = $this->masterId();
|
||||
$master = Db::name('master')->field('password,mobile')->where('id', $mid)->find();
|
||||
$master = Db::name('master')->field('password,mobile,verify_status')->where('id', $mid)->find();
|
||||
$security = Db::name('master_security')->where('master_id', $mid)->find();
|
||||
$rawMobile = trim((string)($master['mobile'] ?? ''));
|
||||
$maskedMobile = strlen($rawMobile) === 11
|
||||
? (substr($rawMobile, 0, 3) . '****' . substr($rawMobile, -4))
|
||||
: $rawMobile;
|
||||
|
||||
$this->success('', [
|
||||
'has_login_password' => !empty($master['password']),
|
||||
'has_payment_password' => $security && $security['payment_password_hash'] !== '',
|
||||
'mobile' => $maskedMobile,
|
||||
'verify_status' => (string)($master['verify_status'] ?? 'draft'),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置或修改师傅登录密码
|
||||
* 设置或修改师傅登录密码(未设置时直接设置,已设置时需校验原密码)
|
||||
* @ApiMethod (POST)
|
||||
*/
|
||||
public function changeLoginPassword()
|
||||
@@ -202,7 +185,7 @@ class MasterAuth extends MasterBase
|
||||
$this->error('登录密码须为6至30位非空字符');
|
||||
}
|
||||
|
||||
$master = Db::name('master')->field('password,mobile')->where('id', $mid)->find();
|
||||
$master = Db::name('master')->field('password')->where('id', $mid)->find();
|
||||
if (!empty($master['password'])) {
|
||||
try {
|
||||
MasterSecurity::verify($mid, 'login', $old);
|
||||
@@ -211,19 +194,23 @@ class MasterAuth extends MasterBase
|
||||
}
|
||||
$ignoreOld = false;
|
||||
} else {
|
||||
$this->verifyBoundPhone($this->request->post('phone_code', ''), (string)$master['mobile']);
|
||||
$ignoreOld = true;
|
||||
}
|
||||
|
||||
if (!$this->masterAuth->changepwd($new, $old, $ignoreOld)) {
|
||||
$this->error($this->masterAuth->getError() ?: '设置失败');
|
||||
}
|
||||
MasterSecurity::ensure($mid);
|
||||
Db::name('master_security')->where('master_id', $mid)->update([
|
||||
'failed_attempts' => 0,
|
||||
'locked_until' => 0,
|
||||
]);
|
||||
MasterToken::clear($mid);
|
||||
$this->success('登录密码已更新,请重新登录');
|
||||
}
|
||||
|
||||
/**
|
||||
* 首次设置师傅支付密码(支持已设登录密码走登录密码验证,或未设登录密码走绑定微信手机号验证)
|
||||
* 首次设置师傅支付密码
|
||||
* @ApiMethod (POST)
|
||||
*/
|
||||
public function setPaymentPassword()
|
||||
@@ -234,20 +221,6 @@ class MasterAuth extends MasterBase
|
||||
$this->error('支付密码须为6位数字');
|
||||
}
|
||||
|
||||
$master = Db::name('master')->field('password,mobile')->where('id', $mid)->find();
|
||||
$phoneCode = trim((string)$this->request->post('phone_code', ''));
|
||||
if ($phoneCode !== '') {
|
||||
$this->verifyBoundPhone($phoneCode, (string)($master['mobile'] ?? ''));
|
||||
} elseif (!empty($master['password'])) {
|
||||
try {
|
||||
MasterSecurity::verify($mid, 'login', (string)$this->request->post('login_password', ''));
|
||||
} catch (\Throwable $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
} else {
|
||||
$this->error('请先验证绑定手机号或设置登录密码');
|
||||
}
|
||||
|
||||
MasterSecurity::ensure($mid);
|
||||
$updated = Db::name('master_security')
|
||||
->where('master_id', $mid)
|
||||
@@ -260,7 +233,7 @@ class MasterAuth extends MasterBase
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改师傅支付密码
|
||||
* 修改师傅支付密码(需校验原支付密码)
|
||||
* @ApiMethod (POST)
|
||||
*/
|
||||
public function changePaymentPassword()
|
||||
@@ -286,18 +259,6 @@ class MasterAuth extends MasterBase
|
||||
$this->success('支付密码修改成功');
|
||||
}
|
||||
|
||||
protected function verifyBoundPhone($code, $mobile)
|
||||
{
|
||||
if (trim((string)$code) === '') {
|
||||
$this->error('请先验证绑定的微信手机号');
|
||||
}
|
||||
$phone = WxLogin::getPhoneNumber((string)$code, 'master');
|
||||
$verified = isset($phone['purePhoneNumber']) ? (string)$phone['purePhoneNumber'] : (string)($phone['phoneNumber'] ?? '');
|
||||
if (isset($phone['error']) || $verified === '' || !hash_equals((string)$mobile, $verified)) {
|
||||
$this->error('手机号验证失败,请使用绑定手机号重新验证');
|
||||
}
|
||||
}
|
||||
|
||||
protected function profileData()
|
||||
{
|
||||
$mid = $this->masterId();
|
||||
|
||||
@@ -175,6 +175,17 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'backend/admin-table-layout',
|
||||
icon: 'fa fa-certificate',
|
||||
classname: 'btn btn-xs btn-success btn-dialog btn-skills-mst',
|
||||
url: 'master/skills'
|
||||
},
|
||||
{
|
||||
name: 'resetpwd',
|
||||
text: '重置密码',
|
||||
title: function (row) {
|
||||
return '重置密码 - ' + (row.realname || row.nickname || row.mobile);
|
||||
},
|
||||
icon: 'fa fa-key',
|
||||
classname: 'btn btn-xs btn-warning btn-dialog btn-resetpwd-mst',
|
||||
url: 'master/resetpwd',
|
||||
visible: function () { return !!table.data('operate-resetpwd'); }
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -230,6 +241,22 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'backend/admin-table-layout',
|
||||
audit: function () {
|
||||
Controller.api.bindevent();
|
||||
},
|
||||
resetpwd: function () {
|
||||
var $form = $("#resetpwd-form");
|
||||
var $pwdGroup = $("#new-password-group");
|
||||
var $pwdInput = $("#c-new-password");
|
||||
$form.on("change", "input[name='row[type]']", function () {
|
||||
var val = $(this).val();
|
||||
if (val === 'both') {
|
||||
$pwdInput.val('');
|
||||
$pwdGroup.hide();
|
||||
} else {
|
||||
$pwdGroup.show();
|
||||
$pwdInput.attr('maxlength', val === 'payment' ? 6 : 30);
|
||||
}
|
||||
});
|
||||
Controller.api.bindevent();
|
||||
},
|
||||
detail: function () {
|
||||
$(document).on('click', '.btn-master-unbind-wx', function () {
|
||||
var id = $(this).data('id');
|
||||
|
||||
@@ -2,50 +2,166 @@
|
||||
<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 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="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 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>
|
||||
<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>
|
||||
<!-- 密码设置 / 修改底部弹窗 -->
|
||||
<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'">
|
||||
<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>
|
||||
<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'">
|
||||
<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>
|
||||
<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>
|
||||
@@ -70,8 +186,31 @@
|
||||
const oldPassword = ref('');
|
||||
const newPassword = ref('');
|
||||
const confirmPassword = ref('');
|
||||
const showOldPwd = ref(false);
|
||||
const showNewPwd = ref(false);
|
||||
const showConfirmPwd = ref(false);
|
||||
|
||||
const sheetTitle = computed(() => mode.value === 'login' ? '登录密码' : '支付密码');
|
||||
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()) {
|
||||
@@ -84,64 +223,86 @@
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
function close() {
|
||||
if (busy.value) return;
|
||||
mode.value = '';
|
||||
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 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' });
|
||||
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 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 = '';
|
||||
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, phone_code: phoneCode });
|
||||
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);
|
||||
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.changePaymentPassword({ old_password: oldPassword.value, new_password: newPassword.value });
|
||||
if (firstSetup) {
|
||||
await api.setPaymentPassword({ new_password: newPassword.value });
|
||||
} else {
|
||||
await api.setPaymentPassword({
|
||||
login_password: oldPassword.value,
|
||||
phone_code: phoneCode,
|
||||
await api.changePaymentPassword({
|
||||
old_password: oldPassword.value,
|
||||
new_password: newPassword.value
|
||||
});
|
||||
}
|
||||
|
||||
busy.value = false;
|
||||
close();
|
||||
uni.showToast({ title: '保存成功' });
|
||||
uni.showToast({ title: firstSetup ? '设置成功' : '修改成功', icon: 'success' });
|
||||
if (setupFromPayment.value && firstSetup) {
|
||||
try { await finishPaymentSetup(uni); } catch (e) { uni.showToast({ title: e.message, icon: 'none' }); }
|
||||
} else {
|
||||
@@ -168,8 +329,9 @@
|
||||
title: '退出登录',
|
||||
content: '确认退出当前师傅账号?',
|
||||
confirmColor: '#F0710D',
|
||||
success: (result) => {
|
||||
success: async (result) => {
|
||||
if (result.confirm) {
|
||||
try { await api.logout(); } catch (e) {}
|
||||
clearAuth();
|
||||
uni.reLaunch({ url: '/pages/login/login' });
|
||||
}
|
||||
@@ -202,20 +364,116 @@
|
||||
|
||||
<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; }
|
||||
.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>
|
||||
|
||||
@@ -16,7 +16,6 @@ export default {
|
||||
|
||||
/* ---------- 师傅端独立鉴权与安全 ---------- */
|
||||
login: (data) => post('/master_auth/login', data, { silent: true }),
|
||||
wxLogin: (data) => post('/master_auth/wxlogin', data, { silent: true }),
|
||||
wxPhoneLogin: (data) => post('/master_auth/wxPhoneLogin', data, { silent: true }),
|
||||
logout: () => post('/master_auth/logout', {}, { silent: true }),
|
||||
profile: () => get('/master_auth/profile'),
|
||||
|
||||
@@ -1,17 +1,8 @@
|
||||
/**
|
||||
* 微信登录统一入口
|
||||
* 解决两个线上问题:
|
||||
* 1) code 一次性(5 分钟、单次有效)——静默登录与手动登录若同时发起会互相抢 code
|
||||
* → 用「单飞(in-flight)」保证同一时刻只有一个换取流程
|
||||
* 2) 40029(invalid code)——可能来自 code 已被消费/过期
|
||||
* → 自动用全新 code 重试一次
|
||||
* 微信登录辅助工具
|
||||
* 师傅端统一使用「获取微信手机号」登录,不做 OpenID 静默登录。
|
||||
* 此处仅提供 getWxCode() 用于在手机号授权时同步换取 OpenID 完成绑定。
|
||||
*/
|
||||
import api from './api.js';
|
||||
import { setToken, setUser } from './request.js';
|
||||
|
||||
let inflight = null;
|
||||
|
||||
/** 取微信一次性 code */
|
||||
export function getWxCode() {
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.login({
|
||||
@@ -21,45 +12,3 @@ export function getWxCode() {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function isCodeInvalid(err) {
|
||||
const code = err && err.data ? Number(err.data.wx_errcode) : 0;
|
||||
if (code === 40029 || code === 40163) return true;
|
||||
return /invalid code|code been used|40029/i.test((err && err.message) || '');
|
||||
}
|
||||
|
||||
/**
|
||||
* 用 code 换 token;遇到 code 失效自动换新 code 重试一次
|
||||
*/
|
||||
async function exchange(payload, retry) {
|
||||
const code = await getWxCode();
|
||||
try {
|
||||
const data = await api.wxLogin(Object.assign({}, payload, { code: code }));
|
||||
setToken(data.token);
|
||||
setUser(data.masterinfo || data.userinfo);
|
||||
return data;
|
||||
} catch (err) {
|
||||
if (retry && isCodeInvalid(err)) {
|
||||
return exchange(payload, false);
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 主动授权登录(点击「微信一键登录」)
|
||||
*/
|
||||
export function wxAuthorizeLogin(payload) {
|
||||
if (inflight) {
|
||||
// 复用在途结果,避免抢同一个 code
|
||||
return inflight.then((data) => {
|
||||
if (data) return data;
|
||||
return exchange(payload || {}, true);
|
||||
});
|
||||
}
|
||||
inflight = exchange(payload || {}, true).then(
|
||||
(data) => { inflight = null; return data; },
|
||||
(err) => { inflight = null; throw err; }
|
||||
);
|
||||
return inflight;
|
||||
}
|
||||
|
||||
在新工单中引用
屏蔽一个用户