@ccs-ui/rc-pro 1.0.0

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.
Files changed (57) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +37 -0
  3. package/es/auth/auth-button.js +59 -0
  4. package/es/auth/auth-dropdown.js +67 -0
  5. package/es/auth/index.js +164 -0
  6. package/es/ccs.js +82 -0
  7. package/es/color-picker/index.js +63 -0
  8. package/es/color-picker/index.less +9 -0
  9. package/es/config.js +11 -0
  10. package/es/context/index.js +11 -0
  11. package/es/date-picker/index.js +59 -0
  12. package/es/drawer/buttons.js +93 -0
  13. package/es/drawer/index.js +8 -0
  14. package/es/drawer/index.less +5 -0
  15. package/es/drawer/open/content.js +43 -0
  16. package/es/drawer/open/destory-fns.js +3 -0
  17. package/es/drawer/open/form.js +32 -0
  18. package/es/drawer/open/index.js +171 -0
  19. package/es/full-screen/index.js +57 -0
  20. package/es/hooks/use-event.js +67 -0
  21. package/es/hooks/use-global.js +10 -0
  22. package/es/hooks/use-once-event.js +16 -0
  23. package/es/hooks/use-page.js +10 -0
  24. package/es/hooks/use-tabs.js +10 -0
  25. package/es/hooks/use-window.js +10 -0
  26. package/es/index.js +27 -0
  27. package/es/interval-button/index.js +118 -0
  28. package/es/keep-alive-tabs/index.js +250 -0
  29. package/es/keep-alive-tabs/index.less +23 -0
  30. package/es/keep-alive-tabs/page.js +37 -0
  31. package/es/loading/index.js +27 -0
  32. package/es/modal/buttons.js +90 -0
  33. package/es/modal/index.js +8 -0
  34. package/es/modal/index.less +25 -0
  35. package/es/modal/open/destory-fns.js +3 -0
  36. package/es/modal/open/drag.js +104 -0
  37. package/es/modal/open/form.js +35 -0
  38. package/es/modal/open/index.js +93 -0
  39. package/es/pro-grid/context.js +4 -0
  40. package/es/pro-grid/index.js +88 -0
  41. package/es/pro-grid/index.less +29 -0
  42. package/es/pro-grid/useProGrid.js +10 -0
  43. package/es/pro-table/index.js +578 -0
  44. package/es/pro-table/index.less +165 -0
  45. package/es/pro-table/search.js +399 -0
  46. package/es/pro-tabs/index.js +77 -0
  47. package/es/pro-tabs/index.less +5 -0
  48. package/es/select/index.js +72 -0
  49. package/es/table/index.js +173 -0
  50. package/es/table/index.less +117 -0
  51. package/es/trigger/index.js +288 -0
  52. package/es/trigger/index.less +42 -0
  53. package/es/types.js +0 -0
  54. package/es/utils.js +205 -0
  55. package/es/virtual-list/index.js +125 -0
  56. package/es/water-mark/index.js +135 -0
  57. package/package.json +102 -0
