ls-pro-common 1.0.61 → 1.0.63

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 (47) hide show
  1. package/CHANGELOG.md +746 -746
  2. package/README.md +22 -22
  3. package/dist/common.css +101 -22
  4. package/dist/common.js +1 -1
  5. package/dist/common.min.css +101 -22
  6. package/dist/common.min.js +1 -1
  7. package/es/components/IconSelector.d.ts +2 -8
  8. package/es/components/IconSelector.js +114 -207
  9. package/es/components/ImageSelector.d.ts +3 -0
  10. package/es/components/ImageSelector.js +128 -24
  11. package/es/components/InputMultiLine.js +1 -1
  12. package/es/components/InputTable.d.ts +5 -0
  13. package/es/components/InputTable.js +26 -4
  14. package/es/components/common.less +176 -119
  15. package/es/hooks/useDtl/index.d.ts +13 -0
  16. package/es/hooks/useDtl/index.js +388 -235
  17. package/es/hooks/usePermission/index.d.ts +1 -0
  18. package/es/hooks/usePermission/index.js +23 -1
  19. package/es/hooks/useSingle/index.d.ts +1 -0
  20. package/es/hooks/useSingle/index.js +3 -1
  21. package/es/http/index.js +27 -8
  22. package/es/service/BaseService.d.ts +8 -0
  23. package/es/service/BaseService.js +69 -26
  24. package/es/typing.d.ts +4 -0
  25. package/es/utils/index.d.ts +49 -0
  26. package/es/utils/index.js +142 -1
  27. package/lib/components/IconSelector.d.ts +2 -8
  28. package/lib/components/IconSelector.js +112 -214
  29. package/lib/components/ImageSelector.d.ts +3 -0
  30. package/lib/components/ImageSelector.js +125 -24
  31. package/lib/components/InputMultiLine.js +1 -1
  32. package/lib/components/InputTable.d.ts +5 -0
  33. package/lib/components/InputTable.js +26 -4
  34. package/lib/components/common.less +176 -119
  35. package/lib/hooks/useDtl/index.d.ts +13 -0
  36. package/lib/hooks/useDtl/index.js +388 -235
  37. package/lib/hooks/usePermission/index.d.ts +1 -0
  38. package/lib/hooks/usePermission/index.js +23 -0
  39. package/lib/hooks/useSingle/index.d.ts +1 -0
  40. package/lib/hooks/useSingle/index.js +3 -1
  41. package/lib/http/index.js +25 -7
  42. package/lib/service/BaseService.d.ts +8 -0
  43. package/lib/service/BaseService.js +69 -26
  44. package/lib/typing.d.ts +4 -0
  45. package/lib/utils/index.d.ts +49 -0
  46. package/lib/utils/index.js +163 -3
  47. package/package.json +2 -2
@@ -2,18 +2,12 @@
2
2
  import type { InputProps, ModalProps } from 'antd';
3
3
  import type { ProFormItemProps } from 'ls-pro-form';
4
4
  export declare type IconSelectorProps = ProFormItemProps<InputProps> & {
5
- /** @name 图标类型 */
6
- type: string;
7
- /** @name 是否可上传,默认可上传 */
8
- uploadable?: boolean;
9
5
  /** @name 弹框title */
10
6
  title?: string;
7
+ defaultValue?: string;
8
+ isInput?: boolean;
11
9
  /** @name 弹框宽度 */
12
10
  modalWidth?: string;
13
- /**
14
- * @name 最大值, 默认2M
15
- */
16
- maxSize?: number;
17
11
  modalProps?: ModalProps;
18
12
  };
19
13
  declare function IconSelector(prop: IconSelectorProps): JSX.Element;
@@ -2,27 +2,20 @@ import "antd/es/modal/style";
2
2
  import _Modal from "antd/es/modal";
3
3
  import "antd/es/card/style";
4
4
  import _Card from "antd/es/card";
