tntd 1.4.6 → 1.4.7

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 (86) hide show
  1. package/components/Layout/HeaderActions.js +90 -128
  2. package/components/LoadingButton/index.js +11 -15
  3. package/dist/stats.json +4958 -4958
  4. package/dist/tntd.js +1 -1
  5. package/es/Layout/HeaderActions.js +10 -10
  6. package/es/LoadingButton/index.js +20 -10
  7. package/lib/ArrayInput/icon.js +27 -31
  8. package/lib/ArrayInput/index.js +211 -298
  9. package/lib/AuthContext.js +2 -13
  10. package/lib/Columns/index.js +71 -100
  11. package/lib/DevelopmentLogin/LoginModal.js +79 -141
  12. package/lib/DevelopmentLogin/index.js +28 -55
  13. package/lib/Ellipsis/Svg/CopySVG.js +23 -71
  14. package/lib/Ellipsis/Svg/TickSVG.js +17 -49
  15. package/lib/Ellipsis/index.js +148 -154
  16. package/lib/Handle/index.js +72 -109
  17. package/lib/Icon/fonts/iconfont.js +1 -43
  18. package/lib/Icon/iconList.js +119 -8
  19. package/lib/Icon/index.js +13 -45
  20. package/lib/Img/Contain.js +49 -81
  21. package/lib/Img/Cover.js +88 -136
  22. package/lib/Img/index.js +36 -89
  23. package/lib/Layout/ActionsContext.js +2 -11
  24. package/lib/Layout/AppList.js +262 -256
  25. package/lib/Layout/Application.js +119 -135
  26. package/lib/Layout/Avatar.js +137 -137
  27. package/lib/Layout/CompatibleLanguage.js +214 -195
  28. package/lib/Layout/EnterpriseLayout/Avatar.js +156 -168
  29. package/lib/Layout/EnterpriseLayout/Language.js +75 -100
  30. package/lib/Layout/EnterpriseLayout/Theme.js +96 -94
  31. package/lib/Layout/EnterpriseLayout/index.js +32 -45
  32. package/lib/Layout/GlobalNavigation/NavigationPopup.js +335 -407
  33. package/lib/Layout/GlobalNavigation/index.js +110 -158
  34. package/lib/Layout/Header.js +165 -116
  35. package/lib/Layout/HeaderActions.js +132 -129
  36. package/lib/Layout/HeaderNavs.js +90 -113
  37. package/lib/Layout/HeaderTabs.js +312 -278
  38. package/lib/Layout/Iconfont.js +2 -15
  39. package/lib/Layout/Language.js +63 -102
  40. package/lib/Layout/Layout.js +272 -261
  41. package/lib/Layout/Logo.js +132 -87
  42. package/lib/Layout/OrgAppList.js +440 -319
  43. package/lib/Layout/SideMenu.js +429 -343
  44. package/lib/Layout/Theme.js +95 -124
  45. package/lib/Layout/checkAuth.js +21 -35
  46. package/lib/Layout/createActions.js +38 -51
  47. package/lib/Layout/images/index.js +33 -41
  48. package/lib/Layout/index.js +110 -161
  49. package/lib/Layout/paaslayout/CompactSideMenu.js +200 -178
  50. package/lib/Layout/paaslayout/Header.js +84 -90
  51. package/lib/Layout/paaslayout/Logo.js +27 -32
  52. package/lib/Layout/paaslayout/SideMenu.js +161 -174
  53. package/lib/Layout/paaslayout/index.js +240 -261
  54. package/lib/Layout/storage.js +20 -78
  55. package/lib/Layout/utils.js +93 -143
  56. package/lib/LoadingButton/index.js +25 -57
  57. package/lib/Modal/index.js +83 -108
  58. package/lib/Page/Box.js +56 -81
  59. package/lib/Page/index.js +151 -173
  60. package/lib/Page/utils.js +12 -30
  61. package/lib/QueryForm/Field/Checkbox.js +11 -33
  62. package/lib/QueryForm/Field/Select.js +63 -99
  63. package/lib/QueryForm/Field/SelectInput.js +69 -114
  64. package/lib/QueryForm/Field/fieldsMap.js +30 -52
  65. package/lib/QueryForm/Field/index.js +76 -158
  66. package/lib/QueryForm/createActions.js +50 -65
  67. package/lib/QueryForm/index.js +304 -383
  68. package/lib/QueryForm/useForm.js +6 -17
  69. package/lib/QueryListScene/List.js +290 -366
  70. package/lib/QueryListScene/QueryForm.js +93 -161
  71. package/lib/QueryListScene/QueryListScene.js +33 -87
  72. package/lib/QueryListScene/Title.js +10 -20
  73. package/lib/QueryListScene/Toolbar.js +8 -31
  74. package/lib/QueryListScene/createActions.js +64 -79
  75. package/lib/QueryListScene/index.js +23 -40
  76. package/lib/QueryListScene/useActions.js +6 -17
  77. package/lib/Select/DropDownWrap.js +60 -124
  78. package/lib/Select/index.js +425 -561
  79. package/lib/Table/ResizableTable/index.js +77 -121
  80. package/lib/Table/index.js +19 -51
  81. package/lib/Title/index.js +34 -52
  82. package/lib/index.js +19 -159
  83. package/lib/locale.js +48 -63
  84. package/package.json +1 -1
  85. package/lib/Layout/EnterpriseLayout/Header.js +0 -113
  86. package/lib/Layout/EnterpriseLayout/HeaderActions.js +0 -104
