ls-pro-common 3.1.65 → 3.1.67

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.
@@ -8,7 +8,7 @@ import React, { useRef, useState, useEffect, useImperativeHandle } from 'react';
8
8
  import { httpGet } from '../http';
9
9
  import { getCache, setCache, treeEach } from '../utils';
10
10
  var AreaCascader = /*#__PURE__*/React.forwardRef(function (props, ref) {
11
- var _useState = useState([]),
11
+ var _useState = useState(getCache('areaOptions', true) || []),
12
12
  _useState2 = _slicedToArray(_useState, 2),
13
13
  options = _useState2[0],
14
14
  setOptions = _useState2[1];
@@ -26,17 +26,16 @@ var AreaCascader = /*#__PURE__*/React.forwardRef(function (props, ref) {
26
26
  while (1) switch (_context.prev = _context.next) {
27
27
  case 0:
28
28
  cacheItems = getCache('areaOptions', true);
29
- if (!(cacheItems && Array.isArray(cacheItems))) {
30
- _context.next = 4;
29
+ if (!(cacheItems && Array.isArray(cacheItems) && cacheItems.length > 0)) {
30
+ _context.next = 3;
31
31
  break;
32
32
  }
33
- setOptions(cacheItems);
34
33
  return _context.abrupt("return");
35
- case 4:
34
+ case 3:
36
35
  api = '/petrel/petrel-location-center-api/sysAdministrativeDivision/allByTree';
37
- _context.next = 7;
36
+ _context.next = 6;
38
37
  return httpGet(api, {}, false);
39
- case 7:
38
+ case 6:
40
39
  result = _context.sent;
41
40
  opts = result.rows || [];
42
41
  treeEach(opts, function (item) {
@@ -50,9 +49,11 @@ var AreaCascader = /*#__PURE__*/React.forwardRef(function (props, ref) {
50
49
  delete item.level;
51
50
  delete item.parentId;
52
51
  });
53
- setCache('areaOptions', opts, true);
52
+ if (opts.length > 0) {
53
+ setCache('areaOptions', opts, true);
54
+ }
54
55
  setOptions(opts);
55
- case 12:
56
+ case 11:
56
57
  case "end":
57
58
  return _context.stop();
58
59
  }
@@ -86,7 +86,7 @@ var AreaPicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
86
86
  while (1) switch (_context.prev = _context.next) {
87
87
  case 0:
88
88
  cacheItems = getCache('areaOptionsPanel', true);
89
- if (!(cacheItems && Array.isArray(cacheItems) && cacheItems.length)) {
89
+ if (!(cacheItems && Array.isArray(cacheItems) && cacheItems.length > 0)) {
90
90
  _context.next = 3;
91
91
  break;
92
92
  }
@@ -108,7 +108,9 @@ var AreaPicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
108
108
  delete item.id;
109
109
  delete item.parentId;
110
110
  });
111
- setCache('areaOptionsPanel', opts, true);
111
+ if (opts.length > 0) {
112
+ setCache('areaOptionsPanel', opts, true);
113
+ }
112
114
  setOptions(opts);
113
115
  setShowData(opts);
114
116
  case 12:
@@ -20,7 +20,7 @@ function httpGetWithCache(_x, _x2) {
20
20
  /** 主数据接口地址 */
21
21
  function _httpGetWithCache() {
22
22
  _httpGetWithCache = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(type, url) {
23
- var _result$flag;
23
+ var _result$flag, _result$rows;
24
24
  var params,
25
25
  cache,
26
26
  cacheKey,
@@ -56,13 +56,16 @@ function _httpGetWithCache() {
56
56
  return httpBatchGet(url, params);
57
57
  case 12:
58
58
  result = _context2.sent;
59
- if ((result === null || result === void 0 ? void 0 : (_result$flag = result.flag) === null || _result$flag === void 0 ? void 0 : _result$flag.retCode) === '0' && cache) {
59
+ if ((result === null || result === void 0 ? void 0 : (_result$flag = result.flag) === null || _result$flag === void 0 ? void 0 : _result$flag.retCode) === '0' && (result === null || result === void 0 ? void 0 : (_result$rows = result.rows) === null || _result$rows === void 0 ? void 0 : _result$rows.length) > 0 && cache) {
60
60
  try {
61
61
  setCache(cacheKey, result, true);
62
62
  } catch (error) {
63
63
  // 缓存太大时无法保存,设置到内存中缓存
64
64
  setMdmCache(cacheKey, result);
65
65
  }
66
+ } else {
67
+ clearCache(cacheKey, true);
68
+ deleteMdmCache(cacheKey);
66
69
  }
67
70
  return _context2.abrupt("return", result);
68
71
  case 15:
@@ -6,5 +6,5 @@ import { ApiResponse } from '../typing';
6
6
  * @param taskName 后台任务名称,
7
7
  * @returns
8
8
  */
9
- declare const taskProcess: (taskId: string, taskName: string | undefined, callback: (result: ApiResponse | false) => void) => void;
9
+ declare const taskProcess: (taskId: string, taskName?: string, callback?: ((result: ApiResponse | false) => void) | undefined) => void;
10
10
  export default taskProcess;
@@ -16,7 +16,7 @@ var taskProcess = function taskProcess(taskId) {
16
16
  var taskName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
17
17
  var callback = arguments.length > 2 ? arguments[2] : undefined;
18
18
  if (!taskId) {
19
- callback(false);
19
+ callback === null || callback === void 0 ? void 0 : callback(false);
20
20
  return;
21
21
  }
22
22
  var exit = false;
@@ -83,7 +83,7 @@ var taskProcess = function taskProcess(taskId) {
83
83
  })),
84
84
  onClose: function onClose() {
85
85
  exit = true;
86
- callback(false);
86
+ callback === null || callback === void 0 ? void 0 : callback(false);
87
87
  document.removeEventListener('mouseup', onUp);
88
88
  document.removeEventListener('mousemove', onMove);
89
89
  }
@@ -105,7 +105,7 @@ var taskProcess = function taskProcess(taskId) {
105
105
  var row = rows === null || rows === void 0 ? void 0 : rows[0];
106
106
  if (!row) {
107
107
  showError('获取任务进度失败,请在消息中心查看任务结果');
108
- callback(result);
108
+ callback === null || callback === void 0 ? void 0 : callback(result);
109
109
  _notification.close(key);
110
110
  } else {
111
111
  var status = row.status,
@@ -127,21 +127,21 @@ var taskProcess = function taskProcess(taskId) {
127
127
  showWarn('任务已终止,请在消息中心查看任务结果');
128
128
  }
129
129
  sleep(1.5).then(function () {
130
- callback(result);
131
130
  _notification.close(key);
131
+ callback === null || callback === void 0 ? void 0 : callback(result);
132
132
  });
133
133
  }
134
134
  }
135
135
  }).catch(function () {
136
136
  showError('获取任务进度失败,请在消息中心查看任务结果');
137
- callback({
137
+ _notification.close(key);
138
+ callback === null || callback === void 0 ? void 0 : callback({
138
139
  flag: {
139
140
  retCode: '9999',
140
141
  retMsg: '获取任务进度失败,请在消息中心查看任务结果'
141
142
  },
142
143
  success: false
143
144
  });
144
- _notification.close(key);
145
145
  });
146
146
  };
147
147
  sleep(1).then(function () {
@@ -8,7 +8,7 @@ import React, { useRef, useState, useEffect, useImperativeHandle } from 'react';
8
8
  import { httpGet } from '../http';
9
9
  import { getCache, setCache, treeEach } from '../utils';
10
10
  var AreaCascader = /*#__PURE__*/React.forwardRef(function (props, ref) {
11
- var _useState = useState([]),
11
+ var _useState = useState(getCache('areaOptions', true) || []),
12
12
  _useState2 = _slicedToArray(_useState, 2),
13
13
  options = _useState2[0],
14
14
  setOptions = _useState2[1];
@@ -26,17 +26,16 @@ var AreaCascader = /*#__PURE__*/React.forwardRef(function (props, ref) {
26
26
  while (1) switch (_context.prev = _context.next) {
27
27
  case 0:
28
28
  cacheItems = getCache('areaOptions', true);
29
- if (!(cacheItems && Array.isArray(cacheItems))) {
30
- _context.next = 4;
29
+ if (!(cacheItems && Array.isArray(cacheItems) && cacheItems.length > 0)) {
30
+ _context.next = 3;
31
31
  break;
32
32
  }
33
- setOptions(cacheItems);
34
33
  return _context.abrupt("return");
35
- case 4:
34
+ case 3:
36
35
  api = '/petrel/petrel-location-center-api/sysAdministrativeDivision/allByTree';
37
- _context.next = 7;
36
+ _context.next = 6;
38
37
  return httpGet(api, {}, false);
39
- case 7:
38
+ case 6:
40
39
  result = _context.sent;
41
40
  opts = result.rows || [];
42
41
  treeEach(opts, function (item) {
@@ -50,9 +49,11 @@ var AreaCascader = /*#__PURE__*/React.forwardRef(function (props, ref) {
50
49
  delete item.level;
51
50
  delete item.parentId;
52
51
  });
53
- setCache('areaOptions', opts, true);
52
+ if (opts.length > 0) {
53
+ setCache('areaOptions', opts, true);
54
+ }
54
55
  setOptions(opts);
55
- case 12:
56
+ case 11:
56
57
  case "end":
57
58
  return _context.stop();
58
59
  }
@@ -86,7 +86,7 @@ var AreaPicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
86
86
  while (1) switch (_context.prev = _context.next) {
87
87
  case 0:
88
88
  cacheItems = getCache('areaOptionsPanel', true);
89
- if (!(cacheItems && Array.isArray(cacheItems) && cacheItems.length)) {
89
+ if (!(cacheItems && Array.isArray(cacheItems) && cacheItems.length > 0)) {
90
90
  _context.next = 3;
91
91
  break;
92
92
  }
@@ -108,7 +108,9 @@ var AreaPicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
108
108
  delete item.id;
109
109
  delete item.parentId;
110
110
  });
111
- setCache('areaOptionsPanel', opts, true);
111
+ if (opts.length > 0) {
112
+ setCache('areaOptionsPanel', opts, true);
113
+ }
112
114
  setOptions(opts);
113
115
  setShowData(opts);
114
116
  case 12:
@@ -20,7 +20,7 @@ function httpGetWithCache(_x, _x2) {
20
20
  /** 主数据接口地址 */
21
21
  function _httpGetWithCache() {
22
22
  _httpGetWithCache = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(type, url) {
23
- var _result$flag;
23
+ var _result$flag, _result$rows;
24
24
  var params,
25
25
  cache,
26
26
  cacheKey,
@@ -56,13 +56,16 @@ function _httpGetWithCache() {
56
56
  return httpBatchGet(url, params);
57
57
  case 12:
58
58
  result = _context2.sent;
59
- if ((result === null || result === void 0 ? void 0 : (_result$flag = result.flag) === null || _result$flag === void 0 ? void 0 : _result$flag.retCode) === '0' && cache) {
59
+ if ((result === null || result === void 0 ? void 0 : (_result$flag = result.flag) === null || _result$flag === void 0 ? void 0 : _result$flag.retCode) === '0' && (result === null || result === void 0 ? void 0 : (_result$rows = result.rows) === null || _result$rows === void 0 ? void 0 : _result$rows.length) > 0 && cache) {
60
60
  try {
61
61
  setCache(cacheKey, result, true);
62
62
  } catch (error) {
63
63
  // 缓存太大时无法保存,设置到内存中缓存
64
64
  setMdmCache(cacheKey, result);
65
65
  }
66
+ } else {
67
+ clearCache(cacheKey, true);
68
+ deleteMdmCache(cacheKey);
66
69
  }
67
70
  return _context2.abrupt("return", result);
68
71
  case 15:
@@ -6,5 +6,5 @@ import { ApiResponse } from '../typing';
6
6
  * @param taskName 后台任务名称,
7
7
  * @returns
8
8
  */
9
- declare const taskProcess: (taskId: string, taskName: string | undefined, callback: (result: ApiResponse | false) => void) => void;
9
+ declare const taskProcess: (taskId: string, taskName?: string, callback?: ((result: ApiResponse | false) => void) | undefined) => void;
10
10
  export default taskProcess;
@@ -16,7 +16,7 @@ var taskProcess = function taskProcess(taskId) {
16
16
  var taskName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
17
17
  var callback = arguments.length > 2 ? arguments[2] : undefined;
18
18
  if (!taskId) {
19
- callback(false);
19
+ callback === null || callback === void 0 ? void 0 : callback(false);
20
20
  return;
21
21
  }
22
22
  var exit = false;
@@ -83,7 +83,7 @@ var taskProcess = function taskProcess(taskId) {
83
83
  })),
84
84
  onClose: function onClose() {
85
85
  exit = true;
86
- callback(false);
86
+ callback === null || callback === void 0 ? void 0 : callback(false);
87
87
  document.removeEventListener('mouseup', onUp);
88
88
  document.removeEventListener('mousemove', onMove);
89
89
  }
@@ -105,7 +105,7 @@ var taskProcess = function taskProcess(taskId) {
105
105
  var row = rows === null || rows === void 0 ? void 0 : rows[0];
106
106
  if (!row) {
107
107
  showError('获取任务进度失败,请在消息中心查看任务结果');
108
- callback(result);
108
+ callback === null || callback === void 0 ? void 0 : callback(result);
109
109
  _notification.close(key);
110
110
  } else {
111
111
  var status = row.status,
@@ -127,21 +127,21 @@ var taskProcess = function taskProcess(taskId) {
127
127
  showWarn('任务已终止,请在消息中心查看任务结果');
128
128
  }
129
129
  sleep(1.5).then(function () {
130
- callback(result);
131
130
  _notification.close(key);
131
+ callback === null || callback === void 0 ? void 0 : callback(result);
132
132
  });
133
133
  }
134
134
  }
135
135
  }).catch(function () {
136
136
  showError('获取任务进度失败,请在消息中心查看任务结果');
137
- callback({
137
+ _notification.close(key);
138
+ callback === null || callback === void 0 ? void 0 : callback({
138
139
  flag: {
139
140
  retCode: '9999',
140
141
  retMsg: '获取任务进度失败,请在消息中心查看任务结果'
141
142
  },
142
143
  success: false
143
144
  });
144
- _notification.close(key);
145
145
  });
146
146
  };
147
147
  sleep(1).then(function () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ls-pro-common",
3
- "version": "3.1.65",
3
+ "version": "3.1.67",
4
4
  "description": "ls-pro-common",
5
5
  "license": "MIT",
6
6
  "sideEffects": [