@ccs-ui/rc-pro 1.0.6 → 1.0.7-rc.10

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.
@@ -23,8 +23,7 @@ import React, { useEffect } from 'react';
23
23
  export default function CcsApiCascader(_ref) {
24
24
  var onQuery = _ref.onQuery,
25
25
  cache = _ref.cache,
26
- _ref$defaultParams = _ref.defaultParams,
27
- defaultParams = _ref$defaultParams === void 0 ? {} : _ref$defaultParams,
26
+ defaultParams = _ref.defaultParams,
28
27
  restProps = _objectWithoutProperties(_ref, _excluded);
29
28
  var _useRequest = useRequest( /*#__PURE__*/function () {
30
29
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(params) {
@@ -61,7 +60,7 @@ export default function CcsApiCascader(_ref) {
61
60
  run = _useRequest.run;
62
61
  useEffect(function () {
63
62
  if (onQuery) run(defaultParams);
64
- }, []);
63
+ }, [defaultParams]);
65
64
  return /*#__PURE__*/React.createElement(Cascader, _extends({
66
65
  options: data,
67
66
  loading: loading,
@@ -16,6 +16,6 @@ type CcsRangePickerProps = {
16
16
  } & Omit<RangePickerProps, 'value' | 'onChange'>;
17
17
  declare function CcsDatePicker({ value, onChange, ...restProps }: CcsDatePickerProps): React.JSX.Element;
18
18
  declare namespace CcsDatePicker {
19
- var RangPicker: ({ value, onChange, ...restProps }: CcsRangePickerProps) => React.JSX.Element;
19
+ var RangePicker: ({ value, onChange, ...restProps }: CcsRangePickerProps) => React.JSX.Element;
20
20
  }
21
21
  export default CcsDatePicker;
@@ -34,7 +34,7 @@ function CcsDatePicker(_ref) {
34
34
  onChange: handleOnChange
35
35
  }, restProps));
36
36
  }
37
- function RangPicker(_ref2) {
37
+ function RangePicker(_ref2) {
38
38
  var value = _ref2.value,
39
39
  onChange = _ref2.onChange,
40
40
  restProps = _objectWithoutProperties(_ref2, _excluded2);
@@ -55,5 +55,5 @@ function RangPicker(_ref2) {
55
55
  onChange: handleOnChange
56
56
  }, restProps));
57
57
  }
58
- CcsDatePicker.RangPicker = RangPicker;
58
+ CcsDatePicker.RangePicker = RangePicker;
59
59
  export default CcsDatePicker;
package/es/index.d.ts CHANGED
@@ -149,9 +149,11 @@ export { default as CcsProGrid } from './pro-grid';
149
149
  export { default as CcsProTable } from './pro-table';
150
150
  export { default as CcsProTabs } from './pro-tabs';
151
151
  export { default as CcsApiSelect } from './select';
152
+ export { default as CcsStatusTag } from './status-tag';
152
153
  export { default as CcsTable } from './table';
153
154
  export { default as CcsTimePicker } from './time-picker';
154
155
  export { default as CcsTrigger } from './trigger';
156
+ export { default as CcsUpload } from './upload';
155
157
  export { default as CcsUtils } from './utils';
156
158
  export { default as CcsVirtualList } from './virtual-list';
157
159
  export { default as CcsWaterMark } from './water-mark';
package/es/index.js CHANGED
@@ -21,9 +21,11 @@ export { default as CcsProGrid } from "./pro-grid";
21
21
  export { default as CcsProTable } from "./pro-table";
22
22
  export { default as CcsProTabs } from "./pro-tabs";
23
23
  export { default as CcsApiSelect } from "./select";
24
+ export { default as CcsStatusTag } from "./status-tag";
24
25
  export { default as CcsTable } from "./table";
25
26
  export { default as CcsTimePicker } from "./time-picker";
26
27
  export { default as CcsTrigger } from "./trigger";
28
+ export { default as CcsUpload } from "./upload";
27
29
  export { default as CcsUtils } from "./utils";
28
30
  export { default as CcsVirtualList } from "./virtual-list";
29
31
  export { default as CcsWaterMark } from "./water-mark";
@@ -107,7 +107,7 @@ function IntervalButton(_ref) {
107
107
  type: "primary"
108
108
  }, restProps, {
109
109
  onClick: onStart,
110
- disabled: disabled
110
+ disabled: restProps.disabled ? true : disabled
111
111
  }), disabled ? "".concat(count, "\u79D2").concat(disabledText) : "".concat(children));
