2
0

初始化项目

This commit is contained in:
caiyuchao
2024-11-14 11:06:38 +08:00
parent 988b9e6799
commit 4ffac789e1
320 changed files with 34244 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
<script setup lang="ts"></script>
<template>
<ExceptionBase type="403" />
</template>
<style scoped></style>

View File

@@ -0,0 +1,7 @@
<script setup lang="ts"></script>
<template>
<ExceptionBase type="404" />
</template>
<style scoped></style>

View File

@@ -0,0 +1,7 @@
<script setup lang="ts"></script>
<template>
<ExceptionBase type="500" />
</template>
<style scoped></style>

View File

@@ -0,0 +1,73 @@
<script setup lang="ts">
import { computed } from 'vue';
import type { Component } from 'vue';
import { getColorPalette, mixColor } from '@sa/utils';
import { $t } from '@/locales';
import { useThemeStore } from '@/store/modules/theme';
import { loginModuleRecord } from '@/constants/app';
import PwdLogin from './modules/pwd-login.vue';
import CodeLogin from './modules/code-login.vue';
import Register from './modules/register.vue';
import ResetPwd from './modules/reset-pwd.vue';
import BindWechat from './modules/bind-wechat.vue';
interface Props {
/** The login module */
module?: UnionKey.LoginModule;
}
const props = defineProps<Props>();
const themeStore = useThemeStore();
interface LoginModule {
label: string;
component: Component;
}
const moduleMap: Record<UnionKey.LoginModule, LoginModule> = {
'pwd-login': { label: loginModuleRecord['pwd-login'], component: PwdLogin },
'code-login': { label: loginModuleRecord['code-login'], component: CodeLogin },
register: { label: loginModuleRecord.register, component: Register },
'reset-pwd': { label: loginModuleRecord['reset-pwd'], component: ResetPwd },
'bind-wechat': { label: loginModuleRecord['bind-wechat'], component: BindWechat }
};
const activeModule = computed(() => moduleMap[props.module || 'pwd-login']);
const bgThemeColor = computed(() =>
themeStore.darkMode ? getColorPalette(themeStore.themeColor, 7) : themeStore.themeColor
);
const bgColor = computed(() => {
const COLOR_WHITE = '#ffffff';
const ratio = themeStore.darkMode ? 0.5 : 0.2;
return mixColor(COLOR_WHITE, themeStore.themeColor, ratio);
});
</script>
<template>
<div class="relative size-full flex-center" :style="{ backgroundColor: bgColor }">
<WaveBg :theme-color="bgThemeColor" />
<ACard class="relative z-4">
<div class="w-400px lt-sm:w-300px">
<header class="flex-y-center justify-between">
<SystemLogo class="text-64px text-primary lt-sm:text-48px" />
<h3 class="text-28px text-primary font-500 lt-sm:text-22px">{{ $t('system.title') }}</h3>
</header>
<main class="pt-24px">
<h3 class="text-18px text-primary font-medium">{{ $t(activeModule.label) }}</h3>
<div class="animation-slide-in-left pt-24px">
<Transition :name="themeStore.page.animateMode" mode="out-in" appear>
<component :is="activeModule.component" />
</Transition>
</div>
</main>
</div>
</ACard>
</div>
</template>
<style scoped></style>

View File

@@ -0,0 +1,11 @@
<script setup lang="ts">
defineOptions({
name: 'BindWechat'
});
</script>
<template>
<div></div>
</template>
<style scoped></style>

View File

