@lambo-design/shared 1.0.0-beta.38 → 1.0.0-beta.381

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 (260) hide show
  1. package/config/config.js +24 -3
  2. package/config/index.js +7 -2
  3. package/config/locale.js +61 -0
  4. package/config/themes/atrovirens/atrovirens.css +590 -0
  5. package/config/themes/atrovirens/atrovirens.css.map +1 -0
  6. package/config/themes/atrovirens/atrovirens.less +681 -0
  7. package/config/themes/atrovirens/var.less +689 -0
  8. package/config/themes/blue/blue.css +590 -0
  9. package/config/themes/blue/blue.css.map +1 -0
  10. package/config/themes/blue/blue.less +684 -0
  11. package/config/themes/blue/var.less +692 -0
  12. package/config/themes/blue-208/blue-208.css +590 -0
  13. package/config/themes/blue-208/blue-208.css.map +1 -0
  14. package/config/themes/blue-208/blue-208.less +685 -0
  15. package/config/themes/blue-208/var.less +691 -0
  16. package/config/themes/blue-digital/blue-digital.css +590 -0
  17. package/config/themes/blue-digital/blue-digital.css.map +1 -0
  18. package/config/themes/blue-digital/blue-digital.less +684 -0
  19. package/config/themes/blue-digital/var.less +692 -0
  20. package/config/themes/blue-leaf/blue-leaf.css +590 -0
  21. package/config/themes/blue-leaf/blue-leaf.css.map +1 -0
  22. package/config/themes/blue-leaf/blue-leaf.less +685 -0
  23. package/config/themes/blue-leaf/var.less +691 -0
  24. package/config/themes/blue-white/blue-white.css +590 -0
  25. package/config/themes/blue-white/blue-white.css.map +1 -0
  26. package/config/themes/blue-white/blue-white.less +685 -0
  27. package/config/themes/blue-white/var.less +691 -0
  28. package/config/themes/blue-white-big/blue-white-big.css +590 -0
  29. package/config/themes/blue-white-big/blue-white-big.css.map +1 -0
  30. package/config/themes/blue-white-big/blue-white-big.less +685 -0
  31. package/config/themes/blue-white-big/var.less +691 -0
  32. package/config/themes/blue-white-tight/blue-white-tight.css +591 -0
  33. package/config/themes/blue-white-tight/blue-white-tight.css.map +1 -0
  34. package/config/themes/blue-white-tight/blue-white-tight.less +685 -0
  35. package/config/themes/blue-white-tight/var.less +693 -0
  36. package/config/themes/canglan/canglan.css +590 -0
  37. package/config/themes/canglan/canglan.css.map +1 -0
  38. package/config/themes/canglan/canglan.less +682 -0
  39. package/config/themes/canglan/var.less +693 -0
  40. package/config/themes/cuiwei/cuiwei.css +590 -0
  41. package/config/themes/cuiwei/cuiwei.css.map +1 -0
  42. package/config/themes/cuiwei/cuiwei.less +682 -0
  43. package/config/themes/cuiwei/var.less +691 -0
  44. package/config/themes/danqing/danqing.css +590 -0
  45. package/config/themes/danqing/danqing.css.map +1 -0
  46. package/config/themes/danqing/danqing.less +682 -0
  47. package/config/themes/danqing/danqing.wxss +576 -0
  48. package/config/themes/danqing/var.less +696 -0
  49. package/config/themes/deep/deep.css +590 -0
  50. package/config/themes/deep/deep.css.map +1 -0
  51. package/config/themes/deep/deep.less +682 -0
  52. package/config/themes/deep/var.less +694 -0
  53. package/config/themes/default/default.css +404 -57
  54. package/config/themes/default/default.css.map +1 -1
  55. package/config/themes/default/default.less +381 -16
  56. package/config/themes/default/var.less +390 -11
  57. package/config/themes/eap/eap.css +590 -0
  58. package/config/themes/eap/eap.css.map +1 -0
  59. package/config/themes/eap/eap.less +685 -0
  60. package/config/themes/eap/var.less +693 -0
  61. package/config/themes/gold/gold.css +590 -0
  62. package/config/themes/gold/gold.css.map +1 -0
  63. package/config/themes/gold/gold.less +685 -0
  64. package/config/themes/gold/var.less +386 -5
  65. package/config/themes/hubei/hubei.css +591 -0
  66. package/config/themes/hubei/hubei.css.map +1 -0
  67. package/config/themes/hubei/hubei.less +685 -0
  68. package/config/themes/hubei/var.less +693 -0
  69. package/config/themes/index.js +34 -4
  70. package/config/themes/lime/lime.css +590 -0
  71. package/config/themes/lime/lime.css.map +1 -0
  72. package/config/themes/lime/lime.less +685 -0
  73. package/config/themes/lime/var.less +385 -5
  74. package/config/themes/orange/orange.css +354 -7
  75. package/config/themes/orange/orange.css.map +1 -1
  76. package/config/themes/orange/orange.less +366 -0
  77. package/config/themes/orange/var.less +386 -5
  78. package/config/themes/red/red.css +354 -7
  79. package/config/themes/red/red.css.map +1 -1
  80. package/config/themes/red/red.less +366 -0
  81. package/config/themes/red/var.less +386 -5
  82. package/config/themes/sichuan/sichuan.css +590 -0
  83. package/config/themes/sichuan/sichuan.css.map +1 -0
  84. package/config/themes/sichuan/sichuan.less +685 -0
  85. package/config/themes/sichuan/var.less +691 -0
  86. package/config/themes/theme-atrovirens.js +572 -0
  87. package/config/themes/theme-b208.js +572 -0
  88. package/config/themes/theme-bd.js +572 -0
  89. package/config/themes/theme-bl.js +572 -0
  90. package/config/themes/theme-blue.js +572 -0
  91. package/config/themes/theme-bw.js +572 -0
  92. package/config/themes/theme-bwb.js +572 -0
  93. package/config/themes/theme-bwt.js +573 -0
  94. package/config/themes/theme-canglan.js +574 -0
  95. package/config/themes/theme-cuiwei.js +574 -0
  96. package/config/themes/theme-danqing.js +575 -0
  97. package/config/themes/theme-deep.js +572 -0
  98. package/config/themes/theme-default.js +378 -56
  99. package/config/themes/theme-eap.js +572 -0
  100. package/config/themes/theme-gold.js +327 -5
  101. package/config/themes/theme-hubei.js +574 -0
  102. package/config/themes/theme-lime.js +327 -5
  103. package/config/themes/theme-orange.js +561 -29
  104. package/config/themes/theme-red.js +564 -33
  105. package/config/themes/theme-sichuan.js +572 -0
  106. package/config/themes/theme-white.js +572 -0
  107. package/config/themes/white/var.less +692 -0
  108. package/config/themes/white/white.css +590 -0
  109. package/config/themes/white/white.css.map +1 -0
  110. package/config/themes/white/white.less +685 -0
  111. package/directives/module/draggable-menu.js +94 -0
  112. package/directives/module/print.js +1 -0
  113. package/directives/module/vue-print-nb/README.md +63 -0
  114. package/directives/module/vue-print-nb/print.js +94 -0
  115. package/directives/module/vue-print-nb/printarea.js +532 -0
  116. package/index.js +7 -1
  117. package/nstyles/common.less +197 -0
  118. package/nstyles/components/404.less +46 -0
  119. package/nstyles/components/button.less +34 -0
  120. package/nstyles/components/date-picker.less +41 -0
  121. package/nstyles/components/drawer.less +20 -0
  122. package/nstyles/components/dropdown.less +18 -0
  123. package/nstyles/components/excel-flow.less +72 -0
  124. package/nstyles/components/form.less +314 -0
  125. package/nstyles/components/index.less +23 -0
  126. package/nstyles/components/layout/collect.less +10 -0
  127. package/nstyles/components/layout/detail-view.less +107 -0
  128. package/nstyles/components/layout/full-screen.less +7 -0
  129. package/nstyles/components/layout/index.less +7 -0
  130. package/nstyles/components/layout/other-menu.less +142 -0
  131. package/nstyles/components/layout/page-view.less +101 -0
  132. package/nstyles/components/layout/sider-trigger.less +41 -0
  133. package/nstyles/components/layout/tags-nav.less +113 -0
  134. package/nstyles/components/modal.less +90 -0
  135. package/nstyles/components/n-button.less +131 -0
  136. package/nstyles/components/n-image-preview.less +131 -0
  137. package/nstyles/components/n-model/index.less +19 -0
  138. package/nstyles/components/n-model/report-index.less +43 -0
  139. package/nstyles/components/n-panel.less +41 -0
  140. package/nstyles/components/n-picker.less +37 -0
  141. package/nstyles/components/n-sign.less +17 -0
  142. package/nstyles/components/n-tooltip.less +10 -0
  143. package/nstyles/components/panel.less +31 -0
  144. package/nstyles/components/select.less +3 -0
  145. package/nstyles/components/sign.less +27 -0
  146. package/nstyles/components/table.less +526 -0
  147. package/nstyles/components/tree.less +260 -0
  148. package/nstyles/components/upload.less +174 -0
  149. package/nstyles/index.less +5 -0
  150. package/nstyles/reset.less +73 -0
  151. package/nstyles/third/ag.less +226 -0
  152. package/nstyles/third/icons/sort-desc.svg +1 -0
  153. package/nstyles/third/icons/sort-up.svg +1 -0
  154. package/nstyles/third/icons/sorting.svg +1 -0
  155. package/nstyles/third/index.less +11 -0
  156. package/nstyles/third/view-design.less +402 -0
  157. package/nstyles/variables/base.less +143 -0
  158. package/nstyles/variables/index.less +4 -0
  159. package/nstyles/variables/theme/default/button.less +7 -0
  160. package/nstyles/variables/theme/default/common.less +60 -0
  161. package/nstyles/variables/theme/default/index.less +7 -0
  162. package/nstyles/variables/theme/default/layout.less +40 -0
  163. package/nstyles/variables/theme/default/table.less +37 -0
  164. package/nstyles/variables/theme/default/tag.less +3 -0
  165. package/nstyles/variables/theme/default/upload.less +3 -0
  166. package/nstyles/variables/theme/index.less +13 -0
  167. package/nstyles/variables/theme/lsv/button.less +7 -0
  168. package/nstyles/variables/theme/lsv/common.less +39 -0
  169. package/nstyles/variables/theme/lsv/index.less +5 -0
  170. package/nstyles/variables/theme/lsv/layout.less +21 -0
  171. package/nstyles/variables/theme/lsv/table.less +20 -0
  172. package/nstyles/variables/theme/lsv/tag.less +3 -0
  173. package/nstyles/variables/theme/small/button.less +7 -0
  174. package/nstyles/variables/theme/small/common.less +41 -0
  175. package/nstyles/variables/theme/small/index.less +5 -0
  176. package/nstyles/variables/theme/small/layout.less +21 -0
  177. package/nstyles/variables/theme/small/table.less +17 -0
  178. package/nstyles/variables/theme/small/tag.less +3 -0
  179. package/package.json +28 -7
  180. package/plugin/index.js +12 -0
  181. package/plugin/module/date-format.js +30 -0
  182. package/plugin/module/loading.js +26 -0
  183. package/plugin/module/warn-handler.js +11 -0
  184. package/styles/image/indicator-card-header.png +0 -0
  185. package/styles/image/inspur.png +0 -0
  186. package/styles/image/lan_navigator.png +0 -0
  187. package/styles/image/layout-header-bg-canglan.png +0 -0
  188. package/styles/image/layout-header-bg-cuiwei.png +0 -0
  189. package/styles/image/layout-header-bg-gold.png +0 -0
  190. package/styles/image/lv_navigator.png +0 -0
  191. package/utils/ajax/abort-controller.js +70 -0
  192. package/utils/ajax/cancel-reason.js +25 -0
  193. package/utils/ajax/cancel-token.js +83 -0
  194. package/utils/ajax/content-type.js +30 -0
  195. package/utils/ajax/headers.js +16 -0
  196. package/utils/ajax/interceptors.js +49 -10
  197. package/utils/ajax/sseFetchUtil.js +127 -0
  198. package/utils/ajax/throttle.js +49 -0
  199. package/utils/assist.js +155 -27
  200. package/utils/base64.js +126 -0
  201. package/utils/blob.js +47 -0
  202. package/utils/context-menu.js +264 -0
  203. package/utils/crypto/aes.js +23 -0
  204. package/utils/crypto/index.js +10 -0
  205. package/utils/crypto/rsa.js +23 -0
  206. package/utils/date.js +334 -305
  207. package/utils/dict/built-in-dict.js +20 -0
  208. package/utils/dict/index.js +191 -0
  209. package/utils/event.js +72 -0
  210. package/utils/excel.js +504 -290
  211. package/utils/file.js +19 -0
  212. package/utils/form/validate.js +29 -0
  213. package/utils/getChild.js +87 -0
  214. package/utils/half-year.js +68 -0
  215. package/utils/index.js +37 -0
  216. package/utils/json.js +44 -0
  217. package/utils/locale/en-US.js +180 -0
  218. package/utils/locale/zh-CN.js +184 -0
  219. package/utils/lodop.js +5 -0
  220. package/utils/menu/generatorDynamicRouter.js +304 -0
  221. package/utils/menu/index.js +482 -15
  222. package/utils/mime_type.js +67 -0
  223. package/utils/modelerUtil.js +4 -1
  224. package/utils/n/api.js +42 -0
  225. package/utils/n/date.js +57 -0
  226. package/utils/n/index.js +10 -0
  227. package/utils/n/is-type.js +176 -0
  228. package/utils/n/number.js +144 -0
  229. package/utils/n/permission-cache.js +11 -0
  230. package/utils/n/reuqest/axiosN.js +17 -0
  231. package/utils/n/reuqest/content-type.js +19 -0
  232. package/utils/n/reuqest/interceptors.js +95 -0
  233. package/utils/n/reuqest/url-params.js +12 -0
  234. package/utils/n/storage.js +51 -0
  235. package/utils/n/token.js +51 -0
  236. package/utils/n/user-cache.js +11 -0
  237. package/utils/n/user.js +34 -0
  238. package/utils/n/uuid.js +16 -0
  239. package/utils/n-generator-routers.js +208 -0
  240. package/utils/n-router.js +205 -0
  241. package/utils/n-theme.js +30 -0
  242. package/utils/number.js +72 -15
  243. package/utils/oss.js +57 -0
  244. package/utils/platform.js +954 -31
  245. package/utils/quarter.js +58 -0
  246. package/utils/storage.js +198 -0
  247. package/utils/style.js +24 -0
  248. package/utils/theme.js +98 -3
  249. package/utils/transfer-queue.js +7 -0
  250. package/utils/transform.js +205 -0
  251. package/utils/type.js +102 -0
  252. package/utils/util.js +795 -0
  253. package/utils/vForm.js +349 -0
  254. package/utils/validator.js +181 -0
  255. package/config/themes/gold/default.css +0 -243
  256. package/config/themes/gold/default.css.map +0 -1
  257. package/config/themes/gold/default.less +0 -320
  258. package/config/themes/lime/default.css +0 -243
  259. package/config/themes/lime/default.css.map +0 -1
  260. package/config/themes/lime/default.less +0 -320