5
- import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
6
- import "antd/es/upload/style";
7
- import _Upload from "antd/es/upload";
8
5
  import "antd/es/button/style";
9
6
  import _Button from "antd/es/button";
10
7
  import "antd/es/input/style";
11
8
  import _Input from "antd/es/input";
12
9
  import _extends from "@babel/runtime/helpers/esm/extends";
13
- import _regeneratorRuntime from "@babel/runtime/regenerator";
14
- import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
10
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
15
11
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
16
12
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
17
- var _excluded = ["type", "uploadable", "readonly", "allowClear", "title", "modalWidth", "name", "maxSize", "modalProps"];
13
+ var _excluded = ["readonly", "allowClear", "title", "modalWidth", "name", "isInput", "modalProps", "defaultValue"];
18
14
  import React from "react";
19
- import { useMemo, useState, useEffect, useContext } from 'react';
15
+ import { useMemo, useState, useContext, useEffect, useRef } from 'react';
20
16
  import { ProFormText, ProFormContext } from 'ls-pro-form';
21
- import { PlusOutlined, UploadOutlined, SearchOutlined } from '@ant-design/icons';
22
- import { httpGet, httpPost } from '../http';
23
- import { getCache, toGatewayUrl, showError, showWarn, showSuccess } from '../utils';
24
- var fileCenter = getCache('file-center-api') || '/zuul/petrel-file-center-api/';
25
- var pageSize = 16;
17
+ import { PlusOutlined, SearchOutlined } from '@ant-design/icons';
18
+ var iconList = ['icon-Menu1', 'icon-Menu2', 'icon-Menu3', 'icon-Menu4', 'icon-Menu5', 'icon-Menu6', 'icon-Menu7', 'icon-Menu8', 'icon-Menu9', 'icon-Menu10', 'icon-Menu11', 'icon-Menu12', 'icon-Menu13', 'icon-Menu14', 'icon-Menu15', 'icon-Menu16', 'icon-Menu17', 'icon-Menu18', 'icon-Menu19', 'icon-Menu20', 'icon-Menu21', 'icon-Menu22', 'icon-Menu23', 'icon-Menu24', 'icon-Menu25', 'icon-Menu26', 'icon-Menu27', 'icon-Menu28', 'icon-Menu29', 'icon-Menu30', 'icon-Menu31', 'icon-Menu32', 'icon-Menu33', 'icon-Menu34', 'icon-Menu35', 'icon-Menu36', 'icon-Menu37', 'icon-Menu38', 'icon-Menu39', 'icon-Menu40', 'icon-Menu41', 'icon-Menu42', 'icon-Menu43', 'icon-Menu44', 'icon-Menu45', 'icon-Menu46', 'icon-Menu47'];
26
19
 
