@hzab/hierarchical-statistics 0.0.5 → 1.0.0-beta

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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ # @hzab/component-boilerplate@0.1.0
2
+ - fix: 删掉@hzab/list-render-mobile
3
+ - fix: 新增移动端下拉刷新
4
+ # @hzab/component-boilerplate@0.0.6
5
+ - fix: 修复跳转同路由,listRender参数依赖没有更新问题
1
6
  # @hzab/component-boilerplate@0.0.5
2
7
  - fix: 暴露面包屑回显数据breadcrumbData
3
8
  # @hzab/component-boilerplate@0.0.4
package/README.md CHANGED
@@ -11,8 +11,8 @@
11
11
  ## 示例
12
12
 
13
13
  ```jsx
14
- import InfiniteListUIPc from "@hzab/hierarchical-statistics/src/components/InfiniteListUiPc";
15
- <InfiniteListUIPc
14
+ import InfiniteListUi from "@hzab/hierarchical-statistics/src/components/InfiniteListUi";
15
+ <InfiniteListUi
16
16
  ref={listRef}
17
17
  style={{
18
18
  maxWidth: "400px",
@@ -47,7 +47,7 @@ import InfiniteListUIPc from "@hzab/hierarchical-statistics/src/components/Infin
47
47
  dynamicHeightMode: true,
48
48
  noMoreComponent: <div>没有更多数据了</div>,
49
49
  }}
50
- ></InfiniteListUIPc>
50
+ ></InfiniteListUi>
51
51
  ```
52
52
 
53
53
  ## API
@@ -58,7 +58,7 @@ import InfiniteListUIPc from "@hzab/hierarchical-statistics/src/components/Infin
58
58
  | -------------------- | ------------------------------| ----- | --------- | ----------------------------------- |
59
59
  | listModal | Object | 是 | - | 列表数据模型DataModel,必须包含getListApi |
60
60
  | breadModel | Object | 否 | - | 回显数据模型DataModel,必须包含getApi |
61
- | showHome | boolean | 否 | - | 是否显示面包屑首页 |
61
+ | showHome | Boolean | 否 | - | 是否显示面包屑首页 |
62
62
  | onNodeClick | function(item) | 否 | - | item点击事件 |
63
63
  | onNodeSelect | function(item) | 否 | - | item选中事件 |
64
64
  | onBreadcrumbClick | function(item) | 否 | - | 回显点击事件 |
@@ -70,10 +70,10 @@ import InfiniteListUIPc from "@hzab/hierarchical-statistics/src/components/Infin
70
70
  | listStyle | CSSProperties | 否 | - | 列表外层样式 |
71
71
  | readcrumbStyle | CSSProperties | 否 | - | 面包屑外层样式 |
72
72
  | separatorStyle | CSSProperties | 否 | - | 面包屑分割符样式 |
73
- | listRenderProps | Object | 否 | - | list-render-mobile 配置 |
74
73
  | virtualPagedListProps| Object | 否 | - | virtualPagedList 配置 |
75
74
  | separator | string | 否 | - | 分隔符 默认"-" |
76
75
  | Slots | Object | 是 | - | 插槽 |
76
+ | isPullRefresh | Boolean | 否 | false | 移动端是否可以下拉刷新 |
77
77
 
78
78
 
79
79
 
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "@hzab/hierarchical-statistics",
3
- "version": "0.0.5",
3
+ "version": "1.0.0-beta",
4
4
  "description": "",
5
5
  "main": "src",
6
6
  "scripts": {
7
7
  "dev": "webpack serve -c ./config/webpack.config.js --env local",
8
8
  "build": "webpack -c ./config/webpack.config.js --env production",
9
+ "publish-beta": "npm publish --beta",
9
10
  "publish-patch": "npm version patch && npm publish --access public",
10
11
  "publish-minor": "npm version minor && npm publish --access public",
11
12
  "publish-major": "npm version major && npm publish --access public",
@@ -48,7 +49,9 @@
48
49
  },
