移除国际化

This commit is contained in:
brian 2023-07-07 17:11:49 +08:00
parent c87ca8333b
commit 0cd329ae7d
11 changed files with 131 additions and 397 deletions

View File

@ -4,9 +4,7 @@ import { join } from 'path';
import defaultSettings from './defaultSettings'; import defaultSettings from './defaultSettings';
import proxy from './proxy'; import proxy from './proxy';
import routes from './routes'; import routes from './routes';
const { REACT_APP_ENV = 'dev' } = process.env; const { REACT_APP_ENV = 'dev' } = process.env;
export default defineConfig({ export default defineConfig({
/** /**
* @name hash * @name hash
@ -14,7 +12,6 @@ export default defineConfig({
* @doc https://umijs.org/docs/api/config#hash * @doc https://umijs.org/docs/api/config#hash
*/ */
hash: true, hash: true,
/** /**
* @name * @name
* @description ie11 使 * @description ie11 使
@ -93,15 +90,7 @@ export default defineConfig({
/** /**
* @name * @name
* @doc https://umijs.org/docs/max/i18n * @doc https://umijs.org/docs/max/i18n
*/ */ /**
locale: {
// default zh-CN
default: 'zh-CN',
antd: true,
// default true, when it is true, will use `navigator.language` overwrite default
baseNavigator: true,
},
/**
* @name antd * @name antd
* @description babel import * @description babel import
* @doc https://umijs.org/docs/max/antd#antd * @doc https://umijs.org/docs/max/antd#antd
@ -125,7 +114,10 @@ export default defineConfig({
*/ */
headScripts: [ headScripts: [
// 解决首次加载时白屏的问题 // 解决首次加载时白屏的问题
{ src: '/scripts/loading.js', async: true }, {
src: '/scripts/loading.js',
async: true,
},
], ],
//================ pro 插件配置 ================= //================ pro 插件配置 =================
presets: ['umi-presets-pro'], presets: ['umi-presets-pro'],

View File

@ -1,63 +1,21 @@
/**
* @name umi
* @description path,component,routes,redirect,wrappers,name,icon
* @param path path 第一种是动态参数 :id *
* @param component location path React src/pages
* @param routes layout 使
* @param redirect
* @param wrappers
* @param name menu.ts menu.xxxx name login menu.ts menu.login
* @param icon https://ant.design/components/icon-cn 注意去除风格后缀和大小写,如想要配置图标为 <StepBackwardOutlined /> 则取值应为 stepBackward 或 StepBackward如想要配置图标为 <UserOutlined /> 则取值应为 user 或者 User
* @doc https://umijs.org/docs/guides/routes
*/
export default [ export default [
{ {
path: '/user', path: '/user',
layout: false, layout: false,
routes: [ routes: [{ name: '登录', path: '/user/login', component: './User/Login' }],
{
name: 'login',
path: '/user/login',
component: './User/Login',
},
],
},
{
path: '/welcome',
name: 'welcome',
icon: 'smile',
component: './Welcome',
}, },
{ path: '/welcome', name: '欢迎', icon: 'smile', component: './Welcome' },
{ {
path: '/admin', path: '/admin',
name: 'admin', name: '管理页',
icon: 'crown', icon: 'crown',
access: 'canAdmin', access: 'canAdmin',
routes: [ routes: [
{ { path: '/admin', redirect: '/admin/sub-page' },
path: '/admin', { path: '/admin/sub-page', name: '二级管理页', component: './Admin' },
redirect: '/admin/sub-page',
},
{
path: '/admin/sub-page',
name: 'sub-page',
component: './Admin',
},
], ],
}, },
{ { name: '查询表格', icon: 'table', path: '/list', component: './TableList' },
name: 'list.table-list', { path: '/', redirect: '/welcome' },
icon: 'table', { path: '*', layout: false, component: './404' },
path: '/list',
component: './TableList',
},
{
path: '/',
redirect: '/welcome',
},
{
path: '*',
layout: false,
component: './404',
},
]; ];

View File

@ -76,8 +76,11 @@
"@umijs/fabric": "^2.14.1", "@umijs/fabric": "^2.14.1",
"@umijs/lint": "^4.0.52", "@umijs/lint": "^4.0.52",
"@umijs/max": "^4.0.52", "@umijs/max": "^4.0.52",
"add": "^2.0.6",
"cross-env": "^7.0.3", "cross-env": "^7.0.3",
"eslint": "^8.34.0", "eslint": "^8.34.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-unicorn": "^47.0.0",
"express": "^4.18.2", "express": "^4.18.2",
"gh-pages": "^3.2.3", "gh-pages": "^3.2.3",
"husky": "^7.0.4", "husky": "^7.0.4",
@ -89,7 +92,8 @@
"swagger-ui-dist": "^4.15.5", "swagger-ui-dist": "^4.15.5",
"ts-node": "^10.9.1", "ts-node": "^10.9.1",
"typescript": "^4.9.5", "typescript": "^4.9.5",
"umi-presets-pro": "^2.0.2" "umi-presets-pro": "^2.0.2",
"yarn": "^1.22.19"
}, },
"engines": { "engines": {
"node": ">=12.0.0" "node": ">=12.0.0"

View File

@ -1,15 +1,14 @@
import Footer from '@/components/Footer'; import Footer from '@/components/Footer';
import { Question, SelectLang } from '@/components/RightContent'; import { Question } from '@/components/RightContent';
import { LinkOutlined } from '@ant-design/icons'; import { LinkOutlined } from '@ant-design/icons';
import type { Settings as LayoutSettings } from '@ant-design/pro-components'; import type { Settings as LayoutSettings } from '@ant-design/pro-components';
import { SettingDrawer } from '@ant-design/pro-components'; import { SettingDrawer } from '@ant-design/pro-components';
import type { RunTimeLayoutConfig } from '@umijs/max'; import type { RunTimeLayoutConfig } from '@umijs/max';
import { history, Link } from '@umijs/max'; import { history, Link } from '@umijs/max';
import defaultSettings from '../config/defaultSettings'; import defaultSettings from '../config/defaultSettings';
import { AvatarDropdown, AvatarName } from './components/RightContent/AvatarDropdown';
import { errorConfig } from './requestErrorConfig'; import { errorConfig } from './requestErrorConfig';
import { currentUser as queryCurrentUser } from './services/ant-design-pro/api'; import { currentUser as queryCurrentUser } from './services/ant-design-pro/api';
import React from 'react';
import { AvatarDropdown, AvatarName } from './components/RightContent/AvatarDropdown';
const isDev = process.env.NODE_ENV === 'development'; const isDev = process.env.NODE_ENV === 'development';
const loginPath = '/user/login'; const loginPath = '/user/login';
@ -52,7 +51,7 @@ export async function getInitialState(): Promise<{
// ProLayout 支持的api https://procomponents.ant.design/components/layout // ProLayout 支持的api https://procomponents.ant.design/components/layout
export const layout: RunTimeLayoutConfig = ({ initialState, setInitialState }) => { export const layout: RunTimeLayoutConfig = ({ initialState, setInitialState }) => {
return { return {
actionsRender: () => [<Question key="doc" />, <SelectLang key="SelectLang" />], actionsRender: () => [<Question key="doc" />],
avatarProps: { avatarProps: {
src: initialState?.currentUser?.avatar, src: initialState?.currentUser?.avatar,
title: <AvatarName />, title: <AvatarName />,

View File

@ -1,17 +1,10 @@
import { GithubOutlined } from '@ant-design/icons'; import { GithubOutlined } from '@ant-design/icons';
import { DefaultFooter } from '@ant-design/pro-components'; import { DefaultFooter } from '@ant-design/pro-components';
import { useIntl } from '@umijs/max'; import '@umijs/max';
import React from 'react'; import React from 'react';
const Footer: React.FC = () => { const Footer: React.FC = () => {
const intl = useIntl(); const defaultMessage = '蚂蚁集团体验技术部出品';
const defaultMessage = intl.formatMessage({
id: 'app.copyright.produced',
defaultMessage: '蚂蚁集团体验技术部出品',
});
const currentYear = new Date().getFullYear(); const currentYear = new Date().getFullYear();
return ( return (
<DefaultFooter <DefaultFooter
style={{ style={{
@ -41,5 +34,4 @@ const Footer: React.FC = () => {
/> />
); );
}; };
export default Footer; export default Footer;

View File

@ -1,9 +1,6 @@
import { QuestionCircleOutlined } from '@ant-design/icons'; import { QuestionCircleOutlined } from '@ant-design/icons';
import { SelectLang as UmiSelectLang } from '@umijs/max'; import '@umijs/max';
import React from 'react';
export type SiderTheme = 'light' | 'dark'; export type SiderTheme = 'light' | 'dark';
export const SelectLang = () => { export const SelectLang = () => {
return ( return (
<UmiSelectLang <UmiSelectLang
@ -13,7 +10,6 @@ export const SelectLang = () => {
/> />
); );
}; };
export const Question = () => { export const Question = () => {
return ( return (
<div <div

View File

@ -1,10 +1,8 @@
import { useIntl } from '@umijs/max'; import '@umijs/max';
import { Button, message, notification } from 'antd'; import { Button, message, notification } from 'antd';
import defaultSettings from '../config/defaultSettings'; import defaultSettings from '../config/defaultSettings';
const { pwa } = defaultSettings; const { pwa } = defaultSettings;
const isHttps = document.location.protocol === 'https:'; const isHttps = document.location.protocol === 'https:';
const clearCache = () => { const clearCache = () => {
// remove all caches // remove all caches
if (window.caches) { if (window.caches) {
@ -23,7 +21,7 @@ const clearCache = () => {
if (pwa) { if (pwa) {
// Notify user if offline now // Notify user if offline now
window.addEventListener('sw.offline', () => { window.addEventListener('sw.offline', () => {
message.warning(useIntl().formatMessage({ id: 'app.pwa.offline' })); message.warning('当前处于离线状态');
}); });
// Pop up a prompt on the page asking the user if they want to use the latest version // Pop up a prompt on the page asking the user if they want to use the latest version
@ -46,9 +44,13 @@ if (pwa) {
resolve(msgEvent.data); resolve(msgEvent.data);
} }
}; };
worker.postMessage({ type: 'skip-waiting' }, [channel.port2]); worker.postMessage(
{
type: 'skip-waiting',
},
[channel.port2],
);
}); });
clearCache(); clearCache();
window.location.reload(); window.location.reload();
return true; return true;
@ -62,12 +64,12 @@ if (pwa) {
reloadSW(); reloadSW();
}} }}
> >
{useIntl().formatMessage({ id: 'app.pwa.serviceworker.updated.ok' })} {'刷新'}
</Button> </Button>
); );
notification.open({ notification.open({
message: useIntl().formatMessage({ id: 'app.pwa.serviceworker.updated' }), message: '有新内容',
description: useIntl().formatMessage({ id: 'app.pwa.serviceworker.updated.hint' }), description: '请点击“刷新”按钮或者手动刷新页面',
btn, btn,
key, key,
onClose: async () => null, onClose: async () => null,
@ -86,6 +88,5 @@ if (pwa) {
serviceWorker.getRegistration().then((sw) => { serviceWorker.getRegistration().then((sw) => {
if (sw) sw.unregister(); if (sw) sw.unregister();
}); });
clearCache(); clearCache();
} }

View File

@ -1,24 +1,14 @@
import { HeartTwoTone, SmileTwoTone } from '@ant-design/icons'; import { HeartTwoTone, SmileTwoTone } from '@ant-design/icons';
import { PageContainer } from '@ant-design/pro-components'; import { PageContainer } from '@ant-design/pro-components';
import { useIntl } from '@umijs/max'; import '@umijs/max';
import { Alert, Card, Typography } from 'antd'; import { Alert, Card, Typography } from 'antd';
import React from 'react'; import React from 'react';
const Admin: React.FC = () => { const Admin: React.FC = () => {
const intl = useIntl();
return ( return (
<PageContainer <PageContainer content={' 这个页面只有 admin 权限才能查看'}>
content={intl.formatMessage({
id: 'pages.admin.subPage.title',
defaultMessage: 'This page can only be viewed by admin',
})}
>
<Card> <Card>
<Alert <Alert
message={intl.formatMessage({ message={'更快更强的重型组件,已经发布。'}
id: 'pages.welcome.alertMessage',
defaultMessage: 'Faster and stronger heavy-duty components have been released.',
})}
type="success" type="success"
showIcon showIcon
banner banner
@ -27,11 +17,21 @@ const Admin: React.FC = () => {
marginBottom: 48, marginBottom: 48,
}} }}
/> />
<Typography.Title level={2} style={{ textAlign: 'center' }}> <Typography.Title
level={2}
style={{
textAlign: 'center',
}}
>
<SmileTwoTone /> Ant Design Pro <HeartTwoTone twoToneColor="#eb2f96" /> You <SmileTwoTone /> Ant Design Pro <HeartTwoTone twoToneColor="#eb2f96" /> You
</Typography.Title> </Typography.Title>
</Card> </Card>
<p style={{ textAlign: 'center', marginTop: 24 }}> <p
style={{
textAlign: 'center',
marginTop: 24,
}}
>
Want to add more pages? Please refer to{' '} Want to add more pages? Please refer to{' '}
<a href="https://pro.ant.design/docs/block-cn" target="_blank" rel="noopener noreferrer"> <a href="https://pro.ant.design/docs/block-cn" target="_blank" rel="noopener noreferrer">
use block use block
@ -41,5 +41,4 @@ const Admin: React.FC = () => {
</PageContainer> </PageContainer>
); );
}; };
export default Admin; export default Admin;

View File

@ -6,10 +6,9 @@ import {
ProFormTextArea, ProFormTextArea,
StepsForm, StepsForm,
} from '@ant-design/pro-components'; } from '@ant-design/pro-components';
import { FormattedMessage, useIntl } from '@umijs/max'; import '@umijs/max';
import { Modal } from 'antd'; import { Modal } from 'antd';
import React from 'react'; import React from 'react';
export type FormValueType = { export type FormValueType = {
target?: string; target?: string;
template?: string; template?: string;
@ -17,16 +16,13 @@ export type FormValueType = {
time?: string; time?: string;
frequency?: string; frequency?: string;
} & Partial<API.RuleListItem>; } & Partial<API.RuleListItem>;
export type UpdateFormProps = { export type UpdateFormProps = {
onCancel: (flag?: boolean, formVals?: FormValueType) => void; onCancel: (flag?: boolean, formVals?: FormValueType) => void;
onSubmit: (values: FormValueType) => Promise<void>; onSubmit: (values: FormValueType) => Promise<void>;
updateModalOpen: boolean; updateModalOpen: boolean;
values: Partial<API.RuleListItem>; values: Partial<API.RuleListItem>;
}; };
const UpdateForm: React.FC<UpdateFormProps> = (props) => { const UpdateForm: React.FC<UpdateFormProps> = (props) => {
const intl = useIntl();
return ( return (
<StepsForm <StepsForm
stepsProps={{ stepsProps={{
@ -36,12 +32,11 @@ const UpdateForm: React.FC<UpdateFormProps> = (props) => {
return ( return (
<Modal <Modal
width={640} width={640}
bodyStyle={{ padding: '32px 40px 48px' }} bodyStyle={{
padding: '32px 40px 48px',
}}
destroyOnClose destroyOnClose
title={intl.formatMessage({ title={'规则配置'}
id: 'pages.searchTable.updateForm.ruleConfig',
defaultMessage: '规则配置',
})}
open={props.updateModalOpen} open={props.updateModalOpen}
footer={submitter} footer={submitter}
onCancel={() => { onCancel={() => {
@ -59,50 +54,28 @@ const UpdateForm: React.FC<UpdateFormProps> = (props) => {
name: props.values.name, name: props.values.name,
desc: props.values.desc, desc: props.values.desc,
}} }}
title={intl.formatMessage({ title={'基本信息'}
id: 'pages.searchTable.updateForm.basicConfig',
defaultMessage: '基本信息',
})}
> >
<ProFormText <ProFormText
name="name" name="name"
label={intl.formatMessage({ label={'规则名称'}
id: 'pages.searchTable.updateForm.ruleName.nameLabel',
defaultMessage: '规则名称',
})}
width="md" width="md"
rules={[ rules={[
{ {
required: true, required: true,
message: ( message: '请输入规则名称!',
<FormattedMessage
id="pages.searchTable.updateForm.ruleName.nameRules"
defaultMessage="请输入规则名称!"
/>
),
}, },
]} ]}
/> />
<ProFormTextArea <ProFormTextArea
name="desc" name="desc"
width="md" width="md"
label={intl.formatMessage({ label={'规则描述'}
id: 'pages.searchTable.updateForm.ruleDesc.descLabel', placeholder={'请输入至少五个字符'}
defaultMessage: '规则描述',
})}
placeholder={intl.formatMessage({
id: 'pages.searchTable.updateForm.ruleDesc.descPlaceholder',
defaultMessage: '请输入至少五个字符',
})}
rules={[ rules={[
{ {
required: true, required: true,
message: ( message: '请输入至少五个字符的规则描述!',
<FormattedMessage
id="pages.searchTable.updateForm.ruleDesc.descRules"
defaultMessage="请输入至少五个字符的规则描述!"
/>
),
min: 5, min: 5,
}, },
]} ]}
@ -113,18 +86,12 @@ const UpdateForm: React.FC<UpdateFormProps> = (props) => {
target: '0', target: '0',
template: '0', template: '0',
}} }}
title={intl.formatMessage({ title={'配置规则属性'}
id: 'pages.searchTable.updateForm.ruleProps.title',
defaultMessage: '配置规则属性',
})}
> >
<ProFormSelect <ProFormSelect
name="target" name="target"
width="md" width="md"
label={intl.formatMessage({ label={'监控对象'}
id: 'pages.searchTable.updateForm.object',
defaultMessage: '监控对象',
})}
valueEnum={{ valueEnum={{
0: '表一', 0: '表一',
1: '表二', 1: '表二',
@ -133,10 +100,7 @@ const UpdateForm: React.FC<UpdateFormProps> = (props) => {
<ProFormSelect <ProFormSelect
name="template" name="template"
width="md" width="md"
label={intl.formatMessage({ label={'规则模板'}
id: 'pages.searchTable.updateForm.ruleProps.templateLabel',
defaultMessage: '规则模板',
})}
valueEnum={{ valueEnum={{
0: '规则模板一', 0: '规则模板一',
1: '规则模板二', 1: '规则模板二',
@ -144,10 +108,7 @@ const UpdateForm: React.FC<UpdateFormProps> = (props) => {
/> />
<ProFormRadio.Group <ProFormRadio.Group
name="type" name="type"
label={intl.formatMessage({ label={'规则类型'}
id: 'pages.searchTable.updateForm.ruleProps.typeLabel',
defaultMessage: '规则类型',
})}
options={[ options={[
{ {
value: '0', value: '0',
@ -165,36 +126,22 @@ const UpdateForm: React.FC<UpdateFormProps> = (props) => {
type: '1', type: '1',
frequency: 'month', frequency: 'month',
}} }}
title={intl.formatMessage({ title={'设定调度周期'}
id: 'pages.searchTable.updateForm.schedulingPeriod.title',
defaultMessage: '设定调度周期',
})}
> >
<ProFormDateTimePicker <ProFormDateTimePicker
name="time" name="time"
width="md" width="md"
label={intl.formatMessage({ label={'开始时间'}
id: 'pages.searchTable.updateForm.schedulingPeriod.timeLabel',
defaultMessage: '开始时间',
})}
rules={[ rules={[
{ {
required: true, required: true,
message: ( message: '请选择开始时间!',
<FormattedMessage
id="pages.searchTable.updateForm.schedulingPeriod.timeRules"
defaultMessage="请选择开始时间!"
/>
),
}, },
]} ]}
/> />
<ProFormSelect <ProFormSelect
name="frequency" name="frequency"
label={intl.formatMessage({ label={'监控对象'}
id: 'pages.searchTable.updateForm.object',
defaultMessage: '监控对象',
})}
width="md" width="md"
valueEnum={{ valueEnum={{
month: '月', month: '月',
@ -205,5 +152,4 @@ const UpdateForm: React.FC<UpdateFormProps> = (props) => {
</StepsForm> </StepsForm>
); );
}; };
export default UpdateForm; export default UpdateForm;

View File

@ -10,7 +10,7 @@ import {
ProFormTextArea, ProFormTextArea,
ProTable, ProTable,
} from '@ant-design/pro-components'; } from '@ant-design/pro-components';
import { FormattedMessage, useIntl } from '@umijs/max'; import '@umijs/max';
import { Button, Drawer, Input, message } from 'antd'; import { Button, Drawer, Input, message } from 'antd';
import React, { useRef, useState } from 'react'; import React, { useRef, useState } from 'react';
import type { FormValueType } from './components/UpdateForm'; import type { FormValueType } from './components/UpdateForm';
@ -24,7 +24,9 @@ import UpdateForm from './components/UpdateForm';
const handleAdd = async (fields: API.RuleListItem) => { const handleAdd = async (fields: API.RuleListItem) => {
const hide = message.loading('正在添加'); const hide = message.loading('正在添加');
try { try {
await addRule({ ...fields }); await addRule({
...fields,
});
hide(); hide();
message.success('Added successfully'); message.success('Added successfully');
return true; return true;
@ -50,7 +52,6 @@ const handleUpdate = async (fields: FormValueType) => {
key: fields.key, key: fields.key,
}); });
hide(); hide();
message.success('Configuration is successful'); message.success('Configuration is successful');
return true; return true;
} catch (error) { } catch (error) {
@ -82,7 +83,6 @@ const handleRemove = async (selectedRows: API.RuleListItem[]) => {
return false; return false;
} }
}; };
const TableList: React.FC = () => { const TableList: React.FC = () => {
/** /**
* @en-US Pop-up window of new window * @en-US Pop-up window of new window
@ -94,9 +94,7 @@ const TableList: React.FC = () => {
* @zh-CN * @zh-CN
* */ * */
const [updateModalOpen, handleUpdateModalOpen] = useState<boolean>(false); const [updateModalOpen, handleUpdateModalOpen] = useState<boolean>(false);
const [showDetail, setShowDetail] = useState<boolean>(false); const [showDetail, setShowDetail] = useState<boolean>(false);
const actionRef = useRef<ActionType>(); const actionRef = useRef<ActionType>();
const [currentRow, setCurrentRow] = useState<API.RuleListItem>(); const [currentRow, setCurrentRow] = useState<API.RuleListItem>();
const [selectedRowsState, setSelectedRows] = useState<API.RuleListItem[]>([]); const [selectedRowsState, setSelectedRows] = useState<API.RuleListItem[]>([]);
@ -105,16 +103,10 @@ const TableList: React.FC = () => {
* @en-US International configuration * @en-US International configuration
* @zh-CN * @zh-CN
* */ * */
const intl = useIntl();
const columns: ProColumns<API.RuleListItem>[] = [ const columns: ProColumns<API.RuleListItem>[] = [
{ {
title: ( title: '规则名称',
<FormattedMessage
id="pages.searchTable.updateForm.ruleName.nameLabel"
defaultMessage="Rule name"
/>
),
dataIndex: 'name', dataIndex: 'name',
tip: 'The rule name is the unique key', tip: 'The rule name is the unique key',
render: (dom, entity) => { render: (dom, entity) => {
@ -131,70 +123,42 @@ const TableList: React.FC = () => {
}, },
}, },
{ {
title: <FormattedMessage id="pages.searchTable.titleDesc" defaultMessage="Description" />, title: '描述',
dataIndex: 'desc', dataIndex: 'desc',
valueType: 'textarea', valueType: 'textarea',
}, },
{ {
title: ( title: '服务调用次数',
<FormattedMessage
id="pages.searchTable.titleCallNo"
defaultMessage="Number of service calls"
/>
),
dataIndex: 'callNo', dataIndex: 'callNo',
sorter: true, sorter: true,
hideInForm: true, hideInForm: true,
renderText: (val: string) => renderText: (val: string) => `${val}${'万'}`,
`${val}${intl.formatMessage({
id: 'pages.searchTable.tenThousand',
defaultMessage: ' 万 ',
})}`,
}, },
{ {
title: <FormattedMessage id="pages.searchTable.titleStatus" defaultMessage="Status" />, title: '状态',
dataIndex: 'status', dataIndex: 'status',
hideInForm: true, hideInForm: true,
valueEnum: { valueEnum: {
0: { 0: {
text: ( text: '关闭',
<FormattedMessage
id="pages.searchTable.nameStatus.default"
defaultMessage="Shut down"
/>
),
status: 'Default', status: 'Default',
}, },
1: { 1: {
text: ( text: '运行中',
<FormattedMessage id="pages.searchTable.nameStatus.running" defaultMessage="Running" />
),
status: 'Processing', status: 'Processing',
}, },
2: { 2: {
text: ( text: '已上线',
<FormattedMessage id="pages.searchTable.nameStatus.online" defaultMessage="Online" />
),
status: 'Success', status: 'Success',
}, },
3: { 3: {
text: ( text: '异常',
<FormattedMessage
id="pages.searchTable.nameStatus.abnormal"
defaultMessage="Abnormal"
/>
),
status: 'Error', status: 'Error',
}, },
}, },
}, },
{ {
title: ( title: '上次调度时间',
<FormattedMessage
id="pages.searchTable.titleUpdatedAt"
defaultMessage="Last scheduled time"
/>
),
sorter: true, sorter: true,
dataIndex: 'updatedAt', dataIndex: 'updatedAt',
valueType: 'dateTime', valueType: 'dateTime',
@ -204,21 +168,13 @@ const TableList: React.FC = () => {
return false; return false;
} }
if (`${status}` === '3') { if (`${status}` === '3') {
return ( return <Input {...rest} placeholder={'请输入异常原因!'} />;
<Input
{...rest}
placeholder={intl.formatMessage({
id: 'pages.searchTable.exception',
defaultMessage: 'Please enter the reason for the exception!',
})}
/>
);
} }
return defaultRender(item); return defaultRender(item);
}, },
}, },
{ {
title: <FormattedMessage id="pages.searchTable.titleOption" defaultMessage="Operating" />, title: '操作',
dataIndex: 'option', dataIndex: 'option',
valueType: 'option', valueType: 'option',
render: (_, record) => [ render: (_, record) => [
@ -229,25 +185,18 @@ const TableList: React.FC = () => {
setCurrentRow(record); setCurrentRow(record);
}} }}
> >
<FormattedMessage id="pages.searchTable.config" defaultMessage="Configuration" />
</a>, </a>,
<a key="subscribeAlert" href="https://procomponents.ant.design/"> <a key="subscribeAlert" href="https://procomponents.ant.design/">
<FormattedMessage
id="pages.searchTable.subscribeAlert"
defaultMessage="Subscribe to alerts"
/>
</a>, </a>,
], ],
}, },
]; ];
return ( return (
<PageContainer> <PageContainer>
<ProTable<API.RuleListItem, API.PageParams> <ProTable<API.RuleListItem, API.PageParams>
headerTitle={intl.formatMessage({ headerTitle={'查询表格'}
id: 'pages.searchTable.title',
defaultMessage: 'Enquiry form',
})}
actionRef={actionRef} actionRef={actionRef}
rowKey="key" rowKey="key"
search={{ search={{
@ -261,7 +210,7 @@ const TableList: React.FC = () => {
handleModalOpen(true); handleModalOpen(true);
}} }}
> >
<PlusOutlined /> <FormattedMessage id="pages.searchTable.new" defaultMessage="New" /> <PlusOutlined />
</Button>, </Button>,
]} ]}
request={rule} request={rule}
@ -276,17 +225,17 @@ const TableList: React.FC = () => {
<FooterToolbar <FooterToolbar
extra={ extra={
<div> <div>
<FormattedMessage id="pages.searchTable.chosen" defaultMessage="Chosen" />{' '} {' '}
<a style={{ fontWeight: 600 }}>{selectedRowsState.length}</a>{' '} <a
<FormattedMessage id="pages.searchTable.item" defaultMessage="项" /> style={{
&nbsp;&nbsp; fontWeight: 600,
}}
>
{selectedRowsState.length}
</a>{' '}
&nbsp;&nbsp;
<span> <span>
<FormattedMessage {selectedRowsState.reduce((pre, item) => pre + item.callNo!, 0)}
id="pages.searchTable.totalServiceCalls"
defaultMessage="Total number of service calls"
/>{' '}
{selectedRowsState.reduce((pre, item) => pre + item.callNo!, 0)}{' '}
<FormattedMessage id="pages.searchTable.tenThousand" defaultMessage="万" />
</span> </span>
</div> </div>
} }
@ -298,24 +247,13 @@ const TableList: React.FC = () => {
actionRef.current?.reloadAndRest?.(); actionRef.current?.reloadAndRest?.();
}} }}
> >
<FormattedMessage
id="pages.searchTable.batchDeletion"
defaultMessage="Batch deletion"
/>
</Button>
<Button type="primary">
<FormattedMessage
id="pages.searchTable.batchApproval"
defaultMessage="Batch approval"
/>
</Button> </Button>
<Button type="primary"></Button>
</FooterToolbar> </FooterToolbar>
)} )}
<ModalForm <ModalForm
title={intl.formatMessage({ title={'新建规则'}
id: 'pages.searchTable.createForm.newRule',
defaultMessage: 'New rule',
})}
width="400px" width="400px"
open={createModalOpen} open={createModalOpen}
onOpenChange={handleModalOpen} onOpenChange={handleModalOpen}
@ -333,12 +271,7 @@ const TableList: React.FC = () => {
rules={[ rules={[
{ {
required: true, required: true,
message: ( message: '规则名称为必填项',
<FormattedMessage
id="pages.searchTable.ruleName"
defaultMessage="Rule name is required"
/>
),
}, },
]} ]}
width="md" width="md"
@ -393,5 +326,4 @@ const TableList: React.FC = () => {
</PageContainer> </PageContainer>
); );
}; };
export default TableList; export default TableList;

View File

@ -16,12 +16,11 @@ import {
ProFormText, ProFormText,
} from '@ant-design/pro-components'; } from '@ant-design/pro-components';
import { useEmotionCss } from '@ant-design/use-emotion-css'; import { useEmotionCss } from '@ant-design/use-emotion-css';
import { FormattedMessage, history, SelectLang, useIntl, useModel, Helmet } from '@umijs/max'; import { Helmet, history, useModel } from '@umijs/max';
import { Alert, message, Tabs } from 'antd'; import { Alert, message, Tabs } from 'antd';
import Settings from '../../../../config/defaultSettings';
import React, { useState } from 'react'; import React, { useState } from 'react';
import { flushSync } from 'react-dom'; import { flushSync } from 'react-dom';
import Settings from '../../../../config/defaultSettings';
const ActionIcons = () => { const ActionIcons = () => {
const langClassName = useEmotionCss(({ token }) => { const langClassName = useEmotionCss(({ token }) => {
return { return {
@ -36,7 +35,6 @@ const ActionIcons = () => {
}, },
}; };
}); });
return ( return (
<> <>
<AlipayCircleOutlined key="AlipayCircleOutlined" className={langClassName} /> <AlipayCircleOutlined key="AlipayCircleOutlined" className={langClassName} />
@ -45,7 +43,6 @@ const ActionIcons = () => {
</> </>
); );
}; };
const Lang = () => { const Lang = () => {
const langClassName = useEmotionCss(({ token }) => { const langClassName = useEmotionCss(({ token }) => {
return { return {
@ -60,14 +57,8 @@ const Lang = () => {
}, },
}; };
}); });
return;
return (
<div className={langClassName} data-lang>
{SelectLang && <SelectLang />}
</div>
);
}; };
const LoginMessage: React.FC<{ const LoginMessage: React.FC<{
content: string; content: string;
}> = ({ content }) => { }> = ({ content }) => {
@ -82,12 +73,10 @@ const LoginMessage: React.FC<{
/> />
); );
}; };
const Login: React.FC = () => { const Login: React.FC = () => {
const [userLoginState, setUserLoginState] = useState<API.LoginResult>({}); const [userLoginState, setUserLoginState] = useState<API.LoginResult>({});
const [type, setType] = useState<string>('account'); const [type, setType] = useState<string>('account');
const { initialState, setInitialState } = useModel('@@initialState'); const { initialState, setInitialState } = useModel('@@initialState');
const containerClassName = useEmotionCss(() => { const containerClassName = useEmotionCss(() => {
return { return {
display: 'flex', display: 'flex',
@ -99,9 +88,6 @@ const Login: React.FC = () => {
backgroundSize: '100% 100%', backgroundSize: '100% 100%',
}; };
}); });
const intl = useIntl();
const fetchUserInfo = async () => { const fetchUserInfo = async () => {
const userInfo = await initialState?.fetchUserInfo?.(); const userInfo = await initialState?.fetchUserInfo?.();
if (userInfo) { if (userInfo) {
@ -113,16 +99,15 @@ const Login: React.FC = () => {
}); });
} }
}; };
const handleSubmit = async (values: API.LoginParams) => { const handleSubmit = async (values: API.LoginParams) => {
try { try {
// 登录 // 登录
const msg = await login({ ...values, type }); const msg = await login({
...values,
type,
});
if (msg.status === 'ok') { if (msg.status === 'ok') {
const defaultLoginSuccessMessage = intl.formatMessage({ const defaultLoginSuccessMessage = '登录成功!';
id: 'pages.login.success',
defaultMessage: '登录成功!',
});
message.success(defaultLoginSuccessMessage); message.success(defaultLoginSuccessMessage);
await fetchUserInfo(); await fetchUserInfo();
const urlParams = new URL(window.location.href).searchParams; const urlParams = new URL(window.location.href).searchParams;
@ -133,25 +118,17 @@ const Login: React.FC = () => {
// 如果失败去设置用户错误信息 // 如果失败去设置用户错误信息
setUserLoginState(msg); setUserLoginState(msg);
} catch (error) { } catch (error) {
const defaultLoginFailureMessage = intl.formatMessage({ const defaultLoginFailureMessage = '登录失败,请重试!';
id: 'pages.login.failure',
defaultMessage: '登录失败,请重试!',
});
console.log(error); console.log(error);
message.error(defaultLoginFailureMessage); message.error(defaultLoginFailureMessage);
} }
}; };
const { status, type: loginType } = userLoginState; const { status, type: loginType } = userLoginState;
return ( return (
<div className={containerClassName}> <div className={containerClassName}>
<Helmet> <Helmet>
<title> <title>
{intl.formatMessage({ {'登录'}- {Settings.title}
id: 'menu.login',
defaultMessage: '登录页',
})}
- {Settings.title}
</title> </title>
</Helmet> </Helmet>
<Lang /> <Lang />
@ -168,18 +145,11 @@ const Login: React.FC = () => {
}} }}
logo={<img alt="logo" src="/logo.svg" />} logo={<img alt="logo" src="/logo.svg" />}
title="Ant Design" title="Ant Design"
subTitle={intl.formatMessage({ id: 'pages.layouts.userLayout.title' })} subTitle={'Ant Design 是西湖区最具影响力的 Web 设计规范'}
initialValues={{ initialValues={{
autoLogin: true, autoLogin: true,
}} }}
actions={[ actions={['其他登录方式 :', <ActionIcons key="icons" />]}
<FormattedMessage
key="loginWith"
id="pages.login.loginWith"
defaultMessage="其他登录方式"
/>,
<ActionIcons key="icons" />,
]}
onFinish={async (values) => { onFinish={async (values) => {
await handleSubmit(values as API.LoginParams); await handleSubmit(values as API.LoginParams);
}} }}
@ -191,28 +161,17 @@ const Login: React.FC = () => {
items={[ items={[
{ {
key: 'account', key: 'account',
label: intl.formatMessage({ label: '账户密码登录',
id: 'pages.login.accountLogin.tab',
defaultMessage: '账户密码登录',
}),
}, },
{ {
key: 'mobile', key: 'mobile',
label: intl.formatMessage({ label: '手机号登录',
id: 'pages.login.phoneLogin.tab',
defaultMessage: '手机号登录',
}),
}, },
]} ]}
/> />
{status === 'error' && loginType === 'account' && ( {status === 'error' && loginType === 'account' && (
<LoginMessage <LoginMessage content={'错误的用户名和密码(admin/ant.design)'} />
content={intl.formatMessage({
id: 'pages.login.accountLogin.errorMessage',
defaultMessage: '账户或密码错误(admin/ant.design)',
})}
/>
)} )}
{type === 'account' && ( {type === 'account' && (
<> <>
@ -222,19 +181,11 @@ const Login: React.FC = () => {
size: 'large', size: 'large',
prefix: <UserOutlined />, prefix: <UserOutlined />,
}} }}
placeholder={intl.formatMessage({ placeholder={'用户名: admin or user'}
id: 'pages.login.username.placeholder',
defaultMessage: '用户名: admin or user',
})}
rules={[ rules={[
{ {
required: true, required: true,
message: ( message: '用户名是必填项!',
<FormattedMessage
id="pages.login.username.required"
defaultMessage="请输入用户名!"
/>
),
}, },
]} ]}
/> />
@ -244,19 +195,11 @@ const Login: React.FC = () => {
size: 'large', size: 'large',
prefix: <LockOutlined />, prefix: <LockOutlined />,
}} }}
placeholder={intl.formatMessage({ placeholder={'密码: ant.design'}
id: 'pages.login.password.placeholder',
defaultMessage: '密码: ant.design',
})}
rules={[ rules={[
{ {
required: true, required: true,
message: ( message: '密码是必填项!',
<FormattedMessage
id="pages.login.password.required"
defaultMessage="请输入密码!"
/>
),
}, },
]} ]}
/> />
@ -272,28 +215,15 @@ const Login: React.FC = () => {
prefix: <MobileOutlined />, prefix: <MobileOutlined />,
}} }}
name="mobile" name="mobile"
placeholder={intl.formatMessage({ placeholder={'请输入手机号!'}
id: 'pages.login.phoneNumber.placeholder',
defaultMessage: '手机号',
})}
rules={[ rules={[
{ {
required: true, required: true,
message: ( message: '手机号是必填项!',
<FormattedMessage
id="pages.login.phoneNumber.required"
defaultMessage="请输入手机号!"
/>
),
}, },
{ {
pattern: /^1\d{10}$/, pattern: /^1\d{10}$/,
message: ( message: '不合法的手机号!',
<FormattedMessage
id="pages.login.phoneNumber.invalid"
defaultMessage="手机号格式错误!"
/>
),
}, },
]} ]}
/> />
@ -305,32 +235,18 @@ const Login: React.FC = () => {
captchaProps={{ captchaProps={{
size: 'large', size: 'large',
}} }}
placeholder={intl.formatMessage({ placeholder={'请输入验证码!'}
id: 'pages.login.captcha.placeholder',
defaultMessage: '请输入验证码',
})}
captchaTextRender={(timing, count) => { captchaTextRender={(timing, count) => {
if (timing) { if (timing) {
return `${count} ${intl.formatMessage({ return `${count} ${'秒后重新获取'}`;
id: 'pages.getCaptchaSecondText',
defaultMessage: '获取验证码',
})}`;
} }
return intl.formatMessage({ return '获取验证码';
id: 'pages.login.phoneLogin.getVerificationCode',
defaultMessage: '获取验证码',
});
}} }}
name="captcha" name="captcha"
rules={[ rules={[
{ {
required: true, required: true,
message: ( message: '验证码是必填项!',
<FormattedMessage
id="pages.login.captcha.required"
defaultMessage="请输入验证码!"
/>
),
}, },
]} ]}
onGetCaptcha={async (phone) => { onGetCaptcha={async (phone) => {
@ -351,14 +267,14 @@ const Login: React.FC = () => {
}} }}
> >
<ProFormCheckbox noStyle name="autoLogin"> <ProFormCheckbox noStyle name="autoLogin">
<FormattedMessage id="pages.login.rememberMe" defaultMessage="自动登录" />
</ProFormCheckbox> </ProFormCheckbox>
<a <a
style={{ style={{
float: 'right', float: 'right',
}} }}
> >
<FormattedMessage id="pages.login.forgotPassword" defaultMessage="忘记密码" /> ?
</a> </a>
</div> </div>
</LoginForm> </LoginForm>
@ -367,5 +283,4 @@ const Login: React.FC = () => {
</div> </div>
); );
}; };
export default Login; export default Login;