mirror of https://github.com/longtai-cn/hippo4j
commit
84be732082
@ -1,9 +1,20 @@
|
||||
export enum STR_MAP {
|
||||
DYNAMIC_THREAD_POOL = 'dynamicThreadPool',
|
||||
THREAD_POOL = 'threadPool',
|
||||
THREAD_POOL_MANAGE = 'threadPoolManage',
|
||||
PROJECT = 'project',
|
||||
SEARCH = 'search',
|
||||
ADD = 'add',
|
||||
SERIAL_NUMBER = 'serial_number',
|
||||
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,2 +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 };
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
import { useContext, useEffect } from 'react';
|
||||
import { useLocalStorageState } from 'ahooks';
|
||||
import { MyContext, THEME_NAME } from '@/context';
|
||||
|
||||
const useThemeMode = (): { isDark: boolean | undefined; setIsDark: (isDark: boolean) => void } => {
|
||||
const [isDark, setIsDark] = useLocalStorageState<boolean>('current-mode', { defaultValue: false });
|
||||
const { setThemeName } = useContext<any>(MyContext);
|
||||
|
||||
useEffect(() => {
|
||||
isDark ? setThemeName(THEME_NAME.DARK) : setThemeName(THEME_NAME.DEFAULT);
|
||||
}, [isDark, setThemeName]);
|
||||
|
||||
return { isDark, setIsDark };
|
||||
};
|
||||
|
||||
export default useThemeMode;
|
@ -0,0 +1,88 @@
|
||||
import { useAntdTable } from 'ahooks';
|
||||
import { Button, Form, Input, Row, Space, Table, Col } from 'antd';
|
||||
import React, { useState } from 'react';
|
||||
import { fetchTenantList } from './service';
|
||||
|
||||
const baseColumns = [
|
||||
{
|
||||
title: '序号',
|
||||
dataIndex: 'num',
|
||||
},
|
||||
{
|
||||
title: '租户',
|
||||
dataIndex: 'tenant',
|
||||
},
|
||||
{
|
||||
title: '租户名称',
|
||||
dataIndex: 'tenantName',
|
||||
},
|
||||
{
|
||||
title: '负责人',
|
||||
dataIndex: 'creator',
|
||||
},
|
||||
{
|
||||
title: '修改时间',
|
||||
dataIndex: 'data',
|
||||
},
|
||||
];
|
||||
|
||||
const Tenant: React.FC = () => {
|
||||
const [editVisible, setEditVisible] = useState(false);
|
||||
const [form] = Form.useForm();
|
||||
const { tableProps, search } = useAntdTable(fetchTenantList, { form });
|
||||
const actions = (type: string) => {
|
||||
switch (type) {
|
||||
case 'create':
|
||||
setEditVisible(true);
|
||||
break;
|
||||
case 'edit':
|
||||
setEditVisible(true);
|
||||
break;
|
||||
case 'delete':
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Form>
|
||||
<Row>
|
||||
<Col span={6}>
|
||||
<Form.Item name="note" rules={[{ required: true }]}>
|
||||
<Input placeholder="租户" />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col span={18}>
|
||||
<Space>
|
||||
<Button onClick={() => search.submit()}>搜索</Button>
|
||||
<Button onClick={() => setEditVisible(true)}>添加</Button>
|
||||
</Space>
|
||||
</Col>
|
||||
</Row>
|
||||
</Form>
|
||||
<Table
|
||||
{...tableProps}
|
||||
rowKey="num"
|
||||
columns={[
|
||||
...baseColumns,
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
render: (text: string, record: any) => {
|
||||
return (
|
||||
<Space>
|
||||
<Button onClick={() => actions('edit')}>编辑</Button>
|
||||
<Button onClick={() => actions('edit')}>删除</Button>
|
||||
</Space>
|
||||
);
|
||||
},
|
||||
},
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Tenant;
|
@ -0,0 +1,8 @@
|
||||
import { lazy } from 'react';
|
||||
import { IRouterList } from '@/typings';
|
||||
|
||||
const Tenant = lazy(() => import('./index'));
|
||||
|
||||
const routerList: IRouterList[] = [{ path: '/tenant', component: () => <Tenant /> }];
|
||||
|
||||
export default routerList;
|
@ -0,0 +1,46 @@
|
||||
import request from '@/utils';
|
||||
|
||||
const fetchTenantList = async (
|
||||
pageProps: { current: number; pageSize: number },
|
||||
formData: { tencent: string | number }
|
||||
) => {
|
||||
// mock request
|
||||
return {
|
||||
total: 3,
|
||||
list: [
|
||||
{
|
||||
num: '1',
|
||||
tenant: 'admin',
|
||||
tenantName: 'admin',
|
||||
creator: 'admin',
|
||||
data: 'admin',
|
||||
},
|
||||
],
|
||||
};
|
||||
const res = await request('/tenants', {
|
||||
method: 'POST',
|
||||
params: {
|
||||
...formData,
|
||||
pageNum: pageProps.current,
|
||||
pageSize: pageProps.pageSize,
|
||||
},
|
||||
});
|
||||
|
||||
if (res && res.success) {
|
||||
return {
|
||||
total: 3,
|
||||
list: [
|
||||
{
|
||||
num: '1',
|
||||
tenant: 'admin',
|
||||
tenantName: 'admin',
|
||||
creator: 'admin',
|
||||
data: 'admin',
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
throw new Error(res.msg || '接口异常');
|
||||
};
|
||||
|
||||
export { fetchTenantList };
|
Loading…
Reference in new issue