diff --git a/config/config.ts b/config/config.ts index c076a947..280405a0 100644 --- a/config/config.ts +++ b/config/config.ts @@ -205,6 +205,32 @@ export default defineConfig({ // schemaPath: "https://gw.alipayobjects.com/os/antfincdn/M%24jrzTTYJN/oneapi.json" schemaPath: join(__dirname, 'oneapi.json'), mock: false, + // Capitalize the first letter of operationId so that generated type + // names follow PascalCase convention, consistent with schema-derived + // types. isCamelCase (default true) normalizes function names back to + // camelCase in service files. + hook: { + customFunctionName: ((data: { + operationId?: string; + method?: string; + path?: string; + }) => { + if (data.operationId) { + return ( + data.operationId.charAt(0).toUpperCase() + + data.operationId.slice(1) + ); + } + const method = data.method || 'get'; + const segments = (data.path || '').split('/').filter(Boolean); + const name = + method + + segments + .map((s) => s.charAt(0).toUpperCase() + s.slice(1)) + .join(''); + return name.charAt(0).toUpperCase() + name.slice(1); + }) as () => any, + }, }, ], diff --git a/src/components/RightContent/AvatarDropdown.tsx b/src/components/RightContent/AvatarDropdown.tsx index d8e6fb0b..f4fedc80 100644 --- a/src/components/RightContent/AvatarDropdown.tsx +++ b/src/components/RightContent/AvatarDropdown.tsx @@ -7,7 +7,7 @@ import { history, useModel } from '@umijs/max'; import type { MenuProps } from 'antd'; import { Spin } from 'antd'; import React, { startTransition } from 'react'; -import { outLogin } from '@/services/ant-design-pro/api'; +import { outLogin } from '@/services/ant-design-pro/login'; import HeaderDropdown from '../HeaderDropdown'; type GlobalHeaderRightProps = { diff --git a/src/pages/table-list/components/CreateForm.tsx b/src/pages/table-list/components/CreateForm.tsx index 3c645823..9d5bab56 100644 --- a/src/pages/table-list/components/CreateForm.tsx +++ b/src/pages/table-list/components/CreateForm.tsx @@ -9,7 +9,7 @@ import { useMutation, useQueryClient } from '@tanstack/react-query'; import { FormattedMessage, useIntl } from '@umijs/max'; import { Button, message } from 'antd'; import type { FC } from 'react'; -import { addRule } from '@/services/ant-design-pro/api'; +import { addRule } from '@/services/ant-design-pro/rule'; interface CreateFormProps { reload?: ActionType['reload']; diff --git a/src/pages/table-list/components/UpdateForm.tsx b/src/pages/table-list/components/UpdateForm.tsx index 3523715e..049fd30f 100644 --- a/src/pages/table-list/components/UpdateForm.tsx +++ b/src/pages/table-list/components/UpdateForm.tsx @@ -10,7 +10,7 @@ import { useMutation, useQueryClient } from '@tanstack/react-query'; import { FormattedMessage, useIntl } from '@umijs/max'; import { Modal, message } from 'antd'; import React, { cloneElement, useCallback, useState } from 'react'; -import { updateRule } from '@/services/ant-design-pro/api'; +import { updateRule } from '@/services/ant-design-pro/rule'; type UpdateFormProps = { trigger?: React.ReactElement; diff --git a/src/pages/table-list/index.tsx b/src/pages/table-list/index.tsx index b1459967..dfc0f1db 100644 --- a/src/pages/table-list/index.tsx +++ b/src/pages/table-list/index.tsx @@ -13,7 +13,7 @@ import { useMutation, useQueryClient } from '@tanstack/react-query'; import { FormattedMessage, useIntl } from '@umijs/max'; import { Button, Drawer, type FormInstance, Input, message } from 'antd'; import React, { useCallback, useRef, useState } from 'react'; -import { removeRule, rule } from '@/services/ant-design-pro/api'; +import { removeRule, rule } from '@/services/ant-design-pro/rule'; import CreateForm from './components/CreateForm'; import UpdateForm from './components/UpdateForm'; diff --git a/src/pages/user/login/index.tsx b/src/pages/user/login/index.tsx index e4218395..8f5a9e62 100644 --- a/src/pages/user/login/index.tsx +++ b/src/pages/user/login/index.tsx @@ -23,8 +23,7 @@ import { Alert, App, Tabs } from 'antd'; import { createStyles } from 'antd-style'; import React, { startTransition, useState } from 'react'; import { Footer } from '@/components'; -import { login } from '@/services/ant-design-pro/api'; -import { getFakeCaptcha } from '@/services/ant-design-pro/login'; +import { getFakeCaptcha, login } from '@/services/ant-design-pro/login'; import Settings from '../../../../config/defaultSettings'; const useStyles = createStyles(({ token }) => { diff --git a/src/services/ant-design-pro/api.ts b/src/services/ant-design-pro/api.ts index 7f9d4a4f..fdd5afaf 100644 --- a/src/services/ant-design-pro/api.ts +++ b/src/services/ant-design-pro/api.ts @@ -1,94 +1,19 @@ // @ts-ignore /* eslint-disable */ -import { request } from '@umijs/max'; +import { request } from "@umijs/max"; /** 获取当前的用户 GET /api/currentUser */ export async function currentUser(options?: { [key: string]: any }) { - return request<{ - data: API.CurrentUser; - }>('/api/currentUser', { - method: 'GET', - ...(options || {}), - }); -} - -/** 退出登录接口 POST /api/login/outLogin */ -export async function outLogin(options?: { [key: string]: any }) { - return request>('/api/login/outLogin', { - method: 'POST', - ...(options || {}), - }); -} - -/** 登录接口 POST /api/login/account */ -export async function login(body: API.LoginParams, options?: { [key: string]: any }) { - return request('/api/login/account', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - data: body, + return request("/api/currentUser", { + method: "GET", ...(options || {}), }); } /** 此处后端没有提供注释 GET /api/notices */ export async function getNotices(options?: { [key: string]: any }) { - return request('/api/notices', { - method: 'GET', + return request("/api/notices", { + method: "GET", ...(options || {}), }); } - -/** 获取规则列表 GET /api/rule */ -export async function rule( - params: { - // query - /** 当前的页码 */ - current?: number; - /** 页面的容量 */ - pageSize?: number; - }, - options?: { [key: string]: any }, -) { - return request('/api/rule', { - method: 'GET', - params: { - ...params, - }, - ...(options || {}), - }); -} - -/** 更新规则 PUT /api/rule */ -export async function updateRule(options?: { [key: string]: any }) { - return request('/api/rule', { - method: 'POST', - data: { - method: 'update', - ...(options || {}), - }, - }); -} - -/** 新建规则 POST /api/rule */ -export async function addRule(options?: { [key: string]: any }) { - return request('/api/rule', { - method: 'POST', - data: { - method: 'post', - ...(options || {}), - }, - }); -} - -/** 删除规则 DELETE /api/rule */ -export async function removeRule(options?: { [key: string]: any }) { - return request>('/api/rule', { - method: 'POST', - data: { - method: 'delete', - ...(options || {}), - }, - }); -} diff --git a/src/services/ant-design-pro/index.ts b/src/services/ant-design-pro/index.ts index 1ac489fe..aa859d62 100644 --- a/src/services/ant-design-pro/index.ts +++ b/src/services/ant-design-pro/index.ts @@ -2,9 +2,11 @@ /* eslint-disable */ // API 更新时间: // API 唯一标识: -import * as api from './api'; -import * as login from './login'; +import * as api from "./api"; +import * as login from "./login"; +import * as rule from "./rule"; export default { api, login, + rule, }; diff --git a/src/services/ant-design-pro/login.ts b/src/services/ant-design-pro/login.ts index 8871ed84..6c5c5d9f 100644 --- a/src/services/ant-design-pro/login.ts +++ b/src/services/ant-design-pro/login.ts @@ -1,21 +1,41 @@ // @ts-ignore /* eslint-disable */ -import { request } from '@umijs/max'; +import { request } from "@umijs/max"; + +/** 登录接口 POST /api/login/account */ +export async function login( + body: API.LoginParams, + options?: { [key: string]: any } +) { + return request("/api/login/account", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + data: body, + ...(options || {}), + }); +} /** 发送验证码 POST /api/login/captcha */ export async function getFakeCaptcha( - params: { - // query - /** 手机号 */ - phone?: string; - }, - options?: { [key: string]: any }, + // 叠加生成的Param类型 (非body参数swagger默认没有生成对象) + params: API.GetFakeCaptchaParams, + options?: { [key: string]: any } ) { - return request('/api/login/captcha', { - method: 'GET', + return request("/api/login/captcha", { + method: "POST", params: { ...params, }, ...(options || {}), }); } + +/** 登录接口 POST /api/login/outLogin */ +export async function outLogin(options?: { [key: string]: any }) { + return request>("/api/login/outLogin", { + method: "POST", + ...(options || {}), + }); +} diff --git a/src/services/ant-design-pro/rule.ts b/src/services/ant-design-pro/rule.ts new file mode 100644 index 00000000..5acf1092 --- /dev/null +++ b/src/services/ant-design-pro/rule.ts @@ -0,0 +1,42 @@ +// @ts-ignore +/* eslint-disable */ +import { request } from "@umijs/max"; + +/** 获取规则列表 GET /api/rule */ +export async function rule( + // 叠加生成的Param类型 (非body参数swagger默认没有生成对象) + params: API.RuleParams, + options?: { [key: string]: any } +) { + return request("/api/rule", { + method: "GET", + params: { + ...params, + }, + ...(options || {}), + }); +} + +/** 新建规则 PUT /api/rule */ +export async function updateRule(options?: { [key: string]: any }) { + return request("/api/rule", { + method: "PUT", + ...(options || {}), + }); +} + +/** 新建规则 POST /api/rule */ +export async function addRule(options?: { [key: string]: any }) { + return request("/api/rule", { + method: "POST", + ...(options || {}), + }); +} + +/** 删除规则 DELETE /api/rule */ +export async function removeRule(options?: { [key: string]: any }) { + return request>("/api/rule", { + method: "DELETE", + ...(options || {}), + }); +} diff --git a/src/services/ant-design-pro/typings.d.ts b/src/services/ant-design-pro/typings.d.ts index 13e5a680..20c65225 100644 --- a/src/services/ant-design-pro/typings.d.ts +++ b/src/services/ant-design-pro/typings.d.ts @@ -1,6 +1,3 @@ -// @ts-ignore -/* eslint-disable */ - declare namespace API { type CurrentUser = { name?: string; @@ -23,36 +20,12 @@ declare namespace API { phone?: string; }; - type LoginResult = { - status?: string; - type?: string; - currentAuthority?: string; - }; - - type PageParams = { - current?: number; - pageSize?: number; - }; - - type RuleListItem = { - key?: number; - disabled?: boolean; - href?: string; - avatar?: string; - name?: string; - owner?: string; - desc?: string; - callNo?: number; - status?: number; - updatedAt?: string; - createdAt?: string; - progress?: number; - }; - - type RuleList = { - data?: RuleListItem[]; - /** 列表的内容总数 */ - total?: number; + type ErrorResponse = { + /** 业务约定的错误码 */ + errorCode: string; + /** 业务上的错误信息 */ + errorMessage?: string; + /** 业务上的请求是否成功 */ success?: boolean; }; @@ -61,6 +34,11 @@ declare namespace API { status?: string; }; + type GetFakeCaptchaParams = { + /** 手机号 */ + phone?: string; + }; + type LoginParams = { username?: string; password?: string; @@ -68,24 +46,12 @@ declare namespace API { type?: string; }; - type ErrorResponse = { - /** 业务约定的错误码 */ - errorCode: string; - /** 业务上的错误信息 */ - errorMessage?: string; - /** 业务上的请求是否成功 */ - success?: boolean; - }; - - type NoticeIconList = { - data?: NoticeIconItem[]; - /** 列表的内容总数 */ - total?: number; - success?: boolean; + type LoginResult = { + status?: string; + type?: string; + currentAuthority?: string; }; - type NoticeIconItemType = 'notification' | 'message' | 'event'; - type NoticeIconItem = { id?: string; extra?: string; @@ -98,4 +64,47 @@ declare namespace API { description?: string; type?: NoticeIconItemType; }; + + type NoticeIconItemType = "notification" | "message" | "event"; + + type NoticeIconList = { + data?: NoticeIconItem[]; + /** 列表的内容总数 */ + total?: number; + success?: boolean; + }; + + type PageParams = { + current?: number; + pageSize?: number; + }; + + type RuleList = { + data?: RuleListItem[]; + /** 列表的内容总数 */ + total?: number; + success?: boolean; + }; + + type RuleListItem = { + key?: number; + disabled?: boolean; + href?: string; + avatar?: string; + name?: string; + owner?: string; + desc?: string; + callNo?: number; + status?: number; + updatedAt?: string; + createdAt?: string; + progress?: number; + }; + + type RuleParams = { + /** 当前的页码 */ + current?: number; + /** 页面的容量 */ + pageSize?: number; + }; }