27
20
  function IconSelector(prop) {
28
21
  //@ts-ignore?
@@ -36,186 +29,125 @@ function IconSelector(prop) {
36
29
 
37
30
  var _useState3 = useState(''),
38
31
  _useState4 = _slicedToArray(_useState3, 2),
39
- imgUrl = _useState4[0],
40
- setImgUrl = _useState4[1];
32
+ icon = _useState4[0],
33
+ setIcon = _useState4[1];
41
34
 
42
- var _useState5 = useState(1),
35
+ var _useState5 = useState(''),
43
36
  _useState6 = _slicedToArray(_useState5, 2),
44
- page = _useState6[0],
45
- setPage = _useState6[1];
46
-
47
- var _useState7 = useState(0),
48
- _useState8 = _slicedToArray(_useState7, 2),
49
- total = _useState8[0],
50
- setTotal = _useState8[1];
51
-
52
- var _useState9 = useState([]),
53
- _useState10 = _slicedToArray(_useState9, 2),
54
- list = _useState10[0],
55
- setList = _useState10[1];
56
-
57
- var _useState11 = useState(''),
58
- _useState12 = _slicedToArray(_useState11, 2),
59
- searchKey = _useState12[0],
60
- setSearchKey = _useState12[1];
61
-
62
- var type = prop.type,
63
- _prop$uploadable = prop.uploadable,
64
- uploadable = _prop$uploadable === void 0 ? true : _prop$uploadable,
65
- _prop$readonly = prop.readonly,
37
+ searchKey = _useState6[0],
38
+ setSearchKey = _useState6[1];
39
+
40
+ var inputRef = useRef();
41
+ var list = useMemo(function () {
42
+ if (!searchKey) return [].concat(iconList);
43
+ return iconList.filter(function (o) {
44
+ return o.includes(searchKey);
45
+ });
46
+ }, [searchKey]);
47
+
48
+ var _prop$readonly = prop.readonly,
66
49
  readonly = _prop$readonly === void 0 ? true : _prop$readonly,
67
- allowClear = prop.allowClear,
50
+ _prop$allowClear = prop.allowClear,
51
+ allowClear = _prop$allowClear === void 0 ? true : _prop$allowClear,
68
52
  _prop$title = prop.title,
69
53
  title = _prop$title === void 0 ? "选择图标" : _prop$title,
70
54
  _prop$modalWidth = prop.modalWidth,
71
- modalWidth = _prop$modalWidth === void 0 ? '600px' : _prop$modalWidth,
55
+ modalWidth = _prop$modalWidth === void 0 ? '630px' : _prop$modalWidth,
72
56
  name = prop.name,
73
- _prop$maxSize = prop.maxSize,
74
- maxSize = _prop$maxSize === void 0 ? 2 : _prop$maxSize,
57
+ _prop$isInput = prop.isInput,
58
+ isInput = _prop$isInput === void 0 ? true : _prop$isInput,
75
59
  modalProps = prop.modalProps,
60
+ defaultValue = prop.defaultValue,
76
61
  rest = _objectWithoutProperties(prop, _excluded);
77
62
 
78
- var uploadImgApi = useMemo(function () {
79
- return toGatewayUrl(fileCenter + 'file/upload/' + type);
80
- }, [type]);
81
- var showImgApi = useMemo(function () {
82
- return fileCenter + 'file/show/' + type;
83
- }, [type]);
84
-
85
- var loadData = /*#__PURE__*/function () {
86
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(pageIndex, keys) {
87
- var url, param, result, rows;
88
- return _regeneratorRuntime.wrap(function _callee$(_context) {
89
- while (1) {
90
- switch (_context.prev = _context.next) {
91
- case 0:
92
- url = "/petrel-itg-api/sysMongo/page";
93
- param = {
94
- "search.status": 1,
95
- "search.collectName": type,
96
- "page.pn": pageIndex,
97
- "page.size": pageSize
98
- };
99
-
100
- if (keys) {
101
- param['search.mongoName_like'] = keys;
102
- }
103
-
104
- _context.next = 5;
105
- return httpGet(url, param);
106
-
107
- case 5:
108
- result = _context.sent;
109
- rows = result.rows || [];
110
- setList(rows);
111
- setTotal(result.total || 0);
112
-
113
- case 9:
114
- case "end":
115
- return _context.stop();
116
- }
117
- }
118
- }, _callee);
119
- }));
120
-
121
- return function loadData(_x, _x2) {
122
- return _ref.apply(this, arguments);
123
- };
124
- }();
125
-
126
63
  useEffect(function () {
127
- if (!visible) return;
128
- loadData(page, searchKey);
129
- }, [visible, page, searchKey]);
130
- var totalPage = useMemo(function () {
131
- if (total === 0) return 1;
132
- return Math.ceil(total / pageSize);
133
- }, [total]);
134
- useEffect(function () {
135
- var val = formRef.current.getFieldsValue();
64
+ var _formRef$current;
65
+
66
+ var val = (_formRef$current = formRef.current) === null || _formRef$current === void 0 ? void 0 : _formRef$current.getFieldsValue();
136
67
 
137
68
  if (val && val[name]) {
138
- setImgUrl(toGatewayUrl(val[name]));
69
+ setIcon(val[name]);
139
70
  }
140
- }, []); // 验证上传文件大小
141
-
142
- var beforeUpload = function beforeUpload(file) {
143
- var sizeLimit = file.size / 1024 / 1024 >= maxSize;
144
-
145
- if (sizeLimit) {
146
- showError("\u4E0A\u4F20\u7684\u6587\u4EF6\u4E0D\u80FD\u5927\u4E8E".concat(maxSize, "M"));
71
+ }, []);
72
+ useEffect(function () {
73
+ if (defaultValue) {
74
+ setIcon(defaultValue);
147
75
  }
76
+ }, [defaultValue]);
77
+ useEffect(function () {
78
+ var _rest$fieldProps;
148
79
 
149
- return !sizeLimit;
150
- }; // 上传图片并调用 sysMongo 接口保存
80
+ 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)) return;
151
81
 
