mirror of
https://github.com/m-xlsea/ruoyi-plus-soybean.git
synced 2025-09-24 07:49:47 +08:00
feat: 新增注册页面
This commit is contained in:
@ -2,8 +2,8 @@
|
||||
import { computed, reactive, ref } from 'vue';
|
||||
import type { SelectOption } from 'naive-ui';
|
||||
import { useLoading } from '@sa/hooks';
|
||||
import { loginModuleRecord } from '@/constants/app';
|
||||
import { fetchCaptchaCode, fetchTenantList } from '@/service/api';
|
||||
// import { fetchGetConfigDetail } from '@/service/api/system/config';
|
||||
import { useAuthStore } from '@/store/modules/auth';
|
||||
import { useRouterPush } from '@/hooks/common/router';
|
||||
import { useFormRules, useNaiveForm } from '@/hooks/common/form';
|
||||
@ -22,6 +22,7 @@ const { loading: codeLoading, startLoading: startCodeLoading, endLoading: endCod
|
||||
const codeUrl = ref<string>();
|
||||
const captchaEnabled = ref<boolean>(false);
|
||||
const tenantEnabled = ref<boolean>(false);
|
||||
const registerEnabled = ref<boolean>(false);
|
||||
const remberMe = ref<boolean>(false);
|
||||
const tenantOption = ref<SelectOption[]>([]);
|
||||
|
||||
@ -101,6 +102,18 @@ function handleLoginRember() {
|
||||
}
|
||||
|
||||
handleLoginRember();
|
||||
|
||||
// async function handleRegister() {
|
||||
// const { data, error } = await fetchGetConfigDetail('sys.account.registerUser');
|
||||
// if (error) return;
|
||||
// registerEnabled.value = data.configValue === 'true';
|
||||
// }
|
||||
|
||||
// handleRegister();
|
||||
|
||||
function handleSocialLogin(type: string) {
|
||||
console.log(type);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@ -130,24 +143,23 @@ handleLoginRember();
|
||||
</NSpin>
|
||||
</div>
|
||||
</NFormItem>
|
||||
<NSpace vertical :size="24">
|
||||
<div class="flex-y-center justify-between">
|
||||
<NSpace vertical :size="16" class="mb-8px">
|
||||
<div class="mx-6px flex-y-center justify-between">
|
||||
<NCheckbox v-model:checked="remberMe">{{ $t('page.login.pwdLogin.rememberMe') }}</NCheckbox>
|
||||
<NButton quaternary @click="toggleLoginModule('reset-pwd')">
|
||||
{{ $t('page.login.pwdLogin.forgetPassword') }}
|
||||
</NButton>
|
||||
<NSpace :size="1">
|
||||
<ButtonIcon class="color-#44b549" icon="ic:outline-wechat" @click="handleSocialLogin('wechat_enterprise')" />
|
||||
<ButtonIcon local-icon="topiam" @click="handleSocialLogin('topiam')" />
|
||||
<ButtonIcon local-icon="maxkey" @click="handleSocialLogin('maxkey')" />
|
||||
<ButtonIcon class="color-#c71d23" icon="simple-icons:gitee" @click="handleSocialLogin('gitee')" />
|
||||
<ButtonIcon class="color-#010409" icon="mdi:github" @click="handleSocialLogin('github')" />
|
||||
</NSpace>
|
||||
</div>
|
||||
<NButton type="primary" size="large" block :loading="authStore.loginLoading" @click="handleSubmit">
|
||||
{{ $t('common.login') }}
|
||||
</NButton>
|
||||
<div class="flex-y-center justify-between gap-12px">
|
||||
<NButton class="flex-1" block @click="toggleLoginModule('code-login')">
|
||||
{{ $t(loginModuleRecord['code-login']) }}
|
||||
</NButton>
|
||||
<NButton class="flex-1" block @click="toggleLoginModule('register')">
|
||||
{{ $t(loginModuleRecord.register) }}
|
||||
</NButton>
|
||||
</div>
|
||||
<NButton v-if="registerEnabled" size="large" block @click="toggleLoginModule('register')">
|
||||
{{ $t('page.login.common.register') }}
|
||||
</NButton>
|
||||
</NSpace>
|
||||
</NForm>
|
||||
</template>
|
||||
|
@ -1,8 +1,10 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, reactive } from 'vue';
|
||||
import { computed, reactive, ref } from 'vue';
|
||||
import type { SelectOption } from 'naive-ui';
|
||||
import { useLoading } from '@sa/hooks';
|
||||
import { fetchCaptchaCode, fetchRegister, fetchTenantList } from '@/service/api';
|
||||
import { useRouterPush } from '@/hooks/common/router';
|
||||
import { useFormRules, useNaiveForm } from '@/hooks/common/form';
|
||||
import { useCaptcha } from '@/hooks/business/captcha';
|
||||
import { $t } from '@/locales';
|
||||
|
||||
defineOptions({
|
||||
@ -11,52 +13,92 @@ defineOptions({
|
||||
|
||||
const { toggleLoginModule } = useRouterPush();
|
||||
const { formRef, validate } = useNaiveForm();
|
||||
const { label, isCounting, loading, getCaptcha } = useCaptcha();
|
||||
const { loading: codeLoading, startLoading: startCodeLoading, endLoading: endCodeLoading } = useLoading();
|
||||
|
||||
interface FormModel {
|
||||
phone: string;
|
||||
code: string;
|
||||
password: string;
|
||||
confirmPassword: string;
|
||||
}
|
||||
const codeUrl = ref<string>();
|
||||
const captchaEnabled = ref<boolean>(false);
|
||||
const tenantEnabled = ref<boolean>(false);
|
||||
const tenantOption = ref<SelectOption[]>([]);
|
||||
|
||||
const model: FormModel = reactive({
|
||||
phone: '',
|
||||
const model: Api.Auth.RegisterForm = reactive({
|
||||
tenantId: '000000',
|
||||
username: '',
|
||||
code: '',
|
||||
password: '',
|
||||
confirmPassword: ''
|
||||
});
|
||||
|
||||
const rules = computed<Record<keyof FormModel, App.Global.FormRule[]>>(() => {
|
||||
const { formRules, createConfirmPwdRule } = useFormRules();
|
||||
type RuleKey = Extract<keyof Api.Auth.RegisterForm, 'username' | 'password' | 'confirmPassword' | 'code' | 'tenantId'>;
|
||||
|
||||
const rules = computed<Record<RuleKey, App.Global.FormRule[]>>(() => {
|
||||
const { formRules, createConfirmPwdRule, createRequiredRule } = useFormRules();
|
||||
|
||||
return {
|
||||
phone: formRules.phone,
|
||||
code: formRules.code,
|
||||
tenantId: tenantEnabled.value ? formRules.tenantId : [],
|
||||
username: formRules.userName,
|
||||
password: formRules.pwd,
|
||||
confirmPassword: createConfirmPwdRule(model.password)
|
||||
confirmPassword: createConfirmPwdRule(model.password!),
|
||||
code: captchaEnabled.value ? [createRequiredRule($t('form.code.required'))] : []
|
||||
};
|
||||
});
|
||||
|
||||
async function handleSubmit() {
|
||||
await validate();
|
||||
// request to register
|
||||
window.$message?.success($t('page.login.common.validateSuccess'));
|
||||
try {
|
||||
// request to register
|
||||
const { error } = await fetchRegister({
|
||||
tenantId: model.tenantId,
|
||||
username: model.username,
|
||||
password: model.password,
|
||||
code: model.code,
|
||||
uuid: model.uuid,
|
||||
grantType: 'password',
|
||||
clientId: import.meta.env.VITE_APP_CLIENT_ID
|
||||
});
|
||||
if (error) return;
|
||||
window.$message?.success('注册成功');
|
||||
} catch {
|
||||
handleFetchCaptchaCode();
|
||||
}
|
||||
}
|
||||
|
||||
async function handleFetchTenantList() {
|
||||
const { data, error } = await fetchTenantList();
|
||||
if (error) return;
|
||||
tenantEnabled.value = data.tenantEnabled;
|
||||
tenantOption.value = data.voList.map(tenant => {
|
||||
return {
|
||||
label: tenant.companyName,
|
||||
value: tenant.tenantId
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
handleFetchTenantList();
|
||||
|
||||
async function handleFetchCaptchaCode() {
|
||||
startCodeLoading();
|
||||
const { data, error } = await fetchCaptchaCode();
|
||||
if (!error) {
|
||||
captchaEnabled.value = data.captchaEnabled;
|
||||
if (data.captchaEnabled) {
|
||||
model.uuid = data.uuid;
|
||||
codeUrl.value = `data:image/gif;base64,${data.img}`;
|
||||
}
|
||||
}
|
||||
endCodeLoading();
|
||||
}
|
||||
|
||||
handleFetchCaptchaCode();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<NForm ref="formRef" :model="model" :rules="rules" size="large" :show-label="false" @keyup.enter="handleSubmit">
|
||||
<NFormItem path="phone">
|
||||
<NInput v-model:value="model.phone" :placeholder="$t('page.login.common.phonePlaceholder')" />
|
||||
<NFormItem v-if="tenantEnabled" path="tenantId">
|
||||
<NSelect v-model:value="model.tenantId" placeholder="请选择/输入公司名称" :options="tenantOption" />
|
||||
</NFormItem>
|
||||
<NFormItem path="code">
|
||||
<div class="w-full flex-y-center gap-16px">
|
||||
<NInput v-model:value="model.code" :placeholder="$t('page.login.common.codePlaceholder')" />
|
||||
<NButton size="large" :disabled="isCounting" :loading="loading" @click="getCaptcha(model.phone)">
|
||||
{{ label }}
|
||||
</NButton>
|
||||
</div>
|
||||
<NFormItem path="username">
|
||||
<NInput v-model:value="model.username" :placeholder="$t('page.login.common.userNamePlaceholder')" />
|
||||
</NFormItem>
|
||||
<NFormItem path="password">
|
||||
<NInput
|
||||
@ -74,15 +116,37 @@ async function handleSubmit() {
|
||||
:placeholder="$t('page.login.common.confirmPasswordPlaceholder')"
|
||||
/>
|
||||
</NFormItem>
|
||||
<NFormItem v-if="captchaEnabled" path="code">
|
||||
<div class="w-full flex-y-center gap-16px">
|
||||
<NInput v-model:value="model.code" :placeholder="$t('page.login.common.codePlaceholder')" />
|
||||
<NSpin :show="codeLoading" :size="28" class="h-42px">
|
||||
<NButton :focusable="false" class="login-code h-42px w-116px" @click="handleFetchCaptchaCode">
|
||||
<img v-if="codeUrl" :src="codeUrl" />
|
||||
<NEmpty v-else :show-icon="false" description="暂无验证码" />
|
||||
</NButton>
|
||||
</NSpin>
|
||||
</div>
|
||||
</NFormItem>
|
||||
<NSpace vertical :size="18" class="w-full">
|
||||
<NButton type="primary" size="large" round block @click="handleSubmit">
|
||||
{{ $t('common.confirm') }}
|
||||
<NButton type="primary" size="large" block @click="handleSubmit">
|
||||
{{ $t('page.login.common.register') }}
|
||||
</NButton>
|
||||
<NButton size="large" round block @click="toggleLoginModule('pwd-login')">
|
||||
<NButton size="large" block @click="toggleLoginModule('pwd-login')">
|
||||
{{ $t('page.login.common.back') }}
|
||||
</NButton>
|
||||
</NSpace>
|
||||
</NForm>
|
||||
</template>
|
||||
|
||||
<style scoped></style>
|
||||
<style scoped lang="scss">
|
||||
.login-code {
|
||||
&.n-button {
|
||||
--n-padding: 0 8px !important;
|
||||
background-color: #c0c0c0;
|
||||
}
|
||||
|
||||
img {
|
||||
height: 40px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
Reference in New Issue
Block a user