ls-pro-common 1.0.0
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.
- package/CHANGELOG.md +746 -0
- package/README.md +23 -0
- package/dist/common.js +2 -0
- package/dist/common.js.LICENSE.txt +29 -0
- package/dist/common.less +0 -0
- package/dist/common.min.js +2 -0
- package/dist/common.min.js.LICENSE.txt +29 -0
- package/es/components/EditModalForm.d.ts +7 -0
- package/es/components/EditModalForm.js +29 -0
- package/es/hooks/useSingle/index.d.ts +29 -0
- package/es/hooks/useSingle/index.js +267 -0
- package/es/http/index.d.ts +47 -0
- package/es/http/index.js +306 -0
- package/es/index.d.ts +10 -0
- package/es/index.js +8 -0
- package/es/service/BaseService.d.ts +15 -0
- package/es/service/BaseService.js +202 -0
- package/es/typing.d.ts +43 -0
- package/es/typing.js +1 -0
- package/es/utils/index.d.ts +80 -0
- package/es/utils/index.js +205 -0
- package/lib/components/EditModalForm.d.ts +7 -0
- package/lib/components/EditModalForm.js +42 -0
- package/lib/hooks/useSingle/index.d.ts +29 -0
- package/lib/hooks/useSingle/index.js +288 -0
- package/lib/http/index.d.ts +47 -0
- package/lib/http/index.js +331 -0
- package/lib/index.d.ts +10 -0
- package/lib/index.js +82 -0
- package/lib/service/BaseService.d.ts +15 -0
- package/lib/service/BaseService.js +216 -0
- package/lib/typing.d.ts +43 -0
- package/lib/typing.js +5 -0
- package/lib/utils/index.d.ts +80 -0
- package/lib/utils/index.js +264 -0
- package/package.json +48 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
Copyright (c) 2018 Jed Watson.
|
|
3
|
+
Licensed under the MIT License (MIT), see
|
|
4
|
+
http://jedwatson.github.io/classnames
|
|
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,7 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { ModalFormProps } from 'ls-pro-form';
|
|
3
|
+
export declare type EditModalFormProps<T = Record<string, any>> = ModalFormProps & {
|
|
4
|
+
labelWidth: number | undefined;
|
|
5
|
+
};
|
|
6
|
+
declare function EditModalForm<T = Record<string, any>>({ labelWidth, ...rest }: EditModalFormProps<T>): JSX.Element;
|
|
7
|
+
export default EditModalForm;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
3
|
+
var _excluded = ["labelWidth"];
|
|
4
|
+
import React from "react";
|
|
5
|
+
import { ModalForm } from 'ls-pro-form';
|
|
6
|
+
|
|
7
|
+
function EditModalForm(_ref) {
|
|
8
|
+
var labelWidth = _ref.labelWidth,
|
|
9
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
|
10
|
+
|
|
11
|
+
var defProps = _objectSpread({
|
|
12
|
+
layout: 'horizontal'
|
|
13
|
+
}, rest);
|
|
14
|
+
|
|
15
|
+
if (labelWidth) {
|
|
16
|
+
defProps.labelCol = {
|
|
17
|
+
flex: "0 0 ".concat(labelWidth, "px")
|
|
18
|
+
};
|
|
19
|
+
defProps.wrapperCol = {
|
|
20
|
+
style: {
|
|
21
|
+
maxWidth: 'calc(100% - 100px)'
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, rest.visible ? /*#__PURE__*/React.createElement(ModalForm, defProps) : null);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export default EditModalForm;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { TableToolbar } from '../../typing';
|
|
2
|
+
interface ActionType {
|
|
3
|
+
reload: (resetPageIndex?: boolean) => void;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* 单表基本增删改查 hooks
|
|
7
|
+
* @param service 单表服务
|
|
8
|
+
* @param toolbar 定义基础功能按钮
|
|
9
|
+
* @param initItem 对象初始值,新增时设置默认值
|
|
10
|
+
* @param onBeforeSave 保存之前方法,开放给每个模块重写
|
|
11
|
+
* @param onBeforeRemove 删除之前方法,开放给每个模块重写
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
14
|
+
declare function useSingle(service: any, toolbar?: TableToolbar, initItem?: any, beforeSave?: Function, beforeRemove?: Function): {
|
|
15
|
+
tableRef: import("react").MutableRefObject<ActionType | undefined>;
|
|
16
|
+
selectRows: any;
|
|
17
|
+
showEdit: boolean;
|
|
18
|
+
editItem: any;
|
|
19
|
+
baseToolBar: JSX.Element[];
|
|
20
|
+
setSelectedRows: import("react").Dispatch<any>;
|
|
21
|
+
setShowEdit: import("react").Dispatch<import("react").SetStateAction<boolean>>;
|
|
22
|
+
setEditItem: import("react").Dispatch<any>;
|
|
23
|
+
onRemove: () => void;
|
|
24
|
+
onSave: (formData: any) => Promise<boolean>;
|
|
25
|
+
onLoad: (params: Record<string, any>, sort: Record<string, any>, filter: Record<string, any>) => Promise<any>;
|
|
26
|
+
onAdd: () => void;
|
|
27
|
+
onEdit: () => void;
|
|
28
|
+
};
|
|
29
|
+
export default useSingle;
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import "antd/es/button/style";
|
|
2
|
+
import _Button from "antd/es/button";
|
|
3
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
4
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
5
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
6
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
7
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
8
|
+
var _excluded = ["current", "pageSize"];
|
|
9
|
+
import React from "react";
|
|
10
|
+
import { useState, useRef } from 'react';
|
|
11
|
+
import { PlusOutlined, EditOutlined, DeleteOutlined, ImportOutlined, ExportOutlined } from '@ant-design/icons';
|
|
12
|
+
import { showConfirm, showWarn, showSuccess } from '../../utils';
|
|
13
|
+
/**
|
|
14
|
+
* 单表基本增删改查 hooks
|
|
15
|
+
* @param service 单表服务
|
|
16
|
+
* @param toolbar 定义基础功能按钮
|
|
17
|
+
* @param initItem 对象初始值,新增时设置默认值
|
|
18
|
+
* @param onBeforeSave 保存之前方法,开放给每个模块重写
|
|
19
|
+
* @param onBeforeRemove 删除之前方法,开放给每个模块重写
|
|
20
|
+
* @returns
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
function useSingle(service, toolbar, initItem, beforeSave, beforeRemove) {
|
|
24
|
+
/** 选中行数据 */
|
|
25
|
+
var _useState = useState([]),
|
|
26
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
27
|
+
selectRows = _useState2[0],
|
|
28
|
+
setSelectedRows = _useState2[1];
|
|
29
|
+
/** 显示新增编辑框 */
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
var _useState3 = useState(false),
|
|
33
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
34
|
+
showEdit = _useState4[0],
|
|
35
|
+
setShowEdit = _useState4[1];
|
|
36
|
+
/** 新增或编辑对象初始值 */
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
var _useState5 = useState(initItem),
|
|
40
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
41
|
+
editItem = _useState6[0],
|
|
42
|
+
setEditItem = _useState6[1];
|
|
43
|
+
/** 表格ref */
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
var tableRef = useRef();
|
|
47
|
+
/** 新增按钮事件 */
|
|
48
|
+
|
|
49
|
+
var onAdd = function onAdd() {
|
|
50
|
+
setEditItem(initItem);
|
|
51
|
+
setShowEdit(true);
|
|
52
|
+
};
|
|
53
|
+
/** 编辑按钮事件 */
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
var onEdit = function onEdit() {
|
|
57
|
+
if (!selectRows.length) {
|
|
58
|
+
showWarn('请先选择需要更改的数据');
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
setEditItem(selectRows[0]);
|
|
63
|
+
setShowEdit(true);
|
|
64
|
+
};
|
|
65
|
+
/** 删除按钮事件 */
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
var onRemove = function onRemove() {
|
|
69
|
+
if (!selectRows.length) {
|
|
70
|
+
showWarn('请选择需要删除的数据');
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
showConfirm('确认要删除选择的数据?').then(function () {
|
|
75
|
+
var ids = selectRows.map(function (o) {
|
|
76
|
+
return o.id;
|
|
77
|
+
});
|
|
78
|
+
service.remove(ids).then(function (result) {
|
|
79
|
+
var _result$flag;
|
|
80
|
+
|
|
81
|
+
if ((result === null || result === void 0 ? void 0 : (_result$flag = result.flag) === null || _result$flag === void 0 ? void 0 : _result$flag.retCode) === '0') {
|
|
82
|
+
showSuccess(result.flag.retMsg);
|
|
83
|
+
|
|
84
|
+
if (tableRef.current) {
|
|
85
|
+
tableRef.current.reload(false);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
/** 新增,更改对应的保存事件 */
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
var onSave = /*#__PURE__*/function () {
|
|
95
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(formData) {
|
|
96
|
+
var _result$flag2;
|
|
97
|
+
|
|
98
|
+
var data, result;
|
|
99
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
100
|
+
while (1) {
|
|
101
|
+
switch (_context.prev = _context.next) {
|
|
102
|
+
case 0:
|
|
103
|
+
data = _objectSpread(_objectSpread({}, initItem), formData);
|
|
104
|
+
_context.t0 = beforeSave;
|
|
105
|
+
|
|
106
|
+
if (!_context.t0) {
|
|
107
|
+
_context.next = 7;
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
_context.next = 5;
|
|
112
|
+
return beforeSave(data);
|
|
113
|
+
|
|
114
|
+
case 5:
|
|
115
|
+
_context.t1 = _context.sent;
|
|
116
|
+
_context.t0 = _context.t1 === false;
|
|
117
|
+
|
|
118
|
+
case 7:
|
|
119
|
+
if (!_context.t0) {
|
|
120
|
+
_context.next = 9;
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return _context.abrupt("return", false);
|
|
125
|
+
|
|
126
|
+
case 9:
|
|
127
|
+
_context.next = 11;
|
|
128
|
+
return service.save(data);
|
|
129
|
+
|
|
130
|
+
case 11:
|
|
131
|
+
result = _context.sent;
|
|
132
|
+
|
|
133
|
+
if (!((result === null || result === void 0 ? void 0 : (_result$flag2 = result.flag) === null || _result$flag2 === void 0 ? void 0 : _result$flag2.retCode) === '0')) {
|
|
134
|
+
_context.next = 16;
|
|
135
|
+
break;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
showSuccess(result.flag.retMsg);
|
|
139
|
+
|
|
140
|
+
if (tableRef.current) {
|
|
141
|
+
tableRef.current.reload(false);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return _context.abrupt("return", true);
|
|
145
|
+
|
|
146
|
+
case 16:
|
|
147
|
+
return _context.abrupt("return", false);
|
|
148
|
+
|
|
149
|
+
case 17:
|
|
150
|
+
case "end":
|
|
151
|
+
return _context.stop();
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}, _callee);
|
|
155
|
+
}));
|
|
156
|
+
|
|
157
|
+
return function onSave(_x) {
|
|
158
|
+
return _ref.apply(this, arguments);
|
|
159
|
+
};
|
|
160
|
+
}();
|
|
161
|
+
/** 加载数据方法 */
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
var onLoad = /*#__PURE__*/function () {
|
|
165
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params, sort, filter) {
|
|
166
|
+
var current, pageSize, rest, param, result;
|
|
167
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
168
|
+
while (1) {
|
|
169
|
+
switch (_context2.prev = _context2.next) {
|
|
170
|
+
case 0:
|
|
171
|
+
current = params.current, pageSize = params.pageSize, rest = _objectWithoutProperties(params, _excluded);
|
|
172
|
+
param = {};
|
|
173
|
+
|
|
174
|
+
if (current) {
|
|
175
|
+
param.page = current;
|
|
176
|
+
param.pageSize = pageSize;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (Object.keys(rest).length) {
|
|
180
|
+
param.where = rest;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
console.log("useSingle", param, sort, filter);
|
|
184
|
+
_context2.next = 7;
|
|
185
|
+
return service.load(param);
|
|
186
|
+
|
|
187
|
+
case 7:
|
|
188
|
+
result = _context2.sent;
|
|
189
|
+
result.data = result.rows;
|
|
190
|
+
result.success = true;
|
|
191
|
+
return _context2.abrupt("return", result);
|
|
192
|
+
|
|
193
|
+
case 11:
|
|
194
|
+
case "end":
|
|
195
|
+
return _context2.stop();
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}, _callee2);
|
|
199
|
+
}));
|
|
200
|
+
|
|
201
|
+
return function onLoad(_x2, _x3, _x4) {
|
|
202
|
+
return _ref2.apply(this, arguments);
|
|
203
|
+
};
|
|
204
|
+
}();
|
|
205
|
+
|
|
206
|
+
var baseToolBar = [];
|
|
207
|
+
|
|
208
|
+
if (toolbar === null || toolbar === void 0 ? void 0 : toolbar.add) {
|
|
209
|
+
baseToolBar.push( /*#__PURE__*/React.createElement(_Button, {
|
|
210
|
+
key: "add",
|
|
211
|
+
onClick: onAdd,
|
|
212
|
+
icon: /*#__PURE__*/React.createElement(PlusOutlined, null)
|
|
213
|
+
}, "\u65B0\u589E"));
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (toolbar === null || toolbar === void 0 ? void 0 : toolbar.edit) {
|
|
217
|
+
baseToolBar.push( /*#__PURE__*/React.createElement(_Button, {
|
|
218
|
+
key: "edit",
|
|
219
|
+
disabled: selectRows.length === 0,
|
|
220
|
+
onClick: onEdit,
|
|
221
|
+
icon: /*#__PURE__*/React.createElement(EditOutlined, null)
|
|
222
|
+
}, "\u7F16\u8F91"));
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
if (toolbar === null || toolbar === void 0 ? void 0 : toolbar.remove) {
|
|
226
|
+
baseToolBar.push( /*#__PURE__*/React.createElement(_Button, {
|
|
227
|
+
key: "remove",
|
|
228
|
+
onClick: onRemove,
|
|
229
|
+
danger: true,
|
|
230
|
+
disabled: selectRows.length === 0,
|
|
231
|
+
icon: /*#__PURE__*/React.createElement(DeleteOutlined, null)
|
|
232
|
+
}, "\u5220\u9664"));
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
if (toolbar === null || toolbar === void 0 ? void 0 : toolbar.import) {
|
|
236
|
+
baseToolBar.push( /*#__PURE__*/React.createElement(_Button, {
|
|
237
|
+
key: "import",
|
|
238
|
+
icon: /*#__PURE__*/React.createElement(ImportOutlined, null)
|
|
239
|
+
}, "\u5BFC\u5165"));
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if (toolbar === null || toolbar === void 0 ? void 0 : toolbar.export) {
|
|
243
|
+
baseToolBar.push( /*#__PURE__*/React.createElement(_Button, {
|
|
244
|
+
key: "export",
|
|
245
|
+
icon: /*#__PURE__*/React.createElement(ExportOutlined, null)
|
|
246
|
+
}, "\u5BFC\u51FA"));
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return {
|
|
250
|
+
tableRef: tableRef,
|
|
251
|
+
selectRows: selectRows,
|
|
252
|
+
showEdit: showEdit,
|
|
253
|
+
editItem: editItem,
|
|
254
|
+
baseToolBar: baseToolBar,
|
|
255
|
+
setSelectedRows: setSelectedRows,
|
|
256
|
+
setShowEdit: setShowEdit,
|
|
257
|
+
setEditItem: setEditItem,
|
|
258
|
+
onRemove: onRemove,
|
|
259
|
+
onSave: onSave,
|
|
260
|
+
onLoad: onLoad,
|
|
261
|
+
onAdd: onAdd,
|
|
262
|
+
onEdit: onEdit
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
;
|
|
267
|
+
export default useSingle;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
declare const request: import("umi-request").RequestMethod<false>;
|
|
2
|
+
/**
|
|
3
|
+
* get请求
|
|
4
|
+
* @param url 接口
|
|
5
|
+
* @param params 参数{key:value}
|
|
6
|
+
* @returns Promise<ApiResponse>
|
|
7
|
+
*/
|
|
8
|
+
export declare function httpGet(url: string, params?: Record<string, any>): Promise<any>;
|
|
9
|
+
/**
|
|
10
|
+
* post请求
|
|
11
|
+
* @param url 接口
|
|
12
|
+
* @param data 参数{key:value}
|
|
13
|
+
* @param isJson json请求还是form请求,默认为json请求
|
|
14
|
+
* @returns Promise<ApiResponse>
|
|
15
|
+
*/
|
|
16
|
+
export declare function httpPost(url: string, data?: Record<string, any>, isJson?: boolean): Promise<any>;
|
|
17
|
+
/**
|
|
18
|
+
* put 请求
|
|
19
|
+
* @param url 接口
|
|
20
|
+
* @param data 参数{key:value}
|
|
21
|
+
* @returns Promise<ApiResponse>
|
|
22
|
+
*/
|
|
23
|
+
export declare function httpPut(url: string, data?: Record<string, any>): Promise<any>;
|
|
24
|
+
/**
|
|
25
|
+
* delete 请求
|
|
26
|
+
* @param url 接口
|
|
27
|
+
* @param data 参数[]
|
|
28
|
+
* @returns Promise<ApiResponse>
|
|
29
|
+
*/
|
|
30
|
+
export declare function httpDelete(url: string, data: any): Promise<any>;
|
|
31
|
+
/**
|
|
32
|
+
* 读取数据字典
|
|
33
|
+
* @param dictCode 字典编码
|
|
34
|
+
* @returns Promise<Record<string,string>>
|
|
35
|
+
*/
|
|
36
|
+
export declare function getDict(dictCode: string): Promise<any>;
|
|
37
|
+
/**
|
|
38
|
+
* 加载下拉框的数据源
|
|
39
|
+
* @param url 后端接口
|
|
40
|
+
* @param param 请求参数
|
|
41
|
+
* @param valueField 值字段
|
|
42
|
+
* @param labelField 显示字段
|
|
43
|
+
* @param showValue 显示值
|
|
44
|
+
* @returns
|
|
45
|
+
*/
|
|
46
|
+
export declare function fetchOptions(url: string, param: any, valueField: string, labelField: string, showValue?: boolean): Promise<any>;
|
|
47
|
+
export default request;
|