@lambo-design/shared 1.0.0-beta.312 → 1.0.0-beta.314
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/nstyles/components/form.less +1 -0
- package/nstyles/third/ag.less +4 -0
- package/package.json +1 -1
- package/styles/image/layout-header-bg-cuiwei.png +0 -0
- package/utils/ajax/abort-controller.js +4 -2
- package/utils/ajax/cancel-reason.js +25 -0
- package/utils/ajax/cancel-token.js +18 -4
- package/utils/ajax/interceptors.js +16 -8
- package/utils/ajax/throttle.js +2 -1
- package/utils/style.js +24 -24
- package/utils/transfer-queue.js +7 -7
package/nstyles/third/ag.less
CHANGED
package/package.json
CHANGED
|
Binary file
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
// 用于存储每个请求的标识和取消函数
|
|
2
|
+
import qs from "qs";
|
|
3
|
+
|
|
2
4
|
const pendingMap = new Map();
|
|
3
5
|
|
|
4
6
|
const getPendingUrl = (config) => {
|
|
@@ -7,7 +9,7 @@ const getPendingUrl = (config) => {
|
|
|
7
9
|
// 生成请求唯一标识
|
|
8
10
|
return headers['is-cancel-token']
|
|
9
11
|
? headers['is-cancel-token']
|
|
10
|
-
: [url, method].join('&');
|
|
12
|
+
: [url, method, qs.stringify(data)].join('&');
|
|
11
13
|
};
|
|
12
14
|
|
|
13
15
|
/**
|
|
@@ -35,7 +37,7 @@ function removePending(config) {
|
|
|
35
37
|
// 如果当前请求在等待中,取消它并将其从等待中移除
|
|
36
38
|
const abortController = pendingMap.get(url);
|
|
37
39
|
if (abortController) {
|
|
38
|
-
abortController.abort(
|
|
40
|
+
abortController.abort();
|
|
39
41
|
}
|
|
40
42
|
pendingMap.delete(url);
|
|
41
43
|
}
|
|
@@ -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
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// axios 0.22.0 版本以后推荐使用abort-controller
|
|
2
2
|
import axios from "axios";
|
|
3
|
-
|
|
3
|
+
import qs from 'qs'
|
|
4
|
+
import {CancelReason} from "./cancel-reason";
|
|
4
5
|
// 存储所有请求的取消函数
|
|
5
6
|
const cancelTokenMap = {};
|
|
6
7
|
|
|
@@ -10,7 +11,7 @@ const getPendingUrl = (config) => {
|
|
|
10
11
|
// 生成请求唯一标识
|
|
11
12
|
return headers['is-cancel-token']
|
|
12
13
|
? headers['is-cancel-token']
|
|
13
|
-
: [url, method,
|
|
14
|
+
: [url, method, qs.stringify(data)].join('&');
|
|
14
15
|
};
|
|
15
16
|
/**
|
|
16
17
|
* 生成请求唯一标识并注册取消函数
|
|
@@ -47,7 +48,12 @@ function removePending(config) {
|
|
|
47
48
|
const cancelFn = cancelTokenMap[requestId];
|
|
48
49
|
|
|
49
50
|
if (cancelFn && typeof cancelFn === 'function') {
|
|
50
|
-
cancelFn(
|
|
51
|
+
cancelFn({
|
|
52
|
+
type: 'cancel',
|
|
53
|
+
url: requestId,
|
|
54
|
+
reason: CancelReason.DUPLICATE,
|
|
55
|
+
message: '数据正在处理,请勿重复提交'
|
|
56
|
+
}); // 执行取消
|
|
51
57
|
delete cancelTokenMap[requestId]; // 清理
|
|
52
58
|
}
|
|
53
59
|
}
|
|
@@ -58,7 +64,15 @@ function removePending(config) {
|
|
|
58
64
|
function removeAllPending() {
|
|
59
65
|
Object.keys(cancelTokenMap).forEach(key => {
|
|
60
66
|
const cancelFn = cancelTokenMap[key];
|
|
61
|
-
cancelFn
|
|
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
|
+
}
|
|
62
76
|
});
|
|
63
77
|
}
|
|
64
78
|
|
|
@@ -6,6 +6,9 @@ import headers from './headers';
|
|
|
6
6
|
import {throttle} from "./throttle";
|
|
7
7
|
import abortController from "./abort-controller"
|
|
8
8
|
import cancelToken from "./cancel-token"
|
|
9
|
+
import { isCancel,Cancel } from "axios";
|
|
10
|
+
import Vue from "vue";
|
|
11
|
+
import {CancelReason} from "./cancel-reason";
|
|
9
12
|
let timer1, timer2;
|
|
10
13
|
let hasDialog = false;
|
|
11
14
|
|
|
@@ -64,9 +67,9 @@ function requestInterceptors(config) {
|
|
|
64
67
|
|
|
65
68
|
// 添加防止重复提交
|
|
66
69
|
if(process.env.VUE_APP_IF_OPEN_NO_REPEAT_SUBMIT && process.env.VUE_APP_IF_OPEN_NO_REPEAT_SUBMIT === "true"){
|
|
67
|
-
if(throttle(config)){
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
+
// if(throttle(config)){
|
|
71
|
+
// return Promise.reject(new Error('数据正在处理,请勿重复提交'));
|
|
72
|
+
// }
|
|
70
73
|
// if(!config.ignoreCancelToken){
|
|
71
74
|
// abortController.addPending(config);
|
|
72
75
|
// }
|
|
@@ -109,11 +112,16 @@ function responseInterceptors(response) {
|
|
|
109
112
|
}
|
|
110
113
|
|
|
111
114
|
function responseError(error) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
|
|
115
|
+
if(isCancel(error)){
|
|
116
|
+
Vue.prototype.$Message.error(error.message)
|
|
117
|
+
return new Promise(() => {});
|
|
118
|
+
} else {
|
|
119
|
+
clearTimeout(timer2);
|
|
120
|
+
timer2 = setTimeout(function () {
|
|
121
|
+
console.error("服务器内部异常,请稍候再试");
|
|
122
|
+
}, 500)
|
|
123
|
+
return Promise.reject(error);
|
|
124
|
+
}
|
|
117
125
|
}
|
|
118
126
|
|
|
119
127
|
export default {
|
package/utils/ajax/throttle.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import qs from 'qs'
|
|
1
2
|
const requestObjMap = {};
|
|
2
3
|
|
|
3
4
|
const getPendingUrl = (config) => {
|
|
4
5
|
const { url, method, data, headers } = config;
|
|
5
6
|
// 生成请求唯一标识
|
|
6
|
-
return [url, method,
|
|
7
|
+
return [url, method, qs.stringify(data), qs.stringify(headers)].join('&');
|
|
7
8
|
};
|
|
8
9
|
/**
|
|
9
10
|
* 防止重复提交
|
package/utils/style.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
const SPECIAL_CHARS_REGEXP = /([\:\-\_]+(.))/g
|
|
2
|
-
const MOZ_HACK_REGEXP = /^moz([A-Z])/
|
|
3
|
-
|
|
4
|
-
function camelCase(name) {
|
|
5
|
-
return name
|
|
6
|
-
.replace(SPECIAL_CHARS_REGEXP, function (_, separator, letter, offset) {
|
|
7
|
-
return offset ? letter.toUpperCase() : letter
|
|
8
|
-
})
|
|
9
|
-
.replace(MOZ_HACK_REGEXP, 'Moz$1')
|
|
10
|
-
}
|
|
11
|
-
// getStyle
|
|
12
|
-
export function getStyle(element, styleName) {
|
|
13
|
-
if (!element || !styleName) return null
|
|
14
|
-
styleName = camelCase(styleName)
|
|
15
|
-
if (styleName === 'float') {
|
|
16
|
-
styleName = 'cssFloat'
|
|
17
|
-
}
|
|
18
|
-
try {
|
|
19
|
-
const computed = document.defaultView.getComputedStyle(element, '')
|
|
20
|
-
return element.style[styleName] || computed ? computed[styleName] : null
|
|
21
|
-
} catch (e) {
|
|
22
|
-
return element.style[styleName]
|
|
23
|
-
}
|
|
24
|
-
}
|
|
1
|
+
const SPECIAL_CHARS_REGEXP = /([\:\-\_]+(.))/g
|
|
2
|
+
const MOZ_HACK_REGEXP = /^moz([A-Z])/
|
|
3
|
+
|
|
4
|
+
function camelCase(name) {
|
|
5
|
+
return name
|
|
6
|
+
.replace(SPECIAL_CHARS_REGEXP, function (_, separator, letter, offset) {
|
|
7
|
+
return offset ? letter.toUpperCase() : letter
|
|
8
|
+
})
|
|
9
|
+
.replace(MOZ_HACK_REGEXP, 'Moz$1')
|
|
10
|
+
}
|
|
11
|
+
// getStyle
|
|
12
|
+
export function getStyle(element, styleName) {
|
|
13
|
+
if (!element || !styleName) return null
|
|
14
|
+
styleName = camelCase(styleName)
|
|
15
|
+
if (styleName === 'float') {
|
|
16
|
+
styleName = 'cssFloat'
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
const computed = document.defaultView.getComputedStyle(element, '')
|
|
20
|
+
return element.style[styleName] || computed ? computed[styleName] : null
|
|
21
|
+
} catch (e) {
|
|
22
|
+
return element.style[styleName]
|
|
23
|
+
}
|
|
24
|
+
}
|
package/utils/transfer-queue.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
let transferIndex = 1000
|
|
2
|
-
|
|
3
|
-
function transferIncrease() {
|
|
4
|
-
transferIndex++
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export { transferIndex, transferIncrease }
|
|
1
|
+
let transferIndex = 1000
|
|
2
|
+
|
|
3
|
+
function transferIncrease() {
|
|
4
|
+
transferIndex++
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export { transferIndex, transferIncrease }
|