112
112
  }
113
113
  export default IntervalButton;
@@ -23,8 +23,7 @@ import React, { useEffect } from 'react';
23
23
  export default function CcsApiSelect(_ref) {
24
24
  var onQuery = _ref.onQuery,
25
25
  cache = _ref.cache,
26
- _ref$defaultParams = _ref.defaultParams,
27
- defaultParams = _ref$defaultParams === void 0 ? {} : _ref$defaultParams,
26
+ defaultParams = _ref.defaultParams,
28
27
  restProps = _objectWithoutProperties(_ref, _excluded);
29
28
  var _useRequest = useRequest( /*#__PURE__*/function () {
30
29
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(params) {
@@ -61,7 +60,7 @@ export default function CcsApiSelect(_ref) {
61
60
  run = _useRequest.run;
62
61
  useEffect(function () {
63
62
  if (onQuery) run(defaultParams);
64
- }, []);
63
+ }, [defaultParams]);
65
64
  return /*#__PURE__*/React.createElement(Select, _extends({
66
65
  options: data,
67
66
  loading: loading,
@@ -0,0 +1,9 @@
1
+ export interface CcsStatusTagProps {
2
+ value: any;
3
+ options: {
4
+ value: any;
5
+ label: string;
6
+ tag: string[];
7
+ }[];
8
+ }
9
+ export default function CcsStatusTag({ value, options, }: CcsStatusTagProps): any;
@@ -0,0 +1,26 @@
1
+ import { Badge, Tag } from 'antd';
2
+ import React from 'react';
3
+ export default function CcsStatusTag(_ref) {
4
+ var value = _ref.value,
5
+ _ref$options = _ref.options,
6
+ options = _ref$options === void 0 ? [] : _ref$options;
7
+ if (value === undefined || value === '') return value;
8
+ var option = options.find(function (op) {
9
+ return op.value === value;
10
+ });
11
+ if (!option) return value;
12
+ var label = option.label,
13
+ tag = option.tag;
14
+ if (tag && tag[0] === 'tag') {
15
+ return /*#__PURE__*/React.createElement(Tag, {
16
+ color: tag[1]
17
+ }, label);
18
+ }
19
+ if (tag && tag[0] === 'badge') {
20
+ return /*#__PURE__*/React.createElement(Badge, {
21
+ status: tag[1],
22
+ text: label
23
+ });
24
+ }
25
+ return label;
26
+ }
@@ -12,6 +12,6 @@ type CcsRangePickerProps = {
12
12
  } & Omit<RangePickerTimeProps<Dayjs>, 'value' | 'onChange' | 'picker'>;
13
13
  declare function CcsDatePicker({ value, onChange, ...restProps }: CcsTimePickerProps): React.JSX.Element;
14
14
  declare namespace CcsDatePicker {
15
- var RangPicker: ({ value, onChange, ...restProps }: CcsRangePickerProps) => React.JSX.Element;
15
+ var RangePicker: ({ value, onChange, ...restProps }: CcsRangePickerProps) => React.JSX.Element;
16
16
  }
17
17
  export default CcsDatePicker;
@@ -36,7 +36,7 @@ function CcsDatePicker(_ref) {
36
36
  onChange: handleOnChange
37
37
  }, restProps));
38
38
  }
39
- function RangPicker(_ref2) {
39
+ function RangePicker(_ref2) {
40
40
  var value = _ref2.value,
41
41
  onChange = _ref2.onChange,
42
42
  restProps = _objectWithoutProperties(_ref2, _excluded2);
@@ -57,5 +57,5 @@ function RangPicker(_ref2) {
57
57
  onChange: handleOnChange
58
58
  }, restProps));
59
59
  }
60
- CcsDatePicker.RangPicker = RangPicker;
60
+ CcsDatePicker.RangePicker = RangePicker;
61
61
  export default CcsDatePicker;
@@ -0,0 +1,14 @@
1
+ import { UploadProps } from 'antd';
2
+ import React from 'react';
3
+ import { ImageUpload } from './upload-image';
4
+ export type CcsUploadProps = Pick<UploadProps, 'maxCount' | 'data' | 'multiple' | 'accept' | 'action' | 'name' | 'headers'> & {
5
+ tokenKey?: string;
6
+ maxFileSize?: number;
7
+ uploadText?: string;
8
+ onChange?: (value: any) => void;
9
+ };
10
+ declare function CcsUpload({ tokenKey, uploadText, maxCount, maxFileSize, onChange, ...otherProps }: CcsUploadProps): React.JSX.Element;
11
+ declare namespace CcsUpload {
12
+ var Image: typeof ImageUpload;
13
+ }
14
+ export default CcsUpload;
@@ -0,0 +1,72 @@
1
+ var _excluded = ["tokenKey", "uploadText", "maxCount", "maxFileSize", "onChange"];
2
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
3
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
4
+ 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."); }
5
+ 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); }
6
+ 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; }
7
+ 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; } }
8
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
9
+ 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; }
10
+ 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; }
11
+ import { UploadOutlined } from '@ant-design/icons';
12
+ import { Button, Upload, message } from 'antd';
13
+ import React, { useState } from 'react';
14
+ import { ImageUpload } from "./upload-image";
15
+ function CcsUpload(_ref) {
16
+ var tokenKey = _ref.tokenKey,
17
+ uploadText = _ref.uploadText,
18
+ _ref$maxCount = _ref.maxCount,
19
+ maxCount = _ref$maxCount === void 0 ? 1 : _ref$maxCount,
20
+ _ref$maxFileSize = _ref.maxFileSize,
21
+ maxFileSize = _ref$maxFileSize === void 0 ? 10 : _ref$maxFileSize,
22
+ onChange = _ref.onChange,
23
+ otherProps = _objectWithoutProperties(_ref, _excluded);
24
+ var _useState = useState([]),
25
+ _useState2 = _slicedToArray(_useState, 2),
26
+ files = _useState2[0],
27
+ setFiles = _useState2[1];
28
+ var handleOnChange = function handleOnChange(_ref2) {
29
+ var fileList = _ref2.fileList;
30
+ setFiles(fileList);
31
+ if (!onChange) return;
32
+ if (maxFileSize === 1) {
33
+ var _fileList$, _fileList$$response;
34
+ // 只能上传一个文件
35
+ onChange((_fileList$ = fileList[0]) === null || _fileList$ === void 0 ? void 0 : (_fileList$$response = _fileList$.response) === null || _fileList$$response === void 0 ? void 0 : _fileList$$response.data);
36
+ } else {
37
+ // 上传完成的文件,返回上传结果集
38
+ onChange(fileList.filter(function (f) {
39
+ return f.status === 'done';
40
+ }).map(function (f) {
41
+ var _f$response;
42
+ return (_f$response = f.response) === null || _f$response === void 0 ? void 0 : _f$response.data;
43
+ }));
44
+ }
45
+ };
46
+
47
+ // 上传大小检查
48
+ var beforeUpload = function beforeUpload(file) {
49
+ var isLt2M = file.size / 1024 / 1024 < maxFileSize;
50
+ if (!isLt2M) {
51
+ message.error("\u6587\u4EF6\u4E0D\u80FD\u5927\u4E8E".concat(maxFileSize, "MB!"));
52
+ }
53
+ return isLt2M;
54
+ };
55
+ var uploadProps = {
56
+ name: 'fileName',
57
+ headers: {
58
+ token: tokenKey ? sessionStorage.getItem(tokenKey) : ''
59
+ }
60
+ };
61
+ return /*#__PURE__*/React.createElement(Upload, _extends({}, uploadProps, {
62
+ onChange: handleOnChange,
63
+ beforeUpload: beforeUpload,
64
+ fileList: files,
65
+ maxCount: maxCount
66
+ }, otherProps), /*#__PURE__*/React.createElement(Button, {
67
+ icon: /*#__PURE__*/React.createElement(UploadOutlined, null),
68
+ disabled: files.length >= maxCount
69
+ }, uploadText));
70
+ }
71
+ CcsUpload.Image = ImageUpload;
72
+ export default CcsUpload;
@@ -0,0 +1,8 @@
1
+ import React from 'react';
2
+ import { CcsUploadProps } from './index';
3
+ type CcsImageUploadProps = CcsUploadProps & {
4
+ crop?: boolean;
5
+ tokenKey?: string;
6
+ };
7
+ export declare function ImageUpload({ crop, tokenKey, uploadText, maxCount, maxFileSize, onChange, ...otherProps }: CcsImageUploadProps): React.JSX.Element;
8
+ export {};
@@ -0,0 +1,132 @@
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 = ["crop", "tokenKey", "uploadText", "maxCount", "maxFileSize", "onChange"];
3
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
4
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
5
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
6
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
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
+ 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; }
14
+ 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; }
15
+ import { PlusOutlined } from '@ant-design/icons';
16
+ import { CcsModal } from "./..";
17
+ import { Upload, message } from 'antd';
18
+ import ImgCrop from 'antd-img-crop';
19
+ import React, { useState } from 'react';
20
+ var getBase64 = function getBase64(file) {
21
+ return new Promise(function (resolve, reject) {
22
+ var reader = new FileReader();
23
+ reader.readAsDataURL(file);
24
+ reader.onload = function () {
25
+ return resolve(reader.result);
26
+ };
27
+ reader.onerror = function (error) {
28
+ return reject(error);
29
+ };
30
+ });
31
+ };
32
+ export function ImageUpload(_ref) {
33
+ var crop = _ref.crop,
34
+ tokenKey = _ref.tokenKey,
35
+ uploadText = _ref.uploadText,
36
+ _ref$maxCount = _ref.maxCount,
37
+ maxCount = _ref$maxCount === void 0 ? 1 : _ref$maxCount,
38
+ _ref$maxFileSize = _ref.maxFileSize,
39
+ maxFileSize = _ref$maxFileSize === void 0 ? 10 : _ref$maxFileSize,
40
+ onChange = _ref.onChange,
41
+ otherProps = _objectWithoutProperties(_ref, _excluded);
42
+ var _useState = useState([]),
43
+ _useState2 = _slicedToArray(_useState, 2),
44
+ files = _useState2[0],
45
+ setFiles = _useState2[1];
46
+ var handleOnChange = function handleOnChange(_ref2) {
47
+ var fileList = _ref2.fileList;
48
+ setFiles(fileList.filter(function (f) {
49
+ return f.status;
50
+ }));
51
+ if (!onChange) return;
52
+ if (maxCount === 1) {
53
+ var _fileList$, _fileList$$response;
54
+ // 只能上传一个文件
55
+ onChange((_fileList$ = fileList[0]) === null || _fileList$ === void 0 ? void 0 : (_fileList$$response = _fileList$.response) === null || _fileList$$response === void 0 ? void 0 : _fileList$$response.data);
56
+ } else {
57
+ // 上传完成的文件,返回上传结果集
58
+ onChange(fileList.filter(function (f) {
59
+ return f.status === 'done';
60
+ }).map(function (f) {
61
+ var _f$response;
62
+ return (_f$response = f.response) === null || _f$response === void 0 ? void 0 : _f$response.data;
63
+ }));
64
+ }
65
+ };
66
+
67
+ // 上传大小检查
68
+ var beforeUpload = function beforeUpload(file) {
69
+ var isLt2M = file.size / 1024 / 1024 < maxFileSize;
70
+ if (!isLt2M) {
71
+ message.error("\u56FE\u7247\u4E0D\u80FD\u5927\u4E8E".concat(maxFileSize, "MB!"));
72
+ }
73
+ return isLt2M;
74
+ };
75
+ var handlePreview = /*#__PURE__*/function () {
76
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(file) {
77
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
78
+ while (1) switch (_context.prev = _context.next) {
79
+ case 0:
80
+ if (file.preview) {
81
+ _context.next = 4;
82
+ break;
83
+ }
84
+ _context.next = 3;
85
+ return getBase64(file.originFileObj);
86
+ case 3:
87
+ file.preview = _context.sent;
88
+ case 4:
89
+ CcsModal.open({
90
+ title: file.name || file.url.substring(file.url.lastIndexOf('/') + 1),
91
+ content: /*#__PURE__*/React.createElement("img", {
92
+ alt: "example",
93
+ style: {
94
+ width: '100%'
95
+ },
96
+ src: file.preview
97
+ }),
98
+ footer: null
99
+ });
100
+ case 5:
101
+ case "end":
102
+ return _context.stop();
103
+ }
104
+ }, _callee);
105
+ }));
106
+ return function handlePreview(_x2) {
107
+ return _ref3.apply(this, arguments);
108
+ };
109
+ }();
110
+ var uploadProps = {
111
+ name: 'fileName',
112
+ headers: {
113
+ token: tokenKey ? sessionStorage.getItem(tokenKey) : ''
114
+ }
115
+ };
116
+ var renderUpload = /*#__PURE__*/React.createElement(Upload, _extends({}, uploadProps, {
117
+ onChange: handleOnChange,
118
+ beforeUpload: beforeUpload,
119
+ fileList: files,
120
+ maxCount: maxCount,
121
+ listType: "picture-card",
122
+ onPreview: handlePreview
123
+ }, otherProps), files.length < maxCount && /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(PlusOutlined, null), /*#__PURE__*/React.createElement("div", {
124
+ style: {
125
+ marginTop: 8
126
+ }
127
+ }, uploadText)));
128
+ return crop ? /*#__PURE__*/React.createElement(ImgCrop, {
129
+ minZoom: 0.5,
130
+ rotationSlider: true
131
+ }, renderUpload) : renderUpload;
132
+ }
@@ -104,5 +104,17 @@ export default class utils {
104
104
  * @returns
105
105
  */
106
106
  static showConfirm: (title: string, content?: string) => Promise<unknown>;
107
+ /**
108
+ * 空对象?
109
+ * @param obj
110
+ * @returns
111
+ */
112
+ static objIsEmpty(obj: any): boolean;
113
+ /**
114
+ * 判断值不为空
115
+ * @param str string,object,array
116
+ * @returns
117
+ */
118
+ static isNil(str: any): boolean;
107
119
  }
