ls-pro-common 1.0.53 → 1.0.56

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.
@@ -0,0 +1,22 @@
1
+ /// <reference types="react" />
2
+ import type { InputProps, ModalProps } from 'antd';
3
+ import type { ProFormItemProps } from 'ls-pro-form';
4
+ export declare type ImageSelectorProps = ProFormItemProps<InputProps> & {
5
+ /**对应后端的类,默认为RETAIL */
6
+ code?: string;
7
+ /** @name 分类(文件夹,eg:mdm,pms...) */
8
+ type: string;
9
+ /** @name 是否可上传,默认可上传 */
10
+ uploadable?: boolean;
11
+ /** @name 弹框title */
12
+ title?: string;
13
+ /** @name 弹框宽度 */
14
+ modalWidth?: string;
15
+ /**
16
+ * @name 最大值, 默认2M
17
+ */
18
+ maxSize?: number;
19
+ modalProps?: ModalProps;
20
+ };
21
+ declare function ImageSelector(prop: ImageSelectorProps): JSX.Element;
22
+ export default ImageSelector;
@@ -0,0 +1,337 @@
1
+ import "antd/es/modal/style";
2
+ import _Modal from "antd/es/modal";
3
+ import "antd/es/empty/style";
4
+ import _Empty from "antd/es/empty";
5
+ import "antd/es/card/style";
6
+ import _Card from "antd/es/card";
7
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
8
+ import "antd/es/upload/style";
9
+ import _Upload from "antd/es/upload";
10
+ import "antd/es/button/style";
11
+ import _Button from "antd/es/button";
12
+ import "antd/es/input/style";
13
+ import _Input from "antd/es/input";
14
+ import _extends from "@babel/runtime/helpers/esm/extends";
15
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
16
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
17
+ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
18
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
19
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
20
+ var _excluded = ["type", "uploadable", "readonly", "allowClear", "title", "modalWidth", "name", "maxSize", "modalProps", "code"];
21
+ import React from "react";
22
+ import { useMemo, useState, useEffect, useContext } from 'react';
23
+ import { ProFormText, ProFormContext } from 'ls-pro-form';
24
+ import { PlusOutlined, UploadOutlined, SearchOutlined } from '@ant-design/icons';
25
+ import { httpGet } from '../http';
26
+ import { getCache, showError, showWarn, showSuccess } from '../utils';
27
+ var fileCenter = getCache('ossPath') || '/petrel/petrel-file-center-api/lesoon/oss/file/';
28
+
29
+ function ImageSelector(prop) {
30
+ //@ts-ignore?
31
+ var _useContext = useContext(ProFormContext),
32
+ formRef = _useContext.formRef;
33
+
34
+ var _useState = useState(false),
35
+ _useState2 = _slicedToArray(_useState, 2),
36
+ visible = _useState2[0],
37
+ setVisible = _useState2[1];
38
+
39
+ var _useState3 = useState(''),
40
+ _useState4 = _slicedToArray(_useState3, 2),
41
+ imgUrl = _useState4[0],
42
+ setImgUrl = _useState4[1];
43
+
44
+ var _useState5 = useState([]),
45
+ _useState6 = _slicedToArray(_useState5, 2),
46
+ list = _useState6[0],
47
+ setList = _useState6[1];
48
+
49
+ var _useState7 = useState(''),
50
+ _useState8 = _slicedToArray(_useState7, 2),
51
+ searchKey = _useState8[0],
52
+ setSearchKey = _useState8[1];
53
+
54
+ var _useState9 = useState(''),
55
+ _useState10 = _slicedToArray(_useState9, 2),
56
+ nextMarker = _useState10[0],
57
+ setNextMarker = _useState10[1];
58
+
59
+ var type = prop.type,
60
+ _prop$uploadable = prop.uploadable,
61
+ uploadable = _prop$uploadable === void 0 ? true : _prop$uploadable,
62
+ _prop$readonly = prop.readonly,
63
+ readonly = _prop$readonly === void 0 ? true : _prop$readonly,
64
+ allowClear = prop.allowClear,
65
+ _prop$title = prop.title,
66
+ title = _prop$title === void 0 ? "选择图标" : _prop$title,
67
+ _prop$modalWidth = prop.modalWidth,
68
+ modalWidth = _prop$modalWidth === void 0 ? '600px' : _prop$modalWidth,
69
+ name = prop.name,
70
+ _prop$maxSize = prop.maxSize,
71
+ maxSize = _prop$maxSize === void 0 ? 5 : _prop$maxSize,
72
+ modalProps = prop.modalProps,
73
+ _prop$code = prop.code,
74
+ code = _prop$code === void 0 ? 'RETAIL' : _prop$code,
75
+ rest = _objectWithoutProperties(prop, _excluded); // 上传地址
76
+
77
+
78
+ var uploadImgApi = useMemo(function () {
79
+ return fileCenter + 'upload/' + code + '?catalogName=' + type;
80
+ }, [code, type]); // 分页加载列表地址
81
+
82
+ var pageImgApi = useMemo(function () {
83
+ return fileCenter + 'page/' + code;
84
+ }, [code]); // 展示地址
85
+
86
+ var showImgApi = useMemo(function () {
87
+ return fileCenter + 'show/' + code;
88
+ }, [code]);
89
+
90
+ var loadData = /*#__PURE__*/function () {
91
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(keys) {
92
+ var _result$data, _result$data2;
93
+
94
+ var url, param, result, rows;
95
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
96
+ while (1) {
97
+ switch (_context.prev = _context.next) {
98
+ case 0:
99
+ url = pageImgApi;
100
+ param = {
101
+ prefix: type,
102
+ maxKeys: 16
103
+ };
104
+
105
+ if (keys) {
106
+ param.prefix = param.prefix + '/' + keys;
107
+ }
108
+
109
+ if (nextMarker) {
110
+ param.nextMarker = nextMarker;
111
+ }
112
+
113
+ _context.next = 6;
114
+ return httpGet(url, param, false);
115
+
116
+ case 6:
117
+ result = _context.sent;
118
+ rows = (((_result$data = result.data) === null || _result$data === void 0 ? void 0 : _result$data.objectList) || []).filter(function (o) {
119
+ return o.dir == false && (!nextMarker || !list.find(function (e) {
120
+ return e.path === o.path;
121
+ }));
122
+ });
123
+ rows.forEach(function (row) {
124
+ row.url = showImgApi + '?fileName=' + row.path;
125
+ });
126
+
127
+ if (!nextMarker) {
128
+ setList(rows);
129
+ } else {
130
+ setList([].concat(_toConsumableArray(list), _toConsumableArray(rows)));
131
+ }
132
+
133
+ setNextMarker((_result$data2 = result.data) === null || _result$data2 === void 0 ? void 0 : _result$data2.nextMarker);
134
+
135
+ case 11:
136
+ case "end":
137
+ return _context.stop();
138
+ }
139
+ }
140
+ }, _callee);
141
+ }));
142
+
143
+ return function loadData(_x) {
144
+ return _ref.apply(this, arguments);
145
+ };
146
+ }();
147
+
148
+ useEffect(function () {
149
+ if (!visible) {
150
+ setNextMarker('');
151
+ setSearchKey('');
152
+ return;
153
+ }
154
+
155
+ loadData(searchKey);
156
+ }, [visible, searchKey]);
157
+ useEffect(function () {
158
+ var val = formRef.current.getFieldsValue();
159
+
160
+ if (val && val[name]) {
161
+ setImgUrl(val[name]);
162
+ }
163
+ }, []); // 验证上传文件大小
164
+
165
+ var beforeUpload = function beforeUpload(file) {
166
+ var sizeLimit = file.size / 1024 / 1024 >= maxSize;
167
+
168
+ if (sizeLimit) {
169
+ showError("\u4E0A\u4F20\u7684\u6587\u4EF6\u4E0D\u80FD\u5927\u4E8E".concat(maxSize, "M"));
170
+ }
171
+
172
+ return !sizeLimit;
173
+ }; // 上传图片
174
+
175
+
176
+ var onUpload = function onUpload(info) {
177
+ if (info.file.status === 'done') {
178
+ var _result$flag;
179
+
180
+ var result = info.file.response;
181
+
182
+ if ((result === null || result === void 0 ? void 0 : (_result$flag = result.flag) === null || _result$flag === void 0 ? void 0 : _result$flag.retCode) === '0') {
183
+ showSuccess(result.flag.retMsg);
184
+ } else {
185
+ var _result$flag2;
186
+
187
+ showError((result === null || result === void 0 ? void 0 : (_result$flag2 = result.flag) === null || _result$flag2 === void 0 ? void 0 : _result$flag2.retMsg) || '上传图片失败,请联系管理员');
188
+ }
189
+ } else if (info.file.status === 'error') {
190
+ showError('上传数据失败,请联系管理员');
191
+ }
192
+
193
+ if (!info.fileList.filter(function (o) {
194
+ return o.status === 'uploading';
195
+ }).length) {
196
+ loadData(searchKey);
197
+ }
198
+ };
199
+
200
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ProFormText, _extends({
201
+ name: name
202
+ }, rest), /*#__PURE__*/React.createElement(_Input, _extends({
203
+ addonAfter: imgUrl ? /*#__PURE__*/React.createElement("img", {
204
+ style: {
205
+ maxWidth: 22,
206
+ maxHeight: 22
207
+ },
208
+ src: imgUrl,
209
+ onClick: function onClick() {
210
+ return setVisible(true);
211
+ }
212
+ }) : /*#__PURE__*/React.createElement(PlusOutlined, {
213
+ onClick: function onClick() {
214
+ var _rest$fieldProps;
215
+
216
+ if ((rest === null || rest === void 0 ? void 0 : rest.disabled) || (rest === null || rest === void 0 ? void 0 : (_rest$fieldProps = rest.fieldProps) === null || _rest$fieldProps === void 0 ? void 0 : _rest$fieldProps.disabled)) {
217
+ return;
218
+ }
219
+
220
+ setVisible(true);
221
+ }
222
+ })
223
+ }, rest.fieldProps, {
224
+ readOnly: readonly,
225
+ allowClear: allowClear
226
+ }))), /*#__PURE__*/React.createElement(_Modal, _extends({
227
+ title: /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("span", null, title), /*#__PURE__*/React.createElement("span", {
228
+ style: {
229
+ display: 'inline-block',
230
+ width: 230,
231
+ marginLeft: 30
232
+ }
233
+ }, /*#__PURE__*/React.createElement(_Input, {
234
+ suffix: /*#__PURE__*/React.createElement(SearchOutlined, null),
235
+ placeholder: "\u8F93\u5165\u56FE\u7247\u540D\u67E5\u8BE2",
236
+ onPressEnter: function onPressEnter(e) {
237
+ setNextMarker('');
238
+ setTimeout(function () {
239
+ setSearchKey(e.target.value || '');
240
+ }, 1);
241
+ }
242
+ }))),
243
+ visible: visible,
244
+ width: modalWidth,
245
+ destroyOnClose: true,
246
+ onCancel: function onCancel() {
247
+ return setVisible(false);
248
+ },
249
+ bodyStyle: {
250
+ padding: 8
251
+ },
252
+ footer: /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("span", {
253
+ style: {
254
+ display: 'inline-block',
255
+ marginRight: 8
256
+ }
257
+ }, /*#__PURE__*/React.createElement(_Upload, {
258
+ beforeUpload: beforeUpload,
259
+ onChange: onUpload,
260
+ action: uploadImgApi,
261
+ showUploadList: false,
262
+ name: "file",
263
+ maxCount: 20,
264
+ multiple: true,
265
+ headers: {
266
+ token: localStorage.getItem('token') || ''
267
+ },
268
+ accept: ".png,.gif,.jpg,.jpeg,.bmp"
269
+ }, /*#__PURE__*/React.createElement(_Button, {
270
+ icon: /*#__PURE__*/React.createElement(UploadOutlined, null)
271
+ }, "\u4E0A\u4F20\u65B0\u56FE"))), /*#__PURE__*/React.createElement(_Button, {
272
+ onClick: function onClick() {
273
+ return loadData(searchKey);
274
+ }
275
+ }, nextMarker ? '加载更多' : '刷新')),
276
+ getContainer: function getContainer() {
277
+ return document.body;
278
+ }
279
+ }, modalProps), /*#__PURE__*/React.createElement("div", {
280
+ style: {
281
+ minHeight: '120px'
282
+ }
283
+ }, list.map(function (o) {
284
+ return /*#__PURE__*/React.createElement(_Card, {
285
+ hoverable: true,
286
+ style: {
287
+ width: '125px',
288
+ height: '130px',
289
+ display: 'inline-block',
290
+ margin: '10px',
291
+ verticalAlign: 'middle'
292
+ },
293
+ bodyStyle: {
294
+ padding: '15px 8px',
295
+ textAlign: 'center'
296
+ },
297
+ onDoubleClick: function onDoubleClick() {
298
+ if (!name) {
299
+ showWarn('选择图标组件未设置name属性');
300
+ return;
301
+ }
302
+
303
+ var formVal = formRef.current.getFieldsValue();
304
+
305
+ var val = _objectSpread({}, formVal); //@ts-ignore
306
+
307
+
308
+ val[name] = o.url;
309
+ formRef.current.setFieldsValue(val);
310
+ setImgUrl(o.url);
311
+ setVisible(false);
312
+ },
313
+ key: o.path
314
+ }, /*#__PURE__*/React.createElement("div", {
315
+ style: {
316
+ height: 80
317
+ }
318
+ }, /*#__PURE__*/React.createElement("img", {
319
+ title: o.name,
320
+ style: {
321
+ maxWidth: '80px',
322
+ maxHeight: '80px'
323
+ },
324
+ src: showImgApi + '?fileName=' + o.path
325
+ })), /*#__PURE__*/React.createElement("div", {
326
+ style: {
327
+ whiteSpace: 'nowrap',
328
+ textOverflow: 'ellipsis',
329
+ overflow: 'hidden'
330
+ }
331
+ }, o.name));
332
+ }), list.length === 0 && /*#__PURE__*/React.createElement(_Empty, {
333
+ image: _Empty.PRESENTED_IMAGE_SIMPLE
334
+ }))));
335
+ }
336
+
337
+ export default ImageSelector;
@@ -50,7 +50,7 @@ var InputMultiLine = /*#__PURE__*/React.forwardRef(function (prop, ref) {
50
50
  allowClear = _prop$allowClear === void 0 ? true : _prop$allowClear,
51
51
  _prop$getPopupContain = prop.getPopupContainer,
52
52
  getPopupContainer = _prop$getPopupContain === void 0 ? function (triggerNode) {
53
- return triggerNode.parentNode;
53
+ return document.body;
54
54
  } : _prop$getPopupContain,
55
55
  rest = _objectWithoutProperties(prop, _excluded); // 设置初始值
56
56
 
@@ -79,7 +79,7 @@ var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
79
79
  triggerCheck = _prop$triggerCheck === void 0 ? 'entry' : _prop$triggerCheck,
80
80
  _prop$getPopupContain = prop.getPopupContainer,
81
81
  getPopupContainer = _prop$getPopupContain === void 0 ? function (triggerNode) {
82
- return triggerNode.parentNode;
82
+ return document.body;
83
83
  } : _prop$getPopupContain,
84
84
  rest = _objectWithoutProperties(prop, _excluded); //显示输入框绑定的name,如果不设置textName,设置为$name__text
85
85
 
package/es/index.d.ts CHANGED
@@ -3,6 +3,7 @@ import InputTable from './components/InputTable';
3
3
  import Page404 from './components/404';
4
4
  import Loading from './components/Loading';
5
5
  import IconSelector from './components/IconSelector';
6
+ import ImageSelector from './components/ImageSelector';
6
7
  import InputMultiLine from './components/InputMultiLine';
7
8
  import AreaCascader from './components/AreaCascader';
8
9
  import BaseService from './service/BaseService';
@@ -16,4 +17,4 @@ import usePermission from './hooks/usePermission';
16
17
  import type { ApiResponse, TableToolbar, BaseApiType, MethodType } from './typing';
17
18
  import type { DtlLyaoutProps } from './components/DtlLayout';
18
19
  export type { ApiResponse, TableToolbar, BaseApiType, MethodType, DtlLyaoutProps };
19
- export { DtlLayout, InputTable, Page404, Loading, IconSelector, InputMultiLine, AreaCascader, BaseService, request, httpDelete, httpGet, httpPost, httpPut, getDict, fetchOptions, utils, useSingle, useDtl, usePermission };
20
+ export { DtlLayout, InputTable, Page404, Loading, IconSelector, ImageSelector, InputMultiLine, AreaCascader, BaseService, request, httpDelete, httpGet, httpPost, httpPut, getDict, fetchOptions, utils, useSingle, useDtl, usePermission };
package/es/index.js CHANGED
@@ -3,6 +3,7 @@ import InputTable from './components/InputTable';
3
3
  import Page404 from './components/404';
4
4
  import Loading from './components/Loading';
5
5
  import IconSelector from './components/IconSelector';
6
+ import ImageSelector from './components/ImageSelector';
6
7
  import InputMultiLine from './components/InputMultiLine';
7
8
  import AreaCascader from './components/AreaCascader';
8
9
  import BaseService from './service/BaseService';
@@ -13,4 +14,4 @@ import * as utils from './utils';
13
14
  import useSingle from './hooks/useSingle';
14
15
  import useDtl from './hooks/useDtl';
15
16
  import usePermission from './hooks/usePermission';
16
- export { DtlLayout, InputTable, Page404, Loading, IconSelector, InputMultiLine, AreaCascader, BaseService, request, httpDelete, httpGet, httpPost, httpPut, getDict, fetchOptions, utils, useSingle, useDtl, usePermission };
17
+ export { DtlLayout, InputTable, Page404, Loading, IconSelector, ImageSelector, InputMultiLine, AreaCascader, BaseService, request, httpDelete, httpGet, httpPost, httpPut, getDict, fetchOptions, utils, useSingle, useDtl, usePermission };
@@ -1,4 +1,4 @@
1
- export { getUrlQuery, setUrlQuery, toGatewayUrl, dateFormat, getResourceProps } from 'ls-pro-table/lib/utils';
1
+ export { getUrlQuery, setUrlQuery, toGatewayUrl, dateFormat, getResourceProps } from 'ls-pro-table';
2
2
  /**
3
3
  * 设置文档title
4
4
  * @param {*} title
package/es/utils/index.js CHANGED
@@ -6,8 +6,8 @@ import _message from "antd/es/message";
6
6
  import _typeof from "@babel/runtime/helpers/esm/typeof";
7
7
  import React from "react";
8
8
  import { QuestionCircleOutlined } from '@ant-design/icons';
9
- import { dateFormat } from "ls-pro-table/es/utils";
10
- export { getUrlQuery, setUrlQuery, toGatewayUrl, dateFormat, getResourceProps } from "ls-pro-table/es/utils";
9
+ import { dateFormat } from 'ls-pro-table';
10
+ export { getUrlQuery, setUrlQuery, toGatewayUrl, dateFormat, getResourceProps } from 'ls-pro-table';
11
11
  /**
12
12
  * 设置文档title
13
13
  * @param {*} title
@@ -0,0 +1,22 @@
1
+ /// <reference types="react" />
2
+ import type { InputProps, ModalProps } from 'antd';
3
+ import type { ProFormItemProps } from 'ls-pro-form';
4
+ export declare type ImageSelectorProps = ProFormItemProps<InputProps> & {
5
+ /**对应后端的类,默认为RETAIL */
6
+ code?: string;
7
+ /** @name 分类(文件夹,eg:mdm,pms...) */
8
+ type: string;
9
+ /** @name 是否可上传,默认可上传 */
10
+ uploadable?: boolean;
11
+ /** @name 弹框title */
12
+ title?: string;
13
+ /** @name 弹框宽度 */
14
+ modalWidth?: string;
15
+ /**
16
+ * @name 最大值, 默认2M
17
+ */
18
+ maxSize?: number;
19
+ modalProps?: ModalProps;
20
+ };
21
+ declare function ImageSelector(prop: ImageSelectorProps): JSX.Element;
22
+ export default ImageSelector;