From 29f08b36575b76aa6343f5441044e0364e691d90 Mon Sep 17 00:00:00 2001 From: linxd <544554903@qq.com> Date: Mon, 30 Jun 2025 19:00:57 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=B4=E6=8A=A4=E9=80=9A=E7=9F=A5=E4=B8=AD?= =?UTF-8?q?=E5=BF=83=E5=A4=9A=E8=AF=AD=E8=A8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/locales/en-US.ts | 2 + src/locales/en-US/noticeManage.ts | 92 ++++++++++++ src/locales/zh-CN.ts | 2 + src/locales/zh-CN/noticeManage.ts | 92 ++++++++++++ src/pages/noticeManage/NoticeManageForm.tsx | 53 ++++--- src/pages/noticeManage/NoticeManageInfo.tsx | 23 ++- src/pages/noticeManage/noticeManage.tsx | 157 ++++++++++++-------- 7 files changed, 332 insertions(+), 89 deletions(-) diff --git a/src/locales/en-US.ts b/src/locales/en-US.ts index 72e972c..b8f1f06 100644 --- a/src/locales/en-US.ts +++ b/src/locales/en-US.ts @@ -7,6 +7,7 @@ import policyManage from './en-US/policyManage'; import userQuestion from './en-US/userQuestion'; import friendLink from './en-US/friendLink'; import downloadManage from './en-US/downloadManage'; +import noticeManage from './en-US/noticeManage'; export default { ...common, @@ -18,4 +19,5 @@ export default { ...userQuestion, ...friendLink, ...downloadManage, + ...noticeManage, }; diff --git a/src/locales/en-US/noticeManage.ts b/src/locales/en-US/noticeManage.ts index e69de29..62e0a45 100644 --- a/src/locales/en-US/noticeManage.ts +++ b/src/locales/en-US/noticeManage.ts @@ -0,0 +1,92 @@ +export default { + // Page Title + 'notice.title': 'Notification Center', + 'notice.selected.count': 'Selected {count} items', + 'notice.warning.select.required': 'Please select records to delete', + 'notice.warning.published.delete': 'Published notices cannot be deleted', + 'notice.confirm.batchDelete': 'Are you sure you want to delete {count} selected notices?', + 'notice.confirm.batchDelete.content': 'This cannot be undone', + 'notice.form.status.placeholder': 'Please select status', + + // Form and Table Fields + 'notice.field.title': 'Title', + 'notice.field.titleEn': 'Title (English)', + 'notice.field.content': 'Content', + 'notice.field.contentEn': 'Content (English)', + 'notice.field.status': 'Status', + 'notice.field.date': 'Date', + 'notice.field.publisher': 'Publisher', + 'notice.field.operation': 'Operation', + 'notice.field.isTop': 'Pin to Top', + 'notice.field.settingEn': 'Set English Content', + + // Status + 'notice.status.draft': 'Draft', + 'notice.status.published': 'Published', + 'notice.status.unpublished': 'Unpublished', + + // Buttons and Actions + 'notice.button.add': 'Add', + 'notice.button.edit': 'Edit', + 'notice.button.delete': 'Delete', + 'notice.button.view': 'View', + 'notice.button.publish': 'Publish', + 'notice.button.unpublish': 'Unpublish', + 'notice.button.top': 'Pin to Top', + 'notice.button.untop': 'Unpin', + 'notice.button.search': 'Search', + 'notice.button.reset': 'Reset', + 'notice.button.submit': 'Submit', + 'notice.button.cancel': 'Cancel', + 'notice.button.close': 'Close', + + // Confirmations + 'notice.confirm.delete': 'Are you sure you want to delete this notice?', + 'notice.confirm.publish': 'Are you sure you want to publish this notice?', + 'notice.confirm.unpublish': 'Are you sure you want to unpublish this notice?', + 'notice.confirm.top': 'Are you sure you want to pin this notice to top?', + 'notice.confirm.untop': 'Are you sure you want to unpin this notice?', + + // Form Hints + 'notice.form.title.placeholder': 'Please enter title', + 'notice.form.title.required': 'Please enter title', + 'notice.form.titleEn.placeholder': 'Please enter English title', + 'notice.form.titleEn.required': 'Please enter English title', + 'notice.form.content.placeholder': 'Please enter content', + 'notice.form.content.required': 'Please enter content', + 'notice.form.contentEn.placeholder': 'Please enter English content', + 'notice.form.contentEn.required': 'Please enter English content', + + // Success and Failure Messages + 'notice.message.get.success': 'Successfully retrieved list', + 'notice.message.get.fail': 'Failed to retrieve list', + 'notice.message.detail.success': 'Successfully retrieved details', + 'notice.message.detail.fail': 'Failed to retrieve details', + 'notice.message.add.success': 'Successfully added', + 'notice.message.add.fail': 'Failed to add', + 'notice.message.update.success': 'Successfully updated', + 'notice.message.update.fail': 'Failed to update', + 'notice.message.delete.success': 'Successfully deleted', + 'notice.message.delete.fail': 'Failed to delete', + 'notice.message.publish.success': 'Successfully published', + 'notice.message.publish.fail': 'Failed to publish', + 'notice.message.unpublish.success': 'Successfully unpublished', + 'notice.message.unpublish.fail': 'Failed to unpublish', + 'notice.message.top.success': 'Successfully pinned to top', + 'notice.message.top.fail': 'Failed to pin to top', + 'notice.message.untop.success': 'Successfully unpinned', + 'notice.message.untop.fail': 'Failed to unpin', + + // Options + 'notice.option.yes': 'Yes', + 'notice.option.no': 'No', + + // Tabs + 'notice.tab.chinese': 'Chinese Version', + 'notice.tab.english': 'English Version', + + // Form Titles + 'notice.view.title': 'View Notice', + 'notice.edit.title': 'Edit Notice', + 'notice.add.title': 'Add Notice', +}; diff --git a/src/locales/zh-CN.ts b/src/locales/zh-CN.ts index 90526ec..0e0bce3 100644 --- a/src/locales/zh-CN.ts +++ b/src/locales/zh-CN.ts @@ -7,6 +7,7 @@ import policyManage from './zh-CN/policyManage'; import userQuestion from './zh-CN/userQuestion'; import friendLink from './zh-CN/friendLink'; import downloadManage from './zh-CN/downloadManage'; +import noticeManage from './zh-CN/noticeManage'; export default { ...common, @@ -18,4 +19,5 @@ export default { ...userQuestion, ...friendLink, ...downloadManage, + ...noticeManage, }; diff --git a/src/locales/zh-CN/noticeManage.ts b/src/locales/zh-CN/noticeManage.ts index e69de29..b0e4e18 100644 --- a/src/locales/zh-CN/noticeManage.ts +++ b/src/locales/zh-CN/noticeManage.ts @@ -0,0 +1,92 @@ +export default { + // 页面标题 + 'notice.title': '通知中心', + 'notice.selected.count': '已选择 {count} 项', + 'notice.warning.select.required': '请选择需要删除的记录', + 'notice.warning.published.delete': '已发布的通知不能删除', + 'notice.confirm.batchDelete': '确定要删除选中的 {count} 条通知吗?', + 'notice.confirm.batchDelete.content': '删除后无法恢复', + 'notice.form.status.placeholder': '请选择状态', + + // 表单和表格字段 + 'notice.field.title': '标题', + 'notice.field.titleEn': '标题(英文)', + 'notice.field.content': '内容', + 'notice.field.contentEn': '内容(英文)', + 'notice.field.status': '状态', + 'notice.field.date': '日期', + 'notice.field.publisher': '发布人', + 'notice.field.operation': '操作', + 'notice.field.isTop': '是否置顶', + 'notice.field.settingEn': '是否设置英文内容', + + // 状态 + 'notice.status.draft': '草稿', + 'notice.status.published': '已发布', + 'notice.status.unpublished': '已下架', + + // 按钮和操作 + 'notice.button.add': '新增', + 'notice.button.edit': '编辑', + 'notice.button.delete': '删除', + 'notice.button.view': '查看', + 'notice.button.publish': '发布', + 'notice.button.unpublish': '下架', + 'notice.button.top': '置顶', + 'notice.button.untop': '取消置顶', + 'notice.button.search': '搜索', + 'notice.button.reset': '重置', + 'notice.button.submit': '提交', + 'notice.button.cancel': '取消', + 'notice.button.close': '关闭', + + // 提示和确认框 + 'notice.confirm.delete': '确定要删除该通知吗?', + 'notice.confirm.publish': '确定要发布该通知吗?', + 'notice.confirm.unpublish': '确定要下架该通知吗?', + 'notice.confirm.top': '确定要置顶该通知吗?', + 'notice.confirm.untop': '确定要取消置顶该通知吗?', + + // 表单提示 + 'notice.form.title.placeholder': '请输入标题', + 'notice.form.title.required': '请输入标题', + 'notice.form.titleEn.placeholder': '请输入英文标题', + 'notice.form.titleEn.required': '请输入英文标题', + 'notice.form.content.placeholder': '请输入通知内容', + 'notice.form.content.required': '请输入通知内容', + 'notice.form.contentEn.placeholder': '请输入英文通知内容', + 'notice.form.contentEn.required': '请输入英文通知内容', + + // 成功和失败提示 + 'notice.message.get.success': '获取列表成功', + 'notice.message.get.fail': '获取列表失败', + 'notice.message.detail.success': '获取详情成功', + 'notice.message.detail.fail': '获取详情失败', + 'notice.message.add.success': '添加成功', + 'notice.message.add.fail': '添加失败', + 'notice.message.update.success': '更新成功', + 'notice.message.update.fail': '更新失败', + 'notice.message.delete.success': '删除成功', + 'notice.message.delete.fail': '删除失败', + 'notice.message.publish.success': '发布成功', + 'notice.message.publish.fail': '发布失败', + 'notice.message.unpublish.success': '下架成功', + 'notice.message.unpublish.fail': '下架失败', + 'notice.message.top.success': '置顶成功', + 'notice.message.top.fail': '置顶失败', + 'notice.message.untop.success': '取消置顶成功', + 'notice.message.untop.fail': '取消置顶失败', + + // 选项 + 'notice.option.yes': '是', + 'notice.option.no': '否', + + // 标签页 + 'notice.tab.chinese': '中文版', + 'notice.tab.english': '英文版', + + // 表单标题 + 'notice.view.title': '查看通知', + 'notice.edit.title': '编辑通知', + 'notice.add.title': '新增通知', +}; diff --git a/src/pages/noticeManage/NoticeManageForm.tsx b/src/pages/noticeManage/NoticeManageForm.tsx index 8d932d8..29faa8a 100644 --- a/src/pages/noticeManage/NoticeManageForm.tsx +++ b/src/pages/noticeManage/NoticeManageForm.tsx @@ -1,5 +1,6 @@ import React, { useState, useEffect } from 'react'; import { Form, Input, Switch, Tabs, message, Button } from 'antd'; +import { useIntl } from 'umi'; import WangEditor from '@/components/WangEidtor/WangEidtor'; import { TopStatus, EnglishSetting } from '@/dicts/noticeManageDict'; import { addNotice, updateNotice, getNoticeDetail } from '@/servers/api/notice'; @@ -14,6 +15,7 @@ interface NoticeManageFormProps { } const NoticeManageForm: React.FC = ({ id, isEdit, onSuccess }) => { + const intl = useIntl(); const [form] = Form.useForm(); const [activeTabKey, setActiveTabKey] = useState('zh'); const [loading, setLoading] = useState(false); @@ -78,6 +80,7 @@ const NoticeManageForm: React.FC = ({ id, isEdit, onSucce } } + message.error(intl.formatMessage({ id: 'notice.message.validate.fail' })); throw error; } @@ -102,10 +105,14 @@ const NoticeManageForm: React.FC = ({ id, isEdit, onSucce } if (response && response.success) { - message.success(isEdit ? '更新成功' : '添加成功'); + message.success(intl.formatMessage({ + id: isEdit ? 'notice.message.update.success' : 'notice.message.add.success' + })); onSuccess(); // 回调父组件 } else { - message.error(response.message || (isEdit ? '更新失败' : '添加失败')); + message.error(response.message || intl.formatMessage({ + id: isEdit ? 'notice.message.update.fail' : 'notice.message.add.fail' + })); } } catch (error: any) { console.error('表单验证或提交失败:', error); @@ -118,63 +125,69 @@ const NoticeManageForm: React.FC = ({ id, isEdit, onSucce return (
- + - + - + - + - + - + - +
- +
diff --git a/src/pages/noticeManage/NoticeManageInfo.tsx b/src/pages/noticeManage/NoticeManageInfo.tsx index 0875d9a..a21f4ee 100644 --- a/src/pages/noticeManage/NoticeManageInfo.tsx +++ b/src/pages/noticeManage/NoticeManageInfo.tsx @@ -1,4 +1,5 @@ import React from 'react'; +import { useIntl } from 'umi'; import { Descriptions, Divider, Card, Tag } from 'antd'; import { NoticeStatus, NoticeStatusText, NoticeStatusColor } from '@/dicts/noticeManageDict'; import styles from './noticeManage.less'; @@ -16,33 +17,39 @@ const getStatusTag = (status: string) => { }; const NoticeManageInfo: React.FC = ({ data }) => { + const intl = useIntl(); if (!data) return null; return (
- + {data.title} {data.titleEn && ( - + {data.titleEn} )} - {data.isTop === '1' ? '是' : '否'} - {getStatusTag(data.status)} - {data.createBy} - {data.createTime} + + {data.isTop === '1' + ? intl.formatMessage({ id: 'notice.option.yes' }) + : intl.formatMessage({ id: 'notice.option.no' }) + } + + {getStatusTag(data.status)} + {data.createBy} + {data.createTime} - 中文内容 + {intl.formatMessage({ id: 'notice.tab.chinese' })}
{data.contentEn && ( <> - 英文内容 + {intl.formatMessage({ id: 'notice.tab.english' })}
diff --git a/src/pages/noticeManage/noticeManage.tsx b/src/pages/noticeManage/noticeManage.tsx index 6d6dafd..ae620be 100644 --- a/src/pages/noticeManage/noticeManage.tsx +++ b/src/pages/noticeManage/noticeManage.tsx @@ -52,7 +52,7 @@ const NoticeManage: React.FC = () => { total: 0, showSizeChanger: true, showQuickJumper: true, - showTotal: (total: number) => `共 ${total} 条记录`, + showTotal: (total: number) => `${total}`, }); const [searchParams, setSearchParams] = useState({}); @@ -103,6 +103,11 @@ const NoticeManage: React.FC = () => { // 首次加载时获取数据 useEffect(() => { fetchNoticeList(1, pagination.pageSize, {}); + // 设置表格分页显示总数的文本 + setPagination({ + ...pagination, + showTotal: (total: number) => intl.formatMessage({ id: 'notice.total.count' }, { total }), + }); }, []); // 处理查看 @@ -129,7 +134,7 @@ const NoticeManage: React.FC = () => { const handleEdit = (record: NoticeType) => { // 检查是否为已发布状态 if (record.status === NoticeStatus.PUBLISHED) { - message.warning('已发布的通知不能编辑'); + message.warning(intl.formatMessage({ id: 'notice.warning.published.edit' })); return; } @@ -148,22 +153,22 @@ const NoticeManage: React.FC = () => { } Modal.confirm({ - title: '确定要删除该通知吗?', + title: intl.formatMessage({ id: 'notice.confirm.delete' }), icon: , - content: `标题: ${record.title}`, - okText: '确定', + content: `${intl.formatMessage({ id: 'notice.field.title' })}: ${record.title}`, + okText: intl.formatMessage({ id: 'notice.button.submit' }), okType: 'danger', - cancelText: '取消', + cancelText: intl.formatMessage({ id: 'notice.button.cancel' }), maskClosable: false, onOk: async () => { try { // 调用删除API const response = await deleteNotice(record.id); if (response && response.success) { - message.success('删除成功'); + message.success(intl.formatMessage({ id: 'notice.message.delete.success' })); fetchNoticeList(pagination.current, pagination.pageSize, searchParams); // 重新加载数据 } else { - message.error(response.message || '删除失败'); + message.error(response.message || intl.formatMessage({ id: 'notice.message.delete.fail' })); } } catch (error) { console.error('删除通知失败:', error); @@ -177,30 +182,39 @@ const NoticeManage: React.FC = () => { const handlePublishStatus = async (record: NoticeType) => { // 状态: 0-草稿,1-已发布,2-已下架 const isPublished = record.status === NoticeStatus.PUBLISHED; - const actionText = isPublished ? '下架' : '发布'; + const actionText = isPublished + ? intl.formatMessage({ id: 'notice.button.unpublish' }) + : intl.formatMessage({ id: 'notice.button.publish' }); + const actionMessageKey = isPublished ? 'notice.confirm.unpublish' : 'notice.confirm.publish'; const newStatus = isPublished ? NoticeStatus.UNPUBLISHED : NoticeStatus.PUBLISHED; Modal.confirm({ - title: `确定要${actionText}该通知吗?`, + title: intl.formatMessage({ id: actionMessageKey }), icon: , - content: `标题: ${record.title}`, - okText: '确定', + content: `${intl.formatMessage({ id: 'notice.field.title' })}: ${record.title}`, + okText: intl.formatMessage({ id: 'notice.button.submit' }), okType: isPublished ? 'danger' : 'primary', - cancelText: '取消', + cancelText: intl.formatMessage({ id: 'notice.button.cancel' }), maskClosable: false, onOk: async () => { try { // 调用API更新状态 const response = await updateNoticeStatus(record.id, newStatus); if (response && response.success) { - message.success(`${actionText}成功`); + message.success(intl.formatMessage({ + id: isPublished ? 'notice.message.unpublish.success' : 'notice.message.publish.success' + })); fetchNoticeList(pagination.current, pagination.pageSize, searchParams); // 重新加载数据 } else { - message.error(response.message || `${actionText}失败`); + message.error(response.message || intl.formatMessage({ + id: isPublished ? 'notice.message.unpublish.fail' : 'notice.message.publish.fail' + })); } } catch (error) { - console.error(`${actionText}失败:`, error); - message.error(`${actionText}失败`); + console.error(`${actionText} failed:`, error); + message.error(intl.formatMessage({ + id: isPublished ? 'notice.message.unpublish.fail' : 'notice.message.publish.fail' + })); } }, }); @@ -209,30 +223,39 @@ const NoticeManage: React.FC = () => { // 处理置顶/取消置顶 const handleToggleTop = async (record: NoticeType) => { const isTop = record.isTop === TopStatus.YES; - const actionText = isTop ? '取消置顶' : '置顶'; + const actionText = isTop + ? intl.formatMessage({ id: 'notice.button.untop' }) + : intl.formatMessage({ id: 'notice.button.top' }); + const actionMessageKey = isTop ? 'notice.confirm.untop' : 'notice.confirm.top'; const newIsTop = isTop ? TopStatus.NO : TopStatus.YES; Modal.confirm({ - title: `确定要${actionText}该通知吗?`, + title: intl.formatMessage({ id: actionMessageKey }), icon: , - content: `标题: ${record.title}`, - okText: '确定', + content: `${intl.formatMessage({ id: 'notice.field.title' })}: ${record.title}`, + okText: intl.formatMessage({ id: 'notice.button.submit' }), okType: 'primary', - cancelText: '取消', + cancelText: intl.formatMessage({ id: 'notice.button.cancel' }), maskClosable: false, onOk: async () => { try { // 调用API更新置顶状态 const response = await updateNoticeTopStatus(record.id, newIsTop); if (response && response.success) { - message.success(`${actionText}成功`); + message.success(intl.formatMessage({ + id: isTop ? 'notice.message.untop.success' : 'notice.message.top.success' + })); fetchNoticeList(pagination.current, pagination.pageSize, searchParams); // 重新加载数据 } else { - message.error(response.message || `${actionText}失败`); + message.error(response.message || intl.formatMessage({ + id: isTop ? 'notice.message.untop.fail' : 'notice.message.top.fail' + })); } } catch (error) { - console.error(`${actionText}失败:`, error); - message.error(`${actionText}失败`); + console.error(`${actionText} failed:`, error); + message.error(intl.formatMessage({ + id: isTop ? 'notice.message.untop.fail' : 'notice.message.top.fail' + })); } }, }); @@ -253,13 +276,13 @@ const NoticeManage: React.FC = () => { const columns = [ { - title: '序号', + title: '#', render: (text: string, record: NoticeType, index: number) => index + 1, width: 80, align: 'center' as const, }, { - title: '标题', + title: intl.formatMessage({ id: 'notice.field.title' }), dataIndex: 'title', key: 'title', ellipsis: { @@ -268,69 +291,76 @@ const NoticeManage: React.FC = () => { render: (title: string, record: NoticeType) => ( - {record.isTop === TopStatus.YES && 置顶} + {record.isTop === TopStatus.YES && ( + + {intl.formatMessage({ id: 'notice.button.top' })} + + )} {title} ), }, { - title: '日期', + title: intl.formatMessage({ id: 'notice.field.date' }), dataIndex: 'createTime', key: 'createTime', align: 'center' as const, }, { - title: '状态', + title: intl.formatMessage({ id: 'notice.field.status' }), dataIndex: 'status', key: 'status', align: 'center' as const, render: (status: string) => getStatusTag(status), }, { - title: '发布人', + title: intl.formatMessage({ id: 'notice.field.publisher' }), dataIndex: 'createBy', key: 'createBy', align: 'center' as const, }, { - title: '操作', + title: intl.formatMessage({ id: 'notice.field.operation' }), key: 'action', width: 300, align: 'center' as const, render: (_: unknown, record: NoticeType) => ( <> {record.status === NoticeStatus.PUBLISHED ? ( <> ) : ( <> )} @@ -370,7 +400,7 @@ const NoticeManage: React.FC = () => { // 处理批量删除 const handleBatchDelete = () => { if (selectedRowKeys.length === 0) { - message.warning('请选择需要删除的记录'); + message.warning(intl.formatMessage({ id: 'notice.warning.select.required' })); return; } @@ -380,17 +410,17 @@ const NoticeManage: React.FC = () => { ); if (hasPublished) { - message.warning('已发布的通知不能删除'); + message.warning(intl.formatMessage({ id: 'notice.warning.published.delete' })); return; } Modal.confirm({ - title: `确定要删除选中的 ${selectedRowKeys.length} 条通知吗?`, + title: intl.formatMessage({ id: 'notice.confirm.batchDelete' }, { count: selectedRowKeys.length }), icon: , - content: '删除后无法恢复', - okText: '确定', + content: intl.formatMessage({ id: 'notice.confirm.batchDelete.content' }), + okText: intl.formatMessage({ id: 'notice.button.submit' }), okType: 'danger', - cancelText: '取消', + cancelText: intl.formatMessage({ id: 'notice.button.cancel' }), maskClosable: false, onOk: async () => { try { @@ -398,11 +428,11 @@ const NoticeManage: React.FC = () => { // 调用批量删除API const response = await batchDeleteNotice(ids); if (response && response.success) { - message.success('批量删除成功'); + message.success(intl.formatMessage({ id: 'notice.message.batchDelete.success' })); setSelectedRowKeys([]); // 清空选择 fetchNoticeList(pagination.current, pagination.pageSize, searchParams); // 重新加载数据 } else { - message.error(response.message || '批量删除失败'); + message.error(response.message || intl.formatMessage({ id: 'notice.message.batchDelete.fail' })); } } catch (error) { console.error('批量删除失败:', error); @@ -434,19 +464,19 @@ const NoticeManage: React.FC = () => { layout="inline" className="filter-form" > - - + + - - + + + @@ -469,7 +499,7 @@ const NoticeManage: React.FC = () => { icon={} onClick={handleAdd} > - 新增 + {intl.formatMessage({ id: 'notice.button.add' })} {hasSelected && ( - 已选择 {selectedRowKeys.length} 项 + {intl.formatMessage({ id: 'notice.selected.count' }, { count: selectedRowKeys.length })} )}
@@ -501,7 +531,12 @@ const NoticeManage: React.FC = () => { {/* 新增/编辑/查看模态框 */} { isViewMode ? [ , ] : null