@ccs-ui/rc-pro 1.2.1-beta-4 → 2.0.1

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 (45) hide show
  1. package/es/auth/auth-button.d.ts +3 -1
  2. package/es/auth/auth-button.js +40 -5
  3. package/es/auth/index.d.ts +2 -1
  4. package/es/ccs.d.ts +27 -66
  5. package/es/color-picker/index.d.ts +2 -4
  6. package/es/config.d.ts +5 -3
  7. package/es/config.js +98 -9
  8. package/es/context/index.d.ts +13 -9
  9. package/es/context/index.js +2 -2
  10. package/es/dialog/DialogRequestButton.d.ts +1 -1
  11. package/es/dialog/DialogSelfOkButton.d.ts +1 -1
  12. package/es/dialog/button.d.ts +3 -3
  13. package/es/dialog/drawer-footer.d.ts +2 -3
  14. package/es/dialog/hook.d.ts +4 -0
  15. package/es/dialog/hook.js +13 -7
  16. package/es/editor/index.d.ts +2 -4
  17. package/es/hooks/use-app.d.ts +6 -0
  18. package/es/hooks/use-app.js +15 -0
  19. package/es/index.d.ts +2 -3
  20. package/es/index.js +2 -3
  21. package/es/layout-keep-alive/index.d.ts +1 -1
  22. package/es/layout-keep-alive/index.js +14 -18
  23. package/es/layout-keep-alive/page.d.ts +1 -0
  24. package/es/layout-single-page/index.d.ts +1 -1
  25. package/es/layout-single-page/index.js +7 -23
  26. package/es/pro-grid/index.d.ts +4 -9
  27. package/es/pro-table/head.d.ts +2 -2
  28. package/es/pro-table/index.less +0 -27
  29. package/es/pro-table/table.d.ts +8 -16
  30. package/es/pro-table/table.js +6 -33
  31. package/es/result/index.js +3 -1
  32. package/es/trigger/index.d.ts +2 -8
  33. package/es/upload/index.d.ts +4 -3
  34. package/es/upload/index.js +48 -10
  35. package/es/upload/upload-image.d.ts +1 -1
  36. package/es/upload/upload-image.js +50 -16
  37. package/es/virtual-list/index.d.ts +3 -4
  38. package/es/water-mark/index.d.ts +3 -10
  39. package/package.json +5 -6
  40. package/es/hooks/use-global.d.ts +0 -4
  41. package/es/hooks/use-global.js +0 -10
  42. package/es/pro-table/search.d.ts +0 -17
  43. package/es/pro-table/search.js +0 -312
  44. package/es/theme.d.ts +0 -12
  45. package/es/theme.js +0 -66