@@ -0,0 +1,11 @@
1
+ export default {
2
+ install : function (Vue, options) {
3
+ Vue.config.warnHandler = function (err, vm, info) {
4
+ if (err.toString().indexOf("Component names should conform to valid custom element name in html5 specification")>0){
5
+ console.warn("[Lambo warn]: " + err + info);
6
+ }else{
7
+ console.error("[Vue warn]: " + err + info);
8
+ }
9
+ }
10
+ }
11
+ }
Binary file
Binary file
Binary file
@@ -0,0 +1,70 @@
1
+ // 用于存储每个请求的标识和取消函数
2
+ import qs from "qs";
3
+
4
+ const pendingMap = new Map();
5
+
6
+ const getPendingUrl = (config) => {
7
+ const { url, method, data, headers } = config;
8
+
9
+ // 生成请求唯一标识
10
+ return headers['is-cancel-token']
11
+ ? headers['is-cancel-token']
12
+ : [url, method, qs.stringify(data)].join('&');
13
+ };
14
+
15
+ /**
16
+ * 添加请求
17
+ * @param config 请求配置
18
+ */
19
+ function addPending(config) {
20
+ removePending(config);
21
+ const url = getPendingUrl(config);
22
+ const controller = new AbortController();
23
+ config.signal = config.signal || controller.signal;
24
+ if (!pendingMap.has(url)) {
25
+ // 如果当前请求不在等待中,将其添加到等待中
26
+ pendingMap.set(url, controller);
27
+ }
28
+ }
29
+
30
+ /**
31
+ * 移除请求
32
+ * @param config 请求配置
33
+ */
34
+ function removePending(config) {
35
+ const url = getPendingUrl(config);
36
+ if (pendingMap.has(url)) {
37
+ // 如果当前请求在等待中,取消它并将其从等待中移除
38
+ const abortController = pendingMap.get(url);
39
+ if (abortController) {
40
+ abortController.abort();
41
+ }
42
+ pendingMap.delete(url);
43
+ }
44
+ }
45
+
46
+ /**
47
+ * 重置
48
+ */
49
+ function reset() {
50
+ pendingMap.clear();
51
+ }
52
+
53
+ /**
54
+ * 清除所有等待中的请求
55
+ */
56
+ function removeAllPending() {
57
+ pendingMap.forEach((abortController) => {
58
+ if (abortController) {
59
+ abortController.abort();
60
+ }
61
+ });
62
+ reset();
63
+ }
64
+
65
+
66
+ export default {
67
+ addPending,
68
+ removePending,
69
+ removeAllPending
70
+ }
@@ -0,0 +1,25 @@
1
+ // 自定义取消原因枚举
2
+ import Vue from "vue";
3
+
4
+ export const CancelReason = {
5
+ USER_ACTION: 'user_action',
6
+ NAVIGATION: 'navigation',
7
+ TIMEOUT: 'timeout',
8
+ DUPLICATE: 'duplicate'
9
+ };
10
+
11
+ export const showReason = (reason)=>{
12
+ switch (reason) {
13
+ case CancelReason.USER_ACTION:
14
+ Vue.prototype.$Message.info('操作已取消')
15
+ break;
16
+ case CancelReason.TIMEOUT:
17
+ Vue.prototype.$Message.error('请求超时,请重试');
18
+ break;
19
+ case CancelReason.DUPLICATE:
20
+ Vue.prototype.$Message.warning('重复请求已取消');
21
+ break;
22
+ default:
23
+ Vue.prototype.$Message.error('请求已取消');
24
+ }
25
+ }
@@ -0,0 +1,83 @@
1
+ // axios 0.22.0 版本以后推荐使用abort-controller
2
+ import axios from "axios";
3
+ import qs from 'qs'
4
+ import {CancelReason} from "./cancel-reason";
5
+ // 存储所有请求的取消函数
6
+ const cancelTokenMap = {};
7
+
8
+ const getPendingUrl = (config) => {
9
+ const { url, method, data, headers } = config;
10
+
11
+ // 生成请求唯一标识
12
+ return headers['is-cancel-token']
13
+ ? headers['is-cancel-token']
14
+ : [url, method, qs.stringify(data)].join('&');
15
+ };
16
+ /**
17
+ * 生成请求唯一标识并注册取消函数
18
+ * @param {Object} config - 请求配置
19
+ * @returns {Object} 增强后的请求配置
20
+ */
21
+ function addPending(config) {
22
+
23
+ // 生成请求唯一标识
24
+ const requestId = getPendingUrl(config);
25
+
26
+ // 获取已存在的取消函数
27
+ const existingCancel = cancelTokenMap[requestId];
28
+
29
+ // 注册取消令牌
30
+ config.cancelToken = config.cancelToken || new axios.CancelToken(cancel => {
31
+ if (!existingCancel) {
32
+ cancelTokenMap[requestId] = cancel;
33
+ }
34
+ });
35
+
36
+ return config;
37
+ }
38
+
39
+ /**
40
+ * 取消指定请求
41
+ * @param {Object} config - 要取消的请求配置
42
+ */
43
+ function removePending(config) {
44
+ const { url, method, data, headers } = config;
45
+
46
+ const requestId = getPendingUrl(config);
47
+
48
+ const cancelFn = cancelTokenMap[requestId];
49
+
50
+ if (cancelFn && typeof cancelFn === 'function') {
51
+ cancelFn({
52
+ type: 'cancel',
53
+ url: requestId,
54
+ reason: CancelReason.DUPLICATE,
55
+ message: '数据正在处理,请勿重复提交'
56
+ }); // 执行取消
57
+ delete cancelTokenMap[requestId]; // 清理
58
+ }
59
+ }
60
+
61
+ /**
62
+ * 取消所有未完成的请求
63
+ */
64
+ function removeAllPending() {
65
+ Object.keys(cancelTokenMap).forEach(key => {
66
+ const cancelFn = cancelTokenMap[key];
67
+ if (cancelFn && typeof cancelFn === 'function') {
68
+ cancelFn({
69
+ type: 'cancel',
70
+ url: key,
71
+ reason: CancelReason.NAVIGATION,
72
+ message: '请求已取消'
73
+ }); // 执行取消
74
+ delete cancelTokenMap[key]; // 清理
75
+ }
76
+ });
77
+ }
78
+
79
+ export default {
80
+ addPending,
81
+ removePending,
82
+ removeAllPending
83
+ }
@@ -0,0 +1,30 @@
1
+ const contentTypeKey = 'Content-Type'
2
+
3
+ export function getContentType(config) {
4
+ // let type = config?.[contentTypeKey] || config?.['content-type'] || ''
5
+ let type = '';
6
+
7
+ if (config && config[contentTypeKey]) {
8
+ type = config[contentTypeKey];
9
+ } else if (config && config['content-type']) {
10
+ type = config['content-type'];
11
+ }
12
+ const suffixIdx = type.indexOf(';')
13
+ if (suffixIdx !== -1) {
14
+ type = type.substring(0, suffixIdx)
15
+ }
16
+
17
+ return type
18
+ }
19
+
20
+ export function setContentType(headers, type) {
21
+ headers[contentTypeKey] = type
22
+ }
23
+
24
+ export const CONTENT_TYPE = {
25
+ form: 'application/x-www-form-urlencoded',
26
+ multiForm: 'multipart/form-data',
27
+ body: 'application/json',
28
+ os: 'application/octet-stream',
29
+ json: 'application/json',
30
+ }
@@ -0,0 +1,16 @@
1
+ let headers = {}
2
+ headers.tenant = {
3
+ tenantCode: 'tenant-code',
4
+ systemType: 'system-type',
5
+ }
6
+
7
+ headers.auth = {
8
+ token: 'token'
9
+ }
10
+
11
+ headers.ajaxHeader = {
12
+ HEADER_TIMESTAMP : 'X-Timestamp',
13
+ HEADER_NONCE : 'X-Nonce'
14
+ }
15
+
16
+ export default headers
@@ -1,9 +1,15 @@
1
1
  import qs from 'qs'
