@hw-component/table 1.2.7 → 1.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,7 +8,7 @@ import type { HTableProps } from "./modal";
8
8
  import useReq from "./hooks/useReq";
9
9
  import useDispatch from "./hooks/useDispatch";
10
10
  import { useState } from "react";
11
- import {useClassName} from "./hooks";
11
+ import { useClassName } from "./hooks";
12
12
  export default ({
13
13
  request,
14
14
  configData,
@@ -57,8 +57,8 @@ export default ({
57
57
  selectedRowData,
58
58
  dataSource: data,
59
59
  });
60
- const contentClassName = useClassName("hw-table-content");
61
- return (
60
+ const contentClassName = useClassName("hw-table-content");
61
+ return (
62
62
  <HTableContext.Provider
63
63
  value={{
64
64
  tableInstance,
@@ -83,7 +83,12 @@ export default ({
83
83
  labelWidth,
84
84
  }}
85
85
  >
86
- <Space direction={"vertical"} size={0} style={{ width: "100%" }} className={contentClassName}>
86
+ <Space
87
+ direction={"vertical"}
88
+ size={0}
89
+ style={{ width: "100%" }}
90
+ className={contentClassName}
91
+ >
87
92
  {!hideHeader && (
88
93
  <Header
89
94
  searchSpan={searchSpan}
@@ -1,35 +1,40 @@
1
1
  import React, { useContext } from "react";
2
- import type { HTableInstance ,ValueTypeConfigModal} from "./modal";
2
+ import type { HTableInstance, ValueTypeConfigModal } from "./modal";
3
3
 
4
4
  interface HTableConfigContextModal {
5
5
  emptyRender?: (table: HTableInstance) => React.ReactNode;
6
6
  errorRender?: (table: HTableInstance, error: Error) => React.ReactNode;
7
- headerStyle?:React.CSSProperties;
8
- tableStyle?:React.CSSProperties;
9
- paginationStyle?:React.CSSProperties;
10
- valueTypeConfig?:ValueTypeConfigModal;
7
+ headerStyle?: React.CSSProperties;
8
+ tableStyle?: React.CSSProperties;
9
+ paginationStyle?: React.CSSProperties;
10
+ valueTypeConfig?: ValueTypeConfigModal;
11
11
  }
12
12
  export const HTableConfigContext =
13
13
  React.createContext<HTableConfigContextModal | null>(null);
14
14
 
15
-
16
15
  export const useHTableConfigContext = ({
17
16
  emptyRender,
18
17
  errorRender,
19
18
  headerStyle,
20
19
  tableStyle,
21
- paginationStyle
20
+ paginationStyle,
22
21
  }: HTableConfigContextModal) => {
23
- const { errorRender: configErrorRender, emptyRender: configEmptyRender,headerStyle:configHeaderStyle,tableStyle:configTableStyle,paginationStyle:configPaginationStyle,valueTypeConfig={} } =
24
- useContext(HTableConfigContext) || {};
22
+ const {
23
+ errorRender: configErrorRender,
24
+ emptyRender: configEmptyRender,
25
+ headerStyle: configHeaderStyle,
26
+ tableStyle: configTableStyle,
27
+ paginationStyle: configPaginationStyle,
28
+ valueTypeConfig = {},
29
+ } = useContext(HTableConfigContext) || {};
25
30
 
26
31
  return {
27
32
  errorRender: errorRender || configErrorRender,
28
33
  emptyRender: emptyRender || configEmptyRender,
29
- headerStyle:headerStyle||configHeaderStyle,
30
- tableStyle:tableStyle||configTableStyle,
31
- paginationStyle:paginationStyle||configPaginationStyle,
32
- valueTypeConfig
34
+ headerStyle: headerStyle || configHeaderStyle,
35
+ tableStyle: tableStyle || configTableStyle,
36
+ paginationStyle: paginationStyle || configPaginationStyle,
37
+ valueTypeConfig,
33
38
  };
34
39
  };
35
40
  const Index: React.FC<HTableConfigContextModal> = ({ children, ...props }) => {
@@ -10,7 +10,7 @@ import type { ModalProps } from "antd";
10
10
  import type { TableProps } from "antd/lib/table";
11
11
  import type { AffixProps } from "antd/lib/affix";
12
12
  import type { OptionModal } from "./HTableBody";
13
- import {GetRowKey} from "rc-table/lib/interface";
13
+ import { GetRowKey } from "rc-table/lib/interface";
14
14
 
15
15
  export interface RowObj {
16
16
  keys?: React.Key[];
@@ -44,7 +44,7 @@ interface HColumns extends Omit<ProColumns, "render" | "title"> {
44
44
  ) => React.ReactNode;
45
45
  rowSelectionTitle?: boolean;
46
46
  title?: string | React.ReactNode;
47
- valueTypeProps?:Record<string, any>
47
+ valueTypeProps?: Record<string, any>;
48
48
  }
49
49
  interface BcItemModal {
50
50
  childrenDataIndex?: ConfigItemModal[] | string[];
@@ -75,7 +75,7 @@ export type HRowSelection = RowSelectionOuter &
75
75
  export interface HTableProps
76
76
  extends Omit<
77
77
  ProTableProps<any, any>,
78
- "request" | "dataSource"| "rowSelection"
78
+ "request" | "dataSource" | "rowSelection"
79
79
  > {
80
80
  request?: (params: ParamsModal) => Promise<ResultModal>;
81
81
  configData: ConfigDataModal;
@@ -154,5 +154,10 @@ export interface ModalTableProps extends ModalProps {
154
154
  request?: HTableProps["request"];
155
155
  }
156
156
 
157
- export type ValueTypeConfigRenderFn=(config:ConfigItemModal,itemData:any,index:number,tableInstance:HTableInstance)=>React.ReactNode;
158
- export type ValueTypeConfigModal=Record<string, ValueTypeConfigRenderFn>;
157
+ export type ValueTypeConfigRenderFn = (
158
+ config: ConfigItemModal,
159
+ itemData: any,
160
+ index: number,
161
+ tableInstance: HTableInstance
162
+ ) => React.ReactNode;
163
+ export type ValueTypeConfigModal = Record<string, ValueTypeConfigRenderFn>;
@@ -1,91 +1,122 @@
1
- import {Row, Tag,Tooltip,Popover} from "antd";
2
- import React, {useMemo} from "react";
3
- import {TooltipProps} from "antd/lib/tooltip";
4
- import {HTableInstance} from "@/components/modal";
5
- type CloseFn=(key:string,tableInstance?:HTableInstance)=>void;
1
+ import { Row, Tag, Tooltip, Popover } from "antd";
2
+ import React, { useMemo } from "react";
3
+ import type { TooltipProps } from "antd/lib/tooltip";
4
+ import type { HTableInstance } from "@/components/modal";
5
+ type CloseFn = (key: string, tableInstance?: HTableInstance) => void;
6
6
  interface IProps {
7
- data:any[];
8
- closable?:boolean;
9
- onClose?:CloseFn;
10
- color?:string;
11
- icon?:React.ReactNode;
12
- tooltip?:boolean|TooltipProps;
13
- fieldNames?:{label?:string,value?:string};
14
- tableInstance?:HTableInstance;
15
- maxLen?:number|null;
7
+ data: any[];
8
+ closable?: boolean;
9
+ onClose?: CloseFn;
10
+ color?: string;
11
+ icon?: React.ReactNode;
12
+ tooltip?: boolean | TooltipProps;
13
+ fieldNames?: { label?: string; value?: string };
14
+ tableInstance?: HTableInstance;
15
+ maxLen?: number | null;
16
16
  }
17
- const getTooltipProps=(title:string,tooltip?:boolean|TooltipProps):TooltipProps=>{
18
- if (!tooltip){
19
- return {
20
- title:null
21
- };
22
- }
23
- if (tooltip===true){
24
- return {
25
- title
26
- }
17
+ const getTooltipProps = (
18
+ title: string,
19
+ tooltip?: boolean | TooltipProps
20
+ ): TooltipProps => {
21
+ if (!tooltip) {
22
+ return {
23
+ title: null,
24
+ };
25
+ }
26
+ if (tooltip === true) {
27
+ return {
28
+ title,
29
+ };
30
+ }
31
+ return {
32
+ ...tooltip,
33
+ title,
34
+ };
35
+ };
36
+ const TagsComponent = (props: IProps) => {
37
+ const {
38
+ data,
39
+ closable,
40
+ onClose,
41
+ color,
42
+ icon,
43
+ fieldNames = {},
44
+ tooltip,
45
+ tableInstance,
46
+ maxLen,
47
+ } = props;
48
+ const { label = "label", value = "value" } = fieldNames;
49
+ const { tagData, moreTag } = useMemo(() => {
50
+ if (!maxLen || !data) {
51
+ return {
52
+ tagData: data,
53
+ };
27
54
  }
28
- return {
29
- ...tooltip,
30
- title,
31
- }
32
- }
33
- const TagsComponent=(props:IProps)=>{
34
- const {data,closable,onClose,color,icon,fieldNames={},tooltip,tableInstance,maxLen}=props;
35
- const {label="label",value="value"}=fieldNames;
36
- const {tagData,moreTag}=useMemo(()=>{
37
- if (!maxLen||!data){
38
- return {
39
- tagData:data
40
- };
41
- }
42
- const tagData=data.slice(0,maxLen);
43
- const moreTag=data.slice(maxLen);
44
- return {
45
- tagData,
46
- moreTag
47
- }
48
- },[data,maxLen]);
49
- const moreLen=moreTag?.length;
55
+ const resultTagData = data.slice(0, maxLen);
56
+ const resultMoreTag = data.slice(maxLen);
57
+ return {
58
+ tagData: resultTagData,
59
+ moreTag: resultMoreTag,
60
+ };
61
+ }, [data, maxLen]);
62
+ const moreLen = moreTag?.length;
50
63
 
51
- return <Row gutter={[8,8]}>
52
- {tagData?.map((tagItem, index)=>{
53
- const tagProps={
54
- closable,
55
- onClose,
56
- color,
57
- icon
58
- }
59
- const indexKey=index.toString();
60
- if (typeof tagItem==="string"){
61
- const tooltipProps=getTooltipProps(tagItem,tooltip);
62
- return <Tooltip {...tooltipProps}>
63
- <Tag key={indexKey} {...tagProps} onClose={(e)=>{
64
- e.preventDefault();
65
- onClose?.(indexKey,tableInstance);
66
- }}>{tagItem}</Tag>
67
- </Tooltip>
68
- }
69
- const {[label]:tagLabel,[value]:tagValue,...props}=tagItem;
70
- const tooltipProps=getTooltipProps(tagLabel,tooltip);
71
- const cuTagProps={
72
- ...tagProps,
73
- ...props
74
- }
75
- const cuKey=tagValue||indexKey;
76
- return <Tooltip {...tooltipProps}>
77
- <Tag key={cuKey} {...cuTagProps} onClose={(e)=>{
78
- e.preventDefault();
79
- cuTagProps?.onClose(cuKey,tableInstance);
80
- }}>{tagLabel}</Tag>
81
- </Tooltip>
82
- })}
83
- {!moreLen?null:
84
- <Popover content={<TagsComponent {...props} maxLen={null} />}>
85
- <Tag>...等{data.length}个</Tag>
86
- </Popover>
87
- }
88
- </Row>
89
- }
64
+ return (
65
+ <Row gutter={[8, 8]}>
66
+ {tagData?.map((tagItem, index) => {
67
+ const tagProps = {
68
+ closable,
69
+ onClose,
70
+ color,
71
+ icon,
72
+ };
73
+ const indexKey = index.toString();
74
+ if (typeof tagItem === "string") {
75
+ const tooltipProps = getTooltipProps(tagItem, tooltip);
76
+ return (
77
+ <Tooltip {...tooltipProps}>
78
+ <Tag
79
+ key={indexKey}
80
+ {...tagProps}
81
+ onClose={(e) => {
82
+ e.preventDefault();
83
+ onClose?.(indexKey, tableInstance);
84
+ }}
85
+ >
86
+ {tagItem}
87
+ </Tag>
88
+ </Tooltip>
89
+ );
90
+ }
91
+ const { [label]: tagLabel, [value]: tagValue, ...itemProps } = tagItem;
92
+ const tooltipProps = getTooltipProps(tagLabel, tooltip);
93
+ const cuTagProps = {
94
+ ...tagProps,
95
+ ...itemProps,
96
+ };
97
+ const cuKey = tagValue || indexKey;
98
+ return (
99
+ <Tooltip {...tooltipProps}>
100
+ <Tag
101
+ key={cuKey}
102
+ {...cuTagProps}
103
+ onClose={(e) => {
104
+ e.preventDefault();
105
+ cuTagProps?.onClose(cuKey, tableInstance);
106
+ }}
107
+ >
108
+ {tagLabel}
109
+ </Tag>
110
+ </Tooltip>
111
+ );
112
+ })}
113
+ {!moreLen ? null : (
114
+ <Popover content={<TagsComponent {...props} maxLen={null} />}>
115
+ <Tag>...等{data.length}个</Tag>
116
+ </Popover>
117
+ )}
118
+ </Row>
119
+ );
120
+ };
90
121
 
91
- export default TagsComponent;
122
+ export default TagsComponent;
@@ -1,75 +1,111 @@
1
- import moment from 'moment'
2
- import {ConfigItemModal, HTableInstance} from "@/components/modal";
1
+ import moment from "moment";
2
+ import type { ConfigItemModal, HTableInstance } from "@/components/modal";
3
3
  import TagsComponent from "./TagsComponent";
4
- import copy from 'copy-to-clipboard';
5
- import {message, Space, Typography} from 'antd';
6
- const {Link,Paragraph}=Typography;
7
- const getTableVal=(config:ConfigItemModal,itemData:any)=>{
8
- const {dataIndex} = config;
9
- const tableDataIndex=(dataIndex as string);
10
- return itemData[tableDataIndex];
11
- }
12
- const dateRender=(config:ConfigItemModal,itemData:any)=>{
13
- const {valueTypeProps={}}=config;
14
- const tableVal=getTableVal(config,itemData);
15
- const {format="YYYY-MM-DD HH:mm:ss",timeStampType="X"}=valueTypeProps;
16
- if (!tableVal){
17
- return "-"
18
- }
19
- const time=moment(tableVal,timeStampType);
20
- return time.format(format);
21
- }
22
- const tagsRender=(config:ConfigItemModal,itemData:any,index:number,tableInstance:HTableInstance)=>{
23
- const {valueTypeProps={}}=config;
24
- const tableVal=getTableVal(config,itemData);
25
- if (!tableVal){
26
- return "-"
27
- }
28
- return <TagsComponent data={tableVal} {...valueTypeProps} tableInstance={tableInstance}/>
29
- }
30
- const copyRender=(config:ConfigItemModal,itemData:any)=>{
31
- const {valueTypeProps={},title,titleStr}=config;
32
- const {successMsg,text}=valueTypeProps;
33
- const msg=successMsg||`复制${title||titleStr}成功!`;
34
- const tableVal=getTableVal(config,itemData);
35
- if (!tableVal){
36
- return "-"
37
- }
38
- let cpText=text;
39
- if (typeof text==="function"){
40
- cpText=text(itemData);
41
- }
42
- return <Link onClick={()=>{
43
- copy(cpText||tableVal);
4
+ import copy from "copy-to-clipboard";
5
+ import {Image, message, Typography,Avatar} from "antd";
6
+
7
+ const { Link, Paragraph } = Typography;
8
+ const getTableVal = (config: ConfigItemModal, itemData: any) => {
9
+ const { dataIndex } = config;
10
+ const tableDataIndex = dataIndex as string;
11
+ return itemData[tableDataIndex];
12
+ };
13
+ const dateRender = (config: ConfigItemModal, itemData: any) => {
14
+ const { valueTypeProps = {} } = config;
15
+ const tableVal = getTableVal(config, itemData);
16
+ const { format = "YYYY-MM-DD HH:mm:ss", timeStampType = "X" } =
17
+ valueTypeProps;
18
+ if (!tableVal) {
19
+ return "-";
20
+ }
21
+ const time = moment(tableVal, timeStampType);
22
+ return time.format(format);
23
+ };
24
+ const tagsRender = (
25
+ config: ConfigItemModal,
26
+ itemData: any,
27
+ index: number,
28
+ tableInstance: HTableInstance
29
+ ) => {
30
+ const { valueTypeProps = {} } = config;
31
+ const tableVal = getTableVal(config, itemData);
32
+ if (!tableVal) {
33
+ return "-";
34
+ }
35
+ return (
36
+ <TagsComponent
37
+ data={tableVal}
38
+ {...valueTypeProps}
39
+ tableInstance={tableInstance}
40
+ />
41
+ );
42
+ };
43
+ const copyRender = (config: ConfigItemModal, itemData: any) => {
44
+ const { valueTypeProps = {}, title, titleStr } = config;
45
+ const { successMsg, text } = valueTypeProps;
46
+ const msg = successMsg || `复制${title || titleStr}成功!`;
47
+ const tableVal = getTableVal(config, itemData);
48
+ if (!tableVal) {
49
+ return "-";
50
+ }
51
+ let cpText = text;
52
+ if (typeof text === "function") {
53
+ cpText = text(itemData);
54
+ }
55
+ return (
56
+ <Link
57
+ style={{ wordBreak: 'break-all' }}
58
+ onClick={() => {
59
+ copy(cpText || tableVal);
44
60
  message.success(msg);
45
- }}>
46
- {tableVal}
61
+ }}
62
+ >
63
+ {tableVal}
47
64
  </Link>
48
- }
49
- const linkRender=(config:ConfigItemModal,itemData:any)=>{
50
- const {valueTypeProps={},}=config;
51
- const {href,target="_blank"}=valueTypeProps;
52
- const tableVal=getTableVal(config,itemData);
53
- let hrefUrl=href;
54
- if (typeof href==="function"){
55
- hrefUrl=href(itemData);
56
- }
57
- return <Link href={hrefUrl||tableVal} target={target}>
58
- {tableVal}
65
+ );
66
+ };
67
+ const linkRender = (config: ConfigItemModal, itemData: any) => {
68
+ const { valueTypeProps = {} } = config;
69
+ const { href, target = "_blank" } = valueTypeProps;
70
+ const tableVal = getTableVal(config, itemData);
71
+ let hrefUrl = href;
72
+ if (typeof href === "function") {
73
+ hrefUrl = href(itemData);
74
+ }
75
+ return (
76
+ <Link href={hrefUrl || tableVal} target={target} style={{ wordBreak: 'break-all' }}>
77
+ {tableVal}
59
78
  </Link>
60
- }
61
- const textRender=(config:ConfigItemModal,itemData:any)=>{
62
- const {valueTypeProps={},}=config;
63
- const {addonBefore,addonAfter,type,ellipsis}=valueTypeProps;
64
- const tableVal=getTableVal(config,itemData);
65
- return <Paragraph type={type} ellipsis={ellipsis}>
66
- {addonBefore}{tableVal}{addonAfter}
79
+ );
80
+ };
81
+ const textRender = (config: ConfigItemModal, itemData: any) => {
82
+ const { valueTypeProps = {} } = config;
83
+ const { addonBefore, addonAfter, type, ellipsis } = valueTypeProps;
84
+ const tableVal = getTableVal(config, itemData);
85
+ return (
86
+ <Paragraph type={type} ellipsis={ellipsis}>
87
+ {addonBefore}
88
+ {tableVal}
89
+ {addonAfter}
67
90
  </Paragraph>
91
+ );
92
+ };
93
+ const imageRender=(config: ConfigItemModal, itemData: any)=>{
94
+ const { valueTypeProps = {} } = config;
95
+ const tableVal = getTableVal(config, itemData);
96
+ return <Image src={tableVal} width={48} {...valueTypeProps}/>;
97
+ }
98
+ const avatarRender=(config: ConfigItemModal, itemData: any)=>{
99
+ const { valueTypeProps = {} } = config;
100
+ const tableVal = getTableVal(config, itemData);
101
+ return <Avatar src={tableVal} size={32} {...valueTypeProps}/>;
68
102
  }
69
103
  export default {
70
- date:dateRender,
71
- tags:tagsRender,
72
- copy:copyRender,
73
- link:linkRender,
74
- text:textRender
75
- }
104
+ date: dateRender,
105
+ tags: tagsRender,
106
+ copy: copyRender,
107
+ link: linkRender,
108
+ text: textRender,
109
+ image:imageRender,
110
+ avatar:avatarRender
111
+ };
@@ -1,20 +1,25 @@
1
- import { ConfigItemModal, HTableInstance} from "@/components/modal";
2
- import React from "react";
3
- import config from './config';
4
- import {ValueTypeConfigModal} from '../modal'
5
- export default (item:ConfigItemModal,tableInstance:HTableInstance,valueTypeConfig:ValueTypeConfigModal)=>{
6
- const { render ,valueType=""} = item;
7
- return (dom: React.ReactNode, itemData: any, index: number)=>{
8
- const valType=(valueType as string);
9
- if (render){
10
- return render(dom, itemData, index, tableInstance);
11
- }
12
- if (valueTypeConfig[valType]){
13
- return valueTypeConfig[valType](item,itemData,index,tableInstance);
14
- }
15
- if (config[valType]){
16
- return config[valType](item,itemData,index,tableInstance);
17
- }
18
- return dom;
19
- }
20
- }
1
+ import type { ConfigItemModal, HTableInstance } from "@/components/modal";
2
+ import type React from "react";
3
+ import config from "./config";
4
+ import type { ValueTypeConfigModal } from "../modal";
5
+ export default (
6
+ item: ConfigItemModal,
7
+ tableInstance: HTableInstance,
8
+ valueTypeConfig: ValueTypeConfigModal
9
+ ) => {
10
+ const { render, valueType = "" } = item;
11
+ return (dom: React.ReactNode, itemData: any, index: number) => {
12
+ const valType = valueType as string;
13
+ let node=dom;
14
+ if (config[valType]) {
15
+ node= config[valType](item, itemData, index, tableInstance);
16
+ }
17
+ if (valueTypeConfig[valType]) {
18
+ node=valueTypeConfig[valType](item, itemData, index, tableInstance);
19
+ }
20
+ if (render) {
21
+ return render(node, itemData, index, tableInstance);
22
+ }
23
+ return node;
24
+ };
25
+ };