From 894da5662320b9cc84b0b96b58b22f4a2b2b9af8 Mon Sep 17 00:00:00 2001 From: MiAn Date: Thu, 26 Nov 2026 17:29:23 +0800 Subject: [PATCH] =?UTF-8?q?feat(security):=20=E4=BC=98=E5=8C=96=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E4=B8=8E=E6=94=AF=E4=BB=98=E5=AF=86=E7=A0=81=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E6=8F=90=E7=A4=BA=E6=96=87=E6=A1=88=E5=B9=B6=E5=AE=8C?= =?UTF-8?q?=E5=96=84=E5=8F=8C=E7=AB=AF=E5=AE=89=E5=85=A8=E4=B8=AD=E5=BF=83?= =?UTF-8?q?=E4=BA=A4=E4=BA=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 安全校验提示:优化 AccountSecurity 与 MasterSecurity 密码错误提示,区分登录密码与支付密码,并增加剩余可重试次数提示 - 接口响应对齐:优化 Auth、MasterAuth、Security、Sms 控制器在短信验证码发送与密码校验时的异常处理与返回格式 - 腾讯云短信SDK:优化 SmsSingleSender::sendWithParam 方法入参默认值 - 双端小程序:优化用户端与师傅端登录页及账号安全中心的密码修改与找回交互逻辑 --- .../qcloudsms/library/SmsSingleSender.php | 2 +- server/application/api/controller/Auth.php | 15 +- .../application/api/controller/MasterAuth.php | 45 +- .../application/api/controller/Security.php | 35 +- server/application/api/controller/Sms.php | 6 +- .../common/library/AccountSecurity.php | 11 +- .../common/library/MasterSecurity.php | 11 +- tests/sms_business_api.js | 6 +- yjyf-app/pages/login/login.vue | 315 ++++++++---- yjyf-app/pages/mine/security.vue | 453 ++++++++++------- yjyf-app/utils/api.js | 10 +- yjyf-master-app/pages/login/login.vue | 315 ++++++++---- yjyf-master-app/pages/master/security.vue | 480 +++++++++++------- yjyf-master-app/utils/api.js | 10 +- 14 files changed, 1090 insertions(+), 624 deletions(-) diff --git a/server/addons/qcloudsms/library/SmsSingleSender.php b/server/addons/qcloudsms/library/SmsSingleSender.php index dc0f104..ddd5103 100644 --- a/server/addons/qcloudsms/library/SmsSingleSender.php +++ b/server/addons/qcloudsms/library/SmsSingleSender.php @@ -79,7 +79,7 @@ class SmsSingleSender * @param string $ext 服务端原样返回的参数,可填空串 * @return string 应答json字符串,详细内容参见腾讯云协议文档 */ - public function sendWithParam($nationCode, $phoneNumber, $templId = 0, $params, + public function sendWithParam($nationCode, $phoneNumber, $templId = 0, $params = [], $sign = "", $extend = "", $ext = "") { $random = $this->util->getRandom(); diff --git a/server/application/api/controller/Auth.php b/server/application/api/controller/Auth.php index d159f7a..dd4bbb5 100644 --- a/server/application/api/controller/Auth.php +++ b/server/application/api/controller/Auth.php @@ -62,9 +62,13 @@ class Auth extends Base $this->error('该账号尚未设置登录密码,请使用微信一键登录后设置密码'); } try { - \app\common\library\AccountSecurity::verify((int)$user['id'], 'login', $password); + \app\common\library\AccountSecurity::verify((int)$user['id'], 'login', $password, '登录密码'); } catch (\Throwable $e) { - $this->error($e->getMessage() === '密码不正确' ? '手机号或密码不正确' : $e->getMessage()); + $msg = $e->getMessage(); + if (strpos($msg, '不正确') !== false) { + $msg = str_replace('登录密码不正确', '手机号或密码不正确', $msg); + } + $this->error($msg); } $this->auth->direct($user['id']); } @@ -102,12 +106,13 @@ class Auth extends Base try { $res = SmsService::sendVerifyCode($mobile, 'user_resetpwd', $this->request->ip()); - $this->success('验证码已发送,请注意查收', array_merge($res, [ - 'mobile' => substr_replace($mobile, '****', 3, 4), - ])); } catch (\Throwable $e) { $this->error($e->getMessage()); + return; } + $this->success('验证码已发送,请注意查收', array_merge($res, [ + 'mobile' => substr_replace($mobile, '****', 3, 4), + ])); } /** diff --git a/server/application/api/controller/MasterAuth.php b/server/application/api/controller/MasterAuth.php index 5147339..8aeeffc 100644 --- a/server/application/api/controller/MasterAuth.php +++ b/server/application/api/controller/MasterAuth.php @@ -56,9 +56,13 @@ class MasterAuth extends MasterBase $this->error('该师傅账号尚未设置登录密码,请使用微信一键登录后在账号安全中设置密码'); } try { - MasterSecurity::verify((int)$master['id'], 'login', $password); + MasterSecurity::verify((int)$master['id'], 'login', $password, '登录密码'); } catch (\Throwable $e) { - $this->error($e->getMessage() === '密码不正确' ? '手机号或密码不正确' : $e->getMessage()); + $msg = $e->getMessage(); + if (strpos($msg, '不正确') !== false) { + $msg = str_replace('登录密码不正确', '手机号或密码不正确', $msg); + } + $this->error($msg); } if (!$this->masterAuth->direct((int)$master['id'])) { $this->error($this->masterAuth->getError() ?: '登录失败'); @@ -199,12 +203,13 @@ class MasterAuth extends MasterBase try { $res = SmsService::sendVerifyCode($mobile, 'master_resetpwd', $this->request->ip()); - $this->success('验证码已发送,请注意查收', array_merge($res, [ - 'mobile' => substr_replace($mobile, '****', 3, 4), - ])); } catch (\Throwable $e) { $this->error($e->getMessage()); + return; } + $this->success('验证码已发送,请注意查收', array_merge($res, [ + 'mobile' => substr_replace($mobile, '****', 3, 4), + ])); } /** @@ -288,12 +293,13 @@ class MasterAuth extends MasterBase try { $res = SmsService::sendVerifyCode($mobile, 'master_changepwd', $this->request->ip()); - $this->success('验证码已发送至绑定手机', array_merge($res, [ - 'mobile' => substr_replace($mobile, '****', 3, 4), - ])); } catch (\Throwable $e) { $this->error($e->getMessage()); + return; } + $this->success('验证码已发送至绑定手机', array_merge($res, [ + 'mobile' => substr_replace($mobile, '****', 3, 4), + ])); } /** @@ -322,9 +328,13 @@ class MasterAuth extends MasterBase $ignoreOld = true; } else { try { - MasterSecurity::verify($mid, 'login', $old); + MasterSecurity::verify($mid, 'login', $old, '原登录密码'); } catch (\Throwable $e) { - $this->error($e->getMessage()); + $msg = $e->getMessage(); + if (strpos($msg, '15分钟') !== false) { + $msg .= ',或点击下方改用短信验证码'; + } + $this->error($msg); } $ignoreOld = false; } @@ -384,12 +394,13 @@ class MasterAuth extends MasterBase try { $res = SmsService::sendVerifyCode($mobile, 'master_paypwd', $this->request->ip()); - $this->success('验证码已发送至绑定手机', array_merge($res, [ - 'mobile' => substr_replace($mobile, '****', 3, 4), - ])); } catch (\Throwable $e) { $this->error($e->getMessage()); + return; } + $this->success('验证码已发送至绑定手机', array_merge($res, [ + 'mobile' => substr_replace($mobile, '****', 3, 4), + ])); } /** @@ -419,9 +430,13 @@ class MasterAuth extends MasterBase } } else { try { - MasterSecurity::verify($mid, 'payment', (string)$this->request->post('old_password', '')); + MasterSecurity::verify($mid, 'payment', (string)$this->request->post('old_password', ''), '原支付密码'); } catch (\Throwable $e) { - $this->error($e->getMessage()); + $msg = $e->getMessage(); + if (strpos($msg, '15分钟') !== false) { + $msg .= ',或点击下方改用短信验证码'; + } + $this->error($msg); } } $updated = Db::name('master_security') diff --git a/server/application/api/controller/Security.php b/server/application/api/controller/Security.php index dbc0209..63dbe87 100644 --- a/server/application/api/controller/Security.php +++ b/server/application/api/controller/Security.php @@ -44,12 +44,13 @@ class Security extends Base try { $res = SmsService::sendVerifyCode($mobile, 'user_changepwd', $this->request->ip()); - $this->success('验证码已发送至绑定手机', array_merge($res, [ - 'mobile' => substr_replace($mobile, '****', 3, 4), - ])); } catch (\Throwable $e) { $this->error($e->getMessage()); + return; } + $this->success('验证码已发送至绑定手机', array_merge($res, [ + 'mobile' => substr_replace($mobile, '****', 3, 4), + ])); } public function changeLoginPassword() @@ -70,7 +71,15 @@ class Security extends Base } $ignoreOld = true; } else { - try { AccountSecurity::verify($uid, 'login', $old); } catch (\Throwable $e) { $this->error($e->getMessage()); } + try { + AccountSecurity::verify($uid, 'login', $old, '原登录密码'); + } catch (\Throwable $e) { + $msg = $e->getMessage(); + if (strpos($msg, '15分钟') !== false) { + $msg .= ',或点击下方改用短信验证码'; + } + $this->error($msg); + } $ignoreOld = false; } } else { @@ -111,12 +120,13 @@ class Security extends Base try { $res = SmsService::sendVerifyCode($mobile, 'user_paypwd', $this->request->ip()); - $this->success('验证码已发送至绑定手机', array_merge($res, [ - 'mobile' => substr_replace($mobile, '****', 3, 4), - ])); } catch (\Throwable $e) { $this->error($e->getMessage()); + return; } + $this->success('验证码已发送至绑定手机', array_merge($res, [ + 'mobile' => substr_replace($mobile, '****', 3, 4), + ])); } public function changePaymentPassword() @@ -139,8 +149,15 @@ class Security extends Base $this->error($e->getMessage()); } } else { - try { AccountSecurity::verify($uid, 'payment', (string)$this->request->post('old_password', '')); } - catch (\Throwable $e) { $this->error($e->getMessage()); } + try { + AccountSecurity::verify($uid, 'payment', (string)$this->request->post('old_password', ''), '原支付密码'); + } catch (\Throwable $e) { + $msg = $e->getMessage(); + if (strpos($msg, '15分钟') !== false) { + $msg .= ',或点击下方改用短信验证码'; + } + $this->error($msg); + } } $updated = Db::name('user_security')->where('user_id', $uid)->where('payment_password_hash', $oldHash)->update([ 'payment_password_hash' => password_hash($new, PASSWORD_DEFAULT), diff --git a/server/application/api/controller/Sms.php b/server/application/api/controller/Sms.php index dd5a354..49075bd 100755 --- a/server/application/api/controller/Sms.php +++ b/server/application/api/controller/Sms.php @@ -87,10 +87,11 @@ class Sms extends Api try { $res = SmsService::sendVerifyCode($mobile, $event, $this->request->ip()); - $this->success('验证码已发送,请注意查收', $res); } catch (\Throwable $e) { $this->error($e->getMessage()); + return; } + $this->success('验证码已发送,请注意查收', $res); } /** @@ -108,9 +109,10 @@ class Sms extends Api try { SmsService::verifyCode($rawMobile, $captcha, $event, false); - $this->success('验证码正确'); } catch (\Throwable $e) { $this->error($e->getMessage()); + return; } + $this->success('验证码正确'); } } diff --git a/server/application/common/library/AccountSecurity.php b/server/application/common/library/AccountSecurity.php index 7b3e990..3965391 100644 --- a/server/application/common/library/AccountSecurity.php +++ b/server/application/common/library/AccountSecurity.php @@ -15,11 +15,12 @@ class AccountSecurity Db::execute("INSERT IGNORE INTO `{$prefix}user_security` (`user_id`) VALUES (?)", [(int)$uid]); } - public static function verify($uid, $kind, $password) + public static function verify($uid, $kind, $password, $label = null) { if (!in_array($kind, ['login', 'payment'], true)) { throw new \InvalidArgumentException('验证类型错误'); } + $label = ($label !== null && $label !== '') ? (string)$label : ($kind === 'payment' ? '支付密码' : '登录密码'); $attemptsField = $kind === 'payment' ? 'payment_failed_attempts' : 'failed_attempts'; $lockedField = $kind === 'payment' ? 'payment_locked_until' : 'locked_until'; self::ensure($uid); @@ -27,7 +28,7 @@ class AccountSecurity try { $row = Db::name('user_security')->where('user_id', (int)$uid)->lock(true)->find(); if ((int)$row[$lockedField] > time()) { - throw new \RuntimeException('密码错误次数过多,请15分钟后重试'); + throw new \RuntimeException($label . '错误次数过多,请15分钟后重试'); } if ($kind === 'login') { $user = Db::name('user')->field('password,salt')->where('id', (int)$uid)->find(); @@ -49,7 +50,11 @@ class AccountSecurity throw $e; } if (!$correct) { - throw new \RuntimeException($failures >= 5 ? '密码错误次数过多,请15分钟后重试' : '密码不正确'); + if ($failures >= 5) { + throw new \RuntimeException($label . '错误次数过多,请15分钟后重试'); + } + $remain = 5 - $failures; + throw new \RuntimeException($label . '不正确,还可尝试 ' . $remain . ' 次'); } return true; } diff --git a/server/application/common/library/MasterSecurity.php b/server/application/common/library/MasterSecurity.php index 289b3dd..58fa534 100644 --- a/server/application/common/library/MasterSecurity.php +++ b/server/application/common/library/MasterSecurity.php @@ -18,11 +18,12 @@ class MasterSecurity Db::execute("INSERT IGNORE INTO `{$prefix}master_security` (`master_id`) VALUES (?)", [(int)$masterId]); } - public static function verify($masterId, $kind, $password) + public static function verify($masterId, $kind, $password, $label = null) { if (!in_array($kind, ['login', 'payment'], true)) { throw new \InvalidArgumentException('验证类型错误'); } + $label = ($label !== null && $label !== '') ? (string)$label : ($kind === 'payment' ? '支付密码' : '登录密码'); $masterId = (int)$masterId; $attemptsField = $kind === 'payment' ? 'payment_failed_attempts' : 'failed_attempts'; $lockedField = $kind === 'payment' ? 'payment_locked_until' : 'locked_until'; @@ -32,7 +33,7 @@ class MasterSecurity try { $row = Db::name('master_security')->where('master_id', $masterId)->lock(true)->find(); if ((int)$row[$lockedField] > time()) { - throw new \RuntimeException('密码错误次数过多,请15分钟后重试'); + throw new \RuntimeException($label . '错误次数过多,请15分钟后重试'); } if ($kind === 'login') { $master = Db::name('master')->field('password,salt')->where('id', $masterId)->find(); @@ -54,7 +55,11 @@ class MasterSecurity throw $e; } if (!$correct) { - throw new \RuntimeException($failures >= 5 ? '密码错误次数过多,请15分钟后重试' : '密码不正确'); + if ($failures >= 5) { + throw new \RuntimeException($label . '错误次数过多,请15分钟后重试'); + } + $remain = 5 - $failures; + throw new \RuntimeException($label . '不正确,还可尝试 ' . $remain . ' 次'); } return true; } diff --git a/tests/sms_business_api.js b/tests/sms_business_api.js index c65051b..c7e7607 100644 --- a/tests/sms_business_api.js +++ b/tests/sms_business_api.js @@ -253,7 +253,11 @@ function api(route, data, token) { }, mToken2); assert.strictEqual(finishRes.json.code, 1, finishRes.json.msg); assert.strictEqual(finishRes.json.data.verify_code, undefined, 'master finish response must not expose verify_code'); - assert.strictEqual(finishRes.json.data.sms_sent, false, 'sms_sent should be false when qcloudsms not configured'); + if (!hasAppId) { + assert.strictEqual(finishRes.json.data.sms_sent, false, 'sms_sent should be false when qcloudsms not configured'); + } else { + assert.strictEqual(typeof finishRes.json.data.sms_sent, 'boolean', 'sms_sent should be a boolean'); + } assert.strictEqual(finishRes.json.data.sms_mobile_mask, '139****5678'); assert.strictEqual(sql(`SELECT status FROM fa_order WHERE id=${orderId}`), '7'); const msgContent = sql(`SELECT content FROM fa_message WHERE receive_type='user' AND receive_id=${uid} AND order_id=${orderId} ORDER BY id DESC LIMIT 1`); diff --git a/yjyf-app/pages/login/login.vue b/yjyf-app/pages/login/login.vue index 96a87d0..ce9db48 100644 --- a/yjyf-app/pages/login/login.vue +++ b/yjyf-app/pages/login/login.vue @@ -131,89 +131,112 @@ + - 短信重置登录密码 + + 重置登录密码 + 验证注册手机号后即可设置新密码 + - - - + + + + 注册手机号 + + + + + - - - - - + + + 短信验证码 + 5分钟内有效 + + + + + + + + + + 新登录密码 + 6至30位非空字符 + + + + + + + + + + + + + 确认新密码 + + + + + + 两次输入的密码不一致 + + - - - - - - - - - - - - - - - - - - - @@ -973,70 +996,154 @@ position: fixed; inset: 0; z-index: 999; - background: rgba(0, 0, 0, 0.5); + background: rgba(15, 23, 42, 0.5); display: flex; align-items: flex-end; } .reset-sheet { width: 100%; + max-height: 90vh; + overflow-y: auto; background: #FFFFFF; - border-radius: 28rpx 28rpx 0 0; - padding: 32rpx 36rpx calc(40rpx + env(safe-area-inset-bottom)); + border-radius: 36rpx 36rpx 0 0; + padding: 16rpx 0 calc(36rpx + env(safe-area-inset-bottom)); box-sizing: border-box; + display: flex; + flex-direction: column; + } + .reset-handle { + width: 72rpx; + height: 8rpx; + border-radius: 999rpx; + background: #E5E6EB; + margin: 0 auto 20rpx; } .reset-head { display: flex; - align-items: center; + align-items: flex-start; justify-content: space-between; - margin-bottom: 28rpx; + padding: 0 32rpx 24rpx; + border-bottom: 1rpx solid #F0F0F2; + } + .reset-head-meta { + display: flex; + flex-direction: column; + gap: 6rpx; } .reset-title { - font-size: 34rpx; + font-size: 36rpx; font-weight: 700; - color: #1D2129; + color: #1F1F1F; + line-height: 1.25; + } + .reset-sub { + font-size: 24rpx; + color: #888888; } .reset-close { - width: 48rpx; - height: 48rpx; + width: 60rpx; + height: 60rpx; + border-radius: 50%; + background: #F5F6F8; display: flex; align-items: center; justify-content: center; + flex-shrink: 0; } .reset-close-ico { - width: 32rpx; - height: 32rpx; + width: 26rpx; + height: 26rpx; opacity: 0.65; } - .reset-sms-row { + .reset-body { + padding: 28rpx 32rpx 0; + display: flex; + flex-direction: column; + gap: 24rpx; + } + .reset-field-group { + display: flex; + flex-direction: column; + gap: 10rpx; + } + .reset-label-row { display: flex; align-items: center; - gap: 16rpx; - margin-bottom: 24rpx; + justify-content: space-between; + padding: 0 4rpx; } - .reset-sms-input-row { - flex: 1; - min-width: 0; - margin-bottom: 0; - } - .reset-sms-btn { - flex-shrink: 0; - height: 96rpx; - line-height: 96rpx; - padding: 0 28rpx; - border-radius: 48rpx; - background: #FFF7F0; - color: #F0710D; + .reset-label { font-size: 26rpx; font-weight: 600; - border: 1.5rpx solid rgba(240, 113, 13, 0.35); + color: #1F1F1F; } - .reset-sms-btn::after { + .reset-rule { + font-size: 22rpx; + color: #888888; + } + .reset-error { + font-size: 22rpx; + color: #E8331B; + padding-left: 4rpx; + } + .reset-input-box { + height: 92rpx; + box-sizing: border-box; + padding: 0 18rpx 0 24rpx; + border-radius: 16rpx; + background: #F7F8FA; + border: 1.5rpx solid #EBEDF0; + display: flex; + align-items: center; + gap: 14rpx; + transition: border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease; + } + .reset-input-box:focus-within { + background: #FFFFFF; + border-color: #F0710D; + box-shadow: 0 0 0 4rpx rgba(240, 113, 13, 0.1); + } + .reset-input-box.is-error { + background: #FFF8F7; + border-color: #E8331B; + } + .reset-prefix-ico { + width: 34rpx; + height: 34rpx; + flex-shrink: 0; + opacity: 0.75; + } + .reset-sms-box { + padding-right: 8rpx; + } + .reset-sms-divider { + width: 1.5rpx; + height: 36rpx; + background: #E5E6EB; + flex-shrink: 0; + } + .reset-inline-btn { + flex-shrink: 0; + height: 76rpx; + padding: 0 20rpx; + margin: 0; + background: transparent; + border: none; + display: flex; + align-items: center; + justify-content: center; + color: #F0710D; + font-size: 26rpx; + font-weight: 700; + } + .reset-inline-btn::after { border: none; } - .reset-sms-btn[disabled] { - opacity: 0.6; - color: #86909C; - background: #F7F8FA; - border-color: #E5E6EB; + .reset-inline-btn[disabled] { + color: #AAAAAA; + font-weight: 500; + } + .reset-submit { + margin-top: 8rpx; } diff --git a/yjyf-app/pages/mine/security.vue b/yjyf-app/pages/mine/security.vue index 752eb8d..6a7ee5d 100644 --- a/yjyf-app/pages/mine/security.vue +++ b/yjyf-app/pages/mine/security.vue @@ -97,120 +97,158 @@ + - {{ sheetTitle }} - 取消 + + {{ sheetTitle }} + {{ sheetDesc }} + + + + - - 原密码验证 - 短信验证码 - - - - - - - - + + + {{ isPaymentMode ? '新支付密码' : '新登录密码' }} + {{ isPaymentMode ? '6位纯数字' : '6至30位非空字符' }} + + + + + + + + + + {{ newPasswordError }} + + + + + {{ isPaymentMode ? '确认支付密码' : '确认新密码' }} + + + + + + + + + + {{ confirmPasswordError || '两次输入的密码不一致' }} + + + + + + + + {{ currentVerifyMode === 'old_password' ? (isPaymentMode ? '忘记原支付密码?改用短信验证码' : '忘记原密码?改用短信验证码') : (isPaymentMode ? '记得原支付密码?改用原密码验证' : '记得原密码?改用原密码验证') }} - - - - - - - - - - - - - - - - - - - - {{ isPaymentMode ? '忘记原支付密码?使用短信验证码修改' : '忘记原密码?使用短信验证码修改' }} @@ -220,7 +258,7 @@ import { onLoad, onShow, onBackPress, onUnload } from '@dcloudio/uni-app'; import YjyfNavBar from '@/components/YjyfNavBar.vue'; import api from '@/utils/api.js'; - import { clearAuth } from '@/utils/request.js'; + import { clearAuth, toLogin } from '@/utils/request.js'; import { finishPaymentSetup } from '@/utils/payment-setup.mjs'; const loaded = ref(false), busy = ref(false), mode = ref(''); @@ -233,6 +271,7 @@ const showOldPwd = ref(false), showNewPwd = ref(false), showConfirmPwd = ref(false); const loginVerifyMode = ref('old_password'), paymentVerifyMode = ref('old_password'); const smsCode = ref(''), smsCountdown = ref(0), sendingSms = ref(false); + const oldPasswordError = ref(''), newPasswordError = ref(''), confirmPasswordError = ref(''), smsCodeError = ref(''), verifyLocked = ref(false); let smsTimer = null; const companyName = ref(''), licenseNo = ref(''), legalPerson = ref(''), licenseImage = ref(''), imagePreview = ref(''); @@ -254,6 +293,8 @@ if (isPaymentMode.value) return status.value.has_payment_password ? '修改支付密码' : '设置支付密码'; return status.value.has_login_password ? '修改登录密码' : '设置登录密码'; }); + const sheetDesc = computed(() => isPaymentMode.value ? '用于账户余额支付安全验证' : '用于 H5 网页端手机号密码登录'); + const passwordMismatch = computed(() => confirmPassword.value.length > 0 && newPassword.value !== confirmPassword.value); async function load() { try { status.value = await api.securityStatus(); loaded.value = true; } catch (e) {} } function clearSmsTimer() { if (smsTimer) { clearInterval(smsTimer); smsTimer = null; } } @@ -265,6 +306,12 @@ else { smsCountdown.value -= 1; } }, 1000); } + function clearFieldErrors() { + oldPasswordError.value = ''; + newPasswordError.value = ''; + confirmPasswordError.value = ''; + smsCodeError.value = ''; + } function resetPwdFields() { oldPassword.value = ''; newPassword.value = ''; @@ -273,12 +320,16 @@ showOldPwd.value = false; showNewPwd.value = false; showConfirmPwd.value = false; + verifyLocked.value = false; + clearFieldErrors(); } function switchVerifyMode(nextMode) { if (isPaymentMode.value) paymentVerifyMode.value = nextMode; else loginVerifyMode.value = nextMode; oldPassword.value = ''; smsCode.value = ''; + verifyLocked.value = false; + clearFieldErrors(); } async function sendPwdSms() { if (sendingSms.value || smsCountdown.value > 0) return; @@ -307,34 +358,60 @@ 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 applyServerFieldError(e) { + if (e && e.code === 401) { + uni.showToast({ title: '登录已失效,请重新登录', icon: 'none' }); + setTimeout(() => toLogin(), 800); + return; + } + const msg = String((e && e.message) || '操作失败,请稍后重试'); + if (/验证码/.test(msg) && !/改用短信验证码/.test(msg)) { + smsCodeError.value = msg; + return; + } + if (/原登录密码|原支付密码|原密码|密码不正确|次数过多|15分钟|旧密码/.test(msg)) { + oldPasswordError.value = msg; + if (/15分钟|次数过多/.test(msg)) verifyLocked.value = true; + return; + } + if (/6位|6至30位|非空字符|新密码/.test(msg)) { + newPasswordError.value = msg; + return; + } + uni.showToast({ title: msg, icon: 'none' }); + } function validPassword() { + clearFieldErrors(); + let ok = true; if (hasCurrentPassword.value) { if (currentVerifyMode.value === 'sms') { if (!/^\d{4,6}$/.test(smsCode.value.trim())) { - uni.showToast({ title: '请输入有效的短信验证码', icon: 'none' }); - return false; + smsCodeError.value = '请输入有效的6位短信验证码'; + ok = false; } } else if (isPaymentMode.value && !/^\d{6}$/.test(oldPassword.value)) { - uni.showToast({ title: '请输入6位原支付密码', icon: 'none' }); - return false; + oldPasswordError.value = '请输入原6位数字支付密码'; + ok = false; } else if (!isPaymentMode.value && !oldPassword.value) { - uni.showToast({ title: '请输入原登录密码', icon: 'none' }); - return false; + oldPasswordError.value = '请输入原登录密码'; + ok = false; } } if (isPaymentMode.value && !/^\d{6}$/.test(newPassword.value)) { - uni.showToast({ title: '支付密码须为6位数字', icon: 'none' }); - return false; + newPasswordError.value = '新支付密码须为6位纯数字'; + ok = false; + } else if (!isPaymentMode.value && !/^\S{6,30}$/.test(newPassword.value)) { + newPasswordError.value = '新登录密码须为6至30位非空字符'; + ok = false; } - if (!isPaymentMode.value && !/^\S{6,30}$/.test(newPassword.value)) { - uni.showToast({ title: '登录密码须为6至30位非空字符', icon: 'none' }); - return false; + if (!confirmPassword.value) { + confirmPasswordError.value = isPaymentMode.value ? '请再次输入新支付密码' : '请再次输入新登录密码'; + ok = false; + } else if (newPassword.value !== confirmPassword.value) { + confirmPasswordError.value = '两次输入的新密码不一致'; + ok = false; } - if (newPassword.value !== confirmPassword.value) { - uni.showToast({ title: '两次输入的新密码不一致', icon: 'none' }); - return false; - } - return true; + return ok; } async function savePassword() { if (busy.value || !validPassword()) return; @@ -344,7 +421,7 @@ const payload = currentVerifyMode.value === 'sms' && hasCurrentPassword.value ? { verify_mode: 'sms', sms_code: smsCode.value.trim(), new_password: newPassword.value } : { verify_mode: 'old_password', old_password: oldPassword.value, new_password: newPassword.value }; - await api.changeLoginPassword(payload); + await api.changeLoginPassword(payload, { silent: true }); clearAuth(); uni.showToast({ title: '密码已更新,请重新登录', icon: 'none' }); setTimeout(() => uni.reLaunch({ url: '/pages/login/login' }), 700); return; } @@ -353,14 +430,16 @@ const payPayload = currentVerifyMode.value === 'sms' ? { verify_mode: 'sms', sms_code: smsCode.value.trim(), new_password: newPassword.value } : { verify_mode: 'old_password', old_password: oldPassword.value, new_password: newPassword.value }; - await api.changePaymentPassword(payPayload); + await api.changePaymentPassword(payPayload, { silent: true }); } - else await api.setPaymentPassword({ new_password: newPassword.value }); + else await api.setPaymentPassword({ new_password: newPassword.value }, { silent: true }); busy.value = false; close(); uni.showToast({ title: firstSetup ? '设置成功' : '修改成功', icon: 'success' }); 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; } + } catch (e) { + applyServerFieldError(e); + } finally { busy.value = false; } } function chooseLicense() { if (busy.value) return; uni.chooseImage({ count: 1, sizeType: ['compressed'], success: async res => { busy.value = true; try { @@ -504,88 +583,109 @@ .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, 0.45); display: flex; align-items: flex-end; } + .mask { position: fixed; inset: 0; z-index: 1000; background: rgba(15, 23, 42, 0.5); display: flex; align-items: flex-end; } .sheet { width: 100%; max-height: 90vh; overflow-y: auto; box-sizing: border-box; - padding: 32rpx 32rpx calc(40rpx + env(safe-area-inset-bottom)); - border-radius: $yjyf-radius-lg $yjyf-radius-lg 0 0; + padding: 16rpx 0 calc(36rpx + env(safe-area-inset-bottom)); + border-radius: 36rpx 36rpx 0 0; background: $yjyf-bg-card; display: flex; flex-direction: column; - gap: 20rpx; } - .sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4rpx; } - .title { color: $yjyf-text-main; font-size: $yjyf-font-title; font-weight: 700; } - .close { color: $yjyf-text-secondary; font-size: $yjyf-font-body; padding: 8rpx 0 8rpx 16rpx; } - - .mode-tabs { display: flex; gap: 16rpx; } - .mode-tab { - flex: 1; - height: 76rpx; - box-sizing: border-box; + .sheet-handle { + width: 72rpx; + height: 8rpx; + border-radius: $yjyf-radius-pill; + background: #E5E6EB; + margin: 0 auto 20rpx; + } + .sheet-head { display: flex; - align-items: center; - justify-content: center; - border-radius: $yjyf-radius-sm; + justify-content: space-between; + align-items: flex-start; + padding: 0 32rpx 24rpx; + border-bottom: 1rpx solid $yjyf-border-color; + } + .sheet-head-meta { display: flex; flex-direction: column; gap: 6rpx; } + .title { color: $yjyf-text-main; font-size: 36rpx; font-weight: 700; line-height: 1.25; } + .sheet-sub { color: $yjyf-text-secondary; font-size: $yjyf-font-sub; } + .sheet-close-btn { + width: 60rpx; + height: 60rpx; + border-radius: 50%; background: $yjyf-bg-page; - border: 1.5rpx solid transparent; - color: $yjyf-text-secondary; - font-size: $yjyf-font-sub; - font-weight: 600; - } - .mode-tab.active { - background: $yjyf-primary-bg; - color: $yjyf-primary; - border-color: rgba(240, 113, 13, 0.35); - } - - .sms-target { font-size: $yjyf-font-micro; color: $yjyf-text-secondary; } - .sms-row { display: flex; align-items: center; gap: 16rpx; } - .sms-input-box { flex: 1; min-width: 0; } - .sms-btn { - flex-shrink: 0; - height: 92rpx; - box-sizing: border-box; display: flex; align-items: center; justify-content: center; - padding: 0 28rpx; - margin: 0; - border-radius: $yjyf-radius-sm; - background: $yjyf-primary-bg; - color: $yjyf-primary; - font-size: $yjyf-font-sub; - font-weight: 600; - border: 1.5rpx solid rgba(240, 113, 13, 0.35); + flex-shrink: 0; } - .sms-btn::after { border: none; } - .sms-btn[disabled] { opacity: 0.6; color: $yjyf-text-secondary; background: $yjyf-bg-page; border-color: $yjyf-border-color; } + .sheet-close-ico { width: 26rpx; height: 26rpx; opacity: 0.65; } + + .sheet-body { + padding: 28rpx 32rpx 0; + display: flex; + flex-direction: column; + gap: 24rpx; + } + + .field-group { display: flex; flex-direction: column; gap: 10rpx; } + .field-label-row { display: flex; align-items: center; justify-content: space-between; padding: 0 4rpx; } + .field-label { font-size: 26rpx; font-weight: 600; color: $yjyf-text-main; } + .field-rule { font-size: $yjyf-font-micro; color: $yjyf-text-secondary; } + .field-error { font-size: $yjyf-font-micro; color: $yjyf-danger; padding-left: 4rpx; } .input-box { height: 92rpx; box-sizing: border-box; - padding: 0 20rpx 0 24rpx; - border-radius: $yjyf-radius-sm; - background: $yjyf-bg-page; - border: 1.5rpx solid transparent; + padding: 0 18rpx 0 24rpx; + border-radius: 16rpx; + background: #F7F8FA; + border: 1.5rpx solid #EBEDF0; display: flex; align-items: center; - gap: 12rpx; + gap: 14rpx; + transition: border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease; } .input-box:focus-within { background: $yjyf-bg-card; border-color: $yjyf-primary; + box-shadow: 0 0 0 4rpx rgba(240, 113, 13, 0.1); } + .input-box.is-error { + background: #FFF8F7; + border-color: $yjyf-danger; + } + .input-prefix-ico { width: 34rpx; height: 34rpx; flex-shrink: 0; opacity: 0.75; } .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; } + .field-placeholder { font-size: 26rpx; color: $yjyf-text-muted; } + .eye-btn { width: 64rpx; height: 64rpx; display: flex; align-items: center; justify-content: center; flex-shrink: 0; } .eye-ico { width: 34rpx; height: 34rpx; } + .sms-box { padding-right: 8rpx; } + .sms-divider { width: 1.5rpx; height: 36rpx; background: #E5E6EB; flex-shrink: 0; } + .inline-sms-btn { + flex-shrink: 0; + height: 76rpx; + padding: 0 20rpx; + margin: 0; + background: transparent; + border: none; + display: flex; + align-items: center; + justify-content: center; + color: $yjyf-primary; + font-size: 26rpx; + font-weight: 700; + } + .inline-sms-btn::after { border: none; } + .inline-sms-btn[disabled] { color: $yjyf-text-muted; font-weight: 500; } + .primary { width: 100%; - height: 90rpx; + height: 92rpx; margin: 8rpx 0 0; padding: 0; display: flex; @@ -595,12 +695,15 @@ background: $yjyf-gradient-primary; box-shadow: $yjyf-shadow-button; color: $yjyf-text-inverse; - font-size: $yjyf-font-body; + font-size: 30rpx; font-weight: 700; border: none; } .primary::after { border: none; } .primary[disabled] { opacity: 0.65; } + .sheet-submit { margin-top: 8rpx; } - .switch-link { text-align: center; font-size: $yjyf-font-sub; color: $yjyf-info; padding-top: 4rpx; } + .switch-row { display: flex; justify-content: center; padding-top: 2rpx; } + .switch-link { padding: 12rpx 24rpx; font-size: $yjyf-font-sub; color: $yjyf-text-secondary; } + .switch-link.is-highlight { color: $yjyf-primary; font-weight: 600; } diff --git a/yjyf-app/utils/api.js b/yjyf-app/utils/api.js index fd109a6..849de81 100644 --- a/yjyf-app/utils/api.js +++ b/yjyf-app/utils/api.js @@ -18,13 +18,13 @@ export default { profile: () => get('/auth/profile'), selectIdentity: (data) => post('/auth/selectIdentity', data), securityStatus: () => get('/security/status'), - sendPasswordSms: () => post('/security/sendPasswordSms', {}), - sendPaymentPasswordSms: () => post('/security/sendPaymentPasswordSms', {}), - changeLoginPassword: (data) => post('/security/changeLoginPassword', data), + sendPasswordSms: (opt) => post('/security/sendPasswordSms', {}, opt), + sendPaymentPasswordSms: (opt) => post('/security/sendPaymentPasswordSms', {}, opt), + changeLoginPassword: (data, opt) => post('/security/changeLoginPassword', data, opt), sendResetPasswordSms: (data) => post('/auth/sendResetPasswordSms', data), resetPasswordBySms: (data) => post('/auth/resetPasswordBySms', data), - setPaymentPassword: (data) => post('/security/setPaymentPassword', data), - changePaymentPassword: (data) => post('/security/changePaymentPassword', data), + setPaymentPassword: (data, opt) => post('/security/setPaymentPassword', data, opt), + changePaymentPassword: (data, opt) => post('/security/changePaymentPassword', data, opt), submitEnterpriseCert: (data) => post('/security/submitEnterpriseCert', data), recognizeEnterpriseLicense: (data) => post('/security/recognizeEnterpriseLicense', data), saveAccount: (data) => post('/auth/saveAccount', data), diff --git a/yjyf-master-app/pages/login/login.vue b/yjyf-master-app/pages/login/login.vue index d2a0670..be45f58 100644 --- a/yjyf-master-app/pages/login/login.vue +++ b/yjyf-master-app/pages/login/login.vue @@ -121,89 +121,112 @@ + - 短信重置登录密码 + + 重置登录密码 + 验证师傅账号绑定手机后即可设置新密码 + - - - + + + + 师傅手机号 + + + + + - - - - - + + + 短信验证码 + 5分钟内有效 + + + + + + + + + + 新登录密码 + 6至30位非空字符 + + + + + + + + + + + + + 确认新密码 + + + + + + 两次输入的密码不一致 + + - - - - - - - - - - - - - - - - - - - @@ -836,70 +859,154 @@ position: fixed; inset: 0; z-index: 999; - background: rgba(0, 0, 0, 0.5); + background: rgba(15, 23, 42, 0.5); display: flex; align-items: flex-end; } .reset-sheet { width: 100%; + max-height: 90vh; + overflow-y: auto; background: #FFFFFF; - border-radius: 28rpx 28rpx 0 0; - padding: 32rpx 36rpx calc(40rpx + env(safe-area-inset-bottom)); + border-radius: 36rpx 36rpx 0 0; + padding: 16rpx 0 calc(36rpx + env(safe-area-inset-bottom)); box-sizing: border-box; + display: flex; + flex-direction: column; + } + .reset-handle { + width: 72rpx; + height: 8rpx; + border-radius: 999rpx; + background: #E5E6EB; + margin: 0 auto 20rpx; } .reset-head { display: flex; - align-items: center; + align-items: flex-start; justify-content: space-between; - margin-bottom: 28rpx; + padding: 0 32rpx 24rpx; + border-bottom: 1rpx solid #F0F0F2; + } + .reset-head-meta { + display: flex; + flex-direction: column; + gap: 6rpx; } .reset-title { - font-size: 34rpx; + font-size: 36rpx; font-weight: 700; - color: #1D2129; + color: #1F1F1F; + line-height: 1.25; + } + .reset-sub { + font-size: 24rpx; + color: #888888; } .reset-close { - width: 48rpx; - height: 48rpx; + width: 60rpx; + height: 60rpx; + border-radius: 50%; + background: #F5F6F8; display: flex; align-items: center; justify-content: center; + flex-shrink: 0; } .reset-close-ico { - width: 32rpx; - height: 32rpx; + width: 26rpx; + height: 26rpx; opacity: 0.65; } - .reset-sms-row { + .reset-body { + padding: 28rpx 32rpx 0; + display: flex; + flex-direction: column; + gap: 24rpx; + } + .reset-field-group { + display: flex; + flex-direction: column; + gap: 10rpx; + } + .reset-label-row { display: flex; align-items: center; - gap: 16rpx; - margin-bottom: 24rpx; + justify-content: space-between; + padding: 0 4rpx; } - .reset-sms-input-row { - flex: 1; - min-width: 0; - margin-bottom: 0; - } - .reset-sms-btn { - flex-shrink: 0; - height: 96rpx; - line-height: 96rpx; - padding: 0 28rpx; - border-radius: 48rpx; - background: #FFF7F0; - color: #F0710D; + .reset-label { font-size: 26rpx; font-weight: 600; - border: 1.5rpx solid rgba(240, 113, 13, 0.35); + color: #1F1F1F; } - .reset-sms-btn::after { + .reset-rule { + font-size: 22rpx; + color: #888888; + } + .reset-error { + font-size: 22rpx; + color: #E8331B; + padding-left: 4rpx; + } + .reset-input-box { + height: 92rpx; + box-sizing: border-box; + padding: 0 18rpx 0 24rpx; + border-radius: 16rpx; + background: #F7F8FA; + border: 1.5rpx solid #EBEDF0; + display: flex; + align-items: center; + gap: 14rpx; + transition: border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease; + } + .reset-input-box:focus-within { + background: #FFFFFF; + border-color: #F0710D; + box-shadow: 0 0 0 4rpx rgba(240, 113, 13, 0.1); + } + .reset-input-box.is-error { + background: #FFF8F7; + border-color: #E8331B; + } + .reset-prefix-ico { + width: 34rpx; + height: 34rpx; + flex-shrink: 0; + opacity: 0.75; + } + .reset-sms-box { + padding-right: 8rpx; + } + .reset-sms-divider { + width: 1.5rpx; + height: 36rpx; + background: #E5E6EB; + flex-shrink: 0; + } + .reset-inline-btn { + flex-shrink: 0; + height: 76rpx; + padding: 0 20rpx; + margin: 0; + background: transparent; + border: none; + display: flex; + align-items: center; + justify-content: center; + color: #F0710D; + font-size: 26rpx; + font-weight: 700; + } + .reset-inline-btn::after { border: none; } - .reset-sms-btn[disabled] { - opacity: 0.6; - color: #86909C; - background: #F7F8FA; - border-color: #E5E6EB; + .reset-inline-btn[disabled] { + color: #AAAAAA; + font-weight: 500; + } + .reset-submit { + margin-top: 8rpx; } diff --git a/yjyf-master-app/pages/master/security.vue b/yjyf-master-app/pages/master/security.vue index ba5014f..3f0a90c 100644 --- a/yjyf-master-app/pages/master/security.vue +++ b/yjyf-master-app/pages/master/security.vue @@ -69,142 +69,158 @@ + - {{ sheetTitle }} - 取消 + + {{ sheetTitle }} + {{ sheetDesc }} + + + + - - - -