ls-pro-common 3.1.62 → 3.1.64

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.
package/es/index.d.ts CHANGED
@@ -9,6 +9,8 @@ export * from './http';
9
9
  export { default as BaseService } from './service/BaseService';
10
10
  /** 导出进度及完成后自动下载 */
11
11
  export { default as exportProcess } from './utils/exportProcess';
12
+ /** 后台任务进度查看 */
13
+ export { default as taskProcess } from './utils/taskProcess';
12
14
  /** Utils 方法,放在第一层级,方便调用 */
13
15
  export * from './utils';
14
16
  /** 主数据请求 */
package/es/index.js CHANGED
@@ -9,6 +9,8 @@ export * from './http';
9
9
  export { default as BaseService } from './service/BaseService';
10
10
  /** 导出进度及完成后自动下载 */
11
11
  export { default as exportProcess } from './utils/exportProcess';
12
+ /** 后台任务进度查看 */
13
+ export { default as taskProcess } from './utils/taskProcess';
12
14
  /** Utils 方法,放在第一层级,方便调用 */
13
15
  export * from './utils';
14
16
  /** 主数据请求 */
@@ -0,0 +1,10 @@
1
+ import { ApiResponse } from '../typing';
2
+ /**
3
+ * 后台任务进度查看
4
+ *
5
+ * @param taskId 后台任务id,
6
+ * @param taskName 后台任务名称,
7
+ * @returns
8
+ */
9
+ declare const taskProcess: (taskId: string, taskName: string | undefined, callback: (result: ApiResponse | false) => void) => void;
10
+ export default taskProcess;
@@ -0,0 +1,151 @@
1
+ import "antd/es/progress/style";
2
+ import _Progress from "antd/es/progress";
3
+ import "antd/es/notification/style";
4
+ import _notification from "antd/es/notification";
5
+ import React from "react";
6
+ import { showSuccess, showError, sleep, showWarn } from '.';
7
+ import { httpGet } from '../http';
8
+ /**
9
+ * 后台任务进度查看
10
+ *
11
+ * @param taskId 后台任务id,
12
+ * @param taskName 后台任务名称,
13
+ * @returns
14
+ */
15
+ var taskProcess = function taskProcess(taskId) {
16
+ var taskName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
17
+ var callback = arguments.length > 2 ? arguments[2] : undefined;
18
+ if (!taskId) {
19
+ callback(false);
20
+ return;
21
+ }
22
+ var exit = false;
23
+ var key = 'task-' + taskId;
24
+ var dom = null;
25
+ var moveState = {
26
+ isMove: false,
27
+ startLeft: 0,
28
+ startTop: 0,
29
+ startX: 0,
30
+ startY: 0,
31
+ h: 88,
32
+ w: 250 //组件宽度
33
+ };
34
+
35
+ var onMove = function onMove(e) {
36
+ requestAnimationFrame(function () {
37
+ var startLeft = moveState.startLeft,
38
+ startTop = moveState.startTop,
39
+ startX = moveState.startX,
40
+ startY = moveState.startY,
41
+ isMove = moveState.isMove,
42
+ h = moveState.h,
43
+ w = moveState.w;
44
+ if (!isMove || !dom) return;
45
+ // 通过计算鼠标的移动距离,计算出组件新的坐标。
46
+ var deltaX = document.body.clientWidth - (e.clientX - startX + startLeft) - w;
47
+ var deltaY = e.clientY - startY + startTop;
48
+ var top = Math.max(0, Math.min(document.body.clientHeight - h, deltaY));
49
+ var right = Math.max(0, Math.min(document.body.clientWidth - w - 30, deltaX));
50
+ dom.style.top = top + 'px';
51
+ dom.style.right = right + 'px';
52
+ });
53
+ };
54
+ var onUp = function onUp() {
55
+ moveState.isMove = false;
56
+ document.body.classList.remove('move-unselect');
57
+ document.removeEventListener('mouseup', onUp);
58
+ document.removeEventListener('mousemove', onMove);
59
+ };
60
+ var loading = function loading(percent) {
61
+ _notification.open({
62
+ className: 'export-process-notification',
63
+ placement: 'topRight',
64
+ key: key,
65
+ duration: 0,
66
+ message: /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("span", {
67
+ className: "export-process-handle",
68
+ onMouseDown: function onMouseDown(e) {
69
+ dom = e.target.closest('.ant-notification-topRight');
70
+ if (!dom) return;
71
+ var rect = dom.getBoundingClientRect();
72
+ moveState.isMove = true;
73
+ moveState.startX = e.clientX;
74
+ moveState.startY = e.clientY;
75
+ moveState.startLeft = rect.left;
76
+ moveState.startTop = rect.top;
77
+ document.body.classList.add('move-unselect');
78
+ document.addEventListener('mouseup', onUp);
79
+ document.addEventListener('mousemove', onMove);
80
+ }
81
+ }, "".concat(taskName || '任务', " \u5904\u7406\u4E2D...")), /*#__PURE__*/React.createElement(_Progress, {
82
+ percent: percent
83
+ })),
84
+ onClose: function onClose() {
85
+ exit = true;
86
+ callback(false);
87
+ document.removeEventListener('mouseup', onUp);
88
+ document.removeEventListener('mousemove', onMove);
89
+ }
90
+ });
91
+ };
92
+ loading(0);
93
+ var getResult = function getResult() {
94
+ if (exit) return;
95
+ var url = '/lesoon/lesoon-msg-center-api/bizAsyncTaskManage/page';
96
+ httpGet(url, {
97
+ page: 1,
98
+ pageSize: 1,
99
+ where: {
100
+ taskId: taskId
101
+ }
102
+ }, false).then(function (result) {
103
+ var _result$rows = result.rows,
104
+ rows = _result$rows === void 0 ? [] : _result$rows;
105
+ var row = rows === null || rows === void 0 ? void 0 : rows[0];
106
+ if (!row) {
107
+ showError('获取任务进度失败,请在消息中心查看任务结果');
108
+ callback(result);
109
+ _notification.close(key);
110
+ } else {
111
+ var status = row.status,
112
+ progress = row.progress;
113
+ if (status < 30) {
114
+ //任务处理中,过3秒后再次获取任务进度。
115
+ loading(progress);
116
+ sleep(3).then(function () {
117
+ return getResult();
118
+ });
119
+ } else {
120
+ // 任务已处理完成或失败或终止,关闭通知。
121
+ if (status === 30) {
122
+ loading(100);
123
+ showSuccess('任务处理完成');
124
+ } else if (status === 40) {
125
+ showError('任务处理失败,请在消息中心查看失败原因');
126
+ } else if (status === 50) {
127
+ showWarn('任务已终止,请在消息中心查看任务结果');
128
+ }
129
+ sleep(1.5).then(function () {
130
+ callback(result);
131
+ _notification.close(key);
132
+ });
133
+ }
134
+ }
135
+ }).catch(function () {
136
+ showError('获取任务进度失败,请在消息中心查看任务结果');
137
+ callback({
138
+ flag: {
139
+ retCode: '9999',
140
+ retMsg: '获取任务进度失败,请在消息中心查看任务结果'
141
+ },
142
+ success: false
143
+ });
144
+ _notification.close(key);
145
+ });
146
+ };
147
+ sleep(1).then(function () {
148
+ return getResult();
149
+ });
150
+ };
151
+ export default taskProcess;
package/lib/index.d.ts CHANGED
@@ -9,6 +9,8 @@ export * from './http';
9
9
  export { default as BaseService } from './service/BaseService';
