ls-pro-common 1.0.7 → 1.0.8

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.
@@ -3,3 +3,27 @@
3
3
  Licensed under the MIT License (MIT), see
4
4
  http://jedwatson.github.io/classnames
5
5
  */
6
+
7
+ /*! *****************************************************************************
8
+ Copyright (c) Microsoft Corporation.
9
+
10
+ Permission to use, copy, modify, and/or distribute this software for any
11
+ purpose with or without fee is hereby granted.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
14
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
15
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
16
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
17
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
18
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19
+ PERFORMANCE OF THIS SOFTWARE.
20
+ ***************************************************************************** */
21
+
22
+ /** @license React v16.13.1
23
+ * react-is.production.min.js
24
+ *
25
+ * Copyright (c) Facebook, Inc. and its affiliates.
26
+ *
27
+ * This source code is licensed under the MIT license found in the
28
+ * LICENSE file in the root directory of this source tree.
29
+ */
@@ -0,0 +1,18 @@
1
+ /// <reference types="react" />
2
+ import type { InputProps } from 'antd';
3
+ import type { ProFormItemProps } from 'ls-pro-form';
4
+ export declare type InputTableProps = ProFormItemProps<InputProps> & {
5
+ columns: any[];
6
+ url: string;
7
+ tableHeight?: number;
8
+ tableWidth?: number;
9
+ multiple?: boolean;
10
+ name: string;
11
+ valueField: string;
12
+ textField?: string;
13
+ textName?: string;
14
+ tableConfig?: any;
15
+ onSelectChange?: (item: any) => void;
16
+ };
17
+ declare function InputTable(prop: InputTableProps): JSX.Element;
18
+ export default InputTable;
@@ -0,0 +1,225 @@
1
+ import "antd/es/input/style";
2
+ import _Input from "antd/es/input";
3
+ import "antd/es/popover/style";
4
+ import _Popover from "antd/es/popover";
5
+ import _extends from "@babel/runtime/helpers/esm/extends";
6
+ import "antd/es/button/style";
7
+ import _Button from "antd/es/button";
8
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
9
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
10
+ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
11
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
12
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
13
+ var _excluded = ["columns", "url", "textName", "name", "tableConfig", "tableHeight", "tableWidth", "readonly", "multiple", "valueField", "textField", "onSelectChange"],
14
+ _excluded2 = ["current", "pageSize"];
15
+ import React from "react";
16
+ import { useRef, useState, useEffect, useContext } from 'react';
17
+ import ProTable from 'ls-pro-table';
18
+ import { ProFormText, ProFormContext } from 'ls-pro-form';
19
+ import { MoreOutlined } from '@ant-design/icons';
20
+ import { httpGet } from '../http';
21
+
22
+ function InputTable(prop) {
23
+ //@ts-ignore
24
+ var _useContext = useContext(ProFormContext),
25
+ formRef = _useContext.formRef;
26
+
27
+ var tableRef = useRef();
28
+
29
+ var _useState = useState(false),
30
+ _useState2 = _slicedToArray(_useState, 2),
31
+ visible = _useState2[0],
32
+ setVisible = _useState2[1];
33
+
34
+ var _useState3 = useState([]),
35
+ _useState4 = _slicedToArray(_useState3, 2),
36
+ selectedRows = _useState4[0],
37
+ setSelectedRows = _useState4[1];
38
+
39
+ var _useState5 = useState(''),
40
+ _useState6 = _slicedToArray(_useState5, 2),
41
+ text = _useState6[0],
42
+ setText = _useState6[1];
43
+
44
+ var columns = prop.columns,
45
+ url = prop.url,
46
+ textName = prop.textName,
47
+ name = prop.name,
48
+ tableConfig = prop.tableConfig,
49
+ _prop$tableHeight = prop.tableHeight,
50
+ tableHeight = _prop$tableHeight === void 0 ? 400 : _prop$tableHeight,
51
+ _prop$tableWidth = prop.tableWidth,
52
+ tableWidth = _prop$tableWidth === void 0 ? 650 : _prop$tableWidth,
53
+ _prop$readonly = prop.readonly,
54
+ readonly = _prop$readonly === void 0 ? true : _prop$readonly,
55
+ multiple = prop.multiple,
56
+ valueField = prop.valueField,
57
+ textField = prop.textField,
58
+ onSelectChange = prop.onSelectChange,
59
+ rest = _objectWithoutProperties(prop, _excluded);
60
+
61
+ var textNameProp = textName || name + '__text';
62
+
63
+ var loadData = /*#__PURE__*/function () {
64
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(param) {
65
+ var current, pageSize, rest, data, result;
66
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
67
+ while (1) {
68
+ switch (_context.prev = _context.next) {
69
+ case 0:
70
+ current = param.current, pageSize = param.pageSize, rest = _objectWithoutProperties(param, _excluded2);
71
+ data = {
72
+ page: current,
73
+ pageSize: pageSize
74
+ };
75
+
76
+ if (Object.keys(rest).length) {
77
+ data.where = rest;
78
+ }
79
+
80
+ _context.next = 5;
81
+ return httpGet(url, data);
82
+
83
+ case 5:
84
+ result = _context.sent;
85
+ return _context.abrupt("return", {
86
+ data: result.rows || [],
87
+ total: result.total || 0,
88
+ success: true
89
+ });
90
+
91
+ case 7:
92
+ case "end":
93
+ return _context.stop();
94
+ }
95
+ }
96
+ }, _callee);
97
+ }));
98
+
99
+ return function loadData(_x) {
100
+ return _ref.apply(this, arguments);
101
+ };
102
+ }();
103
+
104
+ useEffect(function () {
105
+ var _formRef$current;
106
+
107
+ var formValue = formRef === null || formRef === void 0 ? void 0 : (_formRef$current = formRef.current) === null || _formRef$current === void 0 ? void 0 : _formRef$current.getFieldsValue();
108
+ var txt = formValue[textField || valueField];
109
+
110
+ if (txt) {
111
+ setText(txt);
112
+ }
113
+ }, []);
114
+ var tableDom = /*#__PURE__*/React.createElement(ProTable, _extends({
115
+ columns: columns,
116
+ request: loadData,
117
+ rowKey: valueField,
118
+ manualRequest: false,
119
+ actionRef: tableRef,
120
+ search: {
121
+ labelWidth: 70
122
+ },
123
+ options: {
124
+ density: false,
125
+ reload: false,
126
+ setting: false
127
+ },
128
+ form: {
129
+ submitter: {
130
+ resetButtonProps: false
131
+ }
132
+ },
133
+ height: 'full',
134
+ rowSelection: {
135
+ type: multiple ? 'checkbox' : 'radio',
136
+ onChange: function onChange(keys, rows) {
137
+ setSelectedRows(rows);
138
+ }
139
+ },
140
+ tableAlertRender: false,
141
+ onRow: function onRow(record) {
142
+ return {
143
+ onDoubleClick: function onDoubleClick() {
144
+ var _formRef$current2, _formRef$current3;
145
+
146
+ var formValue = formRef === null || formRef === void 0 ? void 0 : (_formRef$current2 = formRef.current) === null || _formRef$current2 === void 0 ? void 0 : _formRef$current2.getFieldsValue();
147
+ formValue[name] = record[valueField];
148
+ setText(record[textField || valueField]); // 如果需要接收名称(指定了名称属性名),则反回名称
149
+
150
+ if (textName) {
151
+ formValue[textNameProp] = record[textField || valueField];
152
+ }
153
+
154
+ (_formRef$current3 = formRef.current) === null || _formRef$current3 === void 0 ? void 0 : _formRef$current3.setFieldsValue(_objectSpread({}, formValue));
155
+ setVisible(false);
156
+ onSelectChange === null || onSelectChange === void 0 ? void 0 : onSelectChange(record);
157
+ }
158
+ };
159
+ },
160
+ toolBarRender: function toolBarRender() {
161
+ return [/*#__PURE__*/React.createElement(_Button, {
162
+ onClick: function onClick() {
163
+ if (selectedRows.length) {
164
+ var _formRef$current4, _formRef$current5;
165
+
166
+ var formValue = formRef === null || formRef === void 0 ? void 0 : (_formRef$current4 = formRef.current) === null || _formRef$current4 === void 0 ? void 0 : _formRef$current4.getFieldsValue();
167
+ formValue[name] = selectedRows.map(function (o) {
168
+ return o[valueField];
169
+ }).join(',');
170
+ var txt = selectedRows.map(function (o) {
171
+ return o[textField || valueField];
172
+ }).join(',');
173
+ setText(txt); // 如果需要接收名称,则反回名称
174
+
175
+ if (textName) {
176
+ formValue[textNameProp] = txt;
177
+ }
178
+
179
+ (_formRef$current5 = formRef.current) === null || _formRef$current5 === void 0 ? void 0 : _formRef$current5.setFieldsValue(_objectSpread({}, formValue));
180
+ }
181
+
182
+ setVisible(false);
183
+ }
184
+ }, "\u786E\u8BA4")];
185
+ },
186
+ headerTitle: "\u53CC\u51FB\u8FD4\u56DE\u5F53\u524D\u884C\u6570\u636E"
187
+ }, tableConfig));
188
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
189
+ style: {
190
+ display: 'none'
191
+ }
192
+ }, /*#__PURE__*/React.createElement(ProFormText, {
193
+ name: name
194
+ })), /*#__PURE__*/React.createElement(ProFormText, _extends({
195
+ name: textNameProp
196
+ }, rest), /*#__PURE__*/React.createElement(_Input, {
197
+ suffix: /*#__PURE__*/React.createElement(_Popover, {
198
+ content: /*#__PURE__*/React.createElement("div", {
199
+ style: {
200
+ width: tableWidth + 'px',
201
+ height: tableHeight + 'px',
202
+ maxHeight: '95vh',
203
+ overflow: 'auto'
204
+ }
205
+ }, tableDom),
206
+ trigger: "click",
207
+ visible: visible,
208
+ onVisibleChange: setVisible
209
+ }, /*#__PURE__*/React.createElement(MoreOutlined, null)),
210
+ onClick: function onClick() {
211
+ return setVisible(true);
212
+ },
213
+ onInput: function onInput(e) {
214
+ var _formRef$current6;
215
+
216
+ var formValue = formRef === null || formRef === void 0 ? void 0 : (_formRef$current6 = formRef.current) === null || _formRef$current6 === void 0 ? void 0 : _formRef$current6.getFieldsValue();
217
+ formValue[name] = e.target.value;
218
+ formRef.current.setFieldsValue(_objectSpread({}, formValue));
219
+ },
220
+ readOnly: readonly,
221
+ value: text
222
+ })));
223
+ }
224
+
225
+ export default InputTable;
@@ -608,6 +608,11 @@ function useDtl(dtlParam) {
608
608
  if (toolConfig === null || toolConfig === void 0 ? void 0 : toolConfig.import) {
609
609
  tableTools.push( /*#__PURE__*/React.createElement(_Button, {
610
610
  key: "import",
611
+ onClick: function onClick() {
612
+ var _tableRef$current, _tableRef$current$sho;
613
+
614
+ tableRef === null || tableRef === void 0 ? void 0 : (_tableRef$current = tableRef.current) === null || _tableRef$current === void 0 ? void 0 : (_tableRef$current$sho = _tableRef$current.showImport) === null || _tableRef$current$sho === void 0 ? void 0 : _tableRef$current$sho.call(_tableRef$current);
615
+ },
611
616
  icon: /*#__PURE__*/React.createElement(ImportOutlined, null)
612
617
  }, "\u5BFC\u5165"));
613
618
  }
@@ -615,6 +620,11 @@ function useDtl(dtlParam) {
615
620
  if (toolConfig === null || toolConfig === void 0 ? void 0 : toolConfig.export) {
616
621
  tableTools.push( /*#__PURE__*/React.createElement(_Button, {
617
622
  key: "export",
623
+ onClick: function onClick() {
624
+ var _tableRef$current2, _tableRef$current2$sh;
625
+
626
+ tableRef === null || tableRef === void 0 ? void 0 : (_tableRef$current2 = tableRef.current) === null || _tableRef$current2 === void 0 ? void 0 : (_tableRef$current2$sh = _tableRef$current2.showExport) === null || _tableRef$current2$sh === void 0 ? void 0 : _tableRef$current2$sh.call(_tableRef$current2);
627
+ },
618
628
  icon: /*#__PURE__*/React.createElement(ExportOutlined, null)
619
629
  }, "\u5BFC\u51FA"));
620
630
  }
@@ -36,5 +36,6 @@ declare function useSingle(inParam: SingleParamType): {
36
36
  onLoad: (params: Record<string, any>, sort: Record<string, any>, filter: Record<string, any>) => Promise<any>;
37
37
  onAdd: () => Promise<void>;
38
38
  onEdit: () => Promise<void>;
39
+ onExport: (url: string, param: any) => Promise<boolean>;
39
40
  };
40
41
  export default useSingle;
@@ -370,6 +370,27 @@ function useSingle(inParam) {
370
370
  };
371
371
  }();
372
372
 
373
+ var onExport = /*#__PURE__*/function () {
374
+ var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(url, param) {
375
+ return _regeneratorRuntime.wrap(function _callee6$(_context6) {
376
+ while (1) {
377
+ switch (_context6.prev = _context6.next) {
378
+ case 0:
379
+ return _context6.abrupt("return", true);
380
+
381
+ case 1:
382
+ case "end":
383
+ return _context6.stop();
384
+ }
385
+ }
386
+ }, _callee6);
387
+ }));
388
+
389
+ return function onExport(_x5, _x6) {
390
+ return _ref6.apply(this, arguments);
391
+ };
392
+ }();
393
+
373
394
  var tableTools = [];