2
2
  import cacheRules from "./cacheconf";
3
- import {getToken,getUrlParams} from '../platform'
3
+ import {getLocalStorage, getToken, getUrlParams} from '../platform'
4
4
  import Bus from '../bus';
5
-
6
-
5
+ import headers from './headers';
6
+ import {throttle} from "./throttle";
7
+ import abortController from "./abort-controller"
8
+ import cancelToken from "./cancel-token"
9
+ import { isCancel,Cancel } from "axios";
10
+ import Vue from "vue";
11
+ import {CancelReason} from "./cancel-reason";
12
+ import {guid} from "../number";
7
13
  let timer1, timer2;
8
14
  let hasDialog = false;
9
15
 
@@ -12,13 +18,24 @@ function requestInterceptors(config) {
12
18
 
13
19
  let token = getToken();
14
20
  if (token) {
15
- config.headers.token = token;
21
+ config.headers[headers.auth.token] = token;
22
+ }
23
+
24
+ let systemType = getLocalStorage('systemType')
25
+ let tenantCode = getLocalStorage('tenantCode')
26
+
27
+ if(systemType && tenantCode){
28
+ config.headers[headers.tenant.tenantCode] = tenantCode;
29
+ config.headers[headers.tenant.systemType] = systemType;
16
30
  }
17
31
 
32
+ config.headers[headers.ajaxHeader.HEADER_TIMESTAMP] = new Date().getTime();
33
+ config.headers[headers.ajaxHeader.HEADER_NONCE] = guid();
34
+
18
35
  //sso_token认证
19
36
  if (params.hasOwnProperty('sso_token')||sessionStorage.getItem('sso_token')) {
20
37
  config.params = Object.assign({
21
- sso_token: params.sso_token||sessionStorage.getItem('sso_token') ,
38
+ sso_token: params.sso_token||sessionStorage.getItem('sso_token'),
22
39
  sso_id: params.sso_id
23
40
  }, config.params)
24
41
  }
@@ -51,6 +68,22 @@ function requestInterceptors(config) {
51
68
  config.url = config.url + "&t=" + new Date().getTime();
52
69
  }
53
70
  }
