mirror of https://github.com/longtai-cn/hippo4j
parent
89fa0b53b4
commit
7d55ceac67
@ -0,0 +1,20 @@
|
||||
export enum STR_MAP {
|
||||
DYNAMIC_THREAD_POOL = 'dynamicThreadPool',
|
||||
THREAD_POOL_MANAGE = 'threadPoolManage',
|
||||
PROJECT = 'project',
|
||||
SEARCH = 'search',
|
||||
ADD = 'add',
|
||||
SERIAL_NUMBER = 'serialNumber',
|
||||
TENANTRY = 'tenantry',
|
||||
THREAD_POOL = 'threadPool',
|
||||
CORE_THREAD = 'coreThread',
|
||||
MAXIMUM_THREAD = 'maximumThread',
|
||||
QUEUE_TYPE = 'queueType',
|
||||
QUEUE_CAPACITY = 'queueCapacity',
|
||||
REJECTION_STRATEGY = 'rejectionStrategy',
|
||||
EXECUTION_TIMEOUT = 'executionTimeout',
|
||||
ALARM_OR_NOT = 'alarmOrNot',
|
||||
CREATION_TIME = 'creationTime',
|
||||
UPDATE_TIME = 'update time',
|
||||
EDIT = 'edit',
|
||||
}
|
@ -1,5 +1,24 @@
|
||||
import { STR_MAP } from './constants';
|
||||
|
||||
const enTranslationMap: { [key: string]: string } = {
|
||||
hello: 'hello',
|
||||
[STR_MAP.DYNAMIC_THREAD_POOL]: 'Dynamic thread pool',
|
||||
[STR_MAP.THREAD_POOL_MANAGE]: 'Thread pool management',
|
||||
[STR_MAP.PROJECT]: 'project',
|
||||
[STR_MAP.SEARCH]: 'search',
|
||||
[STR_MAP.ADD]: 'add',
|
||||
[STR_MAP.SERIAL_NUMBER]: 'number',
|
||||
[STR_MAP.TENANTRY]: 'tenantry',
|
||||
[STR_MAP.THREAD_POOL]: 'thread pool',
|
||||
[STR_MAP.CORE_THREAD]: 'core thread',
|
||||
[STR_MAP.MAXIMUM_THREAD]: 'maximum thread',
|
||||
[STR_MAP.QUEUE_TYPE]: 'queue type',
|
||||
[STR_MAP.QUEUE_CAPACITY]: 'queue capacity',
|
||||
[STR_MAP.REJECTION_STRATEGY]: 'rejection strategy',
|
||||
[STR_MAP.EXECUTION_TIMEOUT]: 'execution timeout',
|
||||
[STR_MAP.ALARM_OR_NOT]: 'alarm or not',
|
||||
[STR_MAP.CREATION_TIME]: 'creation time',
|
||||
[STR_MAP.UPDATE_TIME]: 'update time',
|
||||
[STR_MAP.EDIT]: 'edit',
|
||||
};
|
||||
|
||||
export default enTranslationMap;
|
||||
|
@ -1,5 +1,24 @@
|
||||
import { STR_MAP } from './constants';
|
||||
|
||||
const zhTranslationMap: { [key: string]: string } = {
|
||||
hello: '你好',
|
||||
[STR_MAP.DYNAMIC_THREAD_POOL]: '动态线程池',
|
||||
[STR_MAP.THREAD_POOL_MANAGE]: '线程池管理',
|
||||
[STR_MAP.PROJECT]: '项目',
|
||||
[STR_MAP.SEARCH]: '搜索',
|
||||
[STR_MAP.ADD]: '添加',
|
||||
[STR_MAP.SERIAL_NUMBER]: '序号',
|
||||
[STR_MAP.TENANTRY]: '租户',
|
||||
[STR_MAP.THREAD_POOL]: '线程池',
|
||||
[STR_MAP.CORE_THREAD]: '核心线程',
|
||||
[STR_MAP.MAXIMUM_THREAD]: '最大线程',
|
||||
[STR_MAP.QUEUE_TYPE]: '队列类型',
|
||||
[STR_MAP.QUEUE_CAPACITY]: '队列容量',
|
||||
[STR_MAP.REJECTION_STRATEGY]: '拒绝策略',
|
||||
[STR_MAP.EXECUTION_TIMEOUT]: '执行超时',
|
||||
[STR_MAP.ALARM_OR_NOT]: '是否报警',
|
||||
[STR_MAP.CREATION_TIME]: '创建时间',
|
||||
[STR_MAP.UPDATE_TIME]: '更新时间',
|
||||
[STR_MAP.EDIT]: '操作',
|
||||
};
|
||||
|
||||
export default zhTranslationMap;
|
||||
|
@ -0,0 +1,3 @@
|
||||
export * from './useThemeMode';
|
||||
export * from './useTransLate';
|
||||
export * from './useFormToUrl';
|
@ -0,0 +1,52 @@
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
import { parse } from 'qs';
|
||||
import useUrlState from '@ahooksjs/use-url-state';
|
||||
import { FormInstance } from 'antd';
|
||||
|
||||
export function useFormStateToUrl<T extends Record<string, any>>(
|
||||
form: FormInstance,
|
||||
params?: T
|
||||
): {
|
||||
urlState: any;
|
||||
isFirstMount: boolean;
|
||||
handleSetUrlState: () => void;
|
||||
} {
|
||||
const [state, setState] = useState<any>();
|
||||
const [urlState, setUrlState] = useUrlState<any>();
|
||||
const [count, setCount] = useState<number>(0);
|
||||
|
||||
useEffect(() => {
|
||||
const url = window.location.search.split('?')[1] ?? null;
|
||||
const urlParams = parse(url) as T;
|
||||
const result: Partial<T> = {};
|
||||
setState(urlParams);
|
||||
for (const key in params) {
|
||||
if (Object.prototype.hasOwnProperty.call(params, key)) {
|
||||
const paramValue = urlParams[key];
|
||||
if (paramValue ?? false) {
|
||||
if (typeof params[key] === 'number') {
|
||||
const parsedValue = parseFloat(paramValue);
|
||||
if (!isNaN(parsedValue)) {
|
||||
result[key] = parsedValue as T[keyof T];
|
||||
}
|
||||
} else {
|
||||
result[key] = paramValue as T[keyof T];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
form.setFieldsValue(result);
|
||||
setCount(count => count + 1);
|
||||
}, [setState, setCount, form, params]);
|
||||
|
||||
const handleSetUrlState = () => {
|
||||
const values = form.getFieldsValue();
|
||||
setUrlState({ ...state, ...values });
|
||||
};
|
||||
|
||||
const isFirstMount = useMemo(() => {
|
||||
return count === 1;
|
||||
}, [count]);
|
||||
|
||||
return { urlState, isFirstMount, handleSetUrlState };
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
export const useTran = (str: string): string => {
|
||||
const { t } = useTranslation();
|
||||
return t(str);
|
||||
};
|
@ -0,0 +1,90 @@
|
||||
import { Button, Form, Select, Space, Table, Typography } from 'antd';
|
||||
import { useFormStateToUrl, useTran } from '@/hooks';
|
||||
import { STR_MAP } from '@/config/i18n/locales/constants';
|
||||
import { ColumnProps } from 'antd/es/table';
|
||||
const { Title } = Typography;
|
||||
const { Item } = Form;
|
||||
|
||||
const params = { project: 0, thpool: 0 };
|
||||
const ThreadPoll = () => {
|
||||
const [form] = Form.useForm();
|
||||
const { handleSetUrlState } = useFormStateToUrl<{ project: number; thpool: number }>(form, params);
|
||||
const columns: ColumnProps<any>[] = [
|
||||
{
|
||||
title: useTran(STR_MAP.SERIAL_NUMBER),
|
||||
dataIndex: 'order',
|
||||
},
|
||||
{
|
||||
title: useTran(STR_MAP.PROJECT),
|
||||
dataIndex: 'project',
|
||||
},
|
||||
{
|
||||
title: useTran(STR_MAP.TENANTRY),
|
||||
dataIndex: 'tenantry',
|
||||
},
|
||||
{
|
||||
title: useTran(STR_MAP.THREAD_POOL),
|
||||
dataIndex: 'thread_pool',
|
||||
},
|
||||
{
|
||||
title: useTran(STR_MAP.MAXIMUM_THREAD),
|
||||
dataIndex: 'maximum_thread',
|
||||
},
|
||||
{
|
||||
title: useTran(STR_MAP.QUEUE_TYPE),
|
||||
dataIndex: 'queue_type',
|
||||
},
|
||||
{
|
||||
title: useTran(STR_MAP.REJECTION_STRATEGY),
|
||||
dataIndex: 'tenantry',
|
||||
},
|
||||
{
|
||||
title: useTran(STR_MAP.EXECUTION_TIMEOUT),
|
||||
dataIndex: 'tenantry',
|
||||
},
|
||||
{
|
||||
title: useTran(STR_MAP.ALARM_OR_NOT),
|
||||
dataIndex: 'tenantry',
|
||||
},
|
||||
{
|
||||
title: useTran(STR_MAP.CREATION_TIME),
|
||||
dataIndex: 'tenantry',
|
||||
},
|
||||
{
|
||||
title: useTran(STR_MAP.UPDATE_TIME),
|
||||
dataIndex: 'tenantry',
|
||||
},
|
||||
{
|
||||
title: useTran(STR_MAP.EDIT),
|
||||
dataIndex: 'tenantry',
|
||||
},
|
||||
];
|
||||
|
||||
const handleSubmit = () => {
|
||||
handleSetUrlState();
|
||||
};
|
||||
|
||||
return (
|
||||
<Space direction="vertical" style={{ width: '100%' }} size="large">
|
||||
<Title>{useTran(STR_MAP.THREAD_POOL)}</Title>
|
||||
<Form form={form} layout="inline">
|
||||
<Item name="project" style={{ flex: 1 }}>
|
||||
<Select options={[{ label: '哈哈哈', value: 1 }]} placeholder={useTran(STR_MAP.PROJECT)}></Select>
|
||||
</Item>
|
||||
<Item name="thpool" style={{ flex: 1 }}>
|
||||
<Select options={[{ label: '哈哈哈', value: 1 }]} placeholder={useTran(STR_MAP.PROJECT)}></Select>
|
||||
</Item>
|
||||
<Item style={{ flex: 4 }}>
|
||||
<Space>
|
||||
<Button type="primary" htmlType="submit" onClick={handleSubmit}>
|
||||
{useTran(STR_MAP.SEARCH)}
|
||||
</Button>
|
||||
<Button type="primary">{useTran(STR_MAP.ADD)}</Button>
|
||||
</Space>
|
||||
</Item>
|
||||
</Form>
|
||||
<Table columns={columns}></Table>
|
||||
</Space>
|
||||
);
|
||||
};
|
||||
export default ThreadPoll;
|
@ -0,0 +1,11 @@
|
||||
import { IRouterList } from '@/typings';
|
||||
import ThreadPoll from '.';
|
||||
|
||||
const routerList: IRouterList[] = [
|
||||
{
|
||||
path: '/thread-poll/index',
|
||||
component: ThreadPoll,
|
||||
},
|
||||
];
|
||||
|
||||
export default routerList;
|
Loading…
Reference in new issue