ls-pro-common 1.0.4 → 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.
Files changed (40) hide show
  1. package/dist/common.css +2276 -0
  2. package/dist/common.js +1 -1
  3. package/dist/common.less +1 -0
  4. package/dist/common.min.css +2276 -0
  5. package/dist/common.min.js +1 -1
  6. package/es/components/DtlLayout.d.ts +20 -0
  7. package/es/components/DtlLayout.js +64 -0
  8. package/es/components/InputTable.d.ts +18 -0
  9. package/es/components/InputTable.js +225 -0
  10. package/es/components/common.less +64 -0
  11. package/es/hooks/useDtl/index.d.ts +29 -0
  12. package/es/hooks/useDtl/index.js +654 -0
  13. package/es/hooks/useSingle/index.d.ts +19 -7
  14. package/es/hooks/useSingle/index.js +282 -85
  15. package/es/http/index.d.ts +1 -1
  16. package/es/http/index.js +7 -3
  17. package/es/index.d.ts +6 -3
  18. package/es/index.js +4 -2
  19. package/es/utils/index.d.ts +45 -1
  20. package/es/utils/index.js +90 -1
  21. package/lib/components/DtlLayout.d.ts +20 -0
  22. package/lib/components/DtlLayout.js +81 -0
  23. package/lib/components/InputTable.d.ts +18 -0
  24. package/lib/components/InputTable.js +254 -0
  25. package/lib/components/common.less +64 -0
  26. package/lib/hooks/useDtl/index.d.ts +29 -0
  27. package/lib/hooks/useDtl/index.js +675 -0
  28. package/lib/hooks/useSingle/index.d.ts +19 -7
  29. package/lib/hooks/useSingle/index.js +283 -86
  30. package/lib/http/index.d.ts +1 -1
  31. package/lib/http/index.js +7 -3
  32. package/lib/index.d.ts +6 -3
  33. package/lib/index.js +20 -4
  34. package/lib/utils/index.d.ts +45 -1
  35. package/lib/utils/index.js +114 -3
  36. package/package.json +3 -3
  37. package/es/components/EditModalForm.d.ts +0 -5
  38. package/es/components/EditModalForm.js +0 -29
  39. package/lib/components/EditModalForm.d.ts +0 -5
  40. package/lib/components/EditModalForm.js +0 -42
@@ -0,0 +1,20 @@
1
+ import React from 'react';
2
+ import type { ProFormInstance } from 'ls-pro-form';
3
+ import './common.less';
4
+ export declare type DtlLyaoutProps = Record<string, any> & {
5
+ onExit: (visible?: boolean) => void;
6
+ onSave?: () => void;
7
+ renderButton?: (defaultBtn: JSX.Element[]) => JSX.Element[];
8
+ btnSaveText?: string;
9
+ btnExitText?: string;
10
+ title?: string;
11
+ masterObject?: any;
12
+ keyField?: string;
13
+ bodyClass?: string;
14
+ headerClass?: string;
15
+ bodyStyle?: React.CSSProperties;
16
+ headerStyle?: React.CSSProperties;
17
+ formRef?: React.MutableRefObject<ProFormInstance | undefined>;
18
+ };
19
+ declare function DtlLayout(props: DtlLyaoutProps): JSX.Element;
20
+ export default DtlLayout;
@@ -0,0 +1,64 @@
1
+ import "antd/es/button/style";
2
+ import _Button from "antd/es/button";
3
+ import React, { useMemo } from 'react';
4
+ import classNames from 'classnames';
5
+ import { ArrowLeftOutlined, SaveOutlined } from '@ant-design/icons';
6
+ import './common.less';
7
+
8
+ function DtlLayout(props) {
9
+ var renderButton = props.renderButton,
10
+ title = props.title,
11
+ _props$keyField = props.keyField,
12
+ keyField = _props$keyField === void 0 ? 'id' : _props$keyField,
13
+ masterObject = props.masterObject,
14
+ children = props.children,
15
+ headerClass = props.headerClass,
16
+ headerStyle = props.headerStyle,
17
+ bodyClass = props.bodyClass,
18
+ bodyStyle = props.bodyStyle,
19
+ formRef = props.formRef,
20
+ _props$btnSaveText = props.btnSaveText,
21
+ btnSaveText = _props$btnSaveText === void 0 ? '保存' : _props$btnSaveText,
22
+ _props$btnExitText = props.btnExitText,
23
+ btnExitText = _props$btnExitText === void 0 ? '返回' : _props$btnExitText;
24
+ var dtlTitle = useMemo(function () {
25
+ if (title) return title;
26
+ if (!masterObject) return '';
27
+ return masterObject[keyField] ? '编辑' : '新增';
28
+ }, [title, masterObject, keyField]);
29
+ var btns = [/*#__PURE__*/React.createElement(_Button, {
30
+ key: "btnSave",
31
+ onClick: function onClick() {
32
+ var _formRef$current;
33
+
34
+ if (props.onSave) {
35
+ return props.onSave();
36
+ }
37
+
38
+ formRef === null || formRef === void 0 ? void 0 : (_formRef$current = formRef.current) === null || _formRef$current === void 0 ? void 0 : _formRef$current.submit();
39
+ },
40
+ icon: /*#__PURE__*/React.createElement(SaveOutlined, null)
41
+ }, " ", btnSaveText, " "), /*#__PURE__*/React.createElement(_Button, {
42
+ key: "btnBack",
43
+ onClick: function onClick() {
44
+ return props.onExit(false);
45
+ },
46
+ icon: /*#__PURE__*/React.createElement(ArrowLeftOutlined, null)
47
+ }, " ", btnExitText, " ")];
48
+ var buttons = renderButton ? renderButton(btns) : btns;
49
+ return /*#__PURE__*/React.createElement("div", {
50
+ className: "dtl-layout"
51
+ }, /*#__PURE__*/React.createElement("div", {
52
+ className: classNames('dtl-header', headerClass),
53
+ style: headerStyle
54
+ }, /*#__PURE__*/React.createElement("div", {
55
+ className: "dtl-title"
56
+ }, dtlTitle), /*#__PURE__*/React.createElement("div", {
57
+ className: "dtl-btns"
58
+ }, buttons)), /*#__PURE__*/React.createElement("div", {
59
+ className: classNames('dtl-body', bodyClass),
60
+ style: bodyStyle
61
+ }, children));
62
+ }
63
+
64
+ export default DtlLayout;
@@ -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;
@@ -0,0 +1,64 @@
1
+ .dtl-layout {
2
+ position : absolute;
3
+ top : 0;
4
+ left : 0;
5
+ right : 0;
6
+ bottom : 0;
7
+ background : white;
8
+ display : flex;
9
+ flex-direction: column;
10
+
11
+ .dtl-header {
12
+ display : flex;
13
+ justify-items: center;
14
+ padding : 5px 14px;
15
+ border-bottom: 1px solid #f0f0f0;
16
+
17
+ .dtl-title {
18
+ font-size: 14pt;
19
+ }
20
+
21
+ .dtl-btns {
22
+ flex : 1;
23
+ text-align: right;
24
+
25
+ button+button {
26
+ margin-left: 8px;
27
+ }
28
+ }
29
+ }
30
+
31
+ .dtl-body {
32
+ height : 0;
33
+ flex : 1;
34
+ overflow: auto;
35
+ padding : 12px;
36
+ }
37
+
38
+ .dtl-flex {
39
+ display : flex;
40
+ flex-direction: column;
41
+ }
42
+ }
43
+
44
+ .flex {
45
+ flex: 1;
46
+ }
47
+
48
+ .flex-column {
49
+ display : flex;
50
+ flex-direction: column;
51
+
52
+ .flex {
53
+ height: 0;
54
+ }
55
+ }
56
+
57
+ .flex-row {
58
+ display : flex;
59
+ flex-direction: row;
60
+
61
+ .flex {
62
+ width: 0;
63
+ }
64
+ }
@@ -0,0 +1,29 @@
1
+ import type { ActionType } from 'ls-pro-table';
2
+ import type { ProFormInstance } from 'ls-pro-form';
3
+ import type { SingleParamType } from '../useSingle';
4
+ export declare type DtlParamType = SingleParamType & {
5
+ mstKeyField: string;
6
+ dtlService: any;
7
+ relationField: string;
8
+ dtlItem: any;
9
+ };
10
+ declare function useDtl(dtlParam: DtlParamType): {
11
+ formRef: import("react").MutableRefObject<ProFormInstance<any> | undefined>;
12
+ tableRef: import("react").MutableRefObject<ActionType | undefined>;
13
+ dtlFormRef: import("react").MutableRefObject<ProFormInstance<any> | undefined>;
14
+ selectedRows: any;
15
+ showEdit: boolean;
16
+ editItem: any;
17
+ tableTools: JSX.Element[];
18
+ setSelectedRows: import("react").Dispatch<any>;
19
+ setShowEdit: import("react").Dispatch<import("react").SetStateAction<boolean>>;
20
+ setEditItem: import("react").Dispatch<any>;
21
+ onRemoveDtl: () => void;
22
+ onSaveDtl: (formData: any) => Promise<boolean>;
23
+ onLoadDtl: (params: Record<string, any>, sort: Record<string, any>, filter: Record<string, any>) => Promise<any>;
24
+ onAddDtl: () => Promise<boolean>;
25
+ onEditDtl: () => Promise<boolean>;
26
+ onSaveMst: (values: any) => Promise<void>;
27
+ onRemoveMst: () => Promise<boolean | undefined>;
28
+ };
29
+ export default useDtl;