@yeeyoon/library 2.8.0 → 2.8.4

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.
@@ -1,16 +1,33 @@
1
- import React from 'react';
1
+ import React, { useState, useEffect } from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import ProTable from '@ant-design/pro-table';
4
4
  import { mergeTableColumnCommonConfig } from '../../../utils/utils';
5
5
 
6
+ let paginationData = {
7
+ current: 1,
8
+ pageSize: 10,
9
+ };
10
+ let sortData = {};
11
+ let filterData = {};
12
+
6
13
  const CommonTable = (props) => {
7
14
  const {
8
15
  data,
9
16
  dataTransform,
10
17
  paginationKey = ['each_page', 'current_page'],
18
+ systemTags = [],
11
19
  } = props;
20
+ const [paginationCurrent, setPaginationCurrent] = useState(1);
12
21
  const { rowKey, columns, reqFunc, reqParams, reqCbFn, ...rest } = data;
13
- let sortData = {};
22
+ useEffect(() => {
23
+ paginationData = {
24
+ current: 1,
25
+ pageSize: 10,
26
+ };
27
+ sortData = {};
28
+ filterData = {};
29
+ }, [columns]);
30
+
14
31
  return (
15
32
  <ProTable
16
33
  rowKey={(record) => record[rowKey]}
@@ -18,6 +35,7 @@ const CommonTable = (props) => {
18
35
  pagination={{
19
36
  position: ['bottomCenter'],
20
37
  pageSize: 10,
38
+ current: paginationCurrent,
21
39
  }}
22
40
  options={false}
23
41
  scroll={{
@@ -27,12 +45,14 @@ const CommonTable = (props) => {
27
45
  if (typeof reqFunc !== 'function') return;
28
46
  const { current, pageSize, ...rest } = params;
29
47
  const resp = await reqFunc({
30
- [paginationKey[0]]: pageSize,
31
- [paginationKey[1]]: current,
48
+ [paginationKey[0]]: paginationData.pageSize || pageSize,
49
+ [paginationKey[1]]: paginationData.current || current,
32
50
  ...rest,
33
51
  ...reqParams,
34
52
  ...sortData,
53
+ ...filterData,
35
54
  });
55
+ filterData = {};
36
56
  const { total_data, data } = dataTransform ? dataTransform(resp) : resp;
37
57
  if (reqCbFn) reqCbFn(params, { data, total: total_data });
38
58
  return {
@@ -42,13 +62,36 @@ const CommonTable = (props) => {
42
62
  };
43
63
  }}
44
64
  onChange={(pagination, filters, sorter) => {
65
+ // console.log(pagination, filters, sorter, 'xxxxxxxx');
66
+ if (pagination) {
67
+ const { current, pageSize } = pagination;
68
+ setPaginationCurrent(current);
69
+ paginationData = { current, pageSize };
70
+ }
71
+ if (filters) {
72
+ Object.keys(filters).forEach((key) => {
73
+ if (filters[key]) {
74
+ filterData[key] = filters[key];
75
+ }
76
+ });
77
+ filterData = {
78
+ filters: JSON.stringify({
79
+ system_tags: systemTags,
80
+ ...filterData,
81
+ }),
82
+ };
83
+ rest.actionRef && rest.actionRef.current.reload();
84
+ }
45
85
  if (sorter.field) {
46
86
  const { field, order, column } = sorter;
47
- const { sortType } = column;
48
- sortData = {
49
- sort_direction: `${order === 'ascend' ? 'asc' : 'desc'}`,
50
- sort_by: `${field}${sortType ? '.' + sortType : ''}`,
51
- };
87
+ if (!column) sortData = {};
88
+ else {
89
+ const { sortType } = column;
90
+ sortData = {
91
+ sort_direction: `${order === 'ascend' ? 'asc' : 'desc'}`,
92
+ sort_by: `${field}${sortType ? '.' + sortType : ''}`,
93
+ };
94
+ }
52
95
  } else {
53
96
  sortData = {};
54
97
  }
@@ -62,6 +105,7 @@ CommonTable.propTypes = {
62
105
  data: PropTypes.object,
63
106
  dataTransform: PropTypes.func,
64
107
  paginationKey: PropTypes.array,
108
+ systemTags: PropTypes.array,
65
109
  };
66
110
 
67
111
  export default CommonTable;
@@ -7,7 +7,14 @@ import { notification } from 'antd';
7
7
  const TOKEN_KEY = 'X-Auth-Token';
8
8
  const ID_KEY = 'X-Auth-Id';
9
9
  const REST_KEY = 'Login-Rest-Info';
10
- const qsData = qs.parse(window.location.search.slice(1));
10
+ const { search, hash } = window.location;
11
+ let searchQs = '';
12
+ if (search !== '') {
13
+ searchQs = search.slice(1);
14
+ } else if (hash !== '') {
15
+ searchQs = hash.split('?')[1] || '';
16
+ }
17
+ const qsData = qs.parse(searchQs);
11
18
  const { token, userId, ...rest } = qsData;
12
19
 
13
20
  token && ls.set(TOKEN_KEY, token);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yeeyoon/library",
3
- "version": "2.8.0",
3
+ "version": "2.8.4",
4
4
  "description": "宜云前端组件库和通用服务",
5
5
  "main": "index.js",
6
6
  "repository": {