diff --git a/apps/backend-mock/api/upload.ts b/apps/backend-mock/api/upload.ts new file mode 100644 index 000000000..1bb9e602d --- /dev/null +++ b/apps/backend-mock/api/upload.ts @@ -0,0 +1,13 @@ +import { verifyAccessToken } from '~/utils/jwt-utils'; +import { unAuthorizedResponse } from '~/utils/response'; + +export default eventHandler((event) => { + const userinfo = verifyAccessToken(event); + if (!userinfo) { + return unAuthorizedResponse(event); + } + return useResponseSuccess({ + url: 'https://unpkg.com/@vbenjs/static-source@0.1.7/source/logo-v1.webp', + }); + // return useResponseError("test") +}); diff --git a/apps/backend-mock/routes/[...].ts b/apps/backend-mock/routes/[...].ts index 70c5f7c74..99f544b66 100644 --- a/apps/backend-mock/routes/[...].ts +++ b/apps/backend-mock/routes/[...].ts @@ -7,6 +7,7 @@ export default defineEventHandler(() => {
  • /api/menu/all
  • /api/auth/codes
  • /api/auth/login
  • +
  • /api/upload
  • `; }); diff --git a/apps/web-antd/src/adapter/component/index.ts b/apps/web-antd/src/adapter/component/index.ts index 698f5c786..9cc430135 100644 --- a/apps/web-antd/src/adapter/component/index.ts +++ b/apps/web-antd/src/adapter/component/index.ts @@ -115,7 +115,9 @@ export type ComponentType = | 'DatePicker' | 'DefaultButton' | 'Divider' + | 'FileUpload' | 'IconPicker' + | 'ImageUpload' | 'Input' | 'InputNumber' | 'InputPassword' @@ -125,16 +127,14 @@ export type ComponentType = | 'RadioGroup' | 'RangePicker' | 'Rate' + | 'RichTextarea' | 'Select' | 'Space' | 'Switch' | 'Textarea' - | 'RichTextarea' | 'TimePicker' | 'TreeSelect' | 'Upload' - | 'FileUpload' - | 'ImageUpload' | BaseFormComponentType; async function initComponentAdapter() { diff --git a/apps/web-antd/src/api/core/auth.ts b/apps/web-antd/src/api/core/auth.ts index 809f29cdc..c71f5f598 100644 --- a/apps/web-antd/src/api/core/auth.ts +++ b/apps/web-antd/src/api/core/auth.ts @@ -1,6 +1,7 @@ -import { baseRequestClient, requestClient } from '#/api/request'; import type { AuthPermissionInfo } from '@vben/types'; +import { baseRequestClient, requestClient } from '#/api/request'; + export namespace AuthApi { /** 登录接口参数 */ export interface LoginParams { @@ -41,9 +42,9 @@ export namespace AuthApi { /** 注册接口参数 */ export interface RegisterParams { - username: string - password: string - captchaVerification: string + username: string; + password: string; + captchaVerification: string; } /** 重置密码接口参数 */ @@ -68,16 +69,22 @@ export async function loginApi(data: AuthApi.LoginParams) { /** 刷新 accessToken */ export async function refreshTokenApi(refreshToken: string) { - return baseRequestClient.post(`/system/auth/refresh-token?refreshToken=${refreshToken}`); + return baseRequestClient.post( + `/system/auth/refresh-token?refreshToken=${refreshToken}`, + ); } /** 退出登录 */ export async function logoutApi(accessToken: string) { - return baseRequestClient.post('/system/auth/logout', {}, { - headers: { - Authorization: `Bearer ${accessToken}`, - } - }); + return baseRequestClient.post( + '/system/auth/logout', + {}, + { + headers: { + Authorization: `Bearer ${accessToken}`, + }, + }, + ); } /** 获取权限信息 */ @@ -96,7 +103,9 @@ export async function getTenantSimpleList() { /** 使用租户域名,获得租户信息 */ export async function getTenantByWebsite(website: string) { - return requestClient.get(`/system/tenant/get-by-website?website=${website}`); + return requestClient.get( + `/system/tenant/get-by-website?website=${website}`, + ); } /** 获取验证码 */ @@ -111,23 +120,23 @@ export async function checkCaptcha(data: any) { /** 获取登录验证码 */ export const sendSmsCode = (data: AuthApi.SmsCodeParams) => { - return requestClient.post('/system/auth/send-sms-code', data ) -} + return requestClient.post('/system/auth/send-sms-code', data); +}; /** 短信验证码登录 */ export const smsLogin = (data: AuthApi.SmsLoginParams) => { - return requestClient.post('/system/auth/sms-login', data) -} + return requestClient.post('/system/auth/sms-login', data); +}; /** 注册 */ export const register = (data: AuthApi.RegisterParams) => { - return requestClient.post('/system/auth/register', data) -} + return requestClient.post('/system/auth/register', data); +}; /** 通过短信重置密码 */ export const smsResetPassword = (data: AuthApi.ResetPasswordParams) => { - return requestClient.post('/system/auth/reset-password', data) -} + return requestClient.post('/system/auth/reset-password', data); +}; /** 社交授权的跳转 */ export const socialAuthRedirect = (type: number, redirectUri: string) => { @@ -137,9 +146,12 @@ export const socialAuthRedirect = (type: number, redirectUri: string) => { redirectUri, }, }); -} +}; /** 社交快捷登录 */ export const socialLogin = (data: AuthApi.SocialLoginParams) => { - return requestClient.post('/system/auth/social-login', data); -} + return requestClient.post( + '/system/auth/social-login', + data, + ); +}; diff --git a/apps/web-antd/src/views/_core/authentication/code-login.vue b/apps/web-antd/src/views/_core/authentication/code-login.vue index d3225ee1c..4a3df65fe 100644 --- a/apps/web-antd/src/views/_core/authentication/code-login.vue +++ b/apps/web-antd/src/views/_core/authentication/code-login.vue @@ -2,21 +2,25 @@ import type { VbenFormSchema } from '@vben/common-ui'; import type { Recordable } from '@vben/types'; -import { computed, ref, onMounted } from 'vue'; +import type { AuthApi } from '#/api'; + +import { computed, onMounted, ref } from 'vue'; import { AuthenticationCodeLogin, z } from '@vben/common-ui'; -import { $t } from '@vben/locales'; -import { type AuthApi, sendSmsCode } from '#/api'; import { useAppConfig } from '@vben/hooks'; +import { $t } from '@vben/locales'; +import { useAccessStore } from '@vben/stores'; + import { message } from 'ant-design-vue'; -import { getTenantSimpleList, getTenantByWebsite } from '#/api/core/auth'; -import { useAccessStore } from '@vben/stores'; +import { sendSmsCode } from '#/api'; +import { getTenantByWebsite, getTenantSimpleList } from '#/api/core/auth'; import { useAuthStore } from '#/store'; -const { tenantEnable } = useAppConfig(import.meta.env, import.meta.env.PROD); defineOptions({ name: 'CodeLogin' }); +const { tenantEnable } = useAppConfig(import.meta.env, import.meta.env.PROD); + const authStore = useAuthStore(); const accessStore = useAccessStore(); @@ -37,7 +41,7 @@ const fetchTenantList = async () => { tenantList.value = await getTenantSimpleList(); // 选中租户:域名 > store 中的租户 > 首个租户 - let tenantId: number | null = null; + let tenantId: null | number = null; const websiteTenant = await websiteTenantPromise; if (websiteTenant?.id) { tenantId = websiteTenant.id; @@ -77,11 +81,7 @@ const formSchema = computed((): VbenFormSchema[] => { }, fieldName: 'tenantId', label: $t('authentication.tenant'), - rules: z - .number() - .nullable() - .refine((val) => val != null && val > 0, $t('authentication.tenantTip')) - .default(null), + rules: z.number().positive(), dependencies: { triggerFields: ['tenantId'], if: tenantEnable, @@ -140,7 +140,7 @@ const formSchema = computed((): VbenFormSchema[] => { } finally { loading.value = false; } - } + }, }, fieldName: 'code', label: $t('authentication.code'), diff --git a/apps/web-antd/src/views/_core/authentication/forget-password.vue b/apps/web-antd/src/views/_core/authentication/forget-password.vue index d853a52a7..7feaed7b9 100644 --- a/apps/web-antd/src/views/_core/authentication/forget-password.vue +++ b/apps/web-antd/src/views/_core/authentication/forget-password.vue @@ -2,18 +2,21 @@ import type { VbenFormSchema } from '@vben/common-ui'; import type { Recordable } from '@vben/types'; -import { computed, ref, onMounted, h } from 'vue'; +import type { AuthApi } from '#/api'; -import { AuthenticationForgetPassword, z } from '@vben/common-ui'; -import { $t } from '@vben/locales'; -import { type AuthApi, sendSmsCode, smsResetPassword } from '#/api'; -import { useAppConfig } from '@vben/hooks'; -import { message } from 'ant-design-vue'; +import { computed, onMounted, ref } from 'vue'; import { useRouter } from 'vue-router'; -import { getTenantSimpleList, getTenantByWebsite } from '#/api/core/auth'; +import { AuthenticationForgetPassword, z } from '@vben/common-ui'; +import { useAppConfig } from '@vben/hooks'; +import { $t } from '@vben/locales'; import { useAccessStore } from '@vben/stores'; +import { message } from 'ant-design-vue'; + +import { sendSmsCode, smsResetPassword } from '#/api'; +import { getTenantByWebsite, getTenantSimpleList } from '#/api/core/auth'; + defineOptions({ name: 'ForgetPassword' }); const { tenantEnable } = useAppConfig(import.meta.env, import.meta.env.PROD); @@ -36,7 +39,7 @@ const fetchTenantList = async () => { tenantList.value = await getTenantSimpleList(); // 选中租户:域名 > store 中的租户 > 首个租户 - let tenantId: number | null = null; + let tenantId: null | number = null; const websiteTenant = await websiteTenantPromise; if (websiteTenant?.id) { tenantId = websiteTenant.id; @@ -76,11 +79,7 @@ const formSchema = computed((): VbenFormSchema[] => { }, fieldName: 'tenantId', label: $t('authentication.tenant'), - rules: z - .number() - .nullable() - .refine((val) => val != null && val > 0, $t('authentication.tenantTip')) - .default(null), + rules: z.number().positive(), dependencies: { triggerFields: ['tenantId'], if: tenantEnable, @@ -139,7 +138,7 @@ const formSchema = computed((): VbenFormSchema[] => { } finally { loading.value = false; } - } + }, }, fieldName: 'code', label: $t('authentication.code'), diff --git a/apps/web-antd/src/views/_core/authentication/login.vue b/apps/web-antd/src/views/_core/authentication/login.vue index 50102a439..f7641ec2c 100644 --- a/apps/web-antd/src/views/_core/authentication/login.vue +++ b/apps/web-antd/src/views/_core/authentication/login.vue @@ -1,24 +1,32 @@ diff --git a/playground/src/views/examples/form/basic.vue b/playground/src/views/examples/form/basic.vue index 75e868d8f..d0e91d33a 100644 --- a/playground/src/views/examples/form/basic.vue +++ b/playground/src/views/examples/form/basic.vue @@ -1,5 +1,7 @@