ls-pro-common 3.1.48 → 3.1.50

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 (45) hide show
  1. package/dist/common.js +1 -1
  2. package/dist/common.min.js +1 -1
  3. package/es/components/InputTable.js +26 -19
  4. package/es/http/index.d.ts +34 -28
  5. package/es/http/index.js +153 -153
  6. package/es/utils/cache.d.ts +28 -0
  7. package/es/utils/cache.js +63 -0
  8. package/es/utils/constant.d.ts +12 -0
  9. package/es/utils/constant.js +20 -0
  10. package/es/utils/cookie.d.ts +15 -0
  11. package/es/utils/cookie.js +36 -0
  12. package/es/utils/event.d.ts +16 -0
  13. package/es/utils/event.js +26 -0
  14. package/es/utils/index.d.ts +8 -179
  15. package/es/utils/index.js +12 -423
  16. package/es/utils/print.d.ts +24 -0
  17. package/es/utils/print.js +86 -0
  18. package/es/utils/project.d.ts +33 -0
  19. package/es/utils/project.js +66 -0
  20. package/es/utils/url.d.ts +26 -0
  21. package/es/utils/url.js +113 -0
  22. package/es/utils/user.d.ts +29 -0
  23. package/es/utils/user.js +25 -0
  24. package/lib/components/InputTable.js +26 -19
  25. package/lib/http/index.d.ts +34 -28
  26. package/lib/http/index.js +153 -153
  27. package/lib/utils/cache.d.ts +28 -0
  28. package/lib/utils/cache.js +63 -0
  29. package/lib/utils/constant.d.ts +12 -0
  30. package/lib/utils/constant.js +20 -0
  31. package/lib/utils/cookie.d.ts +15 -0
  32. package/lib/utils/cookie.js +36 -0
  33. package/lib/utils/event.d.ts +16 -0
  34. package/lib/utils/event.js +26 -0
  35. package/lib/utils/index.d.ts +8 -179
  36. package/lib/utils/index.js +12 -423
  37. package/lib/utils/print.d.ts +24 -0
  38. package/lib/utils/print.js +86 -0
  39. package/lib/utils/project.d.ts +33 -0
  40. package/lib/utils/project.js +66 -0
  41. package/lib/utils/url.d.ts +26 -0
  42. package/lib/utils/url.js +113 -0
  43. package/lib/utils/user.d.ts +29 -0
  44. package/lib/utils/user.js +25 -0
  45. package/package.json +1 -1
@@ -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/') || url.startsWith('/lesoon-retail/') || url.startsWith('/scm-bms/')) {
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
+ };
@@ -153,13 +153,13 @@ var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
153
153
  * @param formValue
154
154
  */
155
155
  var setFormValue = function setFormValue(formValue) {
156
- var _prop$onChange;
157
- (_prop$onChange = prop.onChange) === null || _prop$onChange === void 0 ? void 0 : _prop$onChange.call(prop, formValue[name]);
158
156
  if (rowKey) {
159
- var _formRef$current3, _formRef$current3$set;
157
+ var _formRef$current3, _formRef$current3$set, _prop$onChange;
160
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]);
161
160
  } else {
162
- 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]);
163
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);
164
164
  }
165
165
  };
@@ -171,7 +171,7 @@ var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
171
171
  */
172
172
  var loadData = /*#__PURE__*/function () {
173
173
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(param) {
174
- 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;
175
175
  return _regeneratorRuntime.wrap(function _callee$(_context) {
176
176
  while (1) switch (_context.prev = _context.next) {
177
177
  case 0:
@@ -187,10 +187,10 @@ var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
187
187
  return o[tableKey];
188
188
  })));
189
189
  setSelectedKeys(Array.from(new Set(selectedKeys)));
190
- setTimeout(function () {
190
+ requestIdleCallback(function () {
191
191
  var _tableRef$current, _tableRef$current$rel;
192
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);
193
- }, 0);
193
+ });
194
194
  return _context.abrupt("return", {
195
195
  data: _rows,
196
196
  total: _rows.length,
@@ -221,9 +221,9 @@ var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
221
221
  _context.next = 16;
222
222
  return beforeLoad(data);
223
223
  case 16:
224
- _param = _context.sent;
225
- if (typeof _param !== 'boolean' && _param !== undefined) {
226
- data = _param;
224
+ beforeParam = _context.sent;
225
+ if (typeof beforeParam !== 'boolean' && beforeParam !== undefined) {
226
+ data = beforeParam;
227
227
  }
228
228
  case 18:
229
229
  if (!(method !== 'GET')) {
@@ -325,7 +325,6 @@ var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
325
325
  var formValue = getFormValue();
326
326
  if (!formValue) return;
327
327
  formValue[textNameProp] = txt;
328
- console.log('formValue', formValue);
329
328
  setFormValue(formValue);
330
329
  });
331
330
  };
@@ -348,6 +347,7 @@ var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
348
347
  initName(val, false);
349
348
  }
350
349
  }
350
+ // eslint-disable-next-line react-hooks/exhaustive-deps
351
351
  }, [rowKey]);
352
352
  // 处理返回数据
353
353
  var handleValue = function handleValue(row) {
@@ -600,23 +600,30 @@ var InputTable = /*#__PURE__*/React.forwardRef(function (prop, ref) {
600
600
  readOnly: readonly,
601
601
  allowClear: allowClear,
602
602
  ref: inputRef
603
- }, !rowKey ? {} : {
604
- value: text
605
603
  }, fieldProps));