@@ -0,0 +1,288 @@
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
+ var _excluded = ["size", "style", "value", "width", "height", "disabled", "children", "className", "forceRender", "placeholder", "popupContainer", "onChange"];
3
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
4
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
5
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
7
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
8
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
9
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
10
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
11
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
12
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
13
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
14
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
15
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
16
+ import { ConfigProvider, Input, Spin } from 'antd';
17
+ import Trigger from 'rc-trigger';
18
+ import React, { cloneElement, useEffect, useMemo, useRef, useState } from 'react';
19
+ // import _isPlainObject from 'lodash/isPlainObject';
20
+ import { CloseCircleFilled, DownOutlined } from '@ant-design/icons';
21
+ import { useDebounceFn, useEventListener, useUpdate } from 'ahooks';
22
+ import zhCN from 'antd/locale/zh_CN';
23
+ import _isNil from 'lodash/isNil';
24
+ import "./index.less";
25
+ var zIndex = 2000;
26
+ var classPrefix = 'ccs-trigger';
27
+
28
+ /**
29
+ * 适用于Form.Item中的 trigger组件,其内容自行定义,遵循ant form 自定义组件规范
30
+ * @param CcsTriggerPropsType
31
+ * @returns
32
+ */
33
+ var TriggerComponent = function TriggerComponent(props) {
34
+ var _ref$current2;
35
+ var size = props.size,
36
+ style = props.style,
37
+ value = props.value,
38
+ width = props.width,
39
+ height = props.height,
40
+ disabled = props.disabled,
41
+ children = props.children,
42
+ className = props.className,
43
+ forceRender = props.forceRender,
44
+ placeholder = props.placeholder,
45
+ popupContainer = props.popupContainer,
46
+ onChange = props.onChange,
47
+ restProps = _objectWithoutProperties(props, _excluded);
48
+ var inputRef = useRef(null);
49
+ var ref = useRef(null);
50
+ var containerRef = useRef(null);
51
+ var closeRef = useRef(null);
52
+ var downRef = useRef(null);
53
+ var alignRef = useRef({
54
+ points: ['tl', 'bl'],
55
+ offset: [0, 3],
56
+ size: {
57
+ width: width,
58
+ height: height
59
+ },
60
+ maxSize: {
61
+ width: width,
62
+ height: height
63
+ }
64
+ });
65
+ var _useState = useState(null),
66
+ _useState2 = _slicedToArray(_useState, 2),
67
+ visible = _useState2[0],
68
+ setVisible = _useState2[1];
69
+ var update = useUpdate();
70
+ var _useState3 = useState(false),
71
+ _useState4 = _slicedToArray(_useState3, 2),
72
+ loading = _useState4[0],
73
+ setLoading = _useState4[1];
74
+
75
+ // 显示下拉图标
76
+ var onMouseLeave = function onMouseLeave() {
77
+ var _closeRef$current, _downRef$current;
78
+ (_closeRef$current = closeRef.current) === null || _closeRef$current === void 0 ? void 0 : _closeRef$current.classList.replace('ccs-trigger-show', 'ccs-trigger-hidden');
79
+ (_downRef$current = downRef.current) === null || _downRef$current === void 0 ? void 0 : _downRef$current.classList.replace('ccs-trigger-hidden', 'ccs-trigger-show');
80
+ };
81
+
82
+ // 显示清除数据图标
83
+ var onMouseEnter = function onMouseEnter() {
84
+ if (!_isNil(value)) {
85
+ var _downRef$current2, _closeRef$current2;
86
+ (_downRef$current2 = downRef.current) === null || _downRef$current2 === void 0 ? void 0 : _downRef$current2.classList.replace('ccs-trigger-show', 'ccs-trigger-hidden');
87
+ (_closeRef$current2 = closeRef.current) === null || _closeRef$current2 === void 0 ? void 0 : _closeRef$current2.classList.replace('ccs-trigger-hidden', 'ccs-trigger-show');
88
+ }
89
+ };
90
+
91
+ // 获取对齐方式、默认右下侧展开
92
+ var getAlignMode = function getAlignMode() {
93
+ var _ref$current;
94
+ var rect = (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.getBoundingClientRect();
95
+ if (!rect) return;
96
+ var top = rect.top,
97
+ left = rect.left,
98
+ right = rect.right,
99
+ bottom = rect.bottom;
100
+ var _document$body = document.body,
101
+ offsetWidth = _document$body.offsetWidth,
102
+ offsetHeight = _document$body.offsetHeight;
103
+ var rightWidth = offsetWidth - left; // 右侧宽度
104
+ var bottomHeight = offsetHeight - bottom; // 下侧高度
105
+
106
+ // 元素 上右下左弹出框空间 top rightWidth bottomHeight right
107
+ var x = 'right';
108
+ var y = 'bottom';
109
+ if (width) {
110
+ if (rightWidth >= width) {
111
+ // 右侧宽度足够
112
+ } else if (right >= width) {
113
+ // 左侧宽度足够
114
+ x = 'left';
115
+ } else {
116
+ // 两侧宽度都不够,取最大
117
+ x = rightWidth > right ? 'right' : 'left';
118
+ // 弹出框最大宽度
119
+ alignRef.current.size.width = Math.max(right, rightWidth) - 10;
120
+ }
121
+ } else {
122
+ // 没有传入宽度、取最大值
123
+ x = rightWidth > right ? 'right' : 'left';
124
+ alignRef.current.maxSize.width = Math.max(right, rightWidth) - 10;
125
+ }
126
+ if (height) {
127
+ if (bottomHeight >= height) {
128
+ // 底部高度足够
129
+ } else if (top >= height) {
130
+ // 顶部高度足够
131
+ y = 'top';
132
+ } else {
133
+ // 上下高度都不够取最大
134
+ y = bottomHeight > top ? 'bottom' : 'top';
135
+ // 弹出框最大高度
136
+ alignRef.current.size.height = Math.max(top, bottomHeight) - 10;
137
+ }
138
+ } else {
139
+ // 没有传入高度、取最大值
140
+ y = bottomHeight > top ? 'bottom' : 'top';
141
+ alignRef.current.maxSize.height = Math.max(top, bottomHeight) - 10;
142
+ }
143
+ var point0 = 'tl'; // 弹出框对齐点
144
+ var point1 = 'bl'; // 目标对齐点
145
+ var offsetX = 0; // x偏移量
146
+ var offsetY = 3; // y偏移量
147
+
148
+ // 弹出框四个方位展开
149
+ if (x === 'right' && y === 'bottom') {
150
+ // 右下空间足够、默认右下展开
151
+ } else if (x === 'left' && y === 'bottom') {
152
+ // 右边宽度不够、高度足够、左下侧展开
153
+ point1 = 'br';
154
+ point0 = 'tr';
155
+ } else if (x === 'right' && y === 'top') {
156
+ // 右边宽度足够、高度不够、右上侧展开
157
+ point1 = 'tl';
158
+ point0 = 'bl';
159
+ offsetY = -3;
160
+ } else {
161
+ // 右边宽度不够、高度不够、左上侧展开
162
+ point1 = 'tr';
163
+ point0 = 'br';
164
+ offsetY = -3;
165
+ }
166
+ alignRef.current = _objectSpread(_objectSpread({}, alignRef.current), {}, {
167
+ points: [point0, point1],
168
+ offset: [offsetX, offsetY]
169
+ });
170
+ };
171
+
172
+ // resize 防抖
173
+ var _useDebounceFn = useDebounceFn(function (e) {
174
+ if (!alignRef.current.timeStamp && visible) {
175
+ // 防抖开始、关闭已打开的弹出框
176
+ alignRef.current.timeStamp = e.timeStamp;
177
+ setVisible(false);
178
+ } else {
179
+ // 防抖结束
180
+ getAlignMode();
181
+ update();
182
+ alignRef.current.timeStamp = undefined;
183
+ }
184
+ }, {
185
+ wait: 500,
186
+ leading: true
187
+ }),
188
+ run = _useDebounceFn.run;
189
+ var onChangeLabel = function onChangeLabel(text) {
190
+ inputRef.current = text;
191
+ update();
192
+ };
193
+
194
+ // 监听窗口变化
195
+ useEventListener('resize', run, {
196
+ target: window
197
+ });
198
+ var _useState5 = useState(zIndex),
199
+ _useState6 = _slicedToArray(_useState5, 1),
200
+ triggerIndex = _useState6[0];
201
+ useEffect(function () {
202
+ setTimeout(function () {
203
+ getAlignMode();
204
+ }, 10);
205
+ zIndex += 1;
206
+ }, []);
207
+ var _alignRef$current$siz = alignRef.current.size,
208
+ ppWidth = _alignRef$current$siz.width,
209
+ ppHeight = _alignRef$current$siz.height;
210
+ var _alignRef$current$max = alignRef.current.maxSize,
211
+ maxWidth = _alignRef$current$max.width,
212
+ maxHeight = _alignRef$current$max.height;
213
+
214
+ // 如果有初始值则渲染子组件
215
+ var isForceRender = useMemo(function () {
216
+ if (forceRender) return true;
217
+ return !!value;
218
+ }, []);
219
+ return /*#__PURE__*/React.createElement(ConfigProvider, {
220
+ locale: zhCN
221
+ }, /*#__PURE__*/React.createElement(Trigger, {
222
+ mask: true,
223
+ action: ['click'],
224
+ forceRender: isForceRender,
225
+ prefixCls: classPrefix,
226
+ popup: /*#__PURE__*/React.createElement("div", {
227
+ className: "".concat(classPrefix, "-container"),
228
+ ref: containerRef,
229
+ style: {
230
+ width: ppWidth || 'auto',
231
+ minWidth: (_ref$current2 = ref.current) === null || _ref$current2 === void 0 ? void 0 : _ref$current2.clientWidth,
232
+ maxHeight: ppHeight || maxHeight,
233
+ maxWidth: maxWidth
234
+ }
235
+ }, children && /*#__PURE__*/cloneElement(children, _objectSpread({
236
+ value: value,
237
+ onChange: onChange,
238
+ onChangeLabel: onChangeLabel,
239
+ onVisible: setVisible,
240
+ onLoading: setLoading,
241
+ width: ppWidth,
242
+ height: ppHeight
243
+ }, restProps))),
244
+ popupVisible: visible,
245
+ onPopupVisibleChange: function onPopupVisibleChange(e) {
246
+ if (!disabled) setVisible(e);
247
+ },
248
+ showAction: ['click'],
249
+ hideAction: ['click'],
250
+ popupAlign: alignRef.current,
251
+ popupStyle: {
252
+ position: 'absolute'
253
+ },
254
+ getPopupContainer: popupContainer ? function () {
255
+ return ref.current;
256
+ } : undefined,
257
+ zIndex: triggerIndex
258
+ }, /*#__PURE__*/React.createElement("div", {
259
+ ref: ref,
260
+ className: className,
261
+ style: style,
262
+ onMouseEnter: onMouseEnter,
263
+ onMouseLeave: onMouseLeave
264
+ }, /*#__PURE__*/React.createElement(Spin, {
265
+ spinning: loading
266
+ }, /*#__PURE__*/React.createElement(Input, {
267
+ readOnly: true,
268
+ disabled: disabled,
269
+ value: inputRef.current,
270
+ placeholder: placeholder || '请选择',
271
+ size: size || 'middle',
272
+ suffix: !disabled ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(CloseCircleFilled, {
273
+ ref: closeRef,
274
+ onClick: function onClick() {
275
+ if (onChange) {
276
+ onChange(undefined);
277
+ onChangeLabel(undefined);
278
+ onMouseLeave();
279
+ }
280
+ },
281
+ className: "".concat(classPrefix, "-icon ").concat(classPrefix, "-hidden")
282
+ }), /*#__PURE__*/React.createElement(DownOutlined, {
283
+ className: "".concat(classPrefix, "-icon ").concat(classPrefix, "-show"),
284
+ ref: downRef
285
+ })) : null
286
+ })))));
287
+ };
288
+ export default TriggerComponent;
@@ -0,0 +1,42 @@
1
+ // ccs trigger
2
+ .ccs-trigger {
3
+ &-hidden {
4
+ display: none !important;
5
+ }
6
+
7
+ &-show {
8
+ display: block !important;
9
+ }
10
+
11
+ &-icon {
12
+ color: rgb(0 0 0 / 25%) !important;
13
+ font-size: 12px;
14
+ }
15
+
16
+ &-container {
17
+ overflow: auto;
18
+ background: #fff;
19
+ border-radius: 2px;
20
+ box-shadow: 0 3px 6px -4px rgb(0 0 0 / 12%), 0 6px 16px 0 rgb(0 0 0 / 8%),
21
+ 0 9px 28px 8px rgb(0 0 0 / 5%);
22
+ transition: margin 0.3s;
23
+ }
24
+
25
+ &-mask {
26
+ position: fixed;
27
+ top: 0;
28
+ right: 0;
29
+ bottom: 0;
30
+ left: 0;
31
+ height: 100%;
32
+ opacity: 1;
33
+
34
+ &-hidden {
35
+ display: none;
36
+ }
37
+ }
38
+ }
39
+
40
+ .rc-trigger-popup-hidden {
41
+ display: none;
42
+ }
package/es/types.js ADDED
File without changes
package/es/utils.js ADDED
@@ -0,0 +1,205 @@
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
4
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
5
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
7
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
8
+ /* eslint-disable @typescript-eslint/ban-types */
9
+ import { message, Modal } from 'antd';
10
+ import _dayjs from 'dayjs';
11
+ import zhCn from 'dayjs/locale/zh-cn';
12
+ import relativeTime from 'dayjs/plugin/relativeTime';
13
+ import { Base64 } from 'js-base64';
14
+ import localForage from 'localforage';
15
+ import _empty from 'lodash/isEmpty';
16
+ import devWarning from 'rc-util/lib/warning';
17
+ var confirm = Modal.confirm;
18
+ _dayjs.locale(zhCn);
19
+ _dayjs.extend(relativeTime);
20
+ var utils = /*#__PURE__*/function () {
21
+ function utils() {
22
+ _classCallCheck(this, utils);
23
+ }
24
+ _createClass(utils, null, [{
25
+ key: "isFunction",
26
+ value: function isFunction(obj) {
27
+ return typeof obj === 'function';
28
+ }
29
+ }, {
30
+ key: "getStroage",
31
+ value: function getStroage(key) {
32
+ return localForage.getItem(key);
33
+ }
34
+ }, {
35
+ key: "setStroage",
36
+ value: function setStroage(key, value) {
37
+ return localForage.setItem(key, value);
38
+ }
39
+ }, {
40
+ key: "removeStroage",
41
+ value: function removeStroage(key) {
42
+ return localForage.removeItem(key);
43
+ }
44
+ }, {
45
+ key: "showLogWarning",
46
+ value: function showLogWarning(message) {
47
+ if (process.env.NODE_ENV === 'development') {
48
+ console.log("%c ".concat(message), 'color:#ff5722');
49
+ }
50
+ }
51
+ }, {
52
+ key: "showWarning",
53
+ value: function showWarning(valid, message) {
54
+ devWarning(valid, message);
55
+ }
56
+ }, {
57
+ key: "isBrowser",
58
+ value: function isBrowser() {
59
+ if (process.env.NODE_ENV === 'TEST') {
60
+ return true;
61
+ }
62
+ return typeof window !== 'undefined' && typeof window.document !== 'undefined' && !this.isNode;
63
+ }
64
+ }, {
65
+ key: "dayjs",
66
+ value: function dayjs(date) {
67
+ return _dayjs(date);
68
+ }
69
+
70
+ /**
71
+ * 空判断
72
+ * @param val
73
+ * @returns
74
+ */
75
+ }, {
76
+ key: "jsonToBase64",
77
+ value:
78
+ /**
79
+ * json转base64
80
+ * @param value
81
+ * @returns
82
+ */
83
+ function jsonToBase64(value) {
84
+ try {
85
+ var str = JSON.stringify(value);
86
+ return Base64.encode(str);
87
+ } catch (error) {
88
+ return '';
89
+ }
90
+ }
91
+
92
+ /**
93
+ * base64转json
94
+ * @param value
95
+ * @returns
96
+ */
97
+ }, {
98
+ key: "base64ToJson",
99
+ value: function base64ToJson(value) {
100
+ try {
101
+ var str = Base64.decode(value);
102
+ return JSON.parse(str);
103
+ } catch (error) {
104
+ return null;
105
+ }
106
+ }
107
+
108
+ /**
109
+ * JSON.parse
110
+ * @param value
111
+ * @returns
112
+ */
113
+ }, {
114
+ key: "jsonParse",
115
+ value: function jsonParse(value) {
116
+ try {
117
+ return JSON.parse(value);
118
+ } catch (error) {
119
+ return value;
120
+ }
121
+ }
122
+
123
+ /**
124
+ * string to HEX
125
+ * @param {*} str
126
+ */
127
+ }, {
128
+ key: "stringToHex",
129
+ value: function stringToHex(str) {
130
+ if (str === '') return '';
131
+ var hexCharCode = [];
132
+ for (var i = 0; i < str.length; i += 1) {
133
+ hexCharCode.push(str.charCodeAt(i).toString(16));
134
+ }
135
+ return hexCharCode.join('').toUpperCase();
136
+ }
137
+
138
+ /**
139
+ * http result msg
140
+ * @param result
141
+ * @param successText
142
+ * @param failText
143
+ */
144
+ }, {
145
+ key: "messageInfo",
146
+ value: function messageInfo(result, successText, failText) {
147
+ if (result.success) {
148
+ message.success(successText || '操作成功');
149
+ } else {
150
+ message.error(failText || result.msg || '操作失败');
151
+ }
152
+ }
153
+
154
+ /**
155
+ * string to dayjs
156
+ * @param val
157
+ * @param formartType // YYYY-MM-DD HH:mm:ss https://dayjs.fenxianglu.cn/category/display.html#%E6%A0%BC%E5%BC%8F%E5%8C%96
158
+ * @returns
159
+ */
160
+ }, {
161
+ key: "dayjsFmt",
162
+ value: function dayjsFmt(val, formartType) {
163
+ if (!val) return undefined;
164
+ if (formartType) {
165
+ _dayjs(val).format(formartType);
166
+ }
167
+ return _dayjs(val);
168
+ }
169
+
170
+ /**
171
+ * 确认提示框
172
+ * @param title
173
+ * @param content
174
+ * @returns
175
+ */
176
+ }]);
177
+ return utils;
178
+ }();
179
+ _defineProperty(utils, "isNode", typeof process !== 'undefined' && process.versions !== null && process.versions.node !== null);
180
+ _defineProperty(utils, "isEmpty", function (val) {
181
+ return _empty(val);
182
+ });
183
+ _defineProperty(utils, "isNotEmpty", function (val) {
184
+ return !utils.isEmpty(val);
185
+ });
186
+ _defineProperty(utils, "showConfirm", function (title) {
187
+ var content = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
188
+ return new Promise(function (resolve) {
189
+ confirm({
190
+ title: title,
191
+ content: content,
192
+ okText: '确定',
193
+ okType: 'danger',
194
+ cancelText: '取消',
195
+ centered: true,
196
+ onOk: function onOk() {
197
+ resolve(true);
198
+ },
199
+ onCancel: function onCancel() {
200
+ resolve(false);
201
+ }
202
+ });
203
+ });
204
+ });
205
+ export { utils as default };
@@ -0,0 +1,125 @@
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
3
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
6
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
7
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
8
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
9
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
10
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
11
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
12
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
13
+ import { useScroll } from 'ahooks';
14
+ import React, { useEffect, useImperativeHandle, useRef, useState } from 'react';
15
+ import { Scrollbars } from 'react-custom-scrollbars';
16
+ function getArrayIdsNew(start, end) {
17
+ var ids = [];
18
+ for (var i = start; i <= end; i += 1) {
19
+ ids.push(i);
20
+ }
21
+ return ids;
22
+ }
23
+ var VirtualListItem = function VirtualListItem(_ref) {
24
+ var rowHeight = _ref.rowHeight,
25
+ rowRenderer = _ref.rowRenderer,
26
+ index = _ref.index;
27
+ return /*#__PURE__*/React.createElement("div", {
28
+ style: {
29
+ height: rowHeight,
30
+ position: 'absolute',
31
+ top: index * rowHeight,
32
+ width: '100%'
33
+ }
34
+ }, rowRenderer({
35
+ rowHeight: rowHeight,
36
+ index: index
37
+ }));
38
+ };
39
+ var VirtualList = function VirtualList(_ref2) {
40
+ var height = _ref2.height,
41
+ rowCount = _ref2.rowCount,
42
+ rowHeight = _ref2.rowHeight,
43
+ className = _ref2.className,
44
+ _ref2$style = _ref2.style,
45
+ style = _ref2$style === void 0 ? {} : _ref2$style,
46
+ virtualRef = _ref2.virtualRef,
47
+ onScroll = _ref2.onScroll,
48
+ rowRenderer = _ref2.rowRenderer,
49
+ autoHideScroll = _ref2.autoHideScroll,
50
+ overscanRowCount = _ref2.overscanRowCount,
51
+ rowCountChangeScrollTop = _ref2.rowCountChangeScrollTop;
52
+ // 渲染区间
53
+ var _useState = useState([0, overscanRowCount - 1]),
54
+ _useState2 = _slicedToArray(_useState, 2),
55
+ ids = _useState2[0],
56
+ setIds = _useState2[1];
57
+ var ref = useRef(null);
58
+ useImperativeHandle(virtualRef, function () {
59
+ return {
60
+ scrollTop: function scrollTop(top) {
61
+ if (ref.current) ref.current.scrollTop = top;
62
+ }
63
+ };
64
+ });
65
+ useScroll(ref, function (position) {
66
+ var top = position.top;
67
+ var addRowNumber = overscanRowCount - 1;
68
+ var start = Math.trunc((top < 0 ? 0 : top) / rowHeight);
69
+ var end = start + addRowNumber;
70
+ if (ids[0] !== start && ids[1] !== end) {
71
+ setIds([start, end]);
72
+ }
73
+ if (onScroll) {
74
+ onScroll(position);
75
+ }
76
+ return false;
77
+ });
78
+ var onScrollUpdate = function onScrollUpdate(position) {
79
+ var scrollTop = position.scrollTop;
80
+ var addRowNumber = overscanRowCount - 1;
81
+ var start = Math.trunc((scrollTop < 0 ? 0 : scrollTop) / rowHeight);
82
+ var end = start + addRowNumber;
83
+ if (ids[0] !== start && ids[1] !== end) {
84
+ setIds([start, end]);
85
+ }
86
+ if (onScroll) {
87
+ onScroll(position);
88
+ }
89
+ };
90
+ useEffect(function () {
91
+ if (rowCount > 0 && rowCountChangeScrollTop && ref.current) {
92
+ ref.current.scrollTo({
93
+ top: 0,
94
+ behavior: 'smooth'
95
+ });
96
+ }
97
+ }, [rowCount]);
98
+ return rowCount === 0 ? /*#__PURE__*/React.createElement(React.Fragment, null) : /*#__PURE__*/React.createElement("div", {
99
+ className: className,
100
+ style: _objectSpread({
101
+ height: height || '100%'
102
+ }, style),
103
+ ref: ref
104
+ }, /*#__PURE__*/React.createElement(Scrollbars, {
105
+ autoHide: autoHideScroll !== false,
106
+ onUpdate: onScrollUpdate,
107
+ style: {
108
+ flex: '1 1 auto'
109
+ }
110
+ }, /*#__PURE__*/React.createElement("div", {
111
+ style: {
112
+ position: 'relative',
113
+ height: rowHeight * rowCount,
114
+ overflow: 'hidden'
115
+ }
116
+ }, getArrayIdsNew(ids[0], ids[1] >= rowCount ? rowCount - 1 : ids[1]).map(function (i) {
117
+ return /*#__PURE__*/React.createElement(VirtualListItem, {
118
+ rowHeight: rowHeight,
119
+ rowRenderer: rowRenderer,
120
+ key: i,
121
+ index: i
122
+ });
123
+ }))));
124
+ };
125
+ export default VirtualList;