@@ -58,13 +58,10 @@ export default function KeepAliveTabs(_ref) {
58
58
  // 菜单改变,更新用户权限信息
59
59
  useUpdateEffect(function () {
60
60
  components.current.forEach(function (component) {
61
- var _menu$children;
62
61
  var menu = menus.find(function (m) {
63
- return m.nodeData.menuUrl === component.key;
62
+ return m.menuUrl === component.key;
64
63
  });
65
- component.urlAuthList = (menu === null || menu === void 0 || (_menu$children = menu.children) === null || _menu$children === void 0 ? void 0 : _menu$children.map(function (m) {
66
- return m.nodeData.menuUrl;
67
- })) || [];
64
+ component.urlAuthList = (menu === null || menu === void 0 ? void 0 : menu.urlAuthList) || [];
68
65
  component.timestamp = new Date().getTime();
69
66
  });
70
67
  update();
@@ -73,7 +70,7 @@ export default function KeepAliveTabs(_ref) {
73
70
  // 当前菜单
74
71
  var curMenu = useMemo(function () {
75
72
  var menu = menus.find(function (m) {
76
- var menuUrl = m.nodeData.menuUrl;
73
+ var menuUrl = m.menuUrl;
77
74
  if (menuUrl.includes('?')) {
78
75
  return menuUrl.split('?')[0] === pathname;
79
76
  }
@@ -82,7 +79,7 @@ export default function KeepAliveTabs(_ref) {
82
79
 
83
80
  // add document title
84
81
  setTimeout(function () {
85
- document.title = "".concat(appName, " - ").concat((menu === null || menu === void 0 ? void 0 : menu.nodeName) || (menu === null || menu === void 0 ? void 0 : menu.nodeData.menuUrl));
82
+ document.title = "".concat((menu === null || menu === void 0 ? void 0 : menu.menuName) || (menu === null || menu === void 0 ? void 0 : menu.menuUrl), " - ").concat(appName);
86
83
  }, 10);
87
84
 
88
85
  // save history route
@@ -116,7 +113,7 @@ export default function KeepAliveTabs(_ref) {
116
113
  }
117
114
  RouteHistorys.unshift({
118
115
  pathName: pathname,
119
- menuName: (menu === null || menu === void 0 ? void 0 : menu.nodeData.menuName) || '',
116
+ menuName: (menu === null || menu === void 0 ? void 0 : menu.menuName) || '',
120
117
  time: new Date()
121
118
  });
122
119
  CcsUtils.setStroage('_ROUTE_HISTORY', RouteHistorys);
@@ -137,15 +134,14 @@ export default function KeepAliveTabs(_ref) {
137
134
  return c.key === pathname;
138
135
  });
139
136
  if (!component) {
140
- var _curMenu$children;
141
- var urlAuthList = (curMenu === null || curMenu === void 0 || (_curMenu$children = curMenu.children) === null || _curMenu$children === void 0 ? void 0 : _curMenu$children.map(function (m) {
142
- return m.nodeData.menuUrl;
143
- })) || [];
137
+ var _ref3 = curMenu || {},
138
+ _ref3$urlAuthList = _ref3.urlAuthList,
139
+ urlAuthList = _ref3$urlAuthList === void 0 ? [] : _ref3$urlAuthList;
144
140
  components.current = [].concat(_toConsumableArray(components.current), [{
145
141
  locationKey: locationKey,
146
142
  key: pathname,
147
143
  timestamp: new Date().getTime(),
148
- label: curMenu ? curMenu.nodeName : '未知',
144
+ label: curMenu ? curMenu.menuName : '未知',
149
145
  outlet: curMenu ? outlet : /*#__PURE__*/_jsx(Empty, {
150
146
  description: "\u672A\u77E5\u9875\u9762"
151
147
  }),
@@ -224,11 +220,11 @@ export default function KeepAliveTabs(_ref) {
224
220
  },
225
221
  items: components.current,
226
222
  tabBarExtraContent: components.current.length > 2 ? tabBarExtraContent : null
227
- }), components.current.map(function (_ref3) {
228
- var key = _ref3.key,
229
- urlAuthList = _ref3.urlAuthList,
230
- timestamp = _ref3.timestamp,
231
- outlet = _ref3.outlet;
223
+ }), components.current.map(function (_ref4) {
224
+ var key = _ref4.key,
225
+ urlAuthList = _ref4.urlAuthList,
226
+ timestamp = _ref4.timestamp,
227
+ outlet = _ref4.outlet;
232
228
  return /*#__PURE__*/_jsx(Page, {
233
229
  active: key === pathname,
234
230
  location: location,
@@ -9,6 +9,7 @@ export type CachePageProps = {
9
9
  timestamp: number;
10
10
  /** 按钮权限列表 */
11
11
  urlAuthList: string[];
12
+ /** children */
12
13
  children: ReactElement<any, string | JSXElementConstructor<any>> | null;
13
14
  /** 销毁页面 */
14
15
  onDestroy: (path: string) => void;
@@ -2,7 +2,7 @@ import CCS from "..";
2
2
  import './index.less';
3
3
  type PropsType = {
4
4
  appName: string;
5
- menus: CCS.MenuTreeNode[];
5
+ menus: CCS.MenuType[];
6
6
  className?: string;
7
7
  };
8
8
  export default function SinglePage({ appName, menus, className, }: PropsType): import("react/jsx-runtime").JSX.Element;
@@ -29,13 +29,10 @@ export default function SinglePage(_ref) {
29
29
  // 菜单改变,更新用户权限信息
30
30
  useUpdateEffect(function () {
31
31
  components.current.forEach(function (component) {
32
- var _menu$children;
33
32
  var menu = menus.find(function (m) {
34
- return m.nodeData.menuUrl === component.key;
33
+ return m.menuUrl === component.key;
35
34
  });
36
- component.urlAuthList = (menu === null || menu === void 0 || (_menu$children = menu.children) === null || _menu$children === void 0 ? void 0 : _menu$children.map(function (m) {
37
- return m.nodeData.menuUrl;
38
- })) || [];
35
+ component.urlAuthList = (menu === null || menu === void 0 ? void 0 : menu.urlAuthList) || [];
39
36
  component.timestamp = new Date().getTime();
40
37
  });
41
38
  update();
@@ -43,9 +40,8 @@ export default function SinglePage(_ref) {
43
40
 
44
41
  // 当前菜单
45
42
  var menuInfo = useMemo(function () {
46
- var _menu$children2;
47
- var menu = menus.find(function (m) {
48
- var menuUrl = m.nodeData.menuUrl;
43
+ var menu = menus.find(function (_ref2) {
44
+ var menuUrl = _ref2.menuUrl;
49
45
  if (menuUrl.includes('?')) {
50
46
  return menuUrl.split('?')[0] === pathname;
51
47
  }
@@ -55,23 +51,11 @@ export default function SinglePage(_ref) {
55
51
 
56
52
  // add document title
57
53
  setTimeout(function () {
58
- document.title = "".concat(appName, " - ").concat((menu === null || menu === void 0 ? void 0 : menu.nodeName) || (menu === null || menu === void 0 ? void 0 : menu.nodeData.menuUrl));
54
+ document.title = "".concat((menu === null || menu === void 0 ? void 0 : menu.menuName) || (menu === null || menu === void 0 ? void 0 : menu.menuUrl), " - ").concat(appName);
59
55
  }, 10);
60
- var breadcrumbs = [{
61
- title: '首页',
62
- href: '/'
63
- }].concat(_toConsumableArray(menu.parents.map(function (m) {
64
- return {
65
- title: m.name
66
- };
67
- })), [{
68
- title: menu.nodeData.menuName
69
- }]);
70
56
  return {
71
- auth: (menu === null || menu === void 0 || (_menu$children2 = menu.children) === null || _menu$children2 === void 0 ? void 0 : _menu$children2.map(function (btn) {
72
- return btn.nodeData.menuUrl;
73
- })) || [],
74
- breadcrumbs: breadcrumbs,
57
+ auth: menu.urlAuthList || [],
58
+ breadcrumbs: menu.breadcrumb,
75
59
  menu: menu
76
60
  };
77
61
  }, [pathname, menus]);
@@ -1,17 +1,12 @@
1
1
  import { CardProps } from 'antd';
2
- import { CSSProperties, FC, ReactNode } from 'react';
2
+ import { FC } from 'react';
3
+ import { PropsWithCss, PropsWithNodeChildren } from '../ccs';
3
4
  import './index.less';
4
- type ClassProps = {
5
- className?: string;
6
- style?: CSSProperties;
7
- };
8
- type CcsProGridProps = ClassProps & {
5
+ type CcsProGridProps = PropsWithCss & PropsWithNodeChildren & {
9
6
  gutter?: number;
10
- children?: ReactNode;
11
7
  };
12
- type ColProps = CardProps & {
8
+ type ColProps = CardProps & PropsWithNodeChildren & {
13
9
  colWidth?: number;
14
- children?: ReactNode;
15
10
  };
16
11
  type GridInstance = FC<CcsProGridProps> & {
17
12
  Col: typeof GridCol;
@@ -1,11 +1,11 @@
1
1
  import { FormInstance } from 'antd/lib/form';
2
2
  import { ReactElement } from 'react';
3
+ import { PropsWithElementChildren } from '../ccs';
3
4
  import { CcsProTableProps } from './table';
4
- type PropsType<T> = Pick<CcsProTableProps<T>, 'toolbar' | 'formItems' | 'formInitValues' | 'expandForm' | 'title' | 'formItemLabelWidth'> & {
5
+ type PropsType<T> = Pick<CcsProTableProps<T>, 'toolbar' | 'formItems' | 'formInitValues' | 'expandForm' | 'title' | 'formItemLabelWidth'> & PropsWithElementChildren & {
5
6
  /** 更多查询条件 */
6
7
  hasMore?: boolean;
7
8
  form: FormInstance<any>;
8
- children?: ReactElement;
9
9
  /** table 操作栏 */
10
10
  tableOperation: ReactElement;
11
11
  onSearch: () => void;
@@ -37,12 +37,6 @@
37
37
  // margin: 10px;
38
38
  // background: #fff;
39
39
  position: relative;
40
-
41
- &.tradition {
42
- .ant-table-title {
43
- border-radius: 0;
44
- }
45
- }
46
40
  }
47
41
 
48
42
  &-adaptation {
@@ -112,27 +106,6 @@
112
106
  margin-inline-end: 0;
113
107
  }
114
108
  }
115
-
116
- &.tradition {
117
- flex-wrap: wrap;
118
-
119
- & > .ant-form-inline {
120
- flex-wrap: wrap;
121
- justify-content: flex-start;
122
- gap: 10px;
123
- }
124
- }
125
-
126
- &.vertical {
127
- .ant-form-item-row {
128
- flex-direction: row;
129
- align-items: center;
130
- }
131
-
132
- .ant-form-item .ant-form-item-control {
133
- width: auto;
134
- }
135
- }
136
109
  }
137
110
 
138
111
  .ant-form-item-control {
@@ -1,9 +1,9 @@
1
- import { ColProps, TableProps } from 'antd';
1
+ import { TableProps } from 'antd';
2
2
  import { ColumnGroupType, ColumnType } from 'antd/es/table';
3
3
  import { TableSticky } from 'rc-table/lib/interface';
4
4
  import React, { CSSProperties, ReactElement, ReactNode } from 'react';
5
5
  import CCS from '..';
6
- import { HttpPageResult, TableColumns } from '../ccs';
6
+ import { HttpPageResult, PropsWithCss, PropsWithNodeChildren, TableColumns } from '../ccs';
7
7
  import './index.less';
8
8
  type ParamType = Record<string, any>;
9
9
  export type ShowDependType = {
@@ -41,8 +41,7 @@ export type CcsTableProps<T> = Omit<TableProps<T>, 'columns' | 'title'> & {
41
41
  /** table title */
42
42
  title?: ({ selectedRows, data, onClear }: TableTitleType<T>) => ReactNode;
43
43
  };
44
- type FormLayout = 'horizontal' | 'inline' | 'vertical' | 'adaptation';
45
- export type CcsProTableProps<RecordType> = {
44
+ export type CcsProTableProps<RecordType> = Pick<PropsWithCss, 'className'> & PropsWithNodeChildren & {
46
45
  /** api权限标识 */
47
46
  auth?: string | 'ignore';
48
47
  /** 是否初始查询,默认true */
@@ -51,10 +50,6 @@ export type CcsProTableProps<RecordType> = {
51
50
  title?: string;
52
51
  /** 查询条件集合 */
53
52
  formItems?: CCS.TableFormItems;
54
- /** @deprecated 查询条件布局模式,默认:horizontal */
55
- formItemLayout?: FormLayout;
56
- /** @deprecated 查询条件栅格配置,默认:{ xs: 24, sm: 12, md: 8, lg: 8, xl: 6 } */
57
- formItemCol?: ColProps | ColProps[];
58
53
  /** form item label 宽度 */
59
54
  formItemLabelWidth?: number | string;
60
55
  /** 查询form 初始值 */
@@ -67,8 +62,11 @@ export type CcsProTableProps<RecordType> = {
67
62
  expandForm?: boolean;
68
63
  /** table 数据区域 */
69
64
  table?: CcsTableProps<RecordType>;
70
- /** table style */
71
- tableStyle?: CSSProperties;
65
+ /** 语义化styles */
66
+ styles?: {
67
+ root?: CSSProperties;
68
+ table?: CSSProperties;
69
+ };
72
70
  /** 父级值字段 */
73
71
  parentFieldName?: string;
74
72
  /** 水印文字 */
@@ -77,12 +75,6 @@ export type CcsProTableProps<RecordType> = {
77
75
  proRef?: CCS.TableInstanceRef<RecordType>;
78
76
  /** 显示序号 */
79
77
  showNumber?: boolean;
80
- /** class */
81
- className?: string;
82
- /** style */
83
- style?: CSSProperties;
84
- /** children */
85
- children?: ReactNode;
86
78
  /** 执行search 后回调函数 */
87
79
  searchEvent?: () => void;
88
80
  /** 请求前格式化参数 */
@@ -25,10 +25,7 @@ import { getAllChildrenId, getDataById, onTableInModalOrDrawer, onTableInTabItem
25
25
  import HeadComponent from "./head";
26
26
  import "./index.less";
27
27
  import TableOperation from "./operation";
28
- import SearchComponent from "./search";
29
28
  import TableTree from "./tree";
30
-
31
- // 同 antd FormLayout; adaptation为自适应布局
32
29
  import { jsx as _jsx } from "react/jsx-runtime";
33
30
  import { Fragment as _Fragment } from "react/jsx-runtime";
34
31
  import { jsxs as _jsxs } from "react/jsx-runtime";
@@ -47,15 +44,14 @@ var InternalProTable = function InternalProTable(props) {
47
44
  var init = props.init,
48
45
  auth = props.auth,
49
46
  table = props.table,
50
- title = props.title,
51
- style = props.style,
47
+ _props$styles = props.styles,
48
+ styles = _props$styles === void 0 ? {} : _props$styles,
52
49
  proRef = props.proRef,
53
50
  toolbar = props.toolbar,
54
51
  children = props.children,
55
52
  watermark = props.watermark,
56
53
  className = props.className,
57
54
  expandForm = props.expandForm,
58
- tableStyle = props.tableStyle,
59
55
  searchEvent = props.searchEvent,
60
56
  toolbarExtra = props.toolbarExtra,
61
57
  _props$formItems = props.formItems,
@@ -507,7 +503,7 @@ var InternalProTable = function InternalProTable(props) {
507
503
  },
508
504
  children: toolbarExtra
509
505
  });
510
- var rootStyle = style || {};
506
+ var rootStyle = styles.root || {};
511
507
  if (table !== null && table !== void 0 && table.bordered) {
512
508
  rootStyle = _objectSpread({
513
509
  border: "1px solid ".concat(token.colorBorderSecondary),
@@ -518,30 +514,7 @@ var InternalProTable = function InternalProTable(props) {
518
514
  className: classNames(classPrefix, className, _defineProperty({}, 'dark-table', isDark)),
519
515
  style: rootStyle,
520
516
  ref: containerRef,
521
- children: [!(!formItems.length && !toolbar) && isAuth && props.formItemLayout !== 'adaptation' ? /*#__PURE__*/_jsx(SearchComponent, {
522
- form: form,
523
- title: title,
524
- titleBordered: table === null || table === void 0 ? void 0 : table.bordered,
525
- toolbar: newToolbar,
526
- formItems: formItems,
527
- expandForm: expandForm,
528
- formInitValues: formInitValues,
529
- formItemLabelWidth: props.formItemLabelWidth,
530
- formItemLayout: props.formItemLayout,
531
- formItemCol: props.formItemCol,
532
- onSearch: _onSearch,
533
- tableOperation: (table === null || table === void 0 ? void 0 : table.isEnableToolbar) !== false ? /*#__PURE__*/_jsx(TableOperation, {
534
- tableRowSize: tableRowSize,
535
- columns: columns,
536
- tableRef: tableRef,
537
- isInModalOrDrawer: isInModalOrDrawer,
538
- onReset: _onReset,
539
- onChangeRowSize: function onChangeRowSize(e) {
540
- return setTableRowSize(e);
541
- }
542
- }) : /*#__PURE__*/_jsx(_Fragment, {}),
543
- children: newToolbarExtra
544
- }) : /*#__PURE__*/_jsx(HeadComponent, {
517
+ children: [!(!formItems.length && !toolbar) && isAuth && /*#__PURE__*/_jsx(HeadComponent, {
545
518
  form: form,
546
519
  toolbar: newToolbar,
547
520
  formItems: formItems,
@@ -561,8 +534,8 @@ var InternalProTable = function InternalProTable(props) {
561
534
  }) : /*#__PURE__*/_jsx(_Fragment, {}),
562
535
  children: newToolbarExtra
563
536
  }), /*#__PURE__*/_jsxs("div", {
564
- className: "".concat(classPrefix, "-table-content ").concat(props.formItemLayout),
565
- style: tableStyle,
537
+ className: "".concat(classPrefix, "-table-content"),
538
+ style: styles === null || styles === void 0 ? void 0 : styles.table,
566
539
  ref: tableContentRef,
567
540
  children: [renderTable(), children]
568
541
  })]
@@ -19,7 +19,9 @@ function Basic(_ref) {
19
19
  token = _theme$useToken.token;
20
20
  return /*#__PURE__*/_jsxs("div", {
21
21
  style: _objectSpread({
22
- textAlign: 'center',
22
+ display: 'flex',
23
+ flexDirection: 'column',
24
+ alignItems: 'center',
23
25
  padding: 16
24
26
  }, style),
25
27
  children: [/*#__PURE__*/_jsx("img", {
@@ -1,7 +1,7 @@
1
1
  import { SizeType } from 'antd/es/config-provider/SizeContext';
2
- import { CSSProperties, ReactElement } from 'react';
2
+ import { PropsWithCss, PropsWithElementChildren } from '../ccs';
3
3
  import './index.less';
4
- export type CcsTriggerProps = {
4
+ export type CcsTriggerProps = PropsWithCss & PropsWithElementChildren & {
5
5
  /** 下拉框宽度 */
6
6
  width?: number;
7
7
  /** 下拉框高度 */
@@ -16,14 +16,8 @@ export type CcsTriggerProps = {
16
16
  * @default false
17
17
  */
18
18
  disabled?: boolean;
19
- /** 选择内容 */
20
- children?: ReactElement;
21
19
  /** Form.Item value */
22
20
  value?: any;
23
- /** style */
24
- style?: CSSProperties;
25
- /** class */
26
- className?: string;
27
21
  /** input placeholder */
28
22
  placeholder?: string;
29
23
  /**
@@ -1,12 +1,13 @@
1
1
  import { UploadProps } from 'antd';
2
+ import { RecordType } from '../ccs';
2
3
  import { ImageUpload } from './upload-image';
3
- export type CcsUploadProps = Pick<UploadProps, 'maxCount' | 'data' | 'multiple' | 'accept' | 'action' | 'name' | 'headers'> & {
4
- tokenKey?: string;
4
+ export type CcsUploadProps = Pick<UploadProps, 'maxCount' | 'data' | 'multiple' | 'accept' | 'name' | 'headers'> & {
5
5
  maxFileSize?: number;
6
6
  uploadText?: string;
7
7
  onChange?: (value: any) => void;
8
+ uploadRequest: <T = any>(file: File, options?: RecordType) => Promise<T>;
8
9
  };
9
- declare function CcsUpload({ tokenKey, uploadText, maxCount, maxFileSize, onChange, ...otherProps }: CcsUploadProps): import("react/jsx-runtime").JSX.Element;
10
+ declare function CcsUpload({ uploadText, maxCount, maxFileSize, uploadRequest, onChange, ...otherProps }: CcsUploadProps): import("react/jsx-runtime").JSX.Element;
10
11
  declare namespace CcsUpload {
11
12
  var Image: typeof ImageUpload;
12
13
  }
@@ -1,10 +1,13 @@
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 = ["tokenKey", "uploadText", "maxCount", "maxFileSize", "onChange"];
2
+ var _excluded = ["uploadText", "maxCount", "maxFileSize", "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; }
6
6
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
7
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 _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 e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
9
+ 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); } }
10
+ 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); }); }; }
8
11
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
9
12
  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
13
  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); }
@@ -19,12 +22,12 @@ import { useState } from 'react';
19
22
  import { ImageUpload } from "./upload-image";
20
23
  import { jsx as _jsx } from "react/jsx-runtime";
21
24
  function CcsUpload(_ref) {
22
- var tokenKey = _ref.tokenKey,
23
- uploadText = _ref.uploadText,
25
+ var uploadText = _ref.uploadText,
24
26
  _ref$maxCount = _ref.maxCount,
25
27
  maxCount = _ref$maxCount === void 0 ? 1 : _ref$maxCount,
26
28
  _ref$maxFileSize = _ref.maxFileSize,
27
29
  maxFileSize = _ref$maxFileSize === void 0 ? 10 : _ref$maxFileSize,
30
+ uploadRequest = _ref.uploadRequest,
28
31
  onChange = _ref.onChange,
29
32
  otherProps = _objectWithoutProperties(_ref, _excluded);
30
33
  var _useState = useState([]),
@@ -33,8 +36,14 @@ function CcsUpload(_ref) {
33
36
  setFiles = _useState2[1];
34
37
  var handleOnChange = function handleOnChange(_ref2) {
35
38
  var fileList = _ref2.fileList;
39
+ console.log('fileList', fileList);
36
40
  setFiles(fileList);
37
41
  if (!onChange) return;
42
+
43
+ // 文件上传中,不更新结果
44
+ if (fileList.find(function (f) {
45
+ return f.status === 'uploading';
46
+ })) return;
38
47
  if (maxFileSize === 1) {
39
48
  var _fileList$;
40
49
  // 只能上传一个文件
@@ -58,13 +67,42 @@ function CcsUpload(_ref) {
58
67
  }
59
68
  return isLt2M;
60
69
  };
61
- var uploadProps = {
62
- name: 'fileName',
63
- headers: {
64
- token: tokenKey ? sessionStorage.getItem(tokenKey) : ''
65
- }
66
- };
67
- return /*#__PURE__*/_jsx(Upload, _objectSpread(_objectSpread(_objectSpread({}, uploadProps), {}, {
70
+ var onCustomRequest = /*#__PURE__*/function () {
71
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref3) {
72
+ var file, onSuccess, onError, result;
73
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
74
+ while (1) switch (_context.prev = _context.next) {
75
+ case 0:
76
+ file = _ref3.file, onSuccess = _ref3.onSuccess, onError = _ref3.onError;
77
+ _context.next = 3;
78
+ return uploadRequest(file);
79
+ case 3:
80
+ result = _context.sent;
81
+ // 上传成功
82
+ if (result.success && onSuccess) {
83
+ onSuccess(result);
84
+ }
85
+ // 上传失败
86
+ if (!result.success && onError) {
87
+ onError({
88
+ status: 500,
89
+ name: '出错了',
90
+ message: result.msg || '上传失败'
91
+ });
92
+ }
93
+ case 6:
94
+ case "end":
95
+ return _context.stop();
96
+ }
97
+ }, _callee);
98
+ }));
99
+ return function onCustomRequest(_x) {
100
+ return _ref4.apply(this, arguments);
101
+ };
102
+ }();
103
+ return /*#__PURE__*/_jsx(Upload, _objectSpread(_objectSpread({
104
+ customRequest: onCustomRequest,
105
+ name: "fileName",
68
106
  onChange: handleOnChange,
69
107
  beforeUpload: beforeUpload,
70
108
  fileList: files,
@@ -3,5 +3,5 @@ type CcsImageUploadProps = CcsUploadProps & {
3
3
  crop?: boolean;
4
4
  tokenKey?: string;
5
5
  };
6
- export declare function ImageUpload({ crop, tokenKey, uploadText, maxCount, maxFileSize, onChange, ...otherProps }: CcsImageUploadProps): import("react/jsx-runtime").JSX.Element;
6
+ export declare function ImageUpload({ uploadText, maxCount, maxFileSize, crop, uploadRequest, onChange, ...otherProps }: CcsImageUploadProps): import("react/jsx-runtime").JSX.Element;
7
7
  export {};