374
395
 
375
396
  if (toolConfig === null || toolConfig === void 0 ? void 0 : toolConfig.add) {
@@ -402,6 +423,11 @@ function useSingle(inParam) {
402
423
  if (toolConfig === null || toolConfig === void 0 ? void 0 : toolConfig.import) {
403
424
  tableTools.push( /*#__PURE__*/React.createElement(_Button, {
404
425
  key: "import",
426
+ onClick: function onClick() {
427
+ var _tableRef$current, _tableRef$current$sho;
428
+
429
+ tableRef === null || tableRef === void 0 ? void 0 : (_tableRef$current = tableRef.current) === null || _tableRef$current === void 0 ? void 0 : (_tableRef$current$sho = _tableRef$current.showImport) === null || _tableRef$current$sho === void 0 ? void 0 : _tableRef$current$sho.call(_tableRef$current);
430
+ },
405
431
  icon: /*#__PURE__*/React.createElement(ImportOutlined, null)
406
432
  }, "\u5BFC\u5165"));
407
433
  }
@@ -409,6 +435,11 @@ function useSingle(inParam) {
409
435
  if (toolConfig === null || toolConfig === void 0 ? void 0 : toolConfig.export) {
410
436
  tableTools.push( /*#__PURE__*/React.createElement(_Button, {
411
437
  key: "export",
438
+ onClick: function onClick() {
439
+ var _tableRef$current2, _tableRef$current2$sh;
440
+
441
+ tableRef === null || tableRef === void 0 ? void 0 : (_tableRef$current2 = tableRef.current) === null || _tableRef$current2 === void 0 ? void 0 : (_tableRef$current2$sh = _tableRef$current2.showExport) === null || _tableRef$current2$sh === void 0 ? void 0 : _tableRef$current2$sh.call(_tableRef$current2);
442
+ },
412
443
  icon: /*#__PURE__*/React.createElement(ExportOutlined, null)
413
444
  }, "\u5BFC\u51FA"));
414
445
  }
@@ -428,7 +459,8 @@ function useSingle(inParam) {
428
459
  onSave: onSave,
429
460
  onLoad: onLoad,
430
461
  onAdd: onAdd,
431
- onEdit: onEdit
462
+ onEdit: onEdit,
463
+ onExport: onExport
432
464
  };
433
465
  }
434
466
 
package/es/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import DtlLayout from './components/DtlLayout';
2
+ import InputTable from './components/InputTable';
2
3
  import BaseService from './service/BaseService';
3
4
  import request, { httpGet, httpPut, httpPost, httpDelete, getDict, fetchOptions } from './http';
4
5
  import * as utils from './utils';
@@ -9,4 +10,4 @@ import useDtl from './hooks/useDtl';
9
10
  import type { ApiResponse, TableToolbar, BaseApiType, MethodType } from './typing';
10
11
  import type { DtlLyaoutProps } from './components/DtlLayout';
11
12
  export type { ApiResponse, TableToolbar, BaseApiType, MethodType, DtlLyaoutProps };
12
- export { DtlLayout, BaseService, request, httpDelete, httpGet, httpPost, httpPut, getDict, fetchOptions, utils, useSingle, useDtl };
13
+ export { DtlLayout, InputTable, BaseService, request, httpDelete, httpGet, httpPost, httpPut, getDict, fetchOptions, utils, useSingle, useDtl };
package/es/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import DtlLayout from './components/DtlLayout';
2
+ import InputTable from './components/InputTable';
2
3
  import BaseService from './service/BaseService';
3
4
  import request, { httpGet, httpPut, httpPost, httpDelete, getDict, fetchOptions } from './http';
4
5
  import * as utils from './utils';
@@ -6,4 +7,4 @@ import * as utils from './utils';
6
7
 
7
8
  import useSingle from './hooks/useSingle';
8
9
  import useDtl from './hooks/useDtl';
9
- export { DtlLayout, BaseService, request, httpDelete, httpGet, httpPost, httpPut, getDict, fetchOptions, utils, useSingle, useDtl };
10
+ export { DtlLayout, InputTable, BaseService, request, httpDelete, httpGet, httpPost, httpPut, getDict, fetchOptions, utils, useSingle, useDtl };
@@ -6,6 +6,13 @@ export declare const getUrlQuery: (name: string, url?: string) => string;
6
6
  * @returns
7
7
  */
8
8
  export declare const setUrlQuery: (url: string, keyvals?: Record<string, any>) => string;
9
+ /**
10
+ * 给 url 添加网关
11
+ * @param url 原url,以 / 打头
12
+ * @param defGateway 默认网关 /petrel
13
+ * @returns
14
+ */
15
+ export declare const toGatewayUrl: (url: string, defGateway?: string) => string;
9
16
  /**
10
17
  * 设置文档title
11
18
  * @param {*} title
package/es/utils/index.js CHANGED
@@ -38,6 +38,19 @@ export var setUrlQuery = function setUrlQuery(url) {
38
38
 
39
39
  return newUrl;
40
40
  };
41
+ /**
42
+ * 给 url 添加网关
43
+ * @param url 原url,以 / 打头
44
+ * @param defGateway 默认网关 /petrel
45
+ * @returns
46
+ */
47
+
48
+ export var toGatewayUrl = function toGatewayUrl(url) {
49
+ var defGateway = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '/petrel';
50
+ if (url.startsWith('http://') || url.startsWith('https://') || url.startsWith('//')) return url;
51
+ var gateway = getUrlQuery('gateway') || location.origin + defGateway;
52
+ return gateway + url;
53
+ };
41
54
  /**
42
55
  * 设置文档title
43
56
  * @param {*} title
@@ -0,0 +1,18 @@
1
+ /// <reference types="react" />
2
+ import type { InputProps } from 'antd';
3
+ import type { ProFormItemProps } from 'ls-pro-form';
4
+ export declare type InputTableProps = ProFormItemProps<InputProps> & {
5
+ columns: any[];
6
+ url: string;
7
+ tableHeight?: number;
8
+ tableWidth?: number;
9
+ multiple?: boolean;
10
+ name: string;
11
+ valueField: string;
12
+ textField?: string;
13
+ textName?: string;
14
+ tableConfig?: any;
15
+ onSelectChange?: (item: any) => void;
16
+ };
17
+ declare function InputTable(prop: InputTableProps): JSX.Element;
18
+ export default InputTable;