feat(layout): 修改路由跳转

This commit is contained in:
NICE CODE BY DEV 2024-05-08 14:04:04 +08:00
parent bb22f22373
commit 3c0ff5f494
7 changed files with 2 additions and 547 deletions

View File

@ -16,12 +16,12 @@ const Layout = () => {
<FloatButton <FloatButton
tooltip="物料库" tooltip="物料库"
onClick={() => onClick={() =>
(location.href = 'http://10.0.0.222:30098/communal-cabinets') (location.href = 'http://10.0.0.204:30080/materials')
} }
/> />
<FloatButton <FloatButton
tooltip="组件库" tooltip="组件库"
onClick={() => (location.href = 'http://10.0.0.222')} onClick={() => (location.href = 'http://10.0.0.204:30080')}
/> />
<FloatButton tooltip="demo 展示" icon={<ShopOutlined />} /> <FloatButton tooltip="demo 展示" icon={<ShopOutlined />} />
</FloatButton.Group> </FloatButton.Group>

View File

@ -1,21 +0,0 @@
import { PageContainer } from '@ant-design/pro-components';
import { Access, useAccess } from '@umijs/max';
import { Button } from 'antd';
const AccessPage: React.FC = () => {
const access = useAccess();
return (
<PageContainer
ghost
header={{
title: '权限示例',
}}
>
<Access accessible={access.canSeeAdmin}>
<Button> Admin </Button>
</Access>
</PageContainer>
);
};
export default AccessPage;

View File

@ -1,26 +0,0 @@
import { Modal } from 'antd';
import React, { PropsWithChildren } from 'react';
interface CreateFormProps {
modalVisible: boolean;
onCancel: () => void;
}
const CreateForm: React.FC<PropsWithChildren<CreateFormProps>> = (props) => {
const { modalVisible, onCancel } = props;
return (
<Modal
destroyOnClose
title="新建"
width={420}
open={modalVisible}
onCancel={() => onCancel()}
footer={null}
>
{props.children}
</Modal>
);
};
export default CreateForm;

View File

@ -1,138 +0,0 @@
import {
ProFormDateTimePicker,
ProFormRadio,
ProFormSelect,
ProFormText,
ProFormTextArea,
StepsForm,
} from '@ant-design/pro-components';
import { Modal } from 'antd';
import React from 'react';
export interface FormValueType extends Partial<API.UserInfo> {
target?: string;
template?: string;
type?: string;
time?: string;
frequency?: string;
}
export interface UpdateFormProps {
onCancel: (flag?: boolean, formVals?: FormValueType) => void;
onSubmit: (values: FormValueType) => Promise<void>;
updateModalVisible: boolean;
values: Partial<API.UserInfo>;
}
const UpdateForm: React.FC<UpdateFormProps> = (props) => (
<StepsForm
stepsProps={{
size: 'small',
}}
stepsFormRender={(dom, submitter) => {
return (
<Modal
width={640}
bodyStyle={{ padding: '32px 40px 48px' }}
destroyOnClose
title="规则配置"
open={props.updateModalVisible}
footer={submitter}
onCancel={() => props.onCancel()}
>
{dom}
</Modal>
);
}}
onFinish={props.onSubmit}
>
<StepsForm.StepForm
initialValues={{
name: props.values.name,
nickName: props.values.nickName,
}}
title="基本信息"
>
<ProFormText
width="md"
name="name"
label="规则名称"
rules={[{ required: true, message: '请输入规则名称!' }]}
/>
<ProFormTextArea
name="desc"
width="md"
label="规则描述"
placeholder="请输入至少五个字符"
rules={[
{ required: true, message: '请输入至少五个字符的规则描述!', min: 5 },
]}
/>
</StepsForm.StepForm>
<StepsForm.StepForm
initialValues={{
target: '0',
template: '0',
}}
title="配置规则属性"
>
<ProFormSelect
width="md"
name="target"
label="监控对象"
valueEnum={{
0: '表一',
1: '表二',
}}
/>
<ProFormSelect
width="md"
name="template"
label="规则模板"
valueEnum={{
0: '规则模板一',
1: '规则模板二',
}}
/>
<ProFormRadio.Group
name="type"
width="md"
label="规则类型"
options={[
{
value: '0',
label: '强',
},
{
value: '1',
label: '弱',
},
]}
/>
</StepsForm.StepForm>
<StepsForm.StepForm
initialValues={{
type: '1',
frequency: 'month',
}}
title="设定调度周期"
>
<ProFormDateTimePicker
name="time"
label="开始时间"
rules={[{ required: true, message: '请选择开始时间!' }]}
/>
<ProFormSelect
name="frequency"
label="监控对象"
width="xs"
valueEnum={{
month: '月',
week: '周',
}}
/>
</StepsForm.StepForm>
</StepsForm>
);
export default UpdateForm;

View File

@ -1,270 +0,0 @@
import services from '@/services/demo';
import {
ActionType,
FooterToolbar,
PageContainer,
ProDescriptions,
ProDescriptionsItemProps,
ProTable,
} from '@ant-design/pro-components';
import { Button, Divider, Drawer, message } from 'antd';
import React, { useRef, useState } from 'react';
import CreateForm from './components/CreateForm';
import UpdateForm, { FormValueType } from './components/UpdateForm';
const { addUser, queryUserList, deleteUser, modifyUser } =
services.UserController;
/**
*
* @param fields
*/
const handleAdd = async (fields: API.UserInfo) => {
const hide = message.loading('正在添加');
try {
await addUser({ ...fields });
hide();
message.success('添加成功');
return true;
} catch (error) {
hide();
message.error('添加失败请重试!');
return false;
}
};
/**
*
* @param fields
*/
const handleUpdate = async (fields: FormValueType) => {
const hide = message.loading('正在配置');
try {
await modifyUser(
{
userId: fields.id || '',
},
{
name: fields.name || '',
nickName: fields.nickName || '',
email: fields.email || '',
},
);
hide();
message.success('配置成功');
return true;
} catch (error) {
hide();
message.error('配置失败请重试!');
return false;
}
};
/**
*
* @param selectedRows
*/
const handleRemove = async (selectedRows: API.UserInfo[]) => {
const hide = message.loading('正在删除');
if (!selectedRows) return true;
try {
await deleteUser({
userId: selectedRows.find((row) => row.id)?.id || '',
});
hide();
message.success('删除成功,即将刷新');
return true;
} catch (error) {
hide();
message.error('删除失败,请重试');
return false;
}
};
const TableList: React.FC<unknown> = () => {
const [createModalVisible, handleModalVisible] = useState<boolean>(false);
const [updateModalVisible, handleUpdateModalVisible] =
useState<boolean>(false);
const [stepFormValues, setStepFormValues] = useState({});
const actionRef = useRef<ActionType>();
const [row, setRow] = useState<API.UserInfo>();
const [selectedRowsState, setSelectedRows] = useState<API.UserInfo[]>([]);
const columns: ProDescriptionsItemProps<API.UserInfo>[] = [
{
title: '名称',
dataIndex: 'name',
tip: '名称是唯一的 key',
formItemProps: {
rules: [
{
required: true,
message: '名称为必填项',
},
],
},
},
{
title: '昵称',
dataIndex: 'nickName',
valueType: 'text',
},
{
title: '性别',
dataIndex: 'gender',
hideInForm: true,
valueEnum: {
0: { text: '男', status: 'MALE' },
1: { text: '女', status: 'FEMALE' },
},
},
{
title: '操作',
dataIndex: 'option',
valueType: 'option',
render: (_, record) => (
<>
<a
onClick={() => {
handleUpdateModalVisible(true);
setStepFormValues(record);
}}
>
</a>
<Divider type="vertical" />
<a href=""></a>
</>
),
},
];
return (
<PageContainer
header={{
title: 'CRUD 示例',
}}
>
<ProTable<API.UserInfo>
headerTitle="查询表格"
actionRef={actionRef}
rowKey="id"
search={{
labelWidth: 120,
}}
toolBarRender={() => [
<Button
key="1"
type="primary"
onClick={() => handleModalVisible(true)}
>
</Button>,
]}
request={async (params, sorter, filter) => {
const { data, success } = await queryUserList({
...params,
// FIXME: remove @ts-ignore
// @ts-ignore
sorter,
filter,
});
return {
data: data?.list || [],
success,
};
}}
columns={columns}
rowSelection={{
onChange: (_, selectedRows) => setSelectedRows(selectedRows),
}}
/>
{selectedRowsState?.length > 0 && (
<FooterToolbar
extra={
<div>
{' '}
<a style={{ fontWeight: 600 }}>{selectedRowsState.length}</a>{' '}
&nbsp;&nbsp;
</div>
}
>
<Button
onClick={async () => {
await handleRemove(selectedRowsState);
setSelectedRows([]);
actionRef.current?.reloadAndRest?.();
}}
>
</Button>
<Button type="primary"></Button>
</FooterToolbar>
)}
<CreateForm
onCancel={() => handleModalVisible(false)}
modalVisible={createModalVisible}
>
<ProTable<API.UserInfo, API.UserInfo>
onSubmit={async (value) => {
const success = await handleAdd(value);
if (success) {
handleModalVisible(false);
if (actionRef.current) {
actionRef.current.reload();
}
}
}}
rowKey="id"
type="form"
columns={columns}
/>
</CreateForm>
{stepFormValues && Object.keys(stepFormValues).length ? (
<UpdateForm
onSubmit={async (value) => {
const success = await handleUpdate(value);
if (success) {
handleUpdateModalVisible(false);
setStepFormValues({});
if (actionRef.current) {
actionRef.current.reload();
}
}
}}
onCancel={() => {
handleUpdateModalVisible(false);
setStepFormValues({});
}}
updateModalVisible={updateModalVisible}
values={stepFormValues}
/>
) : null}
<Drawer
width={600}
open={!!row}
onClose={() => {
setRow(undefined);
}}
closable={false}
>
{row?.name && (
<ProDescriptions<API.UserInfo>
column={2}
title={row?.name}
request={async () => ({
data: row || {},
})}
params={{
id: row?.name,
}}
columns={columns}
/>
)}
</Drawer>
</PageContainer>
);
};
export default TableList;

View File

@ -1,4 +0,0 @@
export const API_URL =
APP_ENV === 'production'
? 'http://10.0.0.222:31300'
: 'http://10.0.0.222:31300';

View File

@ -1,86 +0,0 @@
import type { RequestConfig } from '@umijs/max';
import { API_URL } from './constants';
const doRequest: RequestConfig = {
timeout: 1000,
baseURL: API_URL,
errorConfig: {
errorHandler(error, opts) {
console.log('errorHandler', error, opts);
// if (opts?.skipErrorHandler) throw error
// try {
// const { res } = ctx;
// const d = await res.text();
// if (res.status === 401 && store.user.isLogin) {
// store.user.resetLoginState();
// message.warning('登录过期,请重新登录!');
// return;
// }
// const isEmptyRes = d === '' || d.replace(/\s/g,"")=== 'tokenisinvalid'; //有些后端接口成功会返回空 做下兼容
// const body = !isEmptyRes ? JSON.parse(d || '{}') : d;
// const sessionCode = sessionStorage.getItem('zhst_errcode') || '{}'
// const ERROR_CODE = JSON.parse(sessionCode);
// if (Number(res.status) === 200) {
// ctx.res = body;
// } else {
// // 先判断Grpc-Metadata-Errorx-Message
// let errMsg = ERROR_CODE[body.code]?.value || body.message || '您的网络发生异常,无法连接服务器'
// toast && message.error(errMsg || body);
// ctx.res = {
// code: body.code,
// message: errMsg
// };
// }
// } catch (error) {
// if (get(error, 'type') !== 'CustomError') {
// toast && message.error('您的网络发生异常,无法连接服务器');
// }
// throw error;
// }
},
errorThrower(res) {
console.log('res', res);
},
},
// 请求
requestInterceptors: [
// 一个二元组,第一个元素是 request 拦截器,第二个元素是错误处理
[
(url, options) => {
return {
url,
options: {
...options,
headers: {
authorization: 'test',
// ...(refererSuffix ? { zhst_referer: `${baseUrl}${refererSuffix}` } : {}),
},
},
};
},
(error) => {
return Promise.reject(error);
},
],
],
// 返回
responseInterceptors: [
// 一个二元组,第一个元素是 request 拦截器,第二个元素是错误处理
[
(response) => {
if (response.status !== 200) {
throw Error(JSON.stringify(response.data));
}
return response;
},
(error) => {
return Promise.reject(error);
},
],
],
};
export default doRequest;