提交 db0faf09 作者: ZhangLingKun

功能:类型封装

上级 77ed35eb
......@@ -37,18 +37,6 @@ export interface ResponseType<D> {
result: D;
}
// 通用接口封装(分页) 不推荐
export interface InterListType<D, T> {
req: D & PaginationProps;
res: Promise<ResponseListType<T>>;
}
// 通用接口封装(不分页) 不推荐
export interface InterType<D, T> {
req: D;
res: Promise<ResponseType<T>>;
}
// 通用接口封装函数(分页) 建议用这个
export interface InterListFunction<D extends object, T> {
(req: D & PaginationProps): Promise<ResponseListType<T>>;
......@@ -63,3 +51,31 @@ export interface InterFunction<D extends object, T> {
export interface InterItemFunction<D extends object, T> {
(req: D & PaginationProps): Promise<ResponseItemType<T>>;
}
// 返回类型封装
// eslint-disable-next-line no-unused-vars
export type InterDataType<T extends (...args: any) => any> = (
ReturnType<T> extends Promise<infer U> ? U : never
) extends { result: infer V }
? V
: never;
// 返回列表类型封装
// eslint-disable-next-line no-unused-vars
export type InterListType<T extends (...args: any) => any> = (
ReturnType<T> extends Promise<infer U> ? U : never
) extends { result: { list: infer V } }
? V
: never;
// 返回类型封装(分页了,但又没有分页)
// eslint-disable-next-line no-unused-vars
export type InterItemType<T extends (...args: any) => any> = (
ReturnType<T> extends Promise<infer U> ? U : never
) extends { result: infer V }
? V
: never;
// 获取参数类型封装
// eslint-disable-next-line no-unused-vars
export type InterReqType<T extends (...args: any) => any> = Parameters<T>[0];
.header {
padding: 15px 20px 5px 20px;
padding: 5px 10px 5px 10px;
background-color: #fff;
margin: 0 0 10px 0;
border-radius: 10px;
......
import React from 'react';
import { useState } from 'react';
import SearchBox from '~/components/search-box';
import { Button } from 'antd';
// 订单状态搜索列表
const statusCodeButtonList = [
{ value: -1, label: '全部订单' },
{ value: 0, label: '沟通意向' },
{ value: 1, label: '签约付款' },
{ value: 2, label: '待发货' },
{ value: 3, label: '待收货' },
{ value: 4, label: '已完成' },
{ value: 5, label: '已关闭' },
];
function ProductOrderView() {
return <div>ProductOrderView</div>;
// 当前选择的是第几个按钮
const [statusCodeButtonIndex, setStatusCodeButtonIndex] = useState<number>(0);
// 订单状态筛选
const statusChangeEvent = (index: number) => {
setStatusCodeButtonIndex(index);
};
return (
<>
<SearchBox
search={[
{
label: '订单编号',
name: 'keyword',
type: 'input',
placeholder: '请输入订单编号',
},
{
label: '买家账号',
name: 'keyword2',
type: 'input',
placeholder: '请输入用户账号',
},
{
label: '相关销售',
name: 'saleId',
type: 'Select',
placeholder: '请选择相关销售',
options: [],
},
{
label: '时间',
name: 'time',
type: 'rangePicker',
placeholder: '请选择创建时间',
},
]}
searchData={(e: any) => console.log('提交数据 --->', e)}
sufFixBtn={
<>
{statusCodeButtonList?.map((i, j) => {
return (
<Button
key={j}
type={j === statusCodeButtonIndex ? 'primary' : 'default'}
onClick={() => statusChangeEvent(j)}
style={{ marginTop: '5px' }}
>
{i.label}
</Button>
);
})}
</>
}
/>
</>
);
}
export default ProductOrderView;
......@@ -62,7 +62,7 @@ export const routerList: Array<RouteObjectType> = [
element: withLoadingComponent(<ProductOrderView />),
meta: {
id: 10010,
title: '销售订单',
title: '商城订单',
icon: <MacCommandOutlined />,
},
},
......@@ -71,7 +71,7 @@ export const routerList: Array<RouteObjectType> = [
element: withLoadingComponent(<EquipmentOrderView />),
meta: {
id: 10020,
title: '设备订单',
title: '租赁订单',
icon: <MacCommandOutlined />,
},
},
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论