108
120
  export {};
package/es/utils/index.js CHANGED
@@ -11,7 +11,9 @@ import zhCn from 'dayjs/locale/zh-cn';
11
11
  import relativeTime from 'dayjs/plugin/relativeTime';
12
12
  import { Base64 } from 'js-base64';
13
13
  import localForage from 'localforage';
14
+ import _isArray from 'lodash/isArray';
14
15
  import _empty from 'lodash/isEmpty';
16
+ import _isObject from 'lodash/isObject';
15
17
  import devWarning from 'rc-util/lib/warning';
16
18
  var confirm = Modal.confirm;
17
19
  _dayjs.locale(zhCn);
@@ -212,6 +214,38 @@ var utils = /*#__PURE__*/function () {
212
214
  * @param content
213
215
  * @returns
214
216
  */
217
+ }, {
218
+ key: "objIsEmpty",
219
+ value:
220
+ /**
221
+ * 空对象?
222
+ * @param obj
223
+ * @returns
224
+ */
225
+ function objIsEmpty(obj) {
226
+ if (!obj) return true;
227
+ return Object.keys(obj).length === 0;
228
+ }
229
+
230
+ /**
231
+ * 判断值不为空
232
+ * @param str string,object,array
233
+ * @returns
234
+ */
235
+ }, {
236
+ key: "isNil",
237
+ value: function isNil(str) {
238
+ if (typeof str === 'string') {
239
+ return str.trim() === '';
240
+ }
241
+ if (_isArray(str)) {
242
+ return str.length === 0;
243
+ }
244
+ if (_isObject(str)) {
245
+ return Object.keys(str).length === 0;
246
+ }
247
+ return str === undefined || str === null;
248
+ }
215
249
  }]);
