@ccs-ui/rc-pro 2.2.4-beta-1 → 2.2.4-beta-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.
@@ -1,16 +1,3 @@
1
- import { RGBColor } from 'react-color';
2
- import { PropsWithCss } from '../ccs';
1
+ import { ColorPickerProps } from 'antd';
3
2
  import './index.less';
4
- export type PropsType = PropsWithCss & {
5
- /** 指定选中项 */
6
- value?: RGBColor;
7
- /** 占位 */
8
- placeholder?: string;
9
- /** 选择完成后的回调 */
10
- onChange?: (value: RGBColor) => void;
11
- };
12
- /**
13
- * 颜色选择组件
14
- */
15
- declare const ColorPicker: ({ onChange, value, style }: PropsType) => import("react/jsx-runtime").JSX.Element;
16
- export default ColorPicker;
3
+ export default function CcsColorPicker({ mode, children, onChange, ...otherProps }: ColorPickerProps): import("react/jsx-runtime").JSX.Element;
@@ -1,67 +1,122 @@
1
1
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ var _excluded = ["mode", "children", "onChange"];
2
3
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
4
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
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; }
5
6
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
7
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
8
+ 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; }
9
+ 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; }
7
10
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
8
11
  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
12
  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
13
  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
14
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
12
15
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
13
- /* eslint-disable @typescript-eslint/ban-types */
14
- import { Popover } from 'antd';
15
- import { useState } from 'react';
16
- import { SketchPicker } from 'react-color';
16
+ import { blue, cyan, gray, green, magenta, orange, presetPalettes, red } from '@ant-design/colors';
17
+ import { Col, ColorPicker, Divider, Row, Select } from 'antd';
17
18
  import "./index.less";
18
19
  import { jsx as _jsx } from "react/jsx-runtime";