49
50
  "peerDependencies": {
50
51
  "@hzab/data-model": ">=1.7.5",
51
- "@hzab/headless-components": ">=0.0.3",
52
- "@hzab/list-render-mobile": ">=1.1.7"
52
+ "@hzab/headless-components": ">=0.0.3"
53
+ },
54
+ "dependencies": {
55
+ "react-window-pull-refresh": "^1.0.9"
53
56
  }
54
57
  }
@@ -1,8 +1,8 @@
1
1
  import "../index.less";
2
2
  const BreadcrumbUI = (props: any) => {
3
- const { readcrumbStyle, separatorStyle, separator, breadcrumbData, terminal, handleBreadcrumbClick } = props;
3
+ const { readcrumbStyle, separatorStyle, separator, breadcrumbData, handleBreadcrumbClick } = props;
4
4
  return (
5
- <div className={`breadcrumb-box ${terminal !== "pc" ? "breadcrumb-box-mobile" : ""}`} style={readcrumbStyle}>
5
+ <div className={`breadcrumb-box`} style={readcrumbStyle}>
6
6
  {breadcrumbData.map((item, index) => (
7
7
  <div className="breadcrumb-item" key={index}>
8
8
  <span
@@ -1,11 +1,12 @@
1
1
  import { ForwardedRef, forwardRef, useImperativeHandle, useRef } from "react";
2
+ import { PullToRefresh } from "react-window-pull-refresh";
2
3
  import VirtualPagedList from "@hzab/headless-components/src/VirtualPagedList";
3
4
  import { ConfigProvider, Spin, Empty, Button } from "antd";
4
5
  import { useInfiniteList } from "../../use-infinite-list";
5
6
  import Breadcrumb from "../Breadcrumb";
6
7
  import { InfiniteListProps, InfiniteListInstance } from "../../type";
7
8
  import "../index.less";
8
- const InfiniteListUIPc = (props: InfiniteListProps, ref: ForwardedRef<InfiniteListInstance>) => {
9
+ const InfiniteListUi = (props: InfiniteListProps, ref: ForwardedRef<InfiniteListInstance>) => {
9
10
  const {
10
11
  states: {
11
12
  listModal,
@@ -22,9 +23,11 @@ const InfiniteListUIPc = (props: InfiniteListProps, ref: ForwardedRef<InfiniteLi
22
23
  listRef,
23
24
  virtualPagedListProps,
24
25
  className,
26
+ refreshKey,
27
+ isPullRefresh,
25
28
  },
26
- actions: { handleSelectId, handleNodeClick, handleBreadcrumbClick, fetchBreadData },
27
- } = useInfiniteList({ ...props, terminal: "pc" });
29
+ actions: { handleSelectId, handleNodeClick, handleBreadcrumbClick, fetchBreadData, handleListRefresh },
30
+ } = useInfiniteList({ ...props });
28
31
 
29
32
  useImperativeHandle(ref, () => ({
30
33
  handleNodeClick,
@@ -34,6 +37,7 @@ const InfiniteListUIPc = (props: InfiniteListProps, ref: ForwardedRef<InfiniteLi
34
37
  breadModel,
35
38
  fetchBreadData,
36
39
  breadcrumbData,
40
+ handleListRefresh,
37
41
  }));
38
42
 
39
43
  const loadData = async (pageNum) => {
@@ -45,13 +49,41 @@ const InfiniteListUIPc = (props: InfiniteListProps, ref: ForwardedRef<InfiniteLi
45
49
  isMore: res?.pagination?.total > (pageNum - 1) * listModal.query.pageSize + res?.list?.length ? true : false,
46
50
  };
47
51
  };
52
+
53
+ const JsxDom = (propJsx) => {
54
+ let jsx = <></>;
55
+ if (isPullRefresh) {
56
+ jsx = (
57
+ <PullToRefresh handleRefresh={handleListRefresh}>
58
+ <VirtualPagedList
59
+ key={refreshKey}
60
+ ref={listRef}
61
+ {...virtualPagedListProps}
62
+ renderItem={Slots.renderItem}
63
+ loadMoreItems={loadData}
64
+ />
65
+ </PullToRefresh>
66
+ );
67
+ } else {
68
+ jsx = (
69
+ <VirtualPagedList
70
+ key={refreshKey}
71
+ ref={listRef}
72
+ {...virtualPagedListProps}
73
+ renderItem={Slots.renderItem}
74
+ loadMoreItems={loadData}
75
+ />
76
+ );
77
+ }
78
+ return jsx;
79
+ };
80
+
48
81
  return (
49
82
  <div className={`infinite-level-box ${className || ""}`} style={style}>
50
83
  <Spin spinning={loading}>
51
84
  {/* 面包屑导航 */}
52
85
  <div className="infinite-level-breadcrumb-position">
53
86
  <Breadcrumb
54
- terminal="pc"
55
87
  readcrumbStyle={readcrumbStyle}
56
88
  separatorStyle={separatorStyle}
57
89
  separator={separator}
@@ -61,17 +93,11 @@ const InfiniteListUIPc = (props: InfiniteListProps, ref: ForwardedRef<InfiniteLi
61
93
  {Slots?.fixRenderCenter && <Slots.fixRenderCenter></Slots.fixRenderCenter>}
62
94
  </div>
63
95
  <div className="infinite-level-list-box" style={listStyle}>
64
- <VirtualPagedList
65
- key={selectedLoadIdNode}
66
- ref={listRef}
67
- {...virtualPagedListProps}
68
- renderItem={Slots.renderItem}
69
- loadMoreItems={loadData}
70
- />
96
+ <JsxDom></JsxDom>
71
97
  </div>
72
98
  </Spin>
73
99
  </div>
74
100
  );
75
101
  };
76
102
 
77
- export default forwardRef<InfiniteListInstance, InfiniteListProps>(InfiniteListUIPc);
103
+ export default forwardRef<InfiniteListInstance, InfiniteListProps>(InfiniteListUi);
package/src/type.d.ts CHANGED
@@ -29,6 +29,8 @@ export interface InfiniteListInstance {
29
29
  breadcrumbData?: any;
30
30
  /** 面包屑数据请求方法 */
31
31
  fetchBreadData?: () => Promise<void>;
32
+ /** 列表刷新 */
33
+ handleListRefresh?: () => void;
32
34
  }
33
35
  export interface InfiniteListProps {
34
36
  /** 添加外层类名 */
@@ -58,8 +60,6 @@ export interface InfiniteListProps {
58
60
  separatorStyle?: object;
59
61
  /** 面包屑外层 自定义css 样式 */
60
62
  readcrumbStyle?: object;
61
- /** 设备是pc,还是mobile */
62
- terminal?: string;
63
63
  /** 列表外层 css 样式 */
64
64
  listStyle?: object;
65
65
  /** list modal */
@@ -70,6 +70,8 @@ export interface InfiniteListProps {
70
70
  listRenderProps?: object;
71
71
  /** virtualPagedList 配置 */
72
72
  virtualPagedListProps?: any;
73
+ /** 是否可下拉刷新 */
74
+ isPullRefresh?: boolean;
73
75
  /** 选中点击事件 */
74
76
  onNodeClick?: (node: ListItem) => void;
75
77
  /** 选中id */
@@ -29,6 +29,7 @@ export function useInfiniteList(props: InfiniteListProps) {
29
29
  breadModel,
30
30
  virtualPagedListProps,
31
31
  className,
32
+ isPullRefresh = false,
32
33
  } = props;
33
34
  const [loading, setLoading] = useState(false);
34
35
  const [selectedLoadIdNode, setSelectedLoadIdNode] = useState<number | null>(null);
@@ -36,6 +37,7 @@ export function useInfiniteList(props: InfiniteListProps) {
36
37
  const [breadcrumbData, setBreadcrumbData] = useState<PathItem[]>(
37
38
  showHome ? [{ value: 0, label: homeBreadcrumb }] : [],
38
39
  );
40
+ const [refreshKey, setRefreshKey] = useState(1);
39
41
  const listRef = useRef<any>(null);
40
42
 
41
43
  /**
@@ -58,7 +60,7 @@ export function useInfiniteList(props: InfiniteListProps) {
58
60
  label: item[fieldList.label],
59
61
  },
60
62
  ]);
61
- listRef.current?.onSearch();
63
+ setRefreshKey((pre) => pre + 1);
62
64
  };
63
65
 
64
66
  /**
@@ -85,7 +87,7 @@ export function useInfiniteList(props: InfiniteListProps) {
85
87
  listModal.query = { ...listModal.query, [parentField]: item.value };
86
88
  setSelectedLoadIdNode(item.value);
87
89
  setBreadcrumbData(breadcrumbData.slice(0, index + 1));
88
- listRef.current?.onSearch();
90
+ setRefreshKey((pre) => pre + 1);
89
91
  };
90
92
 
91
93
  /**
@@ -110,6 +112,11 @@ export function useInfiniteList(props: InfiniteListProps) {
110
112
  setLoading(false);
111
113
  }
112
114
  };
115
+ /** 列表刷新 */
116
+ const handleListRefresh = async () => {
117
+ listModal.query = { ...listModal.query, pageNum: 1 };
118
+ setRefreshKey((pre) => pre + 1);
119
+ };
113
120
 
114
121
  useEffect(() => {
115
122
  fetchBreadData();
@@ -133,12 +140,15 @@ export function useInfiniteList(props: InfiniteListProps) {
133
140
  listModal,
134
141
  breadModel,
135
142
  className,
143
+ refreshKey,
144
+ isPullRefresh,
136
145
  },
137
146
  actions: {
138
147
  handleSelectId,
139
148
  handleNodeClick,
140
149
  handleBreadcrumbClick,
141
150
  fetchBreadData,
151
+ handleListRefresh,
142
152
  },
143
153
  };
144
154
  }
@@ -1,62 +0,0 @@
1
- import { ForwardedRef, forwardRef, useImperativeHandle, useRef } from "react";
2
- import { ConfigProvider, Spin } from "antd";
3
- import ListRender from "@hzab/list-render-mobile";
4
- import { useInfiniteList } from "../../use-infinite-list";
5
- import { InfiniteListProps, InfiniteListInstance } from "../../type";
6
- import Breadcrumb from "../Breadcrumb";
7
- import "../index.less";
8
- const InfiniteListUIMobile = (props: InfiniteListProps, ref: ForwardedRef<InfiniteListInstance>) => {
9
- const {
10
- states: {
11
- readcrumbStyle,
12
- separatorStyle,
13
- separator,
14
- listRenderProps,
15
- style,
16
- listModal,
17
- breadcrumbData,
18
- Slots,
19
- loading,
20
- listRef,
21
- listStyle,
22
- breadModel,
23
- className,
24
- },
25
- actions: { fetchBreadData, handleSelectId, handleNodeClick, handleBreadcrumbClick },
26
- } = useInfiniteList({ ...props, terminal: "mobile" });
27
- useImperativeHandle(ref, () => ({
28
- handleNodeClick,
29
- handleSelectId,
30
- listRef: listRef?.current,
31
- listModal,
32
- breadModel,
33
- fetchBreadData,
34
- breadcrumbData,
35
- }));
36
- return (
37
- <div className={`infinite-level-box ${className || ""}`} style={style}>
38
- <Spin spinning={loading}>
39
- {/* 面包屑导航 */}
40
- <div className="infinite-level-breadcrumb-position">
41
- <Breadcrumb
42
- terminal="mobile"
43
- readcrumbStyle={readcrumbStyle}
44
- separatorStyle={separatorStyle}
45
- separator={separator}
46
- breadcrumbData={breadcrumbData}
47
- handleBreadcrumbClick={handleBreadcrumbClick}
48
- Slots={Slots}
49
- ></Breadcrumb>
50
- {Slots?.fixRenderCenter && <Slots.fixRenderCenter></Slots.fixRenderCenter>}
51
- </div>
52
-
53
- <div className="infinite-level-list-box" style={listStyle}>
54
- {/* 移动端 */}
55
- <ListRender ref={listRef} model={listModal} {...listRenderProps} ItemRender={Slots.renderItem} />
56
- </div>
57
- </Spin>
58
- </div>
59
- );
60
- };
61
-
62
- export default forwardRef<InfiniteListInstance, InfiniteListProps>(InfiniteListUIMobile);