216
250
  return utils;
217
251
  }();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ccs-ui/rc-pro",
3
- "version": "1.0.6",
3
+ "version": "1.0.7-rc.10",
4
4
  "description": "A react library developed with dumi",
5
5
  "license": "MIT",
6
6
  "module": "es/index.js",
@@ -19,8 +19,8 @@
19
19
  "lint:es": "eslint \"{src,test}/**/*.{js,jsx,ts,tsx}\"",
20
20
  "prepare": "husky install && dumi setup",
21
21
  "prepublishOnly": "father doctor && npm run build",
22
- "publish-beta": "father build && npm publish --tag=beta && cnpm sync@ccs-ui/rc-pro",
23
- "publish-prod": "father build && npm publish && cnpm sync @ccs-ui/rc-pro",
22
+ "publish:beta": "father build && npm publish --tag=beta && cnpm sync @ccs-ui/rc-pro",
23
+ "publish:prod": "father build && npm publish && cnpm sync @ccs-ui/rc-pro",
24
24
  "start": "npm run dev",
25
25
  "sync": "cnpm sync @ccs-ui/rc-pro"
26
26
  },
@@ -50,6 +50,7 @@
50
50
  "@ant-design/icons": "^5.1.4",
51
51
  "ahooks": "^3.7.7",
52
52
  "antd": "^5.5.2",
53
+ "antd-img-crop": "^4.12.2",
53
54
  "classnames": "^2.3.2",
54
55
  "dayjs": "^1.11.7",
55
56
  "js-base64": "^3.7.5",