19
- /**
20
- * 颜色选择组件
21
- */
22
- var ColorPicker = function ColorPicker(_ref) {
23
- var onChange = _ref.onChange,
24
- value = _ref.value,
25
- style = _ref.style;
26
- var _useState = useState(false),
27
- _useState2 = _slicedToArray(_useState, 2),
28
- open = _useState2[0],
29
- setOpen = _useState2[1];
30
- var handleChange = function handleChange(e) {
31
- if (onChange) onChange(e.rgb);
32
- setOpen(false);
20
+ import { jsxs as _jsxs } from "react/jsx-runtime";
21
+ import { Fragment as _Fragment } from "react/jsx-runtime";
22
+ function genPresets() {
23
+ var presets = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : presetPalettes;
24
+ return Object.entries(presets).map(function (_ref) {
25
+ var _ref2 = _slicedToArray(_ref, 2),
26
+ label = _ref2[0],
27
+ colors = _ref2[1];
28
+ return {
29
+ label: label,
30
+ colors: colors,
31
+ key: label
32
+ };
33
+ });
34
+ }
35
+ var presets = genPresets({
36
+ blue: blue,
37
+ red: red,
38
+ green: green,
39
+ cyan: cyan,
40
+ orange: orange,
41
+ magenta: magenta,
42
+ gray: gray
43
+ });
44
+ presets.forEach(function (f) {
45
+ f.colors = f.colors.slice(0, 6);
46
+ });
47
+ export default function CcsColorPicker(_ref3) {
48
+ var _ref3$mode = _ref3.mode,
49
+ mode = _ref3$mode === void 0 ? 'single' : _ref3$mode,
50
+ children = _ref3.children,
51
+ _onChange = _ref3.onChange,
52
+ otherProps = _objectWithoutProperties(_ref3, _excluded);
53
+ var customPanelRender = function customPanelRender(_, _ref4) {
54
+ var _ref4$components = _ref4.components,
55
+ Picker = _ref4$components.Picker,
56
+ Presets = _ref4$components.Presets;
57
+ return /*#__PURE__*/_jsxs(Row, {
58
+ justify: "space-between",
59
+ wrap: false,
60
+ style: {
61
+ width: 360
62
+ },
63
+ children: [/*#__PURE__*/_jsx(Col, {
64
+ span: 12,
65
+ children: /*#__PURE__*/_jsx(Presets, {})
66
+ }), /*#__PURE__*/_jsx(Divider, {
67
+ type: "vertical",
68
+ style: {
69
+ height: 'auto'
70
+ }
71
+ }), /*#__PURE__*/_jsx(Col, {
72
+ flex: "auto",
73
+ children: /*#__PURE__*/_jsx(Picker, {})
74
+ })]
75
+ });
76
+ };
77
+ var renderValue = function renderValue() {
78
+ if (!otherProps.value) {
79
+ return /*#__PURE__*/_jsx(Select, {
80
+ popupClassName: "ccs-color-picker-select",
81
+ placeholder: "\u8BF7\u9009\u62E9",
82
+ dropdownRender: function dropdownRender() {
83
+ return /*#__PURE__*/_jsx(_Fragment, {});
84
+ }
85
+ });
86
+ }
87
+ return undefined;
33
88
  };
34
- return /*#__PURE__*/_jsx("div", {
35
- style: {
36
- position: 'relative'
89
+ return /*#__PURE__*/_jsx(ColorPicker, _objectSpread(_objectSpread({
90
+ className: "ccs-color-picker",
91
+ allowClear: true,
92
+ showText: true,
93
+ mode: mode,
94
+ onChange: function onChange(value, css) {
95
+ if (!_onChange) return;
96
+ var colors = value.getColors();
97
+
98
+ // 渐变色
99
+ if (colors.length > 1) {
100
+ var gradientColors = colors.map(function (c) {
101
+ return {
102
+ color: c.color.toRgbString(),
103
+ percent: c.percent
104
+ };
105
+ });
106
+ _onChange(gradientColors, css);
107
+ return;
108
+ }
109
+ if (colors.length === 1) {
110
+ _onChange(value.toCssString(), css);
111
+ return;
112
+ }
37
113
  },
38
- children: /*#__PURE__*/_jsx(Popover, {
39
- open: open,
40
- content: /*#__PURE__*/_jsx(SketchPicker, {
41
- color: value,
42
- onChange: handleChange
43
- }),
44
- children: /*#__PURE__*/_jsx("div", {
45
- style: _objectSpread({
46
- height: 32,
47
- padding: '4px 11px',
48
- border: '1px solid #d9d9d9',
49
- borderRadius: 3,
50
- display: 'flex'
51
- }, style),
52
- children: /*#__PURE__*/_jsx("div", {
53
- onClick: function onClick() {
54
- return setOpen(!open);
55
- },
56
- style: {
57
- border: '1px solid #777',
58
- background: "rgb(".concat(value === null || value === void 0 ? void 0 : value.r, ",").concat(value === null || value === void 0 ? void 0 : value.g, ",").concat(value === null || value === void 0 ? void 0 : value.b, ",").concat(value === null || value === void 0 ? void 0 : value.a, ")"),
59
- width: '100%',
60
- margin: '4px 0'
61
- }
62
- })
63
- })
64
- })
65
- });
66
- };
67
- export default ColorPicker;
114
+ onClear: function onClear() {
115
+ if (_onChange) _onChange(undefined, '');
116
+ },
117
+ presets: presets,
118
+ panelRender: customPanelRender
119
+ }, otherProps), {}, {
120
+ children: children || renderValue()
121
+ }));
122
+ }
@@ -1,9 +1,8 @@
1
- .sketch-picker {
2
- width: 250px !important;
3
- box-shadow: none !important;
4
- padding: 0 !important;
1
+ .ccs-color-picker {
2
+ display: flex;
3
+ justify-content: start;
5
4
  }
6
5
 
7
- .flexbox-fix div {
8
- padding-left: 0 !important;
6
+ .ccs-color-picker-select {
7
+ display: none !important;
9
8
  }
@@ -155,7 +155,6 @@ var HookModal = function HookModal(props) {
155
155
  requestFieldNames: requestFieldNames
156
156
  });
157
157
  }, []);
158
- console.log('footer', footer);
159
158
  return /*#__PURE__*/_jsx(Modal, _objectSpread(_objectSpread({
160
159
  onCancel: onHandleClose,
161
160
  afterClose: afterClose
@@ -16,7 +16,7 @@ export type DialogButtonsProps<T> = Pick<CcsDialogModalProps, 'okText' | 'onClos
16
16
  export type DialogButtonRef = {
17
17
  onSetButtons: (e: React.ReactElement) => void;
18
18
  };
19
- export declare const DialogButtonHolder: <TParams, TData>({ auth, extraBtn, formRef, request, onOk, onClose, buttonRef, requestFieldNames, formInitialValues, preventRequestHandle, }: Pick<CcsDialogModalProps<TParams, TData>, "onClose" | "auth" | "onOk" | "extraBtn" | "request" | "requestFieldNames" | "preventRequestHandle"> & {
19
+ export declare const DialogButtonHolder: <TParams, TData>({ auth, extraBtn, formRef, request, onOk, onClose, buttonRef, requestFieldNames, formInitialValues, preventRequestHandle, }: Pick<CcsDialogModalProps<TParams, TData>, "onOk" | "onClose" | "auth" | "extraBtn" | "preventRequestHandle" | "requestFieldNames" | "request"> & {
20
20
  formRef: React.RefObject<DialogFormRef<TParams>>;
21
21
  formInitialValues: FormProps['initialValues'];
22
22
  buttonRef: RefObject<DialogButtonRef>;
@@ -1,13 +1,33 @@
1
1
  import { UploadProps } from 'antd';
2
+ import { UploadChangeParam } from 'antd/es/upload';
2
3
  import { RecordType } from '../ccs';
3
4
  import { ImageUpload } from './upload-image';
5
+ type FileValue = {
6
+ /** 文件ID */
7
+ fileId: string;
8
+ /** 文件名称 */
9
+ name: string;
10
+ };
4
11
  export type CcsUploadProps = Pick<UploadProps, 'maxCount' | 'data' | 'multiple' | 'accept' | 'name' | 'headers'> & {
12
+ /** 最大文件数 */
5
13
  maxFileSize?: number;
14
+ /** 上传按钮文本 */
6
15
  uploadText?: string;
16
+ /** 图片下载地址 */
17
+ fileDownloadUrl?: string;
18
+ /** 文件id */
19
+ value?: string | string[] | FileValue[];
20
+ /** 上传change事件 */
7
21
  onChange?: (value: any) => void;
22
+ /** 上传请求 */
8
23
  uploadRequest: <T = any>(file: File, options?: RecordType) => Promise<T>;
9
24
  };
10
- declare function CcsUpload({ uploadText, maxCount, maxFileSize, uploadRequest, onChange, ...otherProps }: CcsUploadProps): import("react/jsx-runtime").JSX.Element;
25
+ export type FileUploadList = UploadChangeParam['fileList'][0] & {
26
+ fileId?: string;
27
+ };
28
+ /** 生成图片默认值 */
29
+ export declare function uploadDefaultFlies(value: CcsUploadProps['value'], fileDownloadUrl: string): FileUploadList[];
30
+ declare function CcsUpload({ value, uploadText, maxCount, maxFileSize, fileDownloadUrl, uploadRequest, onChange, ...otherProps }: CcsUploadProps): import("react/jsx-runtime").JSX.Element;
11
31
  declare namespace CcsUpload {
12
32
  var Image: typeof ImageUpload;
13
33
  }
@@ -1,5 +1,4 @@
1
- function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
- var _excluded = ["uploadText", "maxCount", "maxFileSize", "uploadRequest", "onChange"];
1
+ var _excluded = ["value", "uploadText", "maxCount", "maxFileSize", "fileDownloadUrl", "uploadRequest", "onChange"];
3
2
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
4
3
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
5
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; }
@@ -16,21 +15,68 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
16
15
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
17
16
  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; }
18
17
  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; }
18
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
19
19
  import { UploadOutlined } from '@ant-design/icons';
20
20
  import { Button, Upload, message } from 'antd';
21
21
  import { useState } from 'react';
22
22
  import { ImageUpload } from "./upload-image";
23
23
  import { jsx as _jsx } from "react/jsx-runtime";
24
+ /** 生成图片默认值 */
25
+ export function uploadDefaultFlies(value, fileDownloadUrl) {
26
+ if (Array.isArray(value)) {
27
+ return value.map(function (v) {
28
+ if (typeof v === 'string') {
29
+ return {
30
+ uid: v,
31
+ name: v,
32
+ url: "".concat(fileDownloadUrl).concat(v),
33
+ fileId: v
34
+ };
35
+ }
36
+
37
+ // 文件列表
38
+ if (_typeof(v) === 'object') {
39
+ return {
40
+ uid: v.fileId,
41
+ name: v.name,
42
+ url: "".concat(fileDownloadUrl).concat(v.fileId),
43
+ fileId: v.fileId
44
+ };
45
+ }
46
+ return undefined;
47
+ }).filter(function (f) {
48
+ return f;
49
+ });
50
+ }
51
+ if (typeof value === 'string') {
52
+ return [{
53
+ uid: value,
54
+ name: value,
55
+ url: "".concat(fileDownloadUrl).concat(value),
56
+ fileId: value
57
+ }];
58
+ }
59
+ return [];
60
+ }
24
61
  function CcsUpload(_ref) {
25
- var uploadText = _ref.uploadText,
62
+ var _ref$value = _ref.value,
63
+ value = _ref$value === void 0 ? [{
64
+ fileId: 'aaaa',
65
+ name: 'daaaa.txt'
66
+ }] : _ref$value,
67
+ uploadText = _ref.uploadText,
26
68
  _ref$maxCount = _ref.maxCount,
27
69
  maxCount = _ref$maxCount === void 0 ? 1 : _ref$maxCount,
28
70
  _ref$maxFileSize = _ref.maxFileSize,
29
71
  maxFileSize = _ref$maxFileSize === void 0 ? 10 : _ref$maxFileSize,
72
+ _ref$fileDownloadUrl = _ref.fileDownloadUrl,
73
+ fileDownloadUrl = _ref$fileDownloadUrl === void 0 ? '' : _ref$fileDownloadUrl,
30
74
  uploadRequest = _ref.uploadRequest,
31
75
  onChange = _ref.onChange,
32
76
  otherProps = _objectWithoutProperties(_ref, _excluded);
33
- var _useState = useState([]),
77
+ var _useState = useState(function () {
78
+ return uploadDefaultFlies(value, fileDownloadUrl);
79
+ }),
34
80
  _useState2 = _slicedToArray(_useState, 2),
35
81
  files = _useState2[0],
36
82
  setFiles = _useState2[1];
@@ -43,17 +89,16 @@ function CcsUpload(_ref) {
43
89
  if (fileList.find(function (f) {
44
90
  return f.status === 'uploading';
45
91
  })) return;
46
- if (maxFileSize === 1) {
92
+ if (maxCount === 1) {
47
93
  var _fileList$;
48
94
  // 只能上传一个文件
49
- onChange((_fileList$ = fileList[0]) === null || _fileList$ === void 0 || (_fileList$ = _fileList$.response) === null || _fileList$ === void 0 ? void 0 : _fileList$.data);
95
+ onChange((_fileList$ = fileList[0]) === null || _fileList$ === void 0 ? void 0 : _fileList$.fileId);
50
96
  } else {
51
97
  // 上传完成的文件,返回上传结果集
52
98
  onChange(fileList.filter(function (f) {
53
- return f.status === 'done';
99
+ return !!f.fileId;
54
100
  }).map(function (f) {
55
- var _f$response;
56
- return (_f$response = f.response) === null || _f$response === void 0 ? void 0 : _f$response.data;
101
+ return f.fileId;
57
102
  }));
58
103
  }
59
104
  };
@@ -66,6 +111,8 @@ function CcsUpload(_ref) {
66
111
  }
67
112
  return isLt2M;
68
113
  };
114
+
115
+ // 自定义上传
69
116
  var onCustomRequest = /*#__PURE__*/function () {
70
117
  var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref3) {
71
118
  var file, onSuccess, onError, result;
@@ -2,5 +2,5 @@ import { CcsUploadProps } from './index';
2
2
  type CcsImageUploadProps = CcsUploadProps & {
3
3
  crop?: boolean;
4
4
  };
5
- export declare function ImageUpload({ uploadText, maxCount, maxFileSize, crop, uploadRequest, onChange, ...otherProps }: CcsImageUploadProps): import("react/jsx-runtime").JSX.Element;
5
+ export declare function ImageUpload({ uploadText, maxCount, maxFileSize, crop, value, fileDownloadUrl, uploadRequest, onChange, ...otherProps }: CcsImageUploadProps): import("react/jsx-runtime").JSX.Element;
6
6
  export {};
@@ -1,5 +1,5 @@
1
1
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
- var _excluded = ["uploadText", "maxCount", "maxFileSize", "crop", "uploadRequest", "onChange"];
2
+ var _excluded = ["uploadText", "maxCount", "maxFileSize", "crop", "value", "fileDownloadUrl", "uploadRequest", "onChange"];
3
3
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
4
4
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
5
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; }
@@ -21,6 +21,7 @@ import { message, Upload } from 'antd';
21
21
  import ImgCrop from 'antd-img-crop';
22
22
  import { useState } from 'react';
23
23
  import CcsDialog from "../dialog";
24
+ import { uploadDefaultFlies } from "./index";
24
25
  import { jsx as _jsx } from "react/jsx-runtime";
25
26
  import { jsxs as _jsxs } from "react/jsx-runtime";
26
27
  import { Fragment as _Fragment } from "react/jsx-runtime";
@@ -37,27 +38,35 @@ var getBase64 = function getBase64(file) {
37
38
  });
38
39
  };
39
40
  export function ImageUpload(_ref) {
40
- var uploadText = _ref.uploadText,
41
+ var _ref$uploadText = _ref.uploadText,
42
+ uploadText = _ref$uploadText === void 0 ? '上传' : _ref$uploadText,
41
43
  _ref$maxCount = _ref.maxCount,
42
44
  maxCount = _ref$maxCount === void 0 ? 1 : _ref$maxCount,
43
45
  _ref$maxFileSize = _ref.maxFileSize,
44
46
  maxFileSize = _ref$maxFileSize === void 0 ? 10 : _ref$maxFileSize,
45
47
  crop = _ref.crop,
48
+ value = _ref.value,
49
+ _ref$fileDownloadUrl = _ref.fileDownloadUrl,
50
+ fileDownloadUrl = _ref$fileDownloadUrl === void 0 ? '' : _ref$fileDownloadUrl,
46
51
  uploadRequest = _ref.uploadRequest,
47
52
  onChange = _ref.onChange,
48
53
  otherProps = _objectWithoutProperties(_ref, _excluded);
49
- var _useState = useState([]),
54
+ var _useState = useState(function () {
55
+ return uploadDefaultFlies(value, fileDownloadUrl);
56
+ }),
50
57
  _useState2 = _slicedToArray(_useState, 2),
51
58
  files = _useState2[0],
52
59
  setFiles = _useState2[1];
53
60
  var _CcsDialog$useDialog = CcsDialog.useDialog(),
54
- contextHolder = _CcsDialog$useDialog.contextHolder,
55
61
  openModal = _CcsDialog$useDialog.openModal;
56
62
  var handleOnChange = function handleOnChange(_ref2) {
57
63
  var fileList = _ref2.fileList;
58
- setFiles(fileList.filter(function (f) {
59
- return f.status;
60
- }));
64
+ fileList.forEach(function (f) {
65
+ if (!f.fileId && f.response) {
66
+ f.fileId = f.response.data;
67
+ }
68
+ });
69
+ setFiles(fileList);
61
70
  if (!onChange) return;
62
71
 
63
72
  // 文件上传中,不更新结果
@@ -67,14 +76,13 @@ export function ImageUpload(_ref) {
67
76
  if (maxCount === 1) {
68
77
  var _fileList$;
69
78
  // 只能上传一个文件
70
- onChange((_fileList$ = fileList[0]) === null || _fileList$ === void 0 || (_fileList$ = _fileList$.response) === null || _fileList$ === void 0 ? void 0 : _fileList$.data);
79
+ onChange((_fileList$ = fileList[0]) === null || _fileList$ === void 0 ? void 0 : _fileList$.fileId);
71
80
  } else {
72
81
  // 上传完成的文件,返回上传结果集
73
82
  onChange(fileList.filter(function (f) {
74
- return f.status === 'done';
83
+ return !!f.fileId;
75
84
  }).map(function (f) {
76
- var _f$response;
77
- return (_f$response = f.response) === null || _f$response === void 0 ? void 0 : _f$response.data;
85
+ return f.fileId;
78
86
  }));
79
87
  }
80
88
  };
@@ -87,31 +95,42 @@ export function ImageUpload(_ref) {
87
95
  }
88
96
  return isLt2M;
89
97
  };
98
+
99
+ // 预览
90
100
  var handlePreview = /*#__PURE__*/function () {
91
101
  var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(file) {
92
102
  return _regeneratorRuntime().wrap(function _callee$(_context) {
93
103
  while (1) switch (_context.prev = _context.next) {
94
104
  case 0:
95
105
  if (file.preview) {
96
- _context.next = 4;
106
+ _context.next = 8;
107
+ break;
108
+ }
109
+ if (!file.originFileObj) {
110
+ _context.next = 7;
97
111
  break;
98
112
  }
99
- _context.next = 3;
113
+ _context.next = 4;
100
114
  return getBase64(file.originFileObj);
101
- case 3:
102
- file.preview = _context.sent;
103
115
  case 4:
116
+ file.preview = _context.sent;
117
+ _context.next = 8;
118
+ break;
119
+ case 7:
120
+ file.preview = "".concat(fileDownloadUrl).concat(file.fileId);
121
+ case 8:
104
122
  openModal({
105
123
  title: file.name || file.url.substring(file.url.lastIndexOf('/') + 1),
106
124
  content: /*#__PURE__*/_jsx("img", {
107
- alt: "example",
125
+ alt: file.name,
108
126
  style: {
109
127
  width: '100%'
110
128
  },
111
129
  src: file.preview
112
- })
130
+ }),
131
+ footer: null
113
132
  });
114
- case 5:
133
+ case 9:
115
134
  case "end":
116
135
  return _context.stop();
117
136
  }
@@ -121,6 +140,8 @@ export function ImageUpload(_ref) {
121
140
  return _ref3.apply(this, arguments);
122
141
  };
123
142
  }();
143
+
144
+ // 自定义上传
124
145
  var onCustomRequest = /*#__PURE__*/function () {
125
146
  var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref4) {
126
147
  var file, onSuccess, onError, result;
@@ -173,11 +194,11 @@ export function ImageUpload(_ref) {
173
194
  })]
174
195
  })
175
196
  }));
176
- return /*#__PURE__*/_jsxs(_Fragment, {
177
- children: [contextHolder, crop ? /*#__PURE__*/_jsx(ImgCrop, {
197
+ return /*#__PURE__*/_jsx(_Fragment, {
198
+ children: crop ? /*#__PURE__*/_jsx(ImgCrop, {
178
199
  minZoom: 0.5,
179
200
  rotationSlider: true,
180
201
  children: renderUpload
181
- }) : renderUpload]
202
+ }) : renderUpload
182
203
  });
183
204
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ccs-ui/rc-pro",
3
- "version": "2.2.4-beta-1",
3
+ "version": "2.2.4-beta-2",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -65,12 +65,12 @@
65
65
  "lodash.isarray": "^4.0.0",
66
66
  "lodash.isnil": "^4.0.0",
67
67
  "lodash.uniqueid": "^4.0.1",
68
- "react-color": "^2.19.3",
69
68
  "react-custom-scrollbars": "^4.2.1",
70
69
  "react-draggable": "^4.4.5",
71
70
  "react-error-overlay": "^6.0.11",
72
71
  "react-lines-ellipsis": "^0.15.4",
73
- "react-resizable": "^3.0.5"
72
+ "react-resizable": "^3.0.5",
73
+ "@ant-design/colors": "^8.0.0"
74
74
  },
75
75
  "devDependencies": {
76
76
  "@ant-design/compatible": "^5.1.2",
@@ -84,7 +84,6 @@
84
84
  "@types/lodash.isnil": "^4.0.9",
85
85
  "@types/lodash.uniqueid": "^4.0.9",
86
86
  "@types/react": "^18.0.0",
87
- "@types/react-color": "^3.0.6",
88
87
  "@types/react-custom-scrollbars": "^4.0.10",
89
88
  "@types/react-dom": "^18.0.0",
90
89
  "@types/react-lines-ellipsis": "^0.15.6",