606
- console.log('textNameProp', prop);
604
+ // 是否在编辑表格下面使用,如果是,则需要使用 rowKey 和 id 来设置 name
605
+ var isEditable = rowKey && id && id.includes('_');
607
606
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
608
607
  style: {
609
608
  display: 'none'
610
609
  }
611
610
  }, /*#__PURE__*/React.createElement(ProFormText, {
612
- name: rowKey ? id : name
613
- })), rest.label || rowKey ? /*#__PURE__*/React.createElement(ProFormText, _extends({
611
+ name: isEditable ? [rowKey, name] : name
612
+ })), rest.label ?
613
+ /*#__PURE__*/
614
+ // 在ProForm中直接使用
615
+ React.createElement(ProFormText, _extends({
614
616
  name: textNameProp
615
- }, rest, rowKey ? {
617
+ }, rest), InputDom) : isEditable ?
618
+ /*#__PURE__*/
619
+ // 在EditableTable中使用
620
+ React.createElement(_Form.Item, _extends({
621
+ name: [rowKey, textNameProp]
622
+ }, rest, {
616
623
  noStyle: true
617
- } : {}), InputDom) :
624
+ }), InputDom) :
618
625
  /*#__PURE__*/
619
- // 在ProTable的查询面板中
626
+ // 在 ProTable 的查询面板中使用
620
627
  React.createElement(_Form.Item, _extends({
621
628
  name: textNameProp
622
629
  }, rest, {
@@ -43,34 +43,6 @@ export declare function httpPut(url: string, data?: Record<string, any>, needGat
43
43
  * @returns Promise<ApiResponse>
44
44
  */
45
45
  export declare function httpDelete(url: string, data: any, needGateWay?: boolean, timeout?: number): Promise<any>;
46
- /**
47
- * 读取数据字典
48
- *
49
- * @param dictCode 字典编码
50
- * @param showValue 是否显示值
51
- * @param needGateWay 是否需要网关 默认为true
52
- * @param timeout 超时时间,默认60000毫秒
53
- * @param isGet 是否Get请求
54
- * @param valueIsNumber 返回值是否为数字,默认false
55
- * @returns Promise<Record<string,string>[]>
56
- */
57
- export declare function getDict(dictCodes: string, showValue?: boolean, needGateWay?: boolean, timeout?: number, isGet?: boolean, valueIsNumber?: boolean): Promise<any>;
58
- /**
59
- * 加载下拉框的数据源
60
- *
61
- * @param url 后端接口
62
- * @param param 请求参数
63
- * @param valueField 值字段
64
- * @param labelField 显示字段
65
- * @param showValue 显示值
66
- * @param needGateWay 是否需要网关 默认为true
67
- * @param timeout
68
- * @param isGet = true 是否get请求,默认true
69
- * @param valueIsNumber 返回值是否为数字,默认false
70
- * @returns
71
- */
72
- export declare function fetchOptions(url: string, param: any, valueField: string, labelField: string, showValue?: boolean, needGateWay?: boolean, timeout?: number, isGet?: boolean, valueIsNumber?: boolean): Promise<any>;
73
- export declare const getResourceRight: (ids: string[]) => Promise<any>;
74
46
  /** 上传文件进度回调 */
75
47
  export interface UploadProgressCallback {
76
48
  (progress: number): void;
@@ -116,4 +88,38 @@ export declare const httpBatchGet: (url: string, params?: Record<string, any>, n
116
88
  * @returns
117
89
  */
118
90
  export declare const httpBatchPost: (url: string, params?: Record<string, any>, needGateWay?: boolean, timeout?: number) => Promise<any>;
91
+ /**
92
+ * 读取数据字典
93
+ *
94
+ * @param dictCode 字典编码
95
+ * @param showValue 是否显示值
96
+ * @param needGateWay 是否需要网关 默认为true
97
+ * @param timeout 超时时间,默认60000毫秒
98
+ * @param isGet 是否Get请求
99
+ * @param valueIsNumber 返回值是否为数字,默认false
100
+ * @returns Promise<Record<string,string>[]>
101
+ */
102
+ export declare function getDict(dictCodes: string, showValue?: boolean, needGateWay?: boolean, timeout?: number, isGet?: boolean, valueIsNumber?: boolean): Promise<any>;
103
+ /**
104
+ * 加载下拉框的数据源
105
+ *
106
+ * @param url 后端接口
107
+ * @param param 请求参数
108
+ * @param valueField 值字段
109
+ * @param labelField 显示字段
110
+ * @param showValue 显示值
111
+ * @param needGateWay 是否需要网关 默认为true
112
+ * @param timeout
113
+ * @param isGet = true 是否get请求,默认true
114
+ * @param valueIsNumber 返回值是否为数字,默认false
115
+ * @returns
116
+ */
117
+ export declare function fetchOptions(url: string, param: any, valueField: string, labelField: string, showValue?: boolean, needGateWay?: boolean, timeout?: number, isGet?: boolean, valueIsNumber?: boolean): Promise<any>;
118
+ /**
119
+ * 获取用户资源Id对应的权限值
120
+ *
121
+ * @param ids 资源id
122
+ * @returns
123
+ */
124
+ export declare const getResourceRight: (ids: string[]) => Promise<any>;
119
125
  export default request;