From f15c0224c3ecfddf7aeb55bf422883ce273c509a Mon Sep 17 00:00:00 2001 From: tikkhun Date: Thu, 27 Nov 2025 23:50:22 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=A8=A1=E6=9D=BF=E7=AE=A1=E7=90=86):=20?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=A8=A1=E6=9D=BF=E7=AE=A1=E7=90=86=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加模板管理路由和页面组件 - 实现模板的增删改查接口 - 修改产品分类为品牌管理相关代码 - 更新字典管理接口路径 --- .umirc.ts | 14 ++ src/pages/Dict/List/index.tsx | 24 ++-- src/pages/Product/Category/index.tsx | 32 ++--- src/pages/Product/List/index.tsx | 29 ++-- src/pages/Template/index.tsx | 206 +++++++++++++++++++++++++++ src/servers/api/template.ts | 20 +-- 6 files changed, 273 insertions(+), 52 deletions(-) create mode 100644 src/pages/Template/index.tsx diff --git a/.umirc.ts b/.umirc.ts index 44454a2..f810ace 100644 --- a/.umirc.ts +++ b/.umirc.ts @@ -56,6 +56,20 @@ export default defineConfig({ }, ], }, + { + // 模板管理 + name: '模板管理', + path: '/template', + access: 'canSeeDict', // 权限暂用 canSeeDict + routes: [ + { + // 模板列表 + name: '模板列表', + path: '/template/list', + component: './Template', // 对应 src/pages/Template/index.tsx + }, + ], + }, { name: '站点管理', path: '/site', diff --git a/src/pages/Dict/List/index.tsx b/src/pages/Dict/List/index.tsx index 49d01f5..dbe6f4f 100644 --- a/src/pages/Dict/List/index.tsx +++ b/src/pages/Dict/List/index.tsx @@ -32,7 +32,7 @@ const DictPage: React.FC = () => { const fetchDicts = async (title?: string) => { setLoadingDicts(true); try { - const res = await request('/api/dicts', { params: { title } }); + const res = await request('/dict/list', { params: { title } }); if (res) { setDicts(res); } @@ -46,7 +46,7 @@ const DictPage: React.FC = () => { const fetchDictItems = async (dictId?: number) => { setLoadingDictItems(true); try { - const res = await request('/api/dict-items', { params: { dictId } }); + const res = await request('/dict/items', { params: { dictId } }); if (res) { setDictItems(res); } @@ -80,13 +80,13 @@ const DictPage: React.FC = () => { } try { if (editingDict) { - await request(`/api/dicts/${editingDict.id}`, { + await request(`/dict/${editingDict.id}`, { method: 'PUT', data: { name: newDictName, title: newDictTitle }, }); message.success('更新成功'); } else { - await request('/api/dicts', { + await request('/dict', { method: 'POST', data: { name: newDictName, title: newDictTitle }, }); @@ -132,14 +132,14 @@ const DictPage: React.FC = () => { try { if (editingDictItem) { // 编辑 - await request(`/api/dict-items/${editingDictItem.id}`, { + await request(`/dict/item/${editingDictItem.id}`, { method: 'PUT', data: dictItemForm, }); message.success('更新成功'); } else { // 添加 - await request('/api/dict-items', { + await request('/dict/item', { method: 'POST', data: { ...dictItemForm, dictId: selectedDict.id }, }); @@ -155,7 +155,7 @@ const DictPage: React.FC = () => { // 处理删除字典项 const handleDeleteDictItem = async (itemId: number) => { try { - await request(`/api/dict-items/${itemId}`, { method: 'DELETE' }); + await request(`/dict/item/${itemId}`, { method: 'DELETE' }); message.success('删除成功'); fetchDictItems(selectedDict.id); } catch (error) { @@ -166,7 +166,7 @@ const DictPage: React.FC = () => { // 处理删除字典 const handleDeleteDict = async (dictId: number) => { try { - await request(`/api/dicts/${dictId}`, { method: 'DELETE' }); + await request(`/dict/${dictId}`, { method: 'DELETE' }); message.success('删除成功'); fetchDicts(); // 重新获取字典列表 // 如果删除的是当前选中的字典,则清空右侧列表 @@ -244,7 +244,7 @@ const DictPage: React.FC = () => { { if (info.file.status === 'done') { @@ -257,7 +257,7 @@ const DictPage: React.FC = () => { > - + { { > - +
diff --git a/src/pages/Product/Category/index.tsx b/src/pages/Product/Category/index.tsx index c350a82..59c987c 100644 --- a/src/pages/Product/Category/index.tsx +++ b/src/pages/Product/Category/index.tsx @@ -1,8 +1,8 @@ import { - productcontrollerCreatecategory, - productcontrollerDeletecategory, - productcontrollerGetcategories, - productcontrollerUpdatecategory, + productcontrollerCreatebrand, + productcontrollerDeletebrand, + productcontrollerGetbrands, + productcontrollerUpdatebrand, } from '@/servers/api/product'; import { EditOutlined, PlusOutlined } from '@ant-design/icons'; import { @@ -20,7 +20,7 @@ import { useRef } from 'react'; const List: React.FC = () => { const actionRef = useRef(); const { message } = App.useApp(); - const columns: ProColumns[] = [ + const columns: ProColumns[] = [ { title: '名称', dataIndex: 'name', @@ -65,7 +65,7 @@ const List: React.FC = () => { onConfirm={async () => { try { const { success, message: errMsg } = - await productcontrollerDeletecategory({ id: record.id }); + await productcontrollerDeletebrand({ id: record.id }); if (!success) { throw new Error(errMsg); } @@ -85,14 +85,14 @@ const List: React.FC = () => { ]; return ( - - + + headerTitle="查询表格" actionRef={actionRef} rowKey="id" toolBarRender={() => []} request={async (params) => { - const { data, success } = await productcontrollerGetcategories( + const { data, success } = await productcontrollerGetbrands( params, ); return { @@ -112,7 +112,7 @@ const CreateForm: React.FC<{ }> = ({ tableRef }) => { const { message } = App.useApp(); return ( - + title="新建" trigger={ + + + ), + }, + ]; + + return ( + + + headerTitle="查询表格" + actionRef={actionRef} + rowKey="id" + toolBarRender={() => []} + request={async (params) => { + const response = await templatecontrollerGettemplatelist(params as any) as any; + return { + data: response.items || [], + total: response.total || 0, + success: true, + }; + }} + columns={columns} + /> + + ); +}; + +const CreateForm: React.FC<{ + tableRef: React.MutableRefObject; +}> = ({ tableRef }) => { + const { message } = App.useApp(); + return ( + + title="新建" + trigger={ + + } + autoFocusFirstInput + drawerProps={{ + destroyOnHidden: true, + }} + onFinish={async (values) => { + try { + await templatecontrollerCreatetemplate(values); + tableRef.current?.reload(); + message.success('提交成功'); + return true; + } catch (error: any) { + message.error(error.message); + return false; + } + }} + > + + + + ); +}; + +const UpdateForm: React.FC<{ + tableRef: React.MutableRefObject; + values: API.Template; +}> = ({ tableRef, values: initialValues }) => { + const { message } = App.useApp(); + return ( + + title="编辑" + initialValues={initialValues} + trigger={ + + } + autoFocusFirstInput + drawerProps={{ + destroyOnHidden: true, + }} + onFinish={async (values) => { + if (!initialValues.id) return false; + try { + await templatecontrollerUpdatetemplate( + { id: initialValues.id }, + values, + ); + message.success('提交成功'); + tableRef.current?.reload(); + return true; + } catch (error: any) { + message.error(error.message); + return false; + } + }} + > + + + + + + ); +}; + + +export default List; diff --git a/src/servers/api/template.ts b/src/servers/api/template.ts index 420e86d..05e7d8f 100644 --- a/src/servers/api/template.ts +++ b/src/servers/api/template.ts @@ -2,16 +2,6 @@ /* eslint-disable */ import { request } from 'umi'; -/** 此处后端没有提供注释 GET /template/ */ -export async function templatecontrollerGettemplatelist(options?: { - [key: string]: any; -}) { - return request('/template/', { - method: 'GET', - ...(options || {}), - }); -} - /** 此处后端没有提供注释 POST /template/ */ export async function templatecontrollerCreatetemplate( body: API.CreateTemplateDTO, @@ -73,3 +63,13 @@ export async function templatecontrollerDeletetemplate( ...(options || {}), }); } + +/** 此处后端没有提供注释 GET /template/list */ +export async function templatecontrollerGettemplatelist(options?: { + [key: string]: any; +}) { + return request('/template/list', { + method: 'GET', + ...(options || {}), + }); +}