10
10
  /** 导出进度及完成后自动下载 */
11
11
  export { default as exportProcess } from './utils/exportProcess';
12
+ /** 后台任务进度查看 */
13
+ export { default as taskProcess } from './utils/taskProcess';
12
14
  /** Utils 方法,放在第一层级,方便调用 */
13
15
  export * from './utils';
14
16
  /** 主数据请求 */
package/lib/index.js CHANGED
@@ -9,6 +9,8 @@ export * from './http';
9
9
  export { default as BaseService } from './service/BaseService';
10
10
  /** 导出进度及完成后自动下载 */
11
11
  export { default as exportProcess } from './utils/exportProcess';
12
+ /** 后台任务进度查看 */
13
+ export { default as taskProcess } from './utils/taskProcess';
12
14
  /** Utils 方法,放在第一层级,方便调用 */
13
15
  export * from './utils';
14
16
  /** 主数据请求 */
@@ -0,0 +1,10 @@
1
+ import { ApiResponse } from '../typing';
2
+ /**
3
+ * 后台任务进度查看
4
+ *
5
+ * @param taskId 后台任务id,
6
+ * @param taskName 后台任务名称,
7
+ * @returns
8
+ */
9
+ declare const taskProcess: (taskId: string, taskName: string | undefined, callback: (result: ApiResponse | false) => void) => void;
10
+ export default taskProcess;
@@ -0,0 +1,151 @@
1
+ import "antd/es/progress/style";
2
+ import _Progress from "antd/es/progress";
3
+ import "antd/es/notification/style";
4
+ import _notification from "antd/es/notification";
5
+ import React from "react";
6
+ import { showSuccess, showError, sleep, showWarn } from '.';
7
+ import { httpGet } from '../http';
8
+ /**
9
+ * 后台任务进度查看
10
+ *
11
+ * @param taskId 后台任务id,
12
+ * @param taskName 后台任务名称,
13
+ * @returns
14
+ */
15
+ var taskProcess = function taskProcess(taskId) {
16
+ var taskName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
17
+ var callback = arguments.length > 2 ? arguments[2] : undefined;
18
+ if (!taskId) {
19
+ callback(false);
20
+ return;
21
+ }
22
+ var exit = false;
23
+ var key = 'task-' + taskId;
24
+ var dom = null;
25
+ var moveState = {
26
+ isMove: false,
27
+ startLeft: 0,
28
+ startTop: 0,
29
+ startX: 0,
30
+ startY: 0,
31
+ h: 88,
32
+ w: 250 //组件宽度
33
+ };
34
+
35
+ var onMove = function onMove(e) {
36
+ requestAnimationFrame(function () {
37
+ var startLeft = moveState.startLeft,
38
+ startTop = moveState.startTop,
39
+ startX = moveState.startX,
40
+ startY = moveState.startY,
41
+ isMove = moveState.isMove,
42
+ h = moveState.h,
43
+ w = moveState.w;
44
+ if (!isMove || !dom) return;
45
+ // 通过计算鼠标的移动距离,计算出组件新的坐标。
46
+ var deltaX = document.body.clientWidth - (e.clientX - startX + startLeft) - w;
47
+ var deltaY = e.clientY - startY + startTop;
48
+ var top = Math.max(0, Math.min(document.body.clientHeight - h, deltaY));
49
+ var right = Math.max(0, Math.min(document.body.clientWidth - w - 30, deltaX));
50
+ dom.style.top = top + 'px';
51
+ dom.style.right = right + 'px';
52
+ });
53
+ };
54
+ var onUp = function onUp() {
55
+ moveState.isMove = false;
56
+ document.body.classList.remove('move-unselect');
57
+ document.removeEventListener('mouseup', onUp);
58
+ document.removeEventListener('mousemove', onMove);
59
+ };
60
+ var loading = function loading(percent) {
61
+ _notification.open({
62
+ className: 'export-process-notification',
63
+ placement: 'topRight',
64
+ key: key,
65
+ duration: 0,
66
+ message: /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("span", {
67
+ className: "export-process-handle",
68
+ onMouseDown: function onMouseDown(e) {
69
+ dom = e.target.closest('.ant-notification-topRight');
70
+ if (!dom) return;
71
+ var rect = dom.getBoundingClientRect();
72
+ moveState.isMove = true;
73
+ moveState.startX = e.clientX;
74
+ moveState.startY = e.clientY;
75
+ moveState.startLeft = rect.left;
76
+ moveState.startTop = rect.top;
77
+ document.body.classList.add('move-unselect');
78
+ document.addEventListener('mouseup', onUp);
79
+ document.addEventListener('mousemove', onMove);
80
+ }
81
+ }, "".concat(taskName || '任务', " \u5904\u7406\u4E2D...")), /*#__PURE__*/React.createElement(_Progress, {
82
+ percent: percent
83
+ })),
84
+ onClose: function onClose() {
85
+ exit = true;
86
+ callback(false);
87
+ document.removeEventListener('mouseup', onUp);
88
+ document.removeEventListener('mousemove', onMove);
89
+ }
90
+ });
91
+ };
92
+ loading(0);
93
+ var getResult = function getResult() {
94
+ if (exit) return;
95
+ var url = '/lesoon/lesoon-msg-center-api/bizAsyncTaskManage/page';
96
+ httpGet(url, {
97
+ page: 1,
98
+ pageSize: 1,
99
+ where: {
100
+ taskId: taskId
101
+ }
102
+ }, false).then(function (result) {
103
+ var _result$rows = result.rows,
104
+ rows = _result$rows === void 0 ? [] : _result$rows;
105
+ var row = rows === null || rows === void 0 ? void 0 : rows[0];
106
+ if (!row) {
107
+ showError('获取任务进度失败,请在消息中心查看任务结果');
108
+ callback(result);
109
+ _notification.close(key);
110
+ } else {
111
+ var status = row.status,
112
+ progress = row.progress;
113
+ if (status < 30) {
114
+ //任务处理中,过3秒后再次获取任务进度。
115
+ loading(progress);
116
+ sleep(3).then(function () {
117
+ return getResult();
118
+ });
119
+ } else {
120
+ // 任务已处理完成或失败或终止,关闭通知。
121
+ if (status === 30) {
122
+ loading(100);
123
+ showSuccess('任务处理完成');
124
+ } else if (status === 40) {
125
+ showError('任务处理失败,请在消息中心查看失败原因');
126
+ } else if (status === 50) {
127
+ showWarn('任务已终止,请在消息中心查看任务结果');
128
+ }
129
+ sleep(1.5).then(function () {
130
+ callback(result);
131
+ _notification.close(key);
132
+ });
133
+ }
134
+ }
135
+ }).catch(function () {
136
+ showError('获取任务进度失败,请在消息中心查看任务结果');
137
+ callback({
138
+ flag: {
139
+ retCode: '9999',
140
+ retMsg: '获取任务进度失败,请在消息中心查看任务结果'
141
+ },
142
+ success: false
143
+ });
144
+ _notification.close(key);
145
+ });
146
+ };
147
+ sleep(1).then(function () {
148
+ return getResult();
149
+ });
150
+ };
151
+ export default taskProcess;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ls-pro-common",
3
- "version": "3.1.62",
3
+ "version": "3.1.64",
4
4
  "description": "ls-pro-common",
5
5
  "license": "MIT",
6
6
  "sideEffects": [