feat(user agreement): show on not read when trigger login/register

This commit is contained in:
Timi
2026-11-13 12:16:33 +08:00
parent 5fbcc02c98
commit 04ad331e8d
5 changed files with 112 additions and 37 deletions
+21 -7
View File
@@ -49,8 +49,8 @@
/>
</div>
</t-form>
<user-agreement v-model="hasAgreed" />
<t-button class="submit" theme="primary" size="medium" :loading="isSubmitting" :disabled="isExpired || isSubmitting || !hasAgreed" @click="register">注册并登录</t-button>
<user-agreement ref="agreementRef" v-model="hasAgreed" @agree="resumeRegister" @reject="cancelRegister" />
<t-button class="submit" theme="primary" size="medium" :loading="isSubmitting" :disabled="isExpired || isSubmitting" @click="register">注册并登录</t-button>
</section>
</div>
</template>
@@ -78,6 +78,19 @@ const expireAt = ref(0);
const invalidMessage = ref("邀请码无效或已过期,请联系邀请人重新生成。");
const isSubmitting = ref(false);
const hasAgreed = ref(false);
const agreementRef = ref<InstanceType<typeof UserAgreement> | null>(null);
let pendingRegister = false;
async function resumeRegister(): Promise<void> {
if (!pendingRegister) return;
pendingRegister = false;
await nextTick();
await register();
}
function cancelRegister(): void {
pendingRegister = false;
}
const captchaRef = ref<CaptchaExpose | null>(null);
const formModel = reactive({
phoneNo: "",
@@ -196,11 +209,12 @@ async function sendSms(): Promise<void> {
}
async function register(): Promise<void> {
if (isSubmitting.value || !hasAgreed.value || isExpired.value || !validateForm()) {
if (!hasAgreed.value) {
Message.warning("请先阅读并同意用户协议");
return;
}
if (!hasAgreed.value) {
pendingRegister = true;
await agreementRef.value?.open();
return;
}
if (isSubmitting.value || isExpired.value || !validateForm()) {
if (isExpired.value) {
Message.warning("邀请码已失效,请联系邀请人重新生成");
}
+23 -3
View File
@@ -11,9 +11,9 @@
:options="loginTypeOptions"
v-entrance-transition
/>
<password-login v-if="loginType === 'password'" class="form card" :agreement-accepted="hasAgreed" />
<sms-login v-else class="form card" :agreement-accepted="hasAgreed" />
<user-agreement v-model="hasAgreed" />
<password-login v-if="loginType === 'password'" class="form card" :agreement-accepted="hasAgreed" @request-agreement="requestAgreement" />
<sms-login v-else class="form card" :agreement-accepted="hasAgreed" @request-agreement="requestAgreement" />
<user-agreement ref="agreementRef" v-model="hasAgreed" @agree="resumeLogin" @reject="cancelLogin" />
</section>
</div>
</template>
@@ -33,6 +33,26 @@ type LoginType = "password" | "sms";
const loginType = ref<LoginType>("password");
const hasAgreed = ref(false);
const agreementRef = ref<InstanceType<typeof UserAgreement> | null>(null);
let pendingLogin: (() => Promise<void>) | undefined;
async function requestAgreement(resume: () => Promise<void>): Promise<void> {
pendingLogin = resume;
await agreementRef.value?.open();
}
async function resumeLogin(): Promise<void> {
const resume = pendingLogin;
pendingLogin = undefined;
await nextTick();
await resume?.();
}
function cancelLogin(): void {
pendingLogin = undefined;
}
watch(loginType, cancelLogin);
const loginTypeOptions = [
{ value: "password" as LoginType, label: "密码登录" },
{ value: "sms" as LoginType, label: "短信登录" }
+7 -5
View File
@@ -13,7 +13,7 @@
<captcha class="captcha" ref="captchaRef" :width="120" :height="40" :request="CommonAPI.captcha" />
</div>
<div class="exec">
<t-button theme="primary" class="button" type="submit" :loading="isSubmitting" :disabled="isSubmitting || !props.agreementAccepted">登录</t-button>
<t-button theme="primary" class="button" type="submit" :loading="isSubmitting" :disabled="isSubmitting">登录</t-button>
</div>
</t-form>
</template>
@@ -45,6 +45,8 @@ const props = withDefaults(defineProps<{
agreementAccepted: false
});
const emit = defineEmits<{ "request-agreement": [resume: () => Promise<void>] }>();
const route = useRoute();
const router = useRouter();
const userStore = useUserStore();
@@ -62,10 +64,6 @@ function getRedirectPath(): string {
}
function validateForm(): boolean {
if (!props.agreementAccepted) {
Message.warning("请先阅读并同意用户协议");
return false;
}
if (!formModel.user || !formModel.password || !formModel.captcha || !captchaRef.value?.captchaId) {
Message.warning("请输入账号、密码和验证码");
return false;
@@ -74,6 +72,10 @@ function validateForm(): boolean {
}
async function login(): Promise<void> {
if (!props.agreementAccepted) {
emit("request-agreement", login);
return;
}
if (isSubmitting.value || !validateForm()) {
return;
}
+7 -5
View File
@@ -24,7 +24,7 @@
/>
</div>
<div class="exec">
<t-button theme="primary" class="button" type="submit" :loading="isSubmitting" :disabled="isSubmitting || !props.agreementAccepted">登录</t-button>
<t-button theme="primary" class="button" type="submit" :loading="isSubmitting" :disabled="isSubmitting">登录</t-button>
</div>
</t-form>
</template>
@@ -57,6 +57,8 @@ const props = withDefaults(defineProps<{
agreementAccepted: false
});
const emit = defineEmits<{ "request-agreement": [resume: () => Promise<void>] }>();
const route = useRoute();
const router = useRouter();
const userStore = useUserStore();
@@ -142,10 +144,6 @@ async function sendSms(): Promise<void> {
}
function validateForm(): boolean {
if (!props.agreementAccepted) {
Message.warning("请先阅读并同意用户协议");
return false;
}
if (!/^1\d{10}$/.test(formModel.mobilePhone)) {
Message.warning("请输入正确的 11 位手机号");
return false;
@@ -158,6 +156,10 @@ function validateForm(): boolean {
}
async function login(): Promise<void> {
if (!props.agreementAccepted) {
emit("request-agreement", login);
return;
}
if (isSubmitting.value || !validateForm()) {
return;
}
+54 -17
View File
@@ -38,7 +38,7 @@
:label="item.title"
lazy
>
<div class="agreement-item">
<div class="panel">
<t-loading v-if="item.loading" class="loading" text="正在加载协议" />
<article-view
v-else-if="item.article"
@@ -84,6 +84,8 @@ const props = withDefaults(defineProps<{
const emit = defineEmits<{
"update:modelValue": [value: boolean];
agree: [];
reject: [];
}>();
const dialogVisible = ref(false);
@@ -133,6 +135,10 @@ async function handleCheckboxChange(checked: boolean): Promise<void> {
return;
}
await open();
}
async function open(): Promise<void> {
emit("update:modelValue", false);
dialogVisible.value = true;
activeAgreementId.value = "";
@@ -188,12 +194,16 @@ function resolveAttachmentUrl(attachmentId: string): string {
return AttachmentAPI.getReadURL(attachmentId);
}
defineExpose({ open });
function rejectAgreement(): void {
emit("update:modelValue", false);
emit("reject");
}
function agreeAgreement(): void {
emit("update:modelValue", true);
emit("agree");
}
</script>
@@ -219,22 +229,15 @@ function agreeAgreement(): void {
:global(.user-agreement-dialog.t-dialog .t-dialog__body) {
flex: 1 1 auto;
min-height: 0;
display: flex;
overflow: hidden;
min-height: 0;
text-align: unset;
}
:global(.user-agreement-dialog.t-dialog .t-dialog__body-text) {
width: 100%;
flex: 1 1 auto;
min-height: 0;
display: flex;
}
:global(.user-agreement-dialog.t-dialog .t-dialog__footer) {
--td-spacer-1: 0;
--td-button-border-radius: 1rem;
padding: 10px;
min-width: 0;
}
.dialog-content {
@@ -242,6 +245,7 @@ function agreeAgreement(): void {
gap: .5rem;
width: 100%;
min-width: 0;
height: 100%;
flex: 1 1 auto;
display: flex;
@@ -251,12 +255,17 @@ function agreeAgreement(): void {
.tabs {
--td-tab-item-height: 2rem;
width: 100%;
flex: 1 1 auto;
min-height: 0;
width: 100%;
min-width: 0;
display: flex;
flex-direction: column;
overflow: hidden;
min-height: 0;
flex-direction: column;
:deep(.t-tabs__nav) {
border-bottom: 1px solid var(--td-component-border);
}
:deep(.t-tabs__content) {
flex: 1 1 auto;
@@ -269,10 +278,13 @@ function agreeAgreement(): void {
padding: 0 .5rem;
font-size: .75rem;
}
:deep(.t-tabs__item--active) {
font-weight: unset;
}
}
.agreement-item {
padding-top: 1rem;
.panel {
.loading {
padding: 1.5rem 0;
@@ -301,6 +313,31 @@ function agreeAgreement(): void {
}
}
@media (orientation: landscape) and (min-width: 48rem) {
:global(.user-agreement-dialog.t-dialog) {
--td-dialog-width: min(80vw, 48rem);
}
.user-agreement-dialog {
:global(.user-agreement-dialog.t-dialog .t-dialog__content) {
height: min(76vh, 36rem);
max-height: min(76vh, 36rem);
}
.dialog-content {
.tips {
br {
display: none;
}
span + span::before {
content: ",";
}
}
}
}
}
:global(html.theme-dark) {
.user-agreement {
.checkbox {
@@ -310,7 +347,7 @@ function agreeAgreement(): void {
.user-agreement-dialog {
.dialog-content {
.hint {
.tips {
color: #94a3b8;
}