82
+ try {
83
+ if (!inputRef.current) return;
84
+ var el = inputRef.current.clearableInput.containerRef.current.querySelector('.ant-input-clear-icon');
85
+ if (!el) return;
152
86
 
153
- var onUpload = function onUpload(info) {
154
- if (info.file.status === 'done') {
155
- var _result$flag;
87
+ if (icon) {
88
+ el.classList.remove('ant-input-clear-icon-hidden');
89
+ } else {
90
+ el.classList.add('ant-input-clear-icon-hidden');
91
+ }
92
+ } catch (e) {}
93
+ }, [icon]);
156
94
 
157
- var result = info.file.response;
95
+ var showSelector = function showSelector(flag) {
96
+ var _rest$fieldProps2;
158
97
 
159
- if ((result === null || result === void 0 ? void 0 : (_result$flag = result.flag) === null || _result$flag === void 0 ? void 0 : _result$flag.retCode) === '0') {
160
- var f = result.data[0];
161
- var data = {
162
- collectName: type,
163
- mongoUrl: showImgApi + "/" + f.fileId,
164
- mongoName: f.fileName || "",
165
- remarks: "",
166
- status: 1
167
- };
168
- var url = "/petrel/petrel-itg-api/sysMongo";
169
- httpPost(url, data, true, false).then(function (res) {
170
- if (res.flag.retCode === "0") {
171
- showSuccess("上传成功");
98
+ if ((rest === null || rest === void 0 ? void 0 : rest.disabled) || (rest === null || rest === void 0 ? void 0 : (_rest$fieldProps2 = rest.fieldProps) === null || _rest$fieldProps2 === void 0 ? void 0 : _rest$fieldProps2.disabled)) return;
99
+ setVisible(flag);
100
+ };
172
101
 
173
- if (page !== totalPage) {
174
- setPage(totalPage);
175
- } else {
176
- loadData(totalPage, searchKey);
177
- }
178
- } else {
179
- showSuccess(result.flag.retMsg);
180
- }
181
- });
182
- } else {
183
- var _result$flag2;
102
+ var clearValue = function clearValue(e) {
103
+ if (!e || !e.target.value) {
104
+ var _formRef$current2;
184
105
 
185
- showError((result === null || result === void 0 ? void 0 : (_result$flag2 = result.flag) === null || _result$flag2 === void 0 ? void 0 : _result$flag2.retMsg) || '上传图片失败,请联系管理员');
186
- }
187
- } else if (info.file.status === 'error') {
188
- showError('上传数据失败,请联系管理员');
106
+ setIcon('');
107
+ var formValue = formRef === null || formRef === void 0 ? void 0 : (_formRef$current2 = formRef.current) === null || _formRef$current2 === void 0 ? void 0 : _formRef$current2.getFieldsValue();
108
+ formValue[name] = '';
109
+ formRef.current.setFieldsValue(_objectSpread({}, formValue));
189
110
  }
190
111
  };