71
+
72
+ // 添加防止重复提交
73
+ // if(process.env.VUE_APP_IF_OPEN_NO_REPEAT_SUBMIT && process.env.VUE_APP_IF_OPEN_NO_REPEAT_SUBMIT === "true"){
74
+ // if(throttle(config)){
75
+ // return Promise.reject(new Error('数据正在处理,请勿重复提交'));
76
+ // }
77
+ // if(!config.ignoreCancelToken){
78
+ // abortController.addPending(config);
79
+ // }
80
+ // if(!config.isNotCancel){
81
+ // cancelToken.removePending(config)
82
+ // config = cancelToken.addPending(config)
83
+ // }
84
+ // }
85
+
86
+
54
87
  return config;
55
88
  }
56
89
 
@@ -60,6 +93,7 @@ function requestError(error) {
60
93
  }
61
94
 
62
95
  function responseInterceptors(response) {
96
+ response && abortController.removePending(response.config)
63
97
  const data = response.data;
64
98
  if (data instanceof Object) {
65
99
  const code = data["code"];
@@ -82,11 +116,16 @@ function responseInterceptors(response) {
82
116
  }
83
117
 
84
118
  function responseError(error) {
85
- clearTimeout(timer2);
86
- timer2 = setTimeout(function () {
87
- console.error("服务器内部异常,请稍候再试");
88
- }, 500)
89
- return Promise.reject(error);
119
+ if(isCancel(error)){
120
+ Vue.prototype.$Message.error(error.message)
121
+ return new Promise(() => {});
122
+ } else {
123
+ clearTimeout(timer2);
124
+ timer2 = setTimeout(function () {
125
+ console.error("服务器内部异常,请稍候再试");
126
+ }, 500)
127
+ return Promise.reject(error);
128
+ }
90
129
  }
91
130
 
92
131
  export default {
@@ -0,0 +1,127 @@
1
+ import headers from "./headers";
2
+ import {guid} from "../number";
3
+
4
+ class CustomEventSource {
5
+ constructor(url, options) {
6
+ this.url = url;
7
+ options = options || {};
8
+ options.headers = {
9
+ ...options.headers,
10
+ [headers.ajaxHeader.HEADER_TIMESTAMP]: new Date().getTime(),
11
+ [headers.ajaxHeader.HEADER_NONCE]: guid(),
12
+ };
13
+ this.options = options;
14
+ this.listeners = {};
15
+ this.awaitConnect()
16
+ }
17
+
18
+ async awaitConnect() {
19
+ const response = await fetch(this.url, { ...this.options, method: 'POST' });
20
+ const reader = response.body.getReader();
21
+ await this.readStream(reader);
22
+ }
23
+
24
+ async readStream(reader) {
25
+ let done, value, chunk = '';
26
+ const decoder = new TextDecoder('utf-8');
27
+ do {
28
+ ({done, value} = await reader.read());
29
+ if (done) {
30
+ this.dispatchEvent('message_finished');
31
+ } else {
32
+ chunk += decoder.decode(value, { stream: true })
33
+ if (chunk && chunk.trim().endsWith("}")) {
34
+ const lines = chunk.split('\n');
35
+ // chunk = '';
36
+ for (let line of lines) {
37
+ if (line.startsWith('data:')) {
38
+ const data = line.substring(5).trim(); // 去掉 'data:' 前缀
39
+ if (data) {
40
+ try {
41
+ const jsonData = JSON.parse(data);
42
+ }catch (e) {
43
+ // 解析失败,说明数据可能不完整,等待更多数据
44
+ console.warn("JSON 解析失败,等待更多数据:", e);
45
+ break;
46
+ }
47
+ this.dispatchEvent('message', { data: data });
48
+ }
49
+ } else if (line.startsWith("{") && line.endsWith("}")) {
50
+ try {
51
+ const jsonData = JSON.parse(line);
52
+ }catch (e) {
53
+ console.warn("JSON 解析失败,等待更多数据:", e);
54
+ break;
55
+ }
56
+ this.dispatchEvent('message', { data: line });
57
+ }
58
+ }
59
+ chunk = '';
60
+ }
61
+ }
62
+ } while (!done);
63
+ }
64
+
65
+ connect() {
66
+ fetch(this.url, { ...this.options, method: 'POST' })
67
+ .then(response => {
68
+ if (response.ok && response.body) {
69
+ const reader = response.body.getReader();
70
+ this.read(reader);
71
+ } else {
72
+ throw new Error('Failed to connect to the SSE endpoint.');
73
+ }
74
+ })
75
+ .catch(error => {
76
+ console.error('Connection error:', error);
77
+ this.dispatchEvent('message_finished',error);
78
+ });
79
+ }
80
+
81
+ read(reader) {
82
+ reader.read().then(({done,value}) => {
83
+ if (done) {
84
+ this.dispatchEvent('message_finished');
85
+ } else {
86
+ const decoder = new TextDecoder('utf-8');
87
+ const chunk = decoder.decode(value, { stream: true });
88
+ if (chunk) {
89
+ const lines = chunk.split('\n');
90
+ for (let line of lines) {
91
+ if (line.startsWith('data:')) {
92
+ const data = line.substring(5).trim(); // 去掉 'data:' 前缀
93
+ if (data) {
94
+ this.dispatchEvent('message', { data: data });
95
+ }
96
+ } else if (line.startsWith("{") && line.endsWith("}")) {
97
+ this.dispatchEvent('message', { data: line });
98
+ }
99
+ }
100
+ }
101
+
102
+ this.read(reader);
103
+ }
104
+ }).catch(error => {
105
+ console.error('Read error:', error);
106
+ this.dispatchEvent('message_finished',error);
107
+ });
108
+ }
109
+
110
+ addEventListener(type, listener) {
111
+ if (!this.listeners[type]) {
112
+ this.listeners[type] = [];
113
+ }
114
+ this.listeners[type].push(listener);
115
+ }
116
+
117
+ dispatchEvent(type, event) {
118
+ if (this.listeners[type]) {
119
+ this.listeners[type].forEach(listener => listener(event));
120
+ }
121
+ }
122
+ }
123
+
124
+ export default CustomEventSource;
125
+ export {
126
+ CustomEventSource
127
+ }
@@ -0,0 +1,49 @@
1
+ import qs from 'qs'
2
+ const requestObjMap = {};
3
+
4
+ const getPendingUrl = (config) => {
5
+ const { url, method, data, headers } = config;
6
+ // 生成请求唯一标识
7
+ return [url, method, qs.stringify(data), qs.stringify(headers)].join('&');
8
+ };
9
+ /**
10
+ * 防止重复提交
11
+ * 防抖(debounce)和节流(throttle)
12
+ */
13
+ export function throttle(config) {
14
+ let forbidden = false;
15
+ if (config) {
16
+ // 是否需要防止数据重复提交
17
+ const isRepeatSubmit = (config.headers || {}).repeatSubmit === false ;
18
+
19
+ if (!isRepeatSubmit && (config.method === 'post' || config.method === 'put')) {
20
+ const requestObj = {
21
+ url: config.url,
22
+ data: typeof config.data === 'object' ? JSON.stringify(config.data) : config.data,
23
+ time: new Date().getTime()
24
+ }
25
+ const requestId = getPendingUrl(config);
26
+
27
+ const lastRequestObj = requestObjMap[requestId];
28
+
29
+ if (lastRequestObj === undefined || lastRequestObj === null || lastRequestObj === '') {
30
+ requestObjMap[requestId] = requestObj;
31
+ } else {
32
+ const lastUrl = lastRequestObj.url;
33
+ const lastData = lastRequestObj.data;
34
+ const lastTime = lastRequestObj.time;
35
+ // 间隔时间(ms),小于此时间视为重复提交
36
+ const interval = 10000;
37
+ if (lastUrl === requestObj.url && lastData === requestObj.data
38
+ && requestObj.time - lastTime < interval) {
39
+ const message = '数据正在处理,请勿重复提交';
40
+ console.warn(`[${lastUrl}]: ` + message);
41
+ forbidden = true;
42
+ } else {
43
+ requestObjMap[requestId] = requestObj;
44
+ }
45
+ }
46
+ }
47
+ }
48
+ return forbidden
49
+ }