ls-pro-common 3.1.48 → 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.
@@ -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
+ };
@@ -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, {
@@ -0,0 +1,28 @@
1
+ /**
2
+ * 设置本地缓存
3
+ *
4
+ * @param {String} key 关键字
5
+ * @param {Object} data 值
6
+ * @param {Boolean} session 保存到 sessionStorage 还是 localStorage,默认 localStorage
7
+ */
8
+ export declare const setCache: (key: string, data: any, session?: boolean) => void;
9
+ /**
10
+ * 读取本地缓存
11
+ *
12
+ * @param {String} key 关键字
13
+ * @param {boolean} session 从 sessionStorage 取数还是从 localStorage 中取数 默认从 localStorage
14
+ * @returns 关键字对应的值
15
+ */
16
+ export declare const getCache: any;
17
+ /**
18
+ * 读取本地缓存,优先从sessionStorage 取,取不到时再从 localStorage取
19
+ *
20
+ * @param key
21
+ * @returns
22
+ */
23
+ export declare const getCacheSessionFirst: (key: string) => any;
24
+ /**
25
+ * @param key 关键字,不传清除所有
26
+ * @param session 是否session storage , 默认 localStorage
27
+ */
28
+ export declare const clearCache: (key?: string | undefined, session?: boolean) => void;
@@ -0,0 +1,63 @@
1
+ import _typeof from "@babel/runtime/helpers/esm/typeof";
2
+ /**
3
+ * 设置本地缓存
4
+ *
5
+ * @param {String} key 关键字
6
+ * @param {Object} data 值
7
+ * @param {Boolean} session 保存到 sessionStorage 还是 localStorage,默认 localStorage
8
+ */
9
+ export var setCache = function setCache(key, data) {
10
+ var session = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
11
+ if (_typeof(data) === 'object') {
12
+ data = JSON.stringify(data);
13
+ }
14
+ if (session) {
15
+ sessionStorage.setItem(key, data);
16
+ } else {
17
+ localStorage.setItem(key, data);
18
+ }
19
+ };
20
+ /**
21
+ * 读取本地缓存
22
+ *
23
+ * @param {String} key 关键字
24
+ * @param {boolean} session 从 sessionStorage 取数还是从 localStorage 中取数 默认从 localStorage
25
+ * @returns 关键字对应的值
26
+ */
27
+ export var getCache = function getCache(key) {
28
+ var session = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
29
+ var data = session ? sessionStorage.getItem(key) : localStorage.getItem(key);
30
+ if (data && (data.startsWith('{') || data.startsWith('['))) {
31
+ data = JSON.parse(data);
32
+ }
33
+ return data;
34
+ };
35
+ /**
36
+ * 读取本地缓存,优先从sessionStorage 取,取不到时再从 localStorage取
37
+ *
38
+ * @param key
39
+ * @returns
40
+ */
41
+ export var getCacheSessionFirst = function getCacheSessionFirst(key) {
42
+ return getCache(key, true) || getCache(key);
43
+ };
44
+ /**
45
+ * @param key 关键字,不传清除所有
46
+ * @param session 是否session storage , 默认 localStorage
47
+ */
48
+ export var clearCache = function clearCache(key) {
49
+ var session = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
50
+ if (key) {
51
+ if (session) {
52
+ sessionStorage.removeItem(key);
53
+ } else {
54
+ localStorage.removeItem(key);
55
+ }
56
+ } else {
57
+ if (session) {
58
+ sessionStorage.clear();
59
+ } else {
60
+ localStorage.clear();
61
+ }
62
+ }
63
+ };
@@ -0,0 +1,12 @@
1
+ /** @name 状态列表 */
2
+ export declare const statusList: {
3
+ value: number;
4
+ text: string;
5
+ label: string;
6
+ }[];
7
+ /** @name 是否列表 */
8
+ export declare const yesnoList: {
9
+ value: number;
10
+ text: string;
11
+ label: string;
12
+ }[];
@@ -0,0 +1,20 @@
1
+ /** @name 状态列表 */
2
+ export var statusList = [{
3
+ value: 1,
4
+ text: '启用',
5
+ label: '1→启用'
6
+ }, {
7
+ value: 0,
8
+ text: '禁用',
9
+ label: '0→禁用'
10
+ }];
11
+ /** @name 是否列表 */
12
+ export var yesnoList = [{
13
+ value: 1,
14
+ text: '是',
15
+ label: '1→是'
16
+ }, {
17
+ value: 0,
18
+ text: '否',
19
+ label: '0→否'
20
+ }];
@@ -0,0 +1,15 @@
1
+ /**
2
+ * 获取Cookie
3
+ *
4
+ * @param {String} name Cookie名
5
+ * @returns
6
+ */
7
+ export declare const getCookie: (name: string) => string | null;
8
+ /**
9
+ * 设置Cookie
10
+ *
11
+ * @param {any} key Cookie名称
12
+ * @param {any} value Cookie 值
13
+ * @param {Number} day 有效天数 默认1天,
14
+ */
15
+ export declare const setCookie: (key: string, value: string | number, day?: number, sameSite?: boolean) => void;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * 获取Cookie
3
+ *
4
+ * @param {String} name Cookie名
5
+ * @returns
6
+ */
7
+ export var getCookie = function getCookie(name) {
8
+ var arr;
9
+ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)');
10
+ if (arr = document.cookie.match(reg)) return arr[2];else return null;
11
+ };
12
+ /**
13
+ * 设置Cookie
14
+ *
15
+ * @param {any} key Cookie名称
16
+ * @param {any} value Cookie 值
17
+ * @param {Number} day 有效天数 默认1天,
18
+ */
19
+ export var setCookie = function setCookie(key, value) {
20
+ var day = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
21
+ var sameSite = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
22
+ if (day !== 0) {
23
+ var d = new Date(Date.now() + day * 24 * 60 * 60 * 1000);
24
+ if (sameSite) {
25
+ document.cookie = "".concat(key, "=").concat(value, ";expires=").concat(d.toUTCString(), ";path=/;sameSite=None;secure=true");
26
+ } else {
27
+ document.cookie = "".concat(key, "=").concat(value, ";expires=").concat(d.toUTCString(), ";path=/");
28
+ }
29
+ } else {
30
+ if (sameSite) {
31
+ document.cookie = key + '=' + value + ';path=/;sameSite=None;secure=true';
32
+ } else {
33
+ document.cookie = key + '=' + value + ';path=/';
34
+ }
35
+ }
36
+ };
@@ -0,0 +1,16 @@
1
+ /**
2
+ * 绑定事件
3
+ *
4
+ * @param eventName 事件名
5
+ * @param fn 调用函数
6
+ * @param el 源对象,默认为window
7
+ */
8
+ export declare const on: (eventName: string, fn: Function, el: any | undefined) => void;
9
+ /**
10
+ * 解绑事件
11
+ *
12
+ * @param eventName 事件名
13
+ * @param fn 调用函数
14
+ * @param el 源对象,默认为window
15
+ */
16
+ export declare const off: (eventName: string, fn: Function, el: any | undefined) => void;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * 绑定事件
3
+ *
4
+ * @param eventName 事件名
5
+ * @param fn 调用函数
6
+ * @param el 源对象,默认为window
7
+ */
8
+ export var on = function on(eventName, fn, el) {
9
+ if (!el) {
10
+ el = window;
11
+ }
12
+ el.addEventListener(eventName, fn);
13
+ };
14
+ /**
15
+ * 解绑事件
16
+ *
17
+ * @param eventName 事件名
18
+ * @param fn 调用函数
19
+ * @param el 源对象,默认为window
20
+ */
21
+ export var off = function off(eventName, fn, el) {
22
+ if (!el) {
23
+ el = window;
24
+ }
25
+ el.removeEventListener(eventName, fn);
26
+ };