191
112
 
192
113
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ProFormText, _extends({
193
114
  name: name
194
- }, rest), /*#__PURE__*/React.createElement(_Input, _extends({
195
- addonAfter: imgUrl ? /*#__PURE__*/React.createElement("img", {
115
+ }, rest), isInput ? /*#__PURE__*/React.createElement(_Input, _extends({
116
+ addonAfter: icon ? /*#__PURE__*/React.createElement("span", {
196
117
  style: {
197
- maxWidth: 22,
198
- maxHeight: 22
118
+ fontSize: '14px'
199
119
  },
200
- src: imgUrl,
120
+ className: icon,
121
+ title: title,
201
122
  onClick: function onClick() {
202
- return setVisible(true);
123
+ return showSelector(true);
203
124
  }
204
125
  }) : /*#__PURE__*/React.createElement(PlusOutlined, {
126
+ title: title,
205
127
  onClick: function onClick() {
206
- var _rest$fieldProps;
207
-
208
- 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)) {
209
- return;
210
- }
211
-
212
- setVisible(true);
128
+ return showSelector(true);
213
129
  }
214
130
  })
215
131
  }, rest.fieldProps, {
216
132
  readOnly: readonly,
217
- allowClear: allowClear
218
- }))), /*#__PURE__*/React.createElement(_Modal, _extends({
133
+ allowClear: allowClear,
134
+ ref: inputRef,
135
+ onChange: clearValue
136
+ })) : icon ? /*#__PURE__*/React.createElement("span", {
137
+ style: {
138
+ fontSize: '14px'
139
+ },
140
+ className: icon,
141
+ title: title,
142
+ onClick: function onClick() {
143
+ return showSelector(true);
144
+ }
145
+ }) : /*#__PURE__*/React.createElement("a", {
146
+ title: title,
147
+ onClick: function onClick() {
148
+ return showSelector(true);
149
+ }
150
+ }, "\u8BF7\u9009\u62E9")), /*#__PURE__*/React.createElement(_Modal, _extends({
219
151
  title: /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("span", null, title), /*#__PURE__*/React.createElement("span", {
220
152
  style: {
221
153
  display: 'inline-block',
@@ -224,9 +156,8 @@ function IconSelector(prop) {
224
156
  }
225
157
  }, /*#__PURE__*/React.createElement(_Input, {
226
158
  suffix: /*#__PURE__*/React.createElement(SearchOutlined, null),
227
- placeholder: "\u8F93\u5165\u56FE\u7247\u540D\u67E5\u8BE2",
159
+ placeholder: "\u56FE\u6807\u540D\u79F0",
228
160
  onPressEnter: function onPressEnter(e) {
229
- setPage(1);
230
161
  setSearchKey(e.target.value || '');
231
162
  }
232
163
  }))),
@@ -236,49 +167,24 @@ function IconSelector(prop) {
236
167
  onCancel: function onCancel() {
237
168
  return setVisible(false);
238
169
  },
239
- bodyStyle: {
240
- padding: 8
170
+ className: "icon-selector",
171
+ centered: true,
172
+ getContainer: function getContainer() {
173
+ return document.body;
241
174
  },
242
- footer: /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("span", {
243
- style: {
244
- display: 'inline-block',
245
- marginRight: 8
246
- }
247
- }, /*#__PURE__*/React.createElement(_Upload, {
248
- beforeUpload: beforeUpload,
249
- onChange: onUpload,
250
- action: uploadImgApi,
251
- showUploadList: false,
252
- name: "file",
253
- maxCount: 1,
254
- headers: {
255
- token: localStorage.getItem('token') || ''
256
- },
257
- accept: ".png,.gif,.jpg,.jpeg,.bmp"
258
- }, /*#__PURE__*/React.createElement(_Button, {
259
- icon: /*#__PURE__*/React.createElement(UploadOutlined, null)
260
- }, "\u4E0A\u4F20\u65B0\u56FE"))), /*#__PURE__*/React.createElement(_Button, {
261
- disabled: page === 1,
262
- onClick: function onClick() {
263
- setPage(page - 1);
264
- }
265
- }, "\u4E0A\u4E00\u9875"), /*#__PURE__*/React.createElement("span", {
266
- style: {
267
- padding: 8
268
- }
269
- }, page, "/", totalPage), /*#__PURE__*/React.createElement(_Button, {
270
- disabled: page === totalPage,
271
- onClick: function onClick() {
272
- setPage(page + 1);
273
- }
274
- }, "\u4E0B\u4E00\u9875"), /*#__PURE__*/React.createElement(_Button, {
175
+ footer: /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(_Button, {
275
176
  onClick: function onClick() {
276
- return loadData(page, searchKey);
177
+ var formVal = formRef.current.getFieldsValue();
178
+
179
+ var val = _objectSpread({}, formVal); //@ts-ignore
180
+
181
+
182
+ val[name] = '';
183
+ formRef.current.setFieldsValue(val);
184
+ setIcon('');
185
+ setVisible(false);
277
186
  }
278
- }, "\u5237\u65B0")),
279
- getContainer: function getContainer() {
280
- return document.body;
281
- }
187
+ }, "\u6E05\u7A7A"))
282
188
  }, modalProps), /*#__PURE__*/React.createElement("div", {
283
189
  style: {
284
190
  minHeight: '120px'
@@ -299,7 +205,7 @@ function IconSelector(prop) {
299
205
  },
300
206
  onDoubleClick: function onDoubleClick() {
301
207
  if (!name) {
302
- showWarn('选择图标组件未设置name属性');
208
+ console.log('选择图标组件未设置name属性');
303
209
  return;
304
210
  }
305
211
 
@@ -308,30 +214,31 @@ function IconSelector(prop) {
308
214
  var val = _objectSpread({}, formVal); //@ts-ignore
309
215
 
310
216
 
311
- val[name] = o.mongoUrl;
217
+ val[name] = o;
312
218
  formRef.current.setFieldsValue(val);
313
- setImgUrl(toGatewayUrl(o.mongoUrl));
219
+ setIcon(o);
314
220
  setVisible(false);
315
221
  },
316
- key: o.id
222
+ key: o
317
223
  }, /*#__PURE__*/React.createElement("div", {
318
224
  style: {
319
225
  height: 80
320
226
  }
321
- }, /*#__PURE__*/React.createElement("img", {
322
- title: o.mongoName,
227
+ }, /*#__PURE__*/React.createElement("div", {
228
+ title: o,
323
229
  style: {
324
- maxWidth: '80px',
325
- maxHeight: '80px'
230
+ paddingTop: '20px',
231
+ height: '80px',
232
+ fontSize: '20px'
326
233
  },
327
- src: toGatewayUrl(o.mongoUrl)
234
+ className: o
328
235
  })), /*#__PURE__*/React.createElement("div", {
329
236
  style: {
330
237
  whiteSpace: 'nowrap',
331
238
  textOverflow: 'ellipsis',
332
239
  overflow: 'hidden'
333
240
  }
334
- }, o.mongoName));
241
+ }, o));
335
242
  }))));
336
243
  }
337
244
 
@@ -17,6 +17,9 @@ export declare type ImageSelectorProps = ProFormItemProps<InputProps> & {
17
17
  */
18
18
  maxSize?: number;
19
19
  modalProps?: ModalProps;
20
+ isInput?: boolean;
21
+ desc?: string;
22
+ imageClass?: string;
20
23
  };
21
24
  declare function ImageSelector(prop: ImageSelectorProps): JSX.Element;
22
25
  export default ImageSelector;