@@ -1,8 +1,119 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
- var _default = ['system', 'entry', 'permission', 'graph', 'guanjia', 'case', 'celve1', 'shoucang', 'deal-type', 'pm', 'shoukuan', 'zhibiao', 'puzzle', 'user-group', 'yuce', 'jianmo', 'zhuanzhang', 'yunwei', 'baozhang', 'jizhang', 'tongji', 'pingfen', 'limit', 'spider', 'loan', 'access', 'role', 'org', 'celve', 'book', 'tag', 'shixufenxipeizhi', 'all-cases', 'xianeguanli', 'api', 'network', 'analysis', 'calendar', 'backup', 'all', 'attachment', 'chart-line', 'branches', 'chart-area', 'clock', 'check', 'charging-setting', 'chart-pie-alt', 'dashboard', 'datebase', 'check-reply', 'datacenter', 'connection', 'download', 'date-set', 'event', 'event-wait', 'fieldanalysis', 'exchange', 'knowledge', 'key', 'log', 'list', 'menu', 'index', 'project', 'monitorin', 'pointmap', 'ranking', 'model', 'plan', 'task', 'wait', 'upload', 'question-list', 'read', 'setting', 'reply', 'jinjianguanli', 'change-theme', 'application', 'flag-en', 'flag-cn', 'down', 'up', 'workflow', 'sync', 'folder', 'database', 'circle', 'edit', 'edit-color', 'box', 'layer', 'box-color', 'home-color', 'record', 'monitor', 'time-color', 'user', 'function-color', 'record-color', 'warning-color', 'layer-color', 'template', 'template-color', 'monitor-color', 'search', 'user-color', 'function', 'warning', 'search-color', 'home', 'time', 'application', 'plus', 'minus'];
8
- exports["default"] = _default;
1
+ export default [
2
+ 'system',
3
+ 'entry',
4
+ 'permission',
5
+ 'graph',
6
+ 'guanjia',
7
+ 'case',
8
+ 'celve1',
9
+ 'shoucang',
10
+ 'deal-type',
11
+ 'pm',
12
+ 'shoukuan',
13
+ 'zhibiao',
14
+ 'puzzle',
15
+ 'user-group',
16
+ 'yuce',
17
+ 'jianmo',
18
+ 'zhuanzhang',
19
+ 'yunwei',
20
+ 'baozhang',
21
+ 'jizhang',
22
+ 'tongji',
23
+ 'pingfen',
24
+ 'limit',
25
+ 'spider',
26
+ 'loan',
27
+ 'access',
28
+ 'role',
29
+ 'org',
30
+ 'celve',
31
+ 'book',
32
+ 'tag',
33
+ 'shixufenxipeizhi',
34
+ 'all-cases',
35
+ 'xianeguanli',
36
+ 'api',
37
+ 'network',
38
+ 'analysis',
39
+ 'calendar',
40
+ 'backup',
41
+ 'all',
42
+ 'attachment',
43
+ 'chart-line',
44
+ 'branches',
45
+ 'chart-area',
46
+ 'clock',
47
+ 'check',
48
+ 'charging-setting',
49
+ 'chart-pie-alt',
50
+ 'dashboard',
51
+ 'datebase',
52
+ 'check-reply',
53
+ 'datacenter',
54
+ 'connection',
55
+ 'download',
56
+ 'date-set',
57
+ 'event',
58
+ 'event-wait',
59
+ 'fieldanalysis',
60
+ 'exchange',
61
+ 'knowledge',
62
+ 'key',
63
+ 'log',
64
+ 'list',
65
+ 'menu',
66
+ 'index',
67
+ 'project',
68
+ 'monitorin',
69
+ 'pointmap',
70
+ 'ranking',
71
+ 'model',
72
+ 'plan',
73
+ 'task',
74
+ 'wait',
75
+ 'upload',
76
+ 'question-list',
77
+ 'read',
78
+ 'setting',
79
+ 'reply',
80
+ 'jinjianguanli',
81
+ 'change-theme',
82
+ 'application',
83
+ 'flag-en',
84
+ 'flag-cn',
85
+ 'down',
86
+ 'up',
87
+ 'workflow',
88
+ 'sync',
89
+ 'folder',
90
+ 'database',
91
+ 'circle',
92
+ 'edit',
93
+ 'edit-color',
94
+ 'box',
95
+ 'layer',
96
+ 'box-color',
97
+ 'home-color',
98
+ 'record',
99
+ 'monitor',
100
+ 'time-color',
101
+ 'user',
102
+ 'function-color',
103
+ 'record-color',
104
+ 'warning-color',
105
+ 'layer-color',
106
+ 'template',
107
+ 'template-color',
108
+ 'monitor-color',
109
+ 'search',
110
+ 'user-color',
111
+ 'function',
112
+ 'warning',
113
+ 'search-color',
114
+ 'home',
115
+ 'time',
116
+ 'application',
117
+ 'plus',
118
+ 'minus'
119
+ ];
package/lib/Icon/index.js CHANGED
@@ -1,46 +1,14 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "iconList", {
7
- enumerable: true,
8
- get: function get() {
9
- return _iconList["default"];
10
- }
11
- });
12
- exports["default"] = void 0;
13
-
14
- require("./fonts/iconfont");
15
-
16
- require("./index.less");
17
-
18
- var _iconList = _interopRequireDefault(require("./iconList"));
19
-
20
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
21
-
22
- function _extends() { _extends = Object.assign || 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); }
23
-
24
- 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; }
25
-
26
- 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; }
27
-
28
- var _default = function _default(_ref) {
29
- var type = _ref.type,
30
- _ref$prefix = _ref.prefix,
31
- prefix = _ref$prefix === void 0 ? 'tnt-' : _ref$prefix,
32
- _ref$className = _ref.className,
33
- className = _ref$className === void 0 ? '' : _ref$className,
34
- props = _objectWithoutProperties(_ref, ["type", "prefix", "className"]);
35
-
36
- return React.createElement("i", _extends({
37
- className: "tnt-icon ".concat(className),
38
- type: type
39
- }, props), React.createElement("svg", {
40
- "aria-hidden": "true"
41
- }, React.createElement("use", {
42
- xlinkHref: "#".concat(prefix).concat(type)
43
- })));
1
+ import './fonts/iconfont';
2
+ import './index.less';
3
+
4
+ export { default as iconList } from './iconList';
5
+
6
+ export default ({ type, prefix = 'tnt-', className = '', ...props }) => {
7
+ return (
8
+ <i className={`tnt-icon ${className}`} type={type} {...props}>
9
+ <svg aria-hidden="true">
10
+ <use xlinkHref={`#${prefix}${type}`} />
11
+ </svg>
12
+ </i>
13
+ );
44
14
  };
45
-
46
- exports["default"] = _default;
@@ -1,82 +1,50 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = void 0;
7
-
8
- var _react = _interopRequireDefault(require("react"));
9
-
10
- var _classnames = _interopRequireDefault(require("classnames"));
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
13
-
14
- function _extends() { _extends = Object.assign || 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); }
15
-
16
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
17
-
18
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
19
-
20
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
21
-
22
- 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; }
23
-
24
- 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; }
25
-
26
- var _default = function _default(props) {
27
- var alt = props.alt,
28
- title = props.title,
29
- src = props.src,
30
- width = props.width,
31
- height = props.height,
32
- _props$style = props.style,
33
- style = _props$style === void 0 ? {} : _props$style,
34
- className = props.className,
35
- onError = props.onError,
36
- shape = props.shape,
37
- errorImgSrc = props.errorImgSrc,
38
- type = props.type,
39
- others = _objectWithoutProperties(props, ["alt", "title", "src", "width", "height", "style", "className", "onError", "shape", "errorImgSrc", "type"]);
40
-
41
- var styles = _objectSpread({}, style, {
42
- display: 'inline-block',
43
- width: width,
44
- height: height,
45
- overflow: 'hidden'
46
- });
47
-
48
- if (shape === 'rounded') {
49
- styles.borderRadius = '5px';
50
- } else if (shape === 'circle') {
51
- styles.borderRadius = '50%';
52
- }
53
-
54
- var centerStyles = {
55
- width: width,
56
- height: height,
57
- display: 'table-cell',
58
- verticalAlign: 'middle',
59
- textAlign: 'center'
60
- };
61
- var imgStyles = {
62
- width: 'auto',
63
- height: 'auto',
64
- maxWidth: width,
65
- maxHeight: height
66
- };
67
- var cls = (0, _classnames["default"])('tntd-img', shape, className);
68
- return _react["default"].createElement("div", _extends({
69
- className: cls,
70
- style: styles
71
- }, others), _react["default"].createElement("div", {
72
- style: centerStyles
73
- }, _react["default"].createElement("img", {
74
- style: imgStyles,
75
- onError: onError,
76
- src: src,
77
- alt: alt,
78
- title: title
79
- })));
1
+ import React from 'react';
2
+ import classnames from 'classnames';
3
+
4
+ export default props => {
5
+ const { alt, title, src, width, height, style = {}, className, onError, shape, errorImgSrc, type, ...others } = props;
6
+
7
+ const styles = {
8
+ ...style,
9
+ display: 'inline-block',
10
+ width,
11
+ height,
12
+ overflow: 'hidden',
13
+ };
14
+ if (shape === 'rounded') {
15
+ styles.borderRadius = '5px';
16
+ } else if (shape === 'circle') {
17
+ styles.borderRadius = '50%';
18
+ }
19
+
20
+ const centerStyles = {
21
+ width,
22
+ height,
23
+ display: 'table-cell',
24
+ verticalAlign: 'middle',
25
+ textAlign: 'center',
26
+ };
27
+
28
+ const imgStyles = {
29
+ width: 'auto',
30
+ height: 'auto',
31
+ maxWidth: width,
32
+ maxHeight: height,
33
+ };
34
+
35
+ const cls = classnames('tntd-img', shape, className);
36
+
37
+ return (
38
+ <div className={cls} style={styles} {...others}>
39
+ <div style={centerStyles}>
40
+ <img
41
+ style={imgStyles}
42
+ onError={onError}
43
+ src={src}
44
+ alt={alt}
45
+ title={title}
46
+ />
47
+ </div>
48
+ </div>
49
+ );
80
50
  };
81
-
82
- exports["default"] = _default;
package/lib/Img/Cover.js CHANGED
@@ -1,144 +1,96 @@
1
- "use strict";
2
-
3
- function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports["default"] = void 0;
9
-
10
- var _react = _interopRequireWildcard(require("react"));
11
-
12
- var _classnames = _interopRequireDefault(require("classnames"));
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
15
-
16
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
17
-
18
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
19
-
20
- function _extends() { _extends = Object.assign || 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); }
21
-
22
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
23
-
24
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
25
-
26
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
27
-
28
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
29
-
30
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
31
-
32
- function _iterableToArrayLimit(arr, i) { if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { return; } var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
33
-
34
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
35
-
36
- 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; }
37
-
38
- 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; }
39
-
40
- var _default = function _default(props) {
41
- var alt = props.alt,
42
- title = props.title,
43
- src = props.src,
44
- width = props.width,
45
- height = props.height,
46
- _props$style = props.style,
47
- style = _props$style === void 0 ? {} : _props$style,
48
- className = props.className,
49
- onError = props.onError,
50
- shape = props.shape,
51
- errorImgSrc = props.errorImgSrc,
52
- type = props.type,
53
- others = _objectWithoutProperties(props, ["alt", "title", "src", "width", "height", "style", "className", "onError", "shape", "errorImgSrc", "type"]);
1
+ import React from 'react';
2
+ import { useEffect, useState, useRef } from 'react';
3
+ import classnames from 'classnames';
4
+
5
+ export default props => {
6
+ const { alt, title, src, width, height, style = {}, className, onError, shape, errorImgSrc, type, ...others } = props;
7
+ const imgRef = useRef();
8
+ const [imgStyles, setImgStyles] = useState({
9
+ display: 'block',
10
+ maxWidth: 'none',
11
+ width: 'auto',
12
+ height: 'auto',
13
+ // transition: 'opacity 0.2s ease',
14
+ opacity: 0,
15
+ });
16
+
17
+ const getStyles = (wrapWidth, wrapHeight, imgWidth, imgHeight) => {
18
+ // 进行等比运算
19
+ const wrapRatio = wrapWidth / wrapHeight;
20
+ const imgRatio = imgWidth / imgHeight;
21
+
22
+ let finalWidth = 0;
23
+ let finalHeight = 0;
24
+ let finalMarginTop = 0;
25
+ let finalMarginLeft = 0;
26
+
27
+ if (wrapRatio > imgRatio) {
28
+ // 父框宽度更大,以父框的宽度为准,拉伸图片上移
29
+ finalWidth = wrapWidth;
30
+ finalHeight = finalWidth / imgRatio;
31
+ finalMarginTop = ((finalHeight - wrapHeight) / 2) * -1;
32
+ } else {
33
+ // 父框高度更大,以父框高度为准,拉伸图片左移动
34
+ finalHeight = wrapHeight;
35
+ finalWidth = finalHeight * imgRatio;
36
+ finalMarginLeft = ((finalWidth - wrapWidth) / 2) * -1;
37
+ }
38
+
39
+ return {
40
+ height: finalHeight,
41
+ width: finalWidth,
42
+ marginLeft: finalMarginLeft,
43
+ marginTop: finalMarginTop,
44
+ };
45
+ };
54
46
 
55
- var imgRef = (0, _react.useRef)();
47
+ const imgOnload = () => {
48
+ const imgDOM = imgRef.current;
49
+ const { width, height } = props;
50
+ const imgWidth = imgDOM.width;
51
+ const imgHeight = imgDOM.height;
52
+
53
+ const imgStyles2 = getStyles(width, height, imgWidth, imgHeight);
54
+ setImgStyles({
55
+ ...imgStyles,
56
+ ...imgStyles2,
57
+ opacity: 1,
58
+ });
59
+ };
56
60
 
57
- var _useState = (0, _react.useState)({
58
- display: 'block',
59
- maxWidth: 'none',
60
- width: 'auto',
61
- height: 'auto',
62
- // transition: 'opacity 0.2s ease',
63
- opacity: 0
64
- }),
65
- _useState2 = _slicedToArray(_useState, 2),
66
- imgStyles = _useState2[0],
67
- setImgStyles = _useState2[1];
61
+ useEffect(() => {
62
+ if (width || height) {
63
+ imgOnload();
64
+ }
65
+ }, [width, height]);
68
66
 
69
- var getStyles = function getStyles(wrapWidth, wrapHeight, imgWidth, imgHeight) {
70
- // 进行等比运算
71
- var wrapRatio = wrapWidth / wrapHeight;
72
- var imgRatio = imgWidth / imgHeight;
73
- var finalWidth = 0;
74
- var finalHeight = 0;
75
- var finalMarginTop = 0;
76
- var finalMarginLeft = 0;
77
67
 
78
- if (wrapRatio > imgRatio) {
79
- // 父框宽度更大,以父框的宽度为准,拉伸图片上移
80
- finalWidth = wrapWidth;
81
- finalHeight = finalWidth / imgRatio;
82
- finalMarginTop = (finalHeight - wrapHeight) / 2 * -1;
83
- } else {
84
- // 父框高度更大,以父框高度为准,拉伸图片左移动
85
- finalHeight = wrapHeight;
86
- finalWidth = finalHeight * imgRatio;
87
- finalMarginLeft = (finalWidth - wrapWidth) / 2 * -1;
88
- }
89
-
90
- return {
91
- height: finalHeight,
92
- width: finalWidth,
93
- marginLeft: finalMarginLeft,
94
- marginTop: finalMarginTop
68
+ const styles = {
69
+ ...style,
70
+ display: 'inline-block',
71
+ overflow: 'hidden',
72
+ width,
73
+ height,
95
74
  };
96
- };
97
-
98
- var imgOnload = function imgOnload() {
99
- var imgDOM = imgRef.current;
100
- var width = props.width,
101
- height = props.height;
102
- var imgWidth = imgDOM.width;
103
- var imgHeight = imgDOM.height;
104
- var imgStyles2 = getStyles(width, height, imgWidth, imgHeight);
105
- setImgStyles(_objectSpread({}, imgStyles, {}, imgStyles2, {
106
- opacity: 1
107
- }));
108
- };
109
-
110
- (0, _react.useEffect)(function () {
111
- if (width || height) {
112
- imgOnload();
75
+ if (shape === 'rounded') {
76
+ styles.borderRadius = '5px';
77
+ } else if (shape === 'circle') {
78
+ styles.borderRadius = '50%';
113
79
  }
114
- }, [width, height]);
115
80
 
116
- var styles = _objectSpread({}, style, {
117
- display: 'inline-block',
118
- overflow: 'hidden',
119
- width: width,
120
- height: height
121
- });
122
-
123
- if (shape === 'rounded') {
124
- styles.borderRadius = '5px';
125
- } else if (shape === 'circle') {
126
- styles.borderRadius = '50%';
127
- }
128
-
129
- var cls = (0, _classnames["default"])('tntd-img', shape, className);
130
- return _react["default"].createElement("div", _extends({
131
- className: cls,
132
- style: styles
133
- }, others), _react["default"].createElement("img", {
134
- style: imgStyles,
135
- onError: onError,
136
- ref: imgRef,
137
- src: src,
138
- alt: alt,
139
- title: title,
140
- onLoad: imgOnload
141
- }));
81
+ const cls = classnames('tntd-img', shape, className);
82
+
83
+ return (
84
+ <div className={cls} style={styles} {...others}>
85
+ <img
86
+ style={imgStyles}
87
+ onError={onError}
88
+ ref={imgRef}
89
+ src={src}
90
+ alt={alt}
91
+ title={title}
92
+ onLoad={imgOnload}
93
+ />
94
+ </div>
95
+ );
142
96
  };
143
-
144
- exports["default"] = _default;