完成50%

This commit is contained in:
2026-07-23 08:23:59 +08:00
parent 9b0ad62df4
commit f1edc6b533
218 changed files with 24318 additions and 5514 deletions
+281 -157
View File
@@ -3,13 +3,19 @@
<AuthPageShell class="auth-page reset-page">
<view class="reset-content">
<view class="page-heading">
<view class="back-button" hover-class="tap-fade" @click="goBack">
<button
class="auth-plain-button back-button"
aria-label="返回登录"
hover-class="tap-fade"
@click="requestBack"
>
<image
class="back-button__icon"
src="/static/assets/foundation/transparent/chevron-right.png"
mode="aspectFit"
aria-hidden="true"
/>
</view>
</button>
<text class="page-title">重设密码</text>
<text class="page-subtitle">验证手机号后设置新的登录密码</text>
<image
@@ -25,18 +31,22 @@
:class="{ 'field-block--error': fieldErrors.phone }"
>
<view class="input-row">
<text class="input-label">手机号</text>
<label class="input-label" for="a05-phone">手机号</label>
<input
id="a05-phone"
v-model.trim="phone"
class="auth-input"
type="number"
maxlength="11"
:disabled="sendingCode || cooldownSeconds > 0 || submitting"
placeholder="请输入手机号"
placeholder-class="placeholder"
:aria-invalid="Boolean(fieldErrors.phone)"
:aria-describedby="fieldErrors.phone ? 'a05-phone-error' : undefined"
@input="clearFieldError('phone')"
/>
</view>
<text v-if="fieldErrors.phone" class="field-error">{{
<text v-if="fieldErrors.phone" id="a05-phone-error" class="field-error" role="alert">{{
fieldErrors.phone
}}</text>
</view>
@@ -46,24 +56,30 @@
:class="{ 'field-block--error': fieldErrors.verificationCode }"
>
<view class="input-row code-row">
<text class="input-label">验证码</text>
<label class="input-label" for="a05-verification-code">验证码</label>
<input
id="a05-verification-code"
v-model.trim="verificationCode"
class="auth-input"
type="number"
maxlength="6"
maxlength="4"
:disabled="submitting"
placeholder="请输入验证码"
placeholder-class="placeholder"
:aria-invalid="Boolean(fieldErrors.verificationCode)"
:aria-describedby="fieldErrors.verificationCode ? 'a05-verification-code-error' : undefined"
@input="clearFieldError('verificationCode')"
/>
<view
class="get-code"
<button
class="auth-plain-button get-code"
:class="{ 'get-code--disabled': sendingCode || cooldownSeconds > 0 }"
:disabled="sendingCode || submitting || cooldownSeconds > 0"
hover-class="tap-fade"
@click="prepareGetCode"
>获取验证码</view
>{{ sendingCode ? "请求中…" : cooldownSeconds > 0 ? `${cooldownSeconds}s 后重发` : "获取验证码" }}</button
>
</view>
<text v-if="fieldErrors.verificationCode" class="field-error">{{
<text v-if="fieldErrors.verificationCode" id="a05-verification-code-error" class="field-error" role="alert">{{
fieldErrors.verificationCode
}}</text>
</view>
@@ -73,18 +89,22 @@
:class="{ 'field-block--error': fieldErrors.password }"
>
<view class="input-row">
<text class="input-label">新密码</text>
<label class="input-label" for="a05-password">新密码</label>
<input
id="a05-password"
v-model="password"
class="auth-input"
password
maxlength="32"
:disabled="submitting"
placeholder="请设置新密码"
placeholder-class="placeholder"
:aria-invalid="Boolean(fieldErrors.password)"
:aria-describedby="fieldErrors.password ? 'a05-password-error' : undefined"
@input="clearFieldError('password')"
/>
</view>
<text v-if="fieldErrors.password" class="field-error">{{
<text v-if="fieldErrors.password" id="a05-password-error" class="field-error" role="alert">{{
fieldErrors.password
}}</text>
</view>
@@ -94,25 +114,31 @@
:class="{ 'field-block--error': fieldErrors.confirmPassword }"
>
<view class="input-row">
<text class="input-label">确认新密码</text>
<label class="input-label" for="a05-confirm-password">确认新密码</label>
<input
id="a05-confirm-password"
v-model="confirmPassword"
class="auth-input"
password
maxlength="32"
:disabled="submitting"
placeholder="请再次输入新密码"
placeholder-class="placeholder"
:aria-invalid="Boolean(fieldErrors.confirmPassword)"
:aria-describedby="fieldErrors.confirmPassword ? 'a05-confirm-password-error' : undefined"
@input="clearFieldError('confirmPassword')"
/>
</view>
<text v-if="fieldErrors.confirmPassword" class="field-error">{{
<text v-if="fieldErrors.confirmPassword" id="a05-confirm-password-error" class="field-error" role="alert">{{
fieldErrors.confirmPassword
}}</text>
</view>
</view>
<view
class="reset-submit"
<button
class="auth-plain-button reset-submit"
:disabled="submitting || sendingCode || tacVisible"
:aria-busy="submitting"
hover-class="button-hover"
@click="submitReset"
>
@@ -121,64 +147,92 @@
src="/static/assets/foundation/transparent/a01-scroll-primary-v3.png"
mode="aspectFit"
/>
<text class="reset-submit__content">确认重设</text>
</view>
<text class="reset-submit__content">{{ submitting ? "提交中…" : "确认重设" }}</text>
</button>
<text class="reset-tip">重设成功后请使用新密码登录</text>
<view class="login-entry">
<text>想起密码了</text>
<view
class="login-entry__link"
<button
class="auth-plain-button login-entry__link"
:disabled="submitting || sendingCode || tacVisible"
hover-class="tap-fade"
@click="prepareLogin"
>返回登录</view
@click="requestBack"
>返回登录</button
>
</view>
</view>
<template #overlay>
<view v-if="successVisible" class="success-layer">
<view class="success-dialog">
<image
class="success-dialog__skin"
src="/static/assets/modules/auth/transparent/a01-scroll-dialog-v3.png"
mode="aspectFit"
/>
<view class="success-dialog__content">
<image
class="success-mark"
src="/static/assets/foundation/transparent/brand-seal.png"
mode="aspectFit"
/>
<text class="success-title">密码已重设</text>
<text class="success-copy">请返回登录页使用新密码登录</text>
<view
class="success-action"
hover-class="button-hover"
@click="prepareLogin"
>
<image
class="success-action__skin"
src="/static/assets/foundation/transparent/a01-scroll-primary-v3.png"
mode="aspectFit"
/>
<text class="success-action__copy">返回登录</text>
</view>
</view>
</view>
</view>
<TacVerification
:visible="tacVisible"
:context="tacContext"
@success="completeTac"
@failure="handleTacFailure"
@error="handleTacError"
@cancel="closeTac"
/>
<AppDialog
:visible="discardVisible"
title="放弃重设密码?"
message="当前填写内容尚未保存,确认返回后将清空。"
confirm-text="放弃并返回"
cancel-text="继续填写"
show-cancel
compact-actions
:close-on-mask="false"
@confirm="confirmDiscard"
@cancel="cancelDiscard"
/>
<view v-if="feedbackVisible" class="feedback-toast">
<text class="feedback-toast__copy">{{ feedbackMessage }}</text>
</view>
<AppDialog
:visible="successVisible"
title="密码已重设"
message="请返回登录页,使用新密码登录"
confirm-text="返回登录"
:close-on-mask="false"
@confirm="leaveResetSuccess"
>
<image
class="success-mark"
src="/static/assets/foundation/transparent/brand-seal.png"
mode="aspectFit"
aria-hidden="true"
/>
</AppDialog>
<AppToast :visible="feedbackVisible" :message="feedbackMessage" />
</template>
</AuthPageShell>
</template>
<script setup>
import { ref } from "vue";
import { onUnload } from "@dcloudio/uni-app";
import { computed, ref } from "vue";
import { onBackPress, onUnload } from "@dcloudio/uni-app";
import AppDialog from "@/components/AppDialog.vue";
import AppToast from "@/components/AppToast.vue";
import AuthPageShell from "@/components/AuthPageShell.vue";
import TacVerification from "@/components/TacVerification.vue";
import {
appApi,
createRequestController,
isRequestCancelled,
} from "@/utils/api.js";
import {
AUTH_TAC_SCENE,
createTacRenderContext,
isAuthPhone,
normalizeCaptchaRequirement,
normalizeTacSuccess,
} from "@/utils/auth-verification.js";
import { runtimeConfig } from "@/utils/config.js";
import { createDiscardConfirmation } from "@/utils/discard-confirmation.js";
import { calcMD5 } from "@/utils/md5.js";
import {
handleBackPress,
returnTo,
runBackGuard,
} from "@/utils/navigation.js";
import {
PASSWORD_POLICY_MESSAGE,
validatePassword,
@@ -191,23 +245,78 @@ const confirmPassword = ref("");
const successVisible = ref(false);
const feedbackVisible = ref(false);
const feedbackMessage = ref("");
const discardVisible = ref(false);
const tacVisible = ref(false);
const tacContext = ref(null);
const sendingCode = ref(false);
const submitting = ref(false);
const cooldownSeconds = ref(0);
const fieldErrors = ref({
phone: "",
verificationCode: "",
password: "",
confirmPassword: "",
});
const isDirty = computed(() =>
!successVisible.value &&
Boolean(
phone.value ||
verificationCode.value ||
password.value ||
confirmPassword.value,
),
);
let feedbackTimer = null;
let cooldownTimer = null;
let tacSequence = 0;
let pageActive = true;
const authRequestController = createRequestController();
const discardConfirmation = createDiscardConfirmation((visible) => {
discardVisible.value = visible;
});
const requestDiscardConfirmation = discardConfirmation.request;
const confirmDiscard = discardConfirmation.confirm;
const cancelDiscard = discardConfirmation.cancel;
// 重设成功不产生可跨页消费的数据;只有远端 PUT 已成功后才显示该终态。
const leaveResetSuccess = () => returnTo("A01", {});
const closeTac = () => {
tacVisible.value = false;
tacContext.value = null;
};
const cancelPendingRequest = () => {
authRequestController.abort();
sendingCode.value = false;
submitting.value = false;
};
const requestBack = () => {
if (successVisible.value) return leaveResetSuccess();
return runBackGuard({
transientOpen: tacVisible.value || discardVisible.value,
submitting: submitting.value || sendingCode.value,
dirty: isDirty.value,
"close-transient": tacVisible.value ? closeTac : cancelDiscard,
"block-submitting": () => {
cancelPendingRequest();
return requestBack();
},
"confirm-discard": requestDiscardConfirmation,
});
};
onBackPress((event) => handleBackPress(event, requestBack));
onUnload(() => {
pageActive = false;
authRequestController.abort();
if (feedbackTimer) clearTimeout(feedbackTimer);
if (cooldownTimer) clearInterval(cooldownTimer);
discardConfirmation.dispose();
});
const goBack = () => uni.navigateBack();
// 返回登录时替换当前认证页,避免登录与重设页反复叠加。
const prepareLogin = () => uni.redirectTo({ url: "/pages/auth/a01-entry" });
const showFeedback = (message) => {
feedbackMessage.value = message;
feedbackVisible.value = true;
@@ -222,13 +331,91 @@ const clearFieldError = (field) => {
fieldErrors.value[field] = "";
};
const prepareGetCode = () => {
if (!/^1\d{10}$/.test(phone.value)) {
const startCooldown = () => {
cooldownSeconds.value = 60;
if (cooldownTimer) clearInterval(cooldownTimer);
cooldownTimer = setInterval(() => {
cooldownSeconds.value -= 1;
if (cooldownSeconds.value <= 0) {
clearInterval(cooldownTimer);
cooldownTimer = null;
}
}, 1000);
};
const prepareGetCode = async () => {
if (sendingCode.value || submitting.value || cooldownSeconds.value > 0) return;
if (!isAuthPhone(phone.value)) {
fieldErrors.value.phone = "请输入正确手机号";
return;
}
fieldErrors.value.phone = "";
showFeedback("滑动验证待接口接入");
sendingCode.value = true;
try {
const sceneCode = AUTH_TAC_SCENE.FORGOT_PASSWORD;
const requestedPhone = phone.value;
const response = await appApi.getCaptchaRequirement(
{ sceneCode, subject: requestedPhone },
{ requestController: authRequestController },
);
if (!pageActive) return;
if (phone.value !== requestedPhone) throw new Error("手机号已变化,请重新获取验证码");
const requirement = normalizeCaptchaRequirement(response, sceneCode);
tacSequence += 1;
tacContext.value = createTacRenderContext({
requestId: `a05-forgot-${tacSequence}`,
baseUrl: runtimeConfig.baseUrl,
clientId: runtimeConfig.clientId,
tenantId: runtimeConfig.tenantId,
sceneCode,
subject: requestedPhone,
requirement,
});
tacVisible.value = true;
} catch (error) {
if (pageActive && !isRequestCancelled(error)) {
showFeedback(error.message || "安全验证暂不可用");
}
} finally {
if (pageActive) sendingCode.value = false;
}
};
const completeTac = async (result) => {
const expectedContext = tacContext.value;
if (!expectedContext) return;
try {
const ticket = normalizeTacSuccess(result, expectedContext.requestId);
if (phone.value !== expectedContext.subject) throw new Error("手机号已变化,请重新验证");
closeTac();
sendingCode.value = true;
await appApi.sendSmsCode(
{
sceneCode: AUTH_TAC_SCENE.FORGOT_PASSWORD,
phone: expectedContext.subject,
validToken: ticket.validToken,
},
{ requestController: authRequestController },
);
if (!pageActive) return;
startCooldown();
showFeedback("验证码已发送");
} catch (error) {
closeTac();
if (pageActive && !isRequestCancelled(error)) {
showFeedback(error.message || "验证码发送失败");
}
} finally {
if (pageActive) sendingCode.value = false;
}
};
const handleTacFailure = ({ message } = {}) =>
showFeedback(message || "行为验证未通过,请重试");
const handleTacError = ({ message } = {}) => {
closeTac();
showFeedback(message || "安全验证暂不可用");
};
const validateForm = () => {
@@ -238,9 +425,9 @@ const validateForm = () => {
password: "",
confirmPassword: "",
};
if (!/^1\d{10}$/.test(phone.value)) nextErrors.phone = "请输入正确手机号";
if (!/^\d{6}$/.test(verificationCode.value))
nextErrors.verificationCode = "请输入 6 位验证码";
if (!isAuthPhone(phone.value)) nextErrors.phone = "请输入正确手机号";
if (!/^\d{4}$/.test(verificationCode.value))
nextErrors.verificationCode = "请输入 4 位验证码";
const passwordResult = validatePassword(password.value);
if (!passwordResult.valid) nextErrors.password = PASSWORD_POLICY_MESSAGE;
if (!confirmPassword.value) nextErrors.confirmPassword = "请再次输入新密码";
@@ -250,14 +437,32 @@ const validateForm = () => {
return !Object.values(nextErrors).some(Boolean);
};
const submitReset = () => {
const submitReset = async () => {
if (submitting.value || sendingCode.value) return;
if (!validateForm()) return;
successVisible.value = true;
submitting.value = true;
try {
await appApi.resetPassword(
{
phone: phone.value,
passwordHash: calcMD5(password.value),
smsCode: verificationCode.value,
},
{ requestController: authRequestController },
);
if (!pageActive) return;
successVisible.value = true;
} catch (error) {
if (pageActive && !isRequestCancelled(error)) {
showFeedback(error.message || "密码重设失败,请稍后重试");
}
} finally {
if (pageActive) submitting.value = false;
}
};
</script>
<style scoped lang="scss">
@use "../../styles/adaptive-frame-profiles.scss" as adaptive;
.reset-content {
display: flex;
@@ -358,6 +563,9 @@ const submitReset = () => {
color: #a7160c;
font-size: 26rpx;
}
.get-code--disabled {
color: #9f968d;
}
.field-error {
display: block;
padding-top: 4rpx;
@@ -377,8 +585,7 @@ const submitReset = () => {
margin-top: 26rpx;
}
.reset-submit__skin,
.success-action__skin {
.reset-submit__skin {
grid-area: 1 / 1;
width: 100%;
height: 100%;
@@ -414,93 +621,10 @@ const submitReset = () => {
color: #a7160c;
}
.success-layer {
position: fixed;
z-index: 20;
inset: 0;
display: flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
padding: 42rpx;
background: rgba(35, 18, 10, 0.62);
}
.success-dialog {
display: grid;
width: 620rpx;
min-height: 520rpx;
max-height: calc(var(--app-viewport-height) - 40px);
}
.success-dialog__skin {
grid-area: 1 / 1;
width: 100%;
height: 100%;
}
.success-dialog__content {
z-index: 1;
display: flex;
grid-area: 1 / 1;
flex-direction: column;
align-items: center;
box-sizing: border-box;
min-height: 100%;
overflow-y: auto;
padding: 64rpx 64rpx 42rpx;
text-align: center;
}
.success-title {
color: #8f160f;
font-size: 43rpx;
font-weight: 700;
letter-spacing: 4rpx;
}
.success-copy {
margin-top: 18rpx;
color: #513a28;
font-size: 26rpx;
line-height: 40rpx;
}
.success-mark {
width: 82rpx;
height: 82rpx;
margin-bottom: 20rpx;
}
.success-action {
display: grid;
place-items: center;
width: 100%;
min-height: 82rpx;
margin-top: 24rpx;
}
.success-action__copy {
z-index: 1;
grid-area: 1 / 1;
color: #fffaf0;
font-size: 30rpx;
letter-spacing: 4rpx;
}
.feedback-toast {
position: fixed;
z-index: 30;
top: calc(var(--status-bar-height, 0px) + 24rpx);
left: 50%;
display: flex;
align-items: center;
justify-content: center;
@include adaptive.adaptive-feedback-toast;
width: 590rpx;
min-height: 82rpx;
background: transparent;
transform: translateX(-50%);
}
.feedback-toast__copy {
z-index: 1;
padding: 16rpx 36rpx;
color: #5c4330;
font-size: 25rpx;
text-align: center;
margin: 8rpx auto 12rpx;
}
.tap-fade,
.button-hover {