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