@@ -0,0 +1,66 @@
<script setup lang="ts">
import { computed, reactive } from 'vue';
import { $t } from '@/locales';
import { useRouterPush } from '@/hooks/common/router';
import { useAntdForm, useFormRules } from '@/hooks/common/form';
import { useCaptcha } from '@/hooks/business/captcha';
defineOptions({
name: 'CodeLogin'
});
const { toggleLoginModule } = useRouterPush();
const { formRef, validate } = useAntdForm();
const { label, isCounting, loading, getCaptcha } = useCaptcha();
interface FormModel {
phone: string;
code: string;
}
const model: FormModel = reactive({
phone: '',
code: ''
});
const rules = computed<Record<keyof FormModel, App.Global.FormRule[]>>(() => {
const { formRules } = useFormRules();
return {
phone: formRules.phone,
code: formRules.code
};
});
async function handleSubmit() {
await validate();
// request
$message?.success($t('page.login.common.validateSuccess'));
}
</script>
<template>
<AForm ref="formRef" :model="model" :rules="rules">
<AFormItem name="phone">
<AInput v-model:value="model.phone" size="large" :placeholder="$t('page.login.common.phonePlaceholder')" />
</AFormItem>
<AFormItem name="code">
<div class="w-full flex-y-center gap-16px">
<AInput v-model:value="model.code" size="large" :placeholder="$t('page.login.common.codePlaceholder')" />
<AButton size="large" :disabled="isCounting" :loading="loading" @click="getCaptcha(model.phone)">
{{ label }}
</AButton>
</div>
</AFormItem>
<ASpace direction="vertical" size="large" class="w-full">
<AButton type="primary" block size="large" shape="round" @click="handleSubmit">
{{ $t('common.confirm') }}
</AButton>
<AButton block size="large" shape="round" @click="toggleLoginModule('pwd-login')">
{{ $t('page.login.common.back') }}
</AButton>
</ASpace>
</AForm>
</template>
<style scoped></style>

View File

@@ -0,0 +1,81 @@
<script setup lang="ts">
import { $t } from '@/locales';
import { useAntdForm, useFormRules } from '@/hooks/common/form';
import { useAuthStore } from '@/store/modules/auth';
defineOptions({
name: 'PwdLogin'
});
const authStore = useAuthStore();
const { formRef, validate } = useAntdForm();
const { patternRules } = useFormRules();
const codeImg = ref('');
getCheckCode();
const model = reactive({
username: 'ryadmin',
password: 'admin123',
code: '',
uuid: ''
});
const rules = {
username: patternRules.username,
password: patternRules.pwd
};
async function handleSubmit() {
await validate();
await authStore.login({
loginForm: model,
onError() {
getCheckCode();
}
});
}
async function getCheckCode() {
const { data, error } = await doGetCheckCode();
if (!error) {
codeImg.value = `data:image/png;base64,${data.img}`;
model.uuid = data.uuid;
}
}
</script>
<template>
<AForm ref="formRef" :model="model" :rules="rules">
<AFormItem name="username">
<AInput v-model:value="model.username" size="large" :placeholder="$t('page.login.common.userNamePlaceholder')" />
</AFormItem>
<AFormItem name="password">
<AInputPassword
v-model:value="model.password"
size="large"
:placeholder="$t('page.login.common.passwordPlaceholder')"
/>
</AFormItem>
<AFormItem>
<div class="flex gap-4">
<AInput v-model:value="model.code" size="large" :placeholder="$t('page.login.common.checkCode')">
<template #suffix></template>
</AInput>
<AImage :preview="false" :src="codeImg" @click="getCheckCode" />
</div>
</AFormItem>
<ASpace direction="vertical" size="large" class="w-full">
<div class="flex-y-center justify-between">
<ACheckbox>{{ $t('page.login.pwdLogin.rememberMe') }}</ACheckbox>
<AButton type="text">{{ $t('page.login.pwdLogin.forgetPassword') }}</AButton>
</div>
<AButton type="primary" block size="large" shape="round" :loading="authStore.loginLoading" @click="handleSubmit">
{{ $t('common.confirm') }}
</AButton>
</ASpace>
</AForm>
</template>
<style scoped></style>

View File

@@ -0,0 +1,86 @@
<script setup lang="ts">
import { computed, reactive } from 'vue';
import { $t } from '@/locales';
import { useRouterPush } from '@/hooks/common/router';
import { useAntdForm, useFormRules } from '@/hooks/common/form';
import { useCaptcha } from '@/hooks/business/captcha';
defineOptions({
name: 'CodeLogin'
});
const { toggleLoginModule } = useRouterPush();
const { formRef, validate } = useAntdForm();
const { label, isCounting, loading, getCaptcha } = useCaptcha();
interface FormModel {
phone: string;
code: string;
password: string;
confirmPassword: string;
}
const model: FormModel = reactive({
phone: '',
code: '',
password: '',
confirmPassword: ''
});
const rules = computed<Record<keyof FormModel, App.Global.FormRule[]>>(() => {
const { formRules, createConfirmPwdRule } = useFormRules();
return {
phone: formRules.phone,
code: formRules.code,
password: formRules.pwd,
confirmPassword: createConfirmPwdRule(model.password)
};
});
async function handleSubmit() {
await validate();
// request to register
$message?.success($t('page.login.common.validateSuccess'));
}
</script>
<template>
<AForm ref="formRef" :model="model" :rules="rules">
<AFormItem name="phone">
<AInput v-model:value="model.phone" size="large" :placeholder="$t('page.login.common.phonePlaceholder')" />
</AFormItem>
<AFormItem name="code">
<div class="w-full flex-y-center gap-16px">
<AInput v-model:value="model.code" size="large" :placeholder="$t('page.login.common.codePlaceholder')" />
<AButton size="large" :disabled="isCounting" :loading="loading" @click="getCaptcha(model.phone)">
{{ label }}
</AButton>
</div>
</AFormItem>
<AFormItem name="password">
<AInputPassword
v-model:value="model.password"
size="large"
:placeholder="$t('page.login.common.passwordPlaceholder')"
/>
</AFormItem>
<AFormItem name="confirmPassword">
<AInputPassword
v-model:value="model.confirmPassword"
size="large"
:placeholder="$t('page.login.common.confirmPasswordPlaceholder')"
/>
</AFormItem>
<ASpace direction="vertical" size="large" class="w-full">
<AButton type="primary" block size="large" shape="round" @click="handleSubmit">
{{ $t('common.confirm') }}
</AButton>
<AButton block size="large" shape="round" @click="toggleLoginModule('pwd-login')">
{{ $t('page.login.common.back') }}
</AButton>
</ASpace>
</AForm>
</template>
<style scoped></style>

View File

@@ -0,0 +1,80 @@
<script setup lang="ts">
import { computed, reactive } from 'vue';
import { $t } from '@/locales';
import { useRouterPush } from '@/hooks/common/router';
import { useAntdForm, useFormRules } from '@/hooks/common/form';
defineOptions({
name: 'ResetPwd'
});
const { toggleLoginModule } = useRouterPush();
const { formRef, validate } = useAntdForm();
interface FormModel {
phone: string;
code: string;
password: string;
confirmPassword: string;
}
const model: FormModel = reactive({
phone: '',
code: '',
password: '',
confirmPassword: ''
});
type RuleRecord = Partial<Record<keyof FormModel, App.Global.FormRule[]>>;
const rules = computed<RuleRecord>(() => {
const { formRules, createConfirmPwdRule } = useFormRules();
return {
phone: formRules.phone,
password: formRules.pwd,
confirmPassword: createConfirmPwdRule(model.password)
};
});
async function handleSubmit() {
await validate();
// request to reset password
$message?.success($t('page.login.common.validateSuccess'));
}
</script>
<template>
<AForm ref="formRef" :model="model" :rules="rules">
<AFormItem name="phone">
<AInput v-model:value="model.phone" size="large" :placeholder="$t('page.login.common.phonePlaceholder')" />
</AFormItem>
<AFormItem name="code">
<AInput v-model:value="model.code" size="large" :placeholder="$t('page.login.common.codePlaceholder')" />
</AFormItem>
<AFormItem name="password">
<AInputPassword
v-model:value="model.password"
size="large"
:placeholder="$t('page.login.common.passwordPlaceholder')"
/>
</AFormItem>
<AFormItem name="confirmPassword">
<AInputPassword
v-model:value="model.confirmPassword"
size="large"
:placeholder="$t('page.login.common.confirmPasswordPlaceholder')"
/>
</AFormItem>
<ASpace direction="vertical" size="large" class="w-full">
<AButton type="primary" block size="large" shape="round" @click="handleSubmit">
{{ $t('common.confirm') }}
</AButton>
<AButton block size="large" shape="round" @click="toggleLoginModule('pwd-login')">
{{ $t('page.login.common.back') }}
</AButton>
</ASpace>
</AForm>
</template>
<style scoped></style>