ls-pro-common 3.1.47 → 3.1.49

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 (43) hide show
  1. package/dist/common.js +1 -1
  2. package/dist/common.min.js +1 -1
  3. package/es/components/InputTable.d.ts +2 -2
  4. package/es/components/InputTable.js +85 -32
  5. package/es/utils/cache.d.ts +28 -0
  6. package/es/utils/cache.js +63 -0
  7. package/es/utils/constant.d.ts +12 -0
  8. package/es/utils/constant.js +20 -0
  9. package/es/utils/cookie.d.ts +15 -0
  10. package/es/utils/cookie.js +36 -0
  11. package/es/utils/event.d.ts +16 -0
  12. package/es/utils/event.js +26 -0
  13. package/es/utils/index.d.ts +8 -179
  14. package/es/utils/index.js +12 -423
  15. package/es/utils/print.d.ts +24 -0
  16. package/es/utils/print.js +86 -0
  17. package/es/utils/project.d.ts +33 -0
  18. package/es/utils/project.js +66 -0
  19. package/es/utils/url.d.ts +26 -0
  20. package/es/utils/url.js +113 -0
  21. package/es/utils/user.d.ts +29 -0
  22. package/es/utils/user.js +25 -0
  23. package/lib/components/InputTable.d.ts +2 -2
  24. package/lib/components/InputTable.js +85 -32
  25. package/lib/utils/cache.d.ts +28 -0
  26. package/lib/utils/cache.js +63 -0
  27. package/lib/utils/constant.d.ts +12 -0
  28. package/lib/utils/constant.js +20 -0
  29. package/lib/utils/cookie.d.ts +15 -0
  30. package/lib/utils/cookie.js +36 -0
  31. package/lib/utils/event.d.ts +16 -0
  32. package/lib/utils/event.js +26 -0
  33. package/lib/utils/index.d.ts +8 -179
  34. package/lib/utils/index.js +12 -423
  35. package/lib/utils/print.d.ts +24 -0
  36. package/lib/utils/print.js +86 -0
  37. package/lib/utils/project.d.ts +33 -0
  38. package/lib/utils/project.js +66 -0
  39. package/lib/utils/url.d.ts +26 -0
  40. package/lib/utils/url.js +113 -0
  41. package/lib/utils/user.d.ts +29 -0
  42. package/lib/utils/user.js +25 -0
  43. package/package.json +1 -1
@@ -0,0 +1,24 @@
1
+ /**
2
+ * 打印预览
3
+ *
4
+ * @param templateNo 打印模板编码
5
+ * @param reqUrl 业务请求api
6
+ * @param bodyParam Post传参数
7
+ * @param param Get传参数
8
+ * @param method 请求方式,默认post
9
+ * @param isNewPrintCenter 是否是新的打印中心,默认false
10
+ * @returns
11
+ */
12
+ export declare const printView: (templateNo: string, reqUrl: string, bodyParam?: any, param?: any, method?: 'POST' | 'GET', isNewPrintCenter?: boolean) => any;
13
+ /**
14
+ * 直接打印,通过打印组件进行打印。
15
+ *
16
+ * @param taskName 打印任务名
17
+ * @param templateNo 打印模板
18
+ * @param reqUrl 业务请求api
19
+ * @param bodyParam Post传参数
20
+ * @param param Get传参数
21
+ * @param method 请求方式,默认post
22
+ * @returns
23
+ */
24
+ export declare const printAsync: (taskName: string, templateNo: string, reqUrl: string, bodyParam?: any, param?: any, method?: 'POST' | 'GET', isNewPrintCenter?: boolean) => Promise<any>;
@@ -0,0 +1,86 @@
1
+ import { toGatewayUrl } from './url';
2
+ import { getCache } from './cache';
3
+ import { httpPost } from '../http';
4
+ /**
5
+ * 打印预览
6
+ *
7
+ * @param templateNo 打印模板编码
8
+ * @param reqUrl 业务请求api
9
+ * @param bodyParam Post传参数
10
+ * @param param Get传参数
11
+ * @param method 请求方式,默认post
12
+ * @param isNewPrintCenter 是否是新的打印中心,默认false
13
+ * @returns
14
+ */
15
+ export var printView = function printView(templateNo, reqUrl) {
16
+ var bodyParam = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
17
+ var param = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : undefined;
18
+ var method = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 'POST';
19
+ var isNewPrintCenter = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
20
+ var api = '/petrel-print-center-api/report/remote/print/dataStr';
21
+ if (isNewPrintCenter) {
22
+ api = '/lesoon-basic-api/basic/ireport/preview/print/dataStr';
23
+ }
24
+ var printCenterUrl = toGatewayUrl(api);
25
+ reqUrl = toGatewayUrl(reqUrl);
26
+ if (!reqUrl.includes(location.origin)) {
27
+ reqUrl = location.origin + reqUrl;
28
+ }
29
+ var data = {
30
+ templateNo: templateNo,
31
+ printType: 1,
32
+ reqUrl: reqUrl,
33
+ reqMethodType: method,
34
+ params: param || {},
35
+ body: bodyParam || {}
36
+ };
37
+ var openWin = window.open();
38
+ var formStr = "<form style=\"visibility:hidden;\" method=\"POST\" action=\"".concat(printCenterUrl, "\">\n <input type=\"hidden\" name=\"clientPrintData\" value='").concat(JSON.stringify(data), "' />\n </form>");
39
+ openWin.document.body.innerHTML = formStr;
40
+ openWin.document.forms[0].submit();
41
+ return openWin;
42
+ };
43
+ /**
44
+ * 直接打印,通过打印组件进行打印。
45
+ *
46
+ * @param taskName 打印任务名
47
+ * @param templateNo 打印模板
48
+ * @param reqUrl 业务请求api
49
+ * @param bodyParam Post传参数
50
+ * @param param Get传参数
51
+ * @param method 请求方式,默认post
52
+ * @returns
53
+ */
54
+ export var printAsync = function printAsync(taskName, templateNo, reqUrl) {
55
+ var bodyParam = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
56
+ var param = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : undefined;
57
+ var method = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : 'POST';
58
+ var isNewPrintCenter = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : false;
59
+ var api = '/petrel-print-center-api/report/client/print';
60
+ if (isNewPrintCenter) {
61
+ api = '/lesoon-basic-api/basic/client/template/print';
62
+ }
63
+ var printCenterUrl = toGatewayUrl(api);
64
+ if (!printCenterUrl.includes(location.origin)) {
65
+ printCenterUrl = location.origin + printCenterUrl;
66
+ }
67
+ reqUrl = toGatewayUrl(reqUrl);
68
+ if (!reqUrl.includes(location.origin)) {
69
+ reqUrl = location.origin + reqUrl;
70
+ }
71
+ var data = {
72
+ taskName: taskName,
73
+ printReqUrl: printCenterUrl,
74
+ bizVO: {
75
+ templateNo: templateNo,
76
+ printType: 1,
77
+ reqUrl: reqUrl,
78
+ reqMethodType: method,
79
+ params: param || {},
80
+ body: bodyParam || {}
81
+ },
82
+ token: getCache('token') || ''
83
+ };
84
+ var url = 'http://localhost:10050/client/async/print';
85
+ return httpPost(url, data, true, false);
86
+ };
@@ -0,0 +1,33 @@
1
+ /** 是否本地开发环境 */
2
+ export declare const isDev: boolean;
3
+ /** 是否运行在钉钉下面 */
4
+ export declare const isDingtalk: boolean;
5
+ /**
6
+ * 判断是否是微前端子应用
7
+ *
8
+ * @returns String | undefined
9
+ */
10
+ export declare const isQiankunSubApp: () => any;
11
+ /** @name 微前端原生路径 */
12
+ export declare const appPath: (path?: string) => any;
13
+ /**
14
+ * 在主工程中打开模块
15
+ *
16
+ * @param option {path:模块路由,需要加工程编码, resourceId: 资源Id,两者传一个即可,data:参数,moduleName:模块名称}
17
+ */
18
+ export declare const openPageInMain: (option: {
19
+ [key: string]: any;
20
+ path?: string | undefined;
21
+ resourceId?: string | undefined;
22
+ data?: any;
23
+ ifRefreshTarget?: boolean | undefined;
24
+ moduleName?: string | undefined;
25
+ }) => void;
26
+ /** 处理主题 */
27
+ export declare const handleTheme: () => void;
28
+ /**
29
+ * 微前端主工程注入子工程时,子工程调用此方法设置资源Id,权限等参数
30
+ *
31
+ * @param props
32
+ */
33
+ export declare const setCurrentResCode: (props: any) => void;
@@ -0,0 +1,66 @@
1
+ import { getCache } from './cache';
2
+ import { getUrlQuery } from './url';
3
+ /** 是否本地开发环境 */
4
+ export var isDev = location.href.includes('//localhost');
5
+ /** 是否运行在钉钉下面 */
6
+ export var isDingtalk = (window.navigator.userAgent || '').toLowerCase().includes('dingtalk');
7
+ /**
8
+ * 判断是否是微前端子应用
9
+ *
10
+ * @returns String | undefined
11
+ */
12
+ export var isQiankunSubApp = function isQiankunSubApp() {
13
+ // @ts-ignore
14
+ return window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__;
15
+ };
16
+ /** @name 微前端原生路径 */
17
+ export var appPath = function appPath() {
18
+ var path = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
19
+ if (isQiankunSubApp()) {
20
+ return isQiankunSubApp();
21
+ }
22
+ if (path) return path;
23
+ //本地开发环境,判断是否hash路由,如果是hash路由,则返回./
24
+ if (isDev) {
25
+ return location.hash ? './' : '/';
26
+ }
27
+ // 生产环境,返回当前路径
28
+ var p = location.pathname || '';
29
+ if (p === '/') return location.origin + '/';
30
+ return location.origin + '/' + p.split('/')[1] + '/';
31
+ };
32
+ /**
33
+ * 在主工程中打开模块
34
+ *
35
+ * @param option {path:模块路由,需要加工程编码, resourceId: 资源Id,两者传一个即可,data:参数,moduleName:模块名称}
36
+ */
37
+ export var openPageInMain = function openPageInMain(option) {
38
+ var win = top || window;
39
+ win.postMessage({
40
+ type: 'openPage',
41
+ param: option
42
+ });
43
+ };
44
+ /** 处理主题 */
45
+ export var handleTheme = function handleTheme() {
46
+ var theme = getCache('theme');
47
+ if (theme) {
48
+ document.body.classList.add('theme-' + theme);
49
+ }
50
+ };
51
+ /**
52
+ * 微前端主工程注入子工程时,子工程调用此方法设置资源Id,权限等参数
53
+ *
54
+ * @param props
55
+ */
56
+ export var setCurrentResCode = function setCurrentResCode(props) {
57
+ var _props$history;
58
+ var initialValue = props === null || props === void 0 ? void 0 : (_props$history = props.history) === null || _props$history === void 0 ? void 0 : _props$history.initialEntries;
59
+ if (Array.isArray(initialValue) && initialValue.length > 0) {
60
+ var parentParams = initialValue[0];
61
+ window.__initVal__ = parentParams;
62
+ window.__currentResCode__ = getUrlQuery('resCode', parentParams);
63
+ window.__currentRight__ = getUrlQuery('right', parentParams);
64
+ window.__currentResRight__ = getUrlQuery('resRight', parentParams);
65
+ }
66
+ };
@@ -0,0 +1,26 @@
1
+ /**
2
+ * 获取 url 参数
3
+ *
4
+ * @param name
5
+ * @param url
6
+ * @returns
7
+ */
8
+ export declare const getUrlQuery: (name: string, url?: string) => string;
9
+ export declare const getResourceProps: (name: string) => any;
10
+ /**
11
+ * 设置url传参
12
+ *
13
+ * @param {any} url
14
+ * @param {any} keyvals
15
+ * @returns
16
+ */
17
+ export declare const setUrlQuery: (url: string, keyvals?: Record<string, any>) => string;
18
+ /**
19
+ * 给 url 添加网关
20
+ *
21
+ * @param url 原url,以 / 打头
22
+ * @param gatewayKey 设置gateway关键字 默认为 'gateway'
23
+ * @param defaultGateway 默认网关 ''
24
+ * @returns
25
+ */
26
+ export declare const toGatewayUrl: (url: string, gatewayKey?: string, defaultGateway?: string) => string;
@@ -0,0 +1,113 @@
1
+ import { getCache } from './cache';
2
+ /**
3
+ * 获取 url 参数
4
+ *
5
+ * @param name
6
+ * @param url
7
+ * @returns
8
+ */
9
+ export var getUrlQuery = function getUrlQuery(name) {
10
+ var url = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : location.search.slice(1) || '';
11
+ if (!name) return '';
12
+ var reg = new RegExp('(^|[&|?])' + name + '=([^&]*)(&|$)');
13
+ var r = url.match(reg);
14
+ if (r != null) {
15
+ return decodeURIComponent(decodeURI(r[2]));
16
+ }
17
+ return '';
18
+ };
19
+ export var getResourceProps = function getResourceProps(name) {
20
+ if (!name) return '';
21
+ var id = window.__currentResCode__ || getUrlQuery('resCode');
22
+ var obj;
23
+ // window.lsResourceList 为主工程写入的资源
24
+ // @ts-ignore
25
+ var resList = window.lsResourceList || parent.window.lsResourceList || [];
26
+ if (resList.length === 0) {
27
+ resList = getCache('allRes') || [];
28
+ if (!Array.isArray(resList)) {
29
+ resList = [];
30
+ }
31
+ }
32
+ if (id) {
33
+ obj = resList.find(function (o) {
34
+ return o.resourceId === id;
35
+ });
36
+ } else if (location.pathname && location.pathname.length > 3) {
37
+ var url = location.pathname + location.hash;
38
+ obj = resList.find(function (o) {
39
+ return o.microUrl && o.microUrl === location.pathname || o.url === url;
40
+ });
41
+ }
42
+ if (!obj) return '';
43
+ return obj[name] || '';
44
+ };
45
+ /**
46
+ * 设置url传参
47
+ *
48
+ * @param {any} url
49
+ * @param {any} keyvals
50
+ * @returns
51
+ */
52
+ export var setUrlQuery = function setUrlQuery(url) {
53
+ var keyvals = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
54
+ var newUrl = url;
55
+ for (var name in keyvals) {
56
+ var reg = new RegExp('(^|[&|?])' + name + '=([^&]*)(|$)');
57
+ var tmp = (newUrl.includes('?') ? '&' : '?') + name + '=' + keyvals[name];
58
+ if (newUrl.match(reg) != null) {
59
+ // @ts-ignore
60
+ newUrl = newUrl.replace(eval(reg), tmp);
61
+ if (!newUrl.includes('?')) {
62
+ newUrl = newUrl.replace('&', '?');
63
+ }
64
+ } else {
65
+ newUrl = newUrl + tmp;
66
+ }
67
+ }
68
+ return newUrl;
69
+ };
70
+ /**
71
+ * 给 url 添加网关
72
+ *
73
+ * @param url 原url,以 / 打头
74
+ * @param gatewayKey 设置gateway关键字 默认为 'gateway'
75
+ * @param defaultGateway 默认网关 ''
76
+ * @returns
77
+ */
78
+ export var toGatewayUrl = function toGatewayUrl(url) {
79
+ var gatewayKey = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'gateway';
80
+ var defaultGateway = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
81
+ url = url || '';
82
+ // 如果url带有名称,不需要设置网关
83
+ if (url.startsWith('http://') || url.startsWith('https://') || url.startsWith('//')) return url;
84
+ if (url.startsWith('/lesoon/') || url.startsWith('/petrel/')) {
85
+ return location.origin + url;
86
+ }
87
+ // 读取项目的默认网关
88
+ if (!defaultGateway) {
89
+ var _top;
90
+ // @ts-ignore
91
+ defaultGateway = window.defaultGateway || ((_top = top) === null || _top === void 0 ? void 0 : _top.window.lsMainGateway) || '';
92
+ }
93
+ // 取网关的顺序, 1.取url里的传参,2.取资源里的网关, 3. 取项目里设置的默认网关
94
+ var gateway = getUrlQuery(gatewayKey) || getResourceProps(gatewayKey) || defaultGateway;
95
+ // 如果没有找到网关,直接从项目配置中取网关
96
+ if (!gateway) {
97
+ var projects = JSON.parse(sessionStorage.getItem('lsProjects') || '[]');
98
+ var projectKey = localStorage.getItem('projectId');
99
+ if (projectKey && projects.length) {
100
+ var project = projects.find(function (o) {
101
+ return o.projectId === projectKey;
102
+ });
103
+ if (project) {
104
+ gateway = project.gatewayUrl || '';
105
+ }
106
+ }
107
+ }
108
+ // 网关加上域名,避免多次设置
109
+ if (gateway && !gateway.startsWith('http')) {
110
+ gateway = location.origin + gateway;
111
+ }
112
+ return gateway + url;
113
+ };
@@ -0,0 +1,29 @@
1
+ export declare type UserType = {
2
+ id?: string;
3
+ userId?: string;
4
+ userName?: string;
5
+ loginName?: string;
6
+ companyId?: string;
7
+ companyCode?: string;
8
+ companyName?: string;
9
+ email?: string;
10
+ employeeAttr?: string;
11
+ expireTime?: string;
12
+ icon?: string;
13
+ idCard?: string;
14
+ ifAdmin?: number | string;
15
+ orgId?: string;
16
+ orgParentIds?: string;
17
+ phoneNumber?: string;
18
+ remarks?: string;
19
+ };
20
+ /** @name 用户信息 */
21
+ export declare const getUserInfo: () => UserType | null;
22
+ /** @name 用户名 */
23
+ export declare const getUserName: () => string | undefined;
24
+ /** @name 登录名 */
25
+ export declare const getLoginName: () => string | undefined;
26
+ /** @name 公司Id */
27
+ export declare const getCompanyId: () => string | undefined;
28
+ /** @name 用户ID */
29
+ export declare const getUserId: () => string | undefined;
@@ -0,0 +1,25 @@
1
+ import { getCache } from './cache';
2
+ /** @name 用户信息 */
3
+ export var getUserInfo = function getUserInfo() {
4
+ return getCache('user');
5
+ };
6
+ /** @name 用户名 */
7
+ export var getUserName = function getUserName() {
8
+ var _getUserInfo;
9
+ return (_getUserInfo = getUserInfo()) === null || _getUserInfo === void 0 ? void 0 : _getUserInfo.userName;
10
+ };
11
+ /** @name 登录名 */
12
+ export var getLoginName = function getLoginName() {
13
+ var _getUserInfo2;
14
+ return (_getUserInfo2 = getUserInfo()) === null || _getUserInfo2 === void 0 ? void 0 : _getUserInfo2.loginName;
15
+ };
16
+ /** @name 公司Id */
17
+ export var getCompanyId = function getCompanyId() {
18
+ var _getUserInfo3;
19
+ return (_getUserInfo3 = getUserInfo()) === null || _getUserInfo3 === void 0 ? void 0 : _getUserInfo3.companyId;
20
+ };
21
+ /** @name 用户ID */
22
+ export var getUserId = function getUserId() {
23
+ var _getUserInfo4;
24
+ return (_getUserInfo4 = getUserInfo()) === null || _getUserInfo4 === void 0 ? void 0 : _getUserInfo4.userId;
25
+ };
@@ -14,7 +14,7 @@ export declare type InputTableProps = ProFormItemProps<InputProps> & {
14
14
  /** @name 是否支持多选 */
15
15
  multiple?: boolean;
16
16
  /** @name 表单项name, 跟 form.item 的 name一致 */
17
- name: string;
17
+ name?: string;
18
18
  /** @name 返回的值字段,表格中valueField配置的字段时返回给name */
19
19
  valueField: string;
20
20
  /** @name 返回输入框显示的字段,textField字段值返回给textName */
@@ -74,7 +74,7 @@ declare const InputTable: React.ForwardRefExoticComponent<{
74
74
  /** @name 是否支持多选 */
75
75
  multiple?: boolean | undefined;
76
76
  /** @name 表单项name, 跟 form.item 的 name一致 */
77
- name: string;
77
+ name?: string | undefined;
78
78
  /** @name 返回的值字段,表格中valueField配置的字段时返回给name */
79
79
  valueField: string;
80
80
  /** @name 返回输入框显示的字段,textField字段值返回给textName */
@@ -1,3 +1,5 @@
1
+ import "antd/es/form/style";
2
+ import _Form from "antd/es/form";
1
3
  import "antd/es/input/style";
2
4
  import _Input from "antd/es/input";
3
5
  import "antd/es/popover/style";
@@ -11,7 +13,7 @@ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
11
13
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
12
14
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
13
15
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
14
- var _excluded = ["columns", "url", "textName", "name", "tableConfig", "tableHeight", "tableWidth", "readonly", "multiple", "valueField", "labelWidth", "textField", "onSelectChange", "beforeLoad", "afterLoad", "isV2", "allowClear", "keepSelect", "fieldProps", "searchField", "fillMap", "loadOnShow", "triggerCheck", "getPopupContainer", "placement", "arrowPointAtCenter", "rowKey", "method", "changeOnSelect", "record"],
16
+ var _excluded = ["columns", "url", "textName", "name", "tableConfig", "tableHeight", "tableWidth", "readonly", "multiple", "valueField", "labelWidth", "textField", "onSelectChange", "beforeLoad", "afterLoad", "isV2", "allowClear", "keepSelect", "fieldProps", "searchField", "fillMap", "loadOnShow", "triggerCheck", "getPopupContainer", "placement", "arrowPointAtCenter", "method", "changeOnSelect", "rowKey", "record", "id"],
15
17
  _excluded2 = ["current", "pageSize"];
16
18
  import _regeneratorRuntime from "@babel/runtime/regenerator";
17
19
  import React, { useRef, useState, useEffect, useContext, useMemo, useImperativeHandle } from 'react';
@@ -43,7 +45,7 @@ var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
43
45
  var columns = prop.columns,
44
46
  url = prop.url,
45
47
  textName = prop.textName,
46
- name = prop.name,
48
+ itemName = prop.name,
47
49
  tableConfig = prop.tableConfig,
48
50
  _prop$tableHeight = prop.tableHeight,
49
51
  tableHeight = _prop$tableHeight === void 0 ? 400 : _prop$tableHeight,
@@ -80,12 +82,13 @@ var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
80
82
  placement = _prop$placement === void 0 ? 'bottom' : _prop$placement,
81
83
  _prop$arrowPointAtCen = prop.arrowPointAtCenter,
82
84
  arrowPointAtCenter = _prop$arrowPointAtCen === void 0 ? true : _prop$arrowPointAtCen,
83
- rowKey = prop.rowKey,
84
85
  _prop$method = prop.method,
85
86
  method = _prop$method === void 0 ? 'GET' : _prop$method,
86
87
  _prop$changeOnSelect = prop.changeOnSelect,
87
88
  changeOnSelect = _prop$changeOnSelect === void 0 ? true : _prop$changeOnSelect,
89
+ rowKey = prop.rowKey,
88
90
  record = prop.record,
91
+ id = prop.id,
89
92
  rest = _objectWithoutProperties(prop, _excluded);
90
93
  if (!valueField && isDev) {
91
94
  console.error('valueField 属性必须设置');
@@ -93,10 +96,21 @@ var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
93
96
  if (!url && isDev) {
94
97
  console.error('url 属性必须设置');
95
98
  }
99
+ var tableKey = (tableConfig === null || tableConfig === void 0 ? void 0 : tableConfig.rowKey) || valueField || 'id';
100
+ // 处理表单name, 如果不传入通过id来处理。在表格中,自动会添加Id
101
+ var name = useMemo(function () {
102
+ if (itemName) return itemName;
103
+ if (id) {
104
+ if (id.includes('_')) {
105
+ return id.slice(id.indexOf('_') + 1);
106
+ }
107
+ return id;
108
+ }
109
+ return '';
110
+ }, [itemName, id]);
96
111
  if (!name && isDev) {
97
112
  console.error('name 属性必须设置');
98
113
  }
99
- var tableKey = (tableConfig === null || tableConfig === void 0 ? void 0 : tableConfig.rowKey) || valueField || 'id';
100
114
  //显示输入框绑定的name,如果不设置textName,设置为$name__text
101
115
  var textNameProp = useMemo(function () {
102
116
  return textName ? textName : name + '__text';
@@ -120,6 +134,11 @@ var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
120
134
  if (col) return col.searchField || col.dataIndex;
121
135
  return textField || valueField;
122
136
  }, [columns, searchField, valueField, textField]);
137
+ /**
138
+ * 获取表单值
139
+ *
140
+ * @returns
141
+ */
123
142
  var getFormValue = function getFormValue() {
124
143
  var _formRef$current2, _formRef$current2$get;
125
144
  if (rowKey) {
@@ -128,20 +147,31 @@ var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
128
147
  }
129
148
  return formRef === null || formRef === void 0 ? void 0 : (_formRef$current2 = formRef.current) === null || _formRef$current2 === void 0 ? void 0 : (_formRef$current2$get = _formRef$current2.getFieldsValue) === null || _formRef$current2$get === void 0 ? void 0 : _formRef$current2$get.call(_formRef$current2);
130
149
  };
150
+ /**
151
+ * 设置表单值
152
+ *
153
+ * @param formValue
154
+ */
131
155
  var setFormValue = function setFormValue(formValue) {
132
- var _prop$onChange;
133
- (_prop$onChange = prop.onChange) === null || _prop$onChange === void 0 ? void 0 : _prop$onChange.call(prop, formValue[name]);
134
156
  if (rowKey) {
135
- var _formRef$current3, _formRef$current3$set;
157
+ var _formRef$current3, _formRef$current3$set, _prop$onChange;
136
158
  formRef === null || formRef === void 0 ? void 0 : (_formRef$current3 = formRef.current) === null || _formRef$current3 === void 0 ? void 0 : (_formRef$current3$set = _formRef$current3.setFieldsValue) === null || _formRef$current3$set === void 0 ? void 0 : _formRef$current3$set.call(_formRef$current3, _defineProperty({}, rowKey, formValue));
159
+ (_prop$onChange = prop.onChange) === null || _prop$onChange === void 0 ? void 0 : _prop$onChange.call(prop, formValue[textNameProp]);
137
160
  } else {
138
- var _formRef$current4, _formRef$current4$set;
161
+ var _prop$onChange2, _formRef$current4, _formRef$current4$set;
162
+ (_prop$onChange2 = prop.onChange) === null || _prop$onChange2 === void 0 ? void 0 : _prop$onChange2.call(prop, formValue[name]);
139
163
  formRef === null || formRef === void 0 ? void 0 : (_formRef$current4 = formRef.current) === null || _formRef$current4 === void 0 ? void 0 : (_formRef$current4$set = _formRef$current4.setFieldsValue) === null || _formRef$current4$set === void 0 ? void 0 : _formRef$current4$set.call(_formRef$current4, formValue);
140
164
  }
141
165
  };
166
+ /**
167
+ * 加载面板数据
168
+ *
169
+ * @param param
170
+ * @returns
171
+ */
142
172
  var loadData = /*#__PURE__*/function () {
143
173
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(param) {
144
- var current, pageSize, restParams, _selectRowRef$current, _rows, data, _tableRef$current2, _tableRef$current2$cl, _param, result, rows, formValue, val, _selectRowRef$current2, arr, pageSelectedRows;
174
+ var current, pageSize, restParams, _selectRowRef$current, _rows, data, _tableRef$current2, _tableRef$current2$cl, beforeParam, result, rows, formValue, val, _selectRowRef$current2, arr, pageSelectedRows;
145
175
  return _regeneratorRuntime.wrap(function _callee$(_context) {
146
176
  while (1) switch (_context.prev = _context.next) {
147
177
  case 0:
@@ -157,10 +187,10 @@ var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
157
187
  return o[tableKey];
158
188
  })));
159
189
  setSelectedKeys(Array.from(new Set(selectedKeys)));
160
- setTimeout(function () {
190
+ requestIdleCallback(function () {
161
191
  var _tableRef$current, _tableRef$current$rel;
162
192
  (_tableRef$current = tableRef.current) === null || _tableRef$current === void 0 ? void 0 : (_tableRef$current$rel = _tableRef$current.reload) === null || _tableRef$current$rel === void 0 ? void 0 : _tableRef$current$rel.call(_tableRef$current);
163
- }, 0);
193
+ });
164
194
  return _context.abrupt("return", {
165
195
  data: _rows,
166
196
  total: _rows.length,
@@ -191,9 +221,9 @@ var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
191
221
  _context.next = 16;
192
222
  return beforeLoad(data);
193
223
  case 16:
194
- _param = _context.sent;
195
- if (typeof _param !== 'boolean' && _param !== undefined) {
196
- data = _param;
224
+ beforeParam = _context.sent;
225
+ if (typeof beforeParam !== 'boolean' && beforeParam !== undefined) {
226
+ data = beforeParam;
197
227
  }
198
228
  case 18:
199
229
  if (!(method !== 'GET')) {
@@ -254,6 +284,13 @@ var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
254
284
  return _ref.apply(this, arguments);
255
285
  };
256
286
  }();
287
+ /**
288
+ * 如果初始有值时,调用此方法初始化名称
289
+ *
290
+ * @param val
291
+ * @param updateTxt
292
+ * @returns
293
+ */
257
294
  var initName = function initName(val) {
258
295
  var updateTxt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
259
296
  if (!val) return;
@@ -310,6 +347,7 @@ var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
310
347
  initName(val, false);
311
348
  }
312
349
  }
350
+ // eslint-disable-next-line react-hooks/exhaustive-deps
313
351
  }, [rowKey]);
314
352
  // 处理返回数据
315
353
  var handleValue = function handleValue(row) {
@@ -433,6 +471,19 @@ var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
433
471
  (_tableRef$current5 = tableRef.current) === null || _tableRef$current5 === void 0 ? void 0 : (_tableRef$current5$re = _tableRef$current5.reload) === null || _tableRef$current5$re === void 0 ? void 0 : _tableRef$current5$re.call(_tableRef$current5);
434
472
  }
435
473
  }, [visible, loadOnShow]);
474
+ // 处理有值时,可清空
475
+ useEffect(function () {
476
+ if (rest.disabled || (fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.disabled)) return;
477
+ try {
478
+ var el = inputRef.current.input.parentNode;
479
+ if (!el) return;
480
+ if (text) {
481
+ el.classList.add('ant-input-has-value');
482
+ } else {
483
+ el.classList.remove('ant-input-has-value');
484
+ }
485
+ } catch (e) {}
486
+ }, [text, rest, fieldProps]);
436
487
  var tableDom = /*#__PURE__*/React.createElement(ProTable, _extends({
437
488
  className: "ls-input-table",
438
489
  columns: columns,
@@ -549,31 +600,33 @@ var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
549
600
  readOnly: readonly,
550
601
  allowClear: allowClear,
551
602
  ref: inputRef
552
- }, rest.label ? {} : {
553
- value: text
554
603
  }, fieldProps));
555
- // 处理有值时,可清空
556
- useEffect(function () {
557
- if (rest.disabled || (fieldProps === null || fieldProps === void 0 ? void 0 : fieldProps.disabled)) return;
558
- try {
559
- var el = inputRef.current.input.parentNode;
560
- if (!el) return;
561
- if (text) {
562
- el.classList.add('ant-input-has-value');
563
- } else {
564
- el.classList.remove('ant-input-has-value');
565
- }
566
- } catch (e) {}
567
- }, [text, rest, fieldProps]);
604
+ // 是否在编辑表格下面使用,如果是,则需要使用 rowKey 和 id 来设置 name
605
+ var isEditable = rowKey && id && id.includes('_');
568
606
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
569
607
  style: {
570
608
  display: 'none'
571
609
  }
572
610
  }, /*#__PURE__*/React.createElement(ProFormText, {
573
- name: name
574
- })), /*#__PURE__*/React.createElement(ProFormText, _extends({
611
+ name: isEditable ? [rowKey, name] : name
612
+ })), rest.label ?
613
+ /*#__PURE__*/
614
+ // 在ProForm中直接使用
615
+ React.createElement(ProFormText, _extends({
616
+ name: textNameProp
617
+ }, rest), InputDom) : isEditable ?
618
+ /*#__PURE__*/
619
+ // 在EditableTable中使用
620
+ React.createElement(_Form.Item, _extends({
621
+ name: [rowKey, textNameProp]
622
+ }, rest, {
623
+ noStyle: true
624
+ }), InputDom) :
625
+ /*#__PURE__*/
626
+ // 在 ProTable 的查询面板中使用
627
+ React.createElement(_Form.Item, _extends({
575
628
  name: textNameProp
576
- }, rest, rest.label ? {} : {
629
+ }, rest, {
577
630
  noStyle: true
578
631
  }), InputDom));
579
632
  });