@zgfe/business-lib 1.2.51-ljy.1 → 1.2.51-ljy.2

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.
@@ -10,10 +10,10 @@ import '@zgfe/business-lib/es/assets/styles/resetAntd.less';
10
10
  import { Divider, Space, Switch } from 'antd';
11
11
  export default (function () {
12
12
  var _useState = useState({
13
- begin: '2024-07-23',
13
+ begin: '2024-07-11',
14
14
  end: '2024-08-05',
15
- relative: [14, 1],
16
- unit: 'day'
15
+ relative: [4, 1],
16
+ unit: 'week'
17
17
  }),
18
18
  _useState2 = _slicedToArray(_useState, 2),
19
19
  time = _useState2[0],
@@ -17,9 +17,10 @@ import './styles/index.less';
17
17
  import { Popover, Skeleton } from 'antd';
18
18
  import DatePickerContext from './context';
19
19
  import _ from 'lodash';
20
- import { getDateRange } from './utils';
20
+ import { getDateRange, getTypeList } from './utils';
21
21
  import PopoverContent from './popoverContent';
22
22
  import IconFont from '../icon/iconFont';
23
+ import moment from 'moment';
23
24
  export var classPrefix = 'biz-date-picker-old-wrap';
24
25
  var typeMap = {
25
26
  hour: '按小时',
@@ -99,10 +100,29 @@ var BizDatePicker = function BizDatePicker(_ref) {
99
100
  break;
100
101
  }
101
102
  }
102
- setDateRange({
103
- begin: initValue.begin,
104
- end: initValue.end
103
+ var typeList = getTypeList(currentType === null || currentType === void 0 ? void 0 : currentType.value, mode, includeToday);
104
+ var begin = initValue.begin,
105
+ end = initValue.end;
106
+ var item = typeList.find(function (item) {
107
+ var match = getDateRange(currentType === null || currentType === void 0 ? void 0 : currentType.value, item.count, includeToday);
108
+ return moment(begin).isSame(match.begin) && moment(end).isSame(match.end);
105
109
  });
110
+ var active = item === null || item === void 0 ? void 0 : item.count;
111
+ if (active) {
112
+ setDateRange({
113
+ begin: initValue.begin,
114
+ end: initValue.end
115
+ });
116
+ } else {
117
+ if (initValue.relative) {
118
+ setDateRange(getDateRange(currentType === null || currentType === void 0 ? void 0 : currentType.value, initValue.relative[0], includeToday));
119
+ } else {
120
+ setDateRange({
121
+ begin: initValue.begin,
122
+ end: initValue.end
123
+ });
124
+ }
125
+ }
106
126
  setReady(true);
107
127
  }
108
128
  useEffect(function () {
@@ -9,90 +9,8 @@ import { DatePickerTypes } from './types';
9
9
  import { classPrefix } from '.';
10
10
  import DatePickerContext from './context';
11
11
  import moment from 'moment';
12
- import { getDateRange } from './utils';
12
+ import { getDateRange, getTypeList } from './utils';
13
13
  import { Button, InputNumber } from 'antd';
14
- var getTypeList = function getTypeList(currentType, mode, includeToday) {
15
- var _shortcuts$find;
16
- var shortcuts = [{
17
- label: '按小时',
18
- value: DatePickerTypes.Unit.hour,
19
- children: [{
20
- value: '昨天',
21
- count: 1
22
- }, {
23
- value: '前天',
24
- count: 2
25
- }]
26
- }, {
27
- label: '按天',
28
- value: DatePickerTypes.Unit.day,
29
- children: [{
30
- value: '今天',
31
- count: 0
32
- }, {
33
- value: '昨天',
34
- count: 1
35
- }, {
36
- value: '7天',
37
- count: 7
38
- }, {
39
- value: '14天',
40
- count: 14
41
- }, {
42
- value: '30天',
43
- count: 30
44
- }]
45
- }, {
46
- label: '按周',
47
- value: DatePickerTypes.Unit.week,
48
- children: [{
49
- value: '4周',
50
- count: 4
51
- }, {
52
- value: '8周',
53
- count: 8
54
- }, {
55
- value: '12周',
56
- count: 12
57
- }]
58
- }, {
59
- label: '按月',
60
- value: DatePickerTypes.Unit.month,
61
- children: [{
62
- value: '1个月',
63
- count: 1
64
- }, {
65
- value: '2个月',
66
- count: 2
67
- }, {
68
- value: '3个月',
69
- count: 3
70
- }]
71
- }, {
72
- label: '按季度',
73
- value: DatePickerTypes.Unit.quarter,
74
- children: [{
75
- value: '1季度',
76
- count: 1
77
- }, {
78
- value: '2季度',
79
- count: 2
80
- }, {
81
- value: '4季度',
82
- count: 4
83
- }]
84
- }];
85
- var list = (((_shortcuts$find = shortcuts.find(function (item) {
86
- return item.value === currentType;
87
- })) === null || _shortcuts$find === void 0 ? void 0 : _shortcuts$find.children) || []).filter(function (item) {
88
- if (currentType === 'day') {
89
- if ((mode === 'general' || !includeToday) && (item.count === 0 || item.count === 1)) return false;
90
- return true;
91
- }
92
- return true;
93
- });
94
- return list;
95
- };
96
14
  var DateOptionMap = {
97
15
  day: '天',
98
16
  week: '周',
@@ -111,7 +29,8 @@ var PickerShortcut = function PickerShortcut(_ref) {
111
29
  setRelative = _useContext.setRelative,
112
30
  setLabel = _useContext.setLabel,
113
31
  setOpen = _useContext.setOpen;
114
- var _useState = useState(),
32
+ var list = getTypeList(currentType, mode, includeToday);
33
+ var _useState = useState(list[0].count),
115
34
  _useState2 = _slicedToArray(_useState, 2),
116
35
  active = _useState2[0],
117
36
  setActive = _useState2[1];
@@ -119,7 +38,6 @@ var PickerShortcut = function PickerShortcut(_ref) {
119
38
  _useState4 = _slicedToArray(_useState3, 2),
120
39
  numbers = _useState4[0],
121
40
  setNumbers = _useState4[1];
122
- var list = getTypeList(currentType, mode, includeToday);
123
41
  useEffect(function () {
124
42
  list = getTypeList(currentType, mode, includeToday);
125
43
  if (!relative && !dateRange) {
@@ -173,6 +91,7 @@ var PickerShortcut = function PickerShortcut(_ref) {
173
91
  setActive(item.count);
174
92
  setLabel === null || setLabel === void 0 ? void 0 : setLabel(item === null || item === void 0 ? void 0 : item.value);
175
93
  if (setRelative) setRelative([item.count, includeToday ? 0 : 1]);
94
+ setOpen === null || setOpen === void 0 ? void 0 : setOpen(false);
176
95
  }
177
96
  }, item.value);
178
97
  }))), currentType !== DatePickerTypes.Unit.hour && /*#__PURE__*/React.createElement("div", {
@@ -1,7 +1,9 @@
1
1
  import moment from 'moment';
2
2
  import { DatePickerTypes } from './types';
3
+ import { DatePickerContextProps } from './context';
3
4
  export declare const getDateRange: (type: DatePickerTypes.Unit, count: number, includeToday: boolean) => {
4
5
  begin: string;
5
6
  end: string;
6
7
  };
7
8
  export declare const isTodayInRange: (_startDate: moment.Moment, _endDate: moment.Moment) => boolean;
9
+ export declare const getTypeList: (currentType: DatePickerTypes.Unit, mode: DatePickerContextProps['mode'], includeToday: boolean) => DatePickerTypes.ListOption[];
@@ -44,4 +44,86 @@ export var isTodayInRange = function isTodayInRange(_startDate, _endDate) {
44
44
  var endDate = moment(_endDate).add(1, 'days').format('x');
45
45
  var dateToCheck = moment(new Date()).format('x');
46
46
  return dateToCheck >= startDate && dateToCheck <= endDate;
47
+ };
48
+ export var getTypeList = function getTypeList(currentType, mode, includeToday) {
49
+ var _shortcuts$find;
50
+ var shortcuts = [{
51
+ label: '按小时',
52
+ value: DatePickerTypes.Unit.hour,
53
+ children: [{
54
+ value: '昨天',
55
+ count: 1
56
+ }, {
57
+ value: '前天',
58
+ count: 2
59
+ }]
60
+ }, {
61
+ label: '按天',
62
+ value: DatePickerTypes.Unit.day,
63
+ children: [{
64
+ value: '今天',
65
+ count: 0
66
+ }, {
67
+ value: '昨天',
68
+ count: 1
69
+ }, {
70
+ value: '7天',
71
+ count: 7
72
+ }, {
73
+ value: '14天',
74
+ count: 14
75
+ }, {
76
+ value: '30天',
77
+ count: 30
78
+ }]
79
+ }, {
80
+ label: '按周',
81
+ value: DatePickerTypes.Unit.week,
82
+ children: [{
83
+ value: '4周',
84
+ count: 4
85
+ }, {
86
+ value: '8周',
87
+ count: 8
88
+ }, {
89
+ value: '12周',
90
+ count: 12
91
+ }]
92
+ }, {
93
+ label: '按月',
94
+ value: DatePickerTypes.Unit.month,
95
+ children: [{
96
+ value: '1个月',
97
+ count: 1
98
+ }, {
99
+ value: '2个月',
100
+ count: 2
101
+ }, {
102
+ value: '3个月',
103
+ count: 3
104
+ }]
105
+ }, {
106
+ label: '按季度',
107
+ value: DatePickerTypes.Unit.quarter,
108
+ children: [{
109
+ value: '1季度',
110
+ count: 1
111
+ }, {
112
+ value: '2季度',
113
+ count: 2
114
+ }, {
115
+ value: '4季度',
116
+ count: 4
117
+ }]
118
+ }];
119
+ var list = (((_shortcuts$find = shortcuts.find(function (item) {
120
+ return item.value === currentType;
121
+ })) === null || _shortcuts$find === void 0 ? void 0 : _shortcuts$find.children) || []).filter(function (item) {
122
+ if (currentType === 'day') {
123
+ if ((mode === 'general' || !includeToday) && (item.count === 0 || item.count === 1)) return false;
124
+ return true;
125
+ }
126
+ return true;
127
+ });
128
+ return list;
47
129
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zgfe/business-lib",
3
- "version": "1.2.51-ljy.1",
3
+ "version": "1.2.51-ljy.2",
4
4
  "module": "es/index.js",
5
5
  "typings": "es/index.d.ts",
6
6
  "files": [
@@ -55,7 +55,7 @@
55
55
  "react": "^16.12.0 || ^17.0.0",
56
56
  "yorkie": "^2.0.0"
57
57
  },
58
- "gitHead": "9a7a09c57f1d248349441367e54a637f97d8f4f5",
58
+ "gitHead": "4ec2943a33bb54f7b6035e846dea5cc65dc4e275",
59
59
  "gitHooks": {
60
60
  "pre-commit": "lint-staged"
61
61
  }