vue2-client 1.18.39 → 1.18.40
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/.eslintrc.js +90 -90
- package/Components.md +60 -60
- package/docs/index.md +30 -30
- package/docs//350/257/267/346/261/202/345/267/245/345/205/267/344/275/277/347/224/250/350/257/264/346/230/216.md +353 -0
- package/index.js +31 -31
- package/jest-transform-stub.js +8 -8
- package/jest.setup.js +7 -7
- package/package.json +1 -1
- package/src/assets/img/querySlotDemo.svg +15 -15
- package/src/base-client/components/common/AmapMarker/AmapPointRendering.vue +120 -120
- package/src/base-client/components/common/CitySelect/index.js +3 -3
- package/src/base-client/components/common/CitySelect/index.md +109 -109
- package/src/base-client/components/common/CreateQuery/CreateQuery.vue +669 -669
- package/src/base-client/components/common/CreateQuery/index.js +3 -3
- package/src/base-client/components/common/CreateQuery/index.md +42 -42
- package/src/base-client/components/common/CreateSimpleFormQuery/index.js +3 -3
- package/src/base-client/components/common/CreateSimpleFormQuery/index.md +42 -42
- package/src/base-client/components/common/FormGroupEdit/index.js +3 -3
- package/src/base-client/components/common/FormGroupEdit/index.md +43 -43
- package/src/base-client/components/common/FormGroupQuery/FormGroupQuery.vue +166 -166
- package/src/base-client/components/common/FormGroupQuery/index.js +3 -3
- package/src/base-client/components/common/FormGroupQuery/index.md +43 -43
- package/src/base-client/components/common/JSONToTree/jsontotree.vue +271 -271
- package/src/base-client/components/common/PersonSetting/PersonSetting.vue +208 -208
- package/src/base-client/components/common/PersonSetting/index.js +3 -3
- package/src/base-client/components/common/Tree/Tree.vue +149 -149
- package/src/base-client/components/common/Tree/index.js +2 -2
- package/src/base-client/components/common/Upload/index.js +3 -3
- package/src/base-client/components/common/XAddNativeForm/index.md +146 -146
- package/src/base-client/components/common/XCard/XCard.vue +64 -64
- package/src/base-client/components/common/XDataDrawer/XDataDrawer.vue +180 -180
- package/src/base-client/components/common/XDataDrawer/index.js +3 -3
- package/src/base-client/components/common/XDataDrawer/index.md +41 -41
- package/src/base-client/components/common/XDescriptions/index.js +3 -3
- package/src/base-client/components/common/XDescriptions/index.md +322 -322
- package/src/base-client/components/common/XForm/index.md +178 -178
- package/src/base-client/components/common/XFormTable/demo.vue +2 -4
- package/src/base-client/components/common/XReport/print.js +186 -186
- package/src/base-client/components/common/XReportGrid/XReportTrGroup.vue +1 -1
- package/src/base-client/components/common/XStepView/XStepView.vue +252 -252
- package/src/base-client/components/common/XStepView/index.js +3 -3
- package/src/base-client/components/common/XStepView/index.md +31 -31
- package/src/base-client/components/common/XTable/XTable.vue +1715 -1715
- package/src/base-client/components/common/XTable/XTableWrapper.vue +786 -769
- package/src/base-client/components/common/XTable/index.md +255 -255
- package/src/base-client/components/system/DictionaryDetailsView/DictionaryDetailsView.vue +232 -232
- package/src/base-client/plugins/Config.js +19 -19
- package/src/base-client/plugins/tabs-page-plugin.js +39 -39
- package/src/components/Charts/Bar.vue +62 -62
- package/src/components/Charts/ChartCard.vue +134 -134
- package/src/components/Charts/Liquid.vue +67 -67
- package/src/components/Charts/MiniArea.vue +39 -39
- package/src/components/Charts/MiniBar.vue +39 -39
- package/src/components/Charts/MiniProgress.vue +75 -75
- package/src/components/Charts/MiniSmoothArea.vue +40 -40
- package/src/components/Charts/Radar.vue +68 -68
- package/src/components/Charts/RankList.vue +77 -77
- package/src/components/Charts/TagCloud.vue +113 -113
- package/src/components/Charts/TransferBar.vue +64 -64
- package/src/components/Charts/Trend.vue +82 -82
- package/src/components/Charts/chart.less +12 -12
- package/src/components/Charts/smooth.area.less +13 -13
- package/src/components/NumberInfo/NumberInfo.vue +54 -54
- package/src/components/NumberInfo/index.js +3 -3
- package/src/components/NumberInfo/index.less +54 -54
- package/src/components/NumberInfo/index.md +43 -43
- package/src/components/card/ChartCard.vue +79 -79
- package/src/components/chart/Bar.vue +60 -60
- package/src/components/chart/MiniArea.vue +67 -67
- package/src/components/chart/MiniBar.vue +59 -59
- package/src/components/chart/MiniProgress.vue +57 -57
- package/src/components/chart/Radar.vue +80 -80
- package/src/components/chart/RankingList.vue +60 -60
- package/src/components/chart/Trend.vue +79 -79
- package/src/components/chart/index.less +9 -9
- package/src/components/checkbox/ColorCheckbox.vue +157 -157
- package/src/components/input/IInput.vue +66 -66
- package/src/components/menu/SideMenu.vue +75 -75
- package/src/components/menu/menu.js +273 -273
- package/src/components/tool/AStepItem.vue +60 -60
- package/src/composables/demo/UseRequestDemo.vue +175 -0
- package/src/composables/index.js +6 -0
- package/src/composables/useGlobalLoading.js +206 -0
- package/src/composables/usePost.js +221 -0
- package/src/layouts/CommonLayout.vue +56 -56
- package/src/layouts/header/HeaderNotice.vue +177 -177
- package/src/lib.js +1 -1
- package/src/mock/extend/index.js +84 -84
- package/src/mock/goods/index.js +108 -108
- package/src/pages/dashboard/workplace/WorkPlace.vue +141 -141
- package/src/pages/system/dictionary/index.vue +44 -44
- package/src/pages/system/monitor/loginInfor/index.vue +37 -37
- package/src/pages/system/monitor/operLog/index.vue +37 -37
- package/src/services/api/cas.js +79 -79
- package/src/services/api/restTools.js +34 -46
- package/src/store/modules/setting.js +119 -119
- package/src/utils/authority-utils.js +85 -85
- package/src/utils/errorCode.js +6 -6
- package/src/utils/map-utils.js +47 -47
- package/src/utils/request.js +103 -0
- package/vue.config.js +9 -4
- package//350/277/201/347/247/273/346/227/245/345/277/227.md +15 -15
|
@@ -1,85 +1,85 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 判断是否有路由的权限
|
|
3
|
-
* @param authority 路由权限配置
|
|
4
|
-
* @param permissions 用户权限集合
|
|
5
|
-
* @returns {boolean|*}
|
|
6
|
-
*/
|
|
7
|
-
function hasPermission (authority, permissions) {
|
|
8
|
-
let required = '*'
|
|
9
|
-
if (typeof authority === 'string') {
|
|
10
|
-
required = authority
|
|
11
|
-
} else if (Array.isArray(authority)) {
|
|
12
|
-
required = authority
|
|
13
|
-
} else if (typeof authority === 'object') {
|
|
14
|
-
required = authority.permission
|
|
15
|
-
}
|
|
16
|
-
return required === '*' || hasAnyItem(required, permissions, (r, t) => !!(r === t || r === t.id))
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* 判断是否有路由需要的角色
|
|
21
|
-
* @param authority 路由权限配置
|
|
22
|
-
* @param roles 用户角色集合
|
|
23
|
-
*/
|
|
24
|
-
function hasRole (authority, roles) {
|
|
25
|
-
let required
|
|
26
|
-
if (typeof authority === 'object') {
|
|
27
|
-
required = authority.role
|
|
28
|
-
}
|
|
29
|
-
return authority === '*' || hasAnyItem(required, roles, (r, t) => !!(r === t || r === t.id))
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* 判断目标数组是否有所需元素
|
|
34
|
-
* @param {String | String[]}required 所需元素,数组或单个元素
|
|
35
|
-
* @param {String[]|Object[]} source 目标数组
|
|
36
|
-
* @param {Function} filter 匹配条件
|
|
37
|
-
* (r: String, s: String|Object) => boolean
|
|
38
|
-
* @returns {boolean}
|
|
39
|
-
*/
|
|
40
|
-
function hasAnyItem (required, source, filter) {
|
|
41
|
-
if (!required) {
|
|
42
|
-
return false
|
|
43
|
-
}
|
|
44
|
-
const checkedList = Array.isArray(required) ? required : [required]
|
|
45
|
-
return !!source.find(s => checkedList.find(r => filter(r, s)))
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* 路由权限校验
|
|
50
|
-
* @param route 路由
|
|
51
|
-
* @param permissions 用户权限集合
|
|
52
|
-
* @param roles 用户角色集合
|
|
53
|
-
* @returns {boolean}
|
|
54
|
-
*/
|
|
55
|
-
function hasAuthority (route, permissions, roles) {
|
|
56
|
-
const authorities = [...route.meta.pAuthorities, route.meta.authority]
|
|
57
|
-
for (const authority of authorities) {
|
|
58
|
-
if (!hasPermission(authority, permissions) && !hasRole(authority, roles)) {
|
|
59
|
-
return false
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
return true
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* 根据权限配置过滤菜单数据
|
|
67
|
-
* @param menuData
|
|
68
|
-
* @param permissions
|
|
69
|
-
* @param roles
|
|
70
|
-
*/
|
|
71
|
-
function filterMenu (menuData, permissions, roles) {
|
|
72
|
-
return menuData.filter(menu => {
|
|
73
|
-
if (menu.meta && menu.meta.invisible === undefined) {
|
|
74
|
-
if (!hasAuthority(menu, permissions, roles)) {
|
|
75
|
-
return false
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
if (menu.children && menu.children.length > 0) {
|
|
79
|
-
menu.children = filterMenu(menu.children, permissions, roles)
|
|
80
|
-
}
|
|
81
|
-
return true
|
|
82
|
-
})
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export { filterMenu, hasAuthority }
|
|
1
|
+
/**
|
|
2
|
+
* 判断是否有路由的权限
|
|
3
|
+
* @param authority 路由权限配置
|
|
4
|
+
* @param permissions 用户权限集合
|
|
5
|
+
* @returns {boolean|*}
|
|
6
|
+
*/
|
|
7
|
+
function hasPermission (authority, permissions) {
|
|
8
|
+
let required = '*'
|
|
9
|
+
if (typeof authority === 'string') {
|
|
10
|
+
required = authority
|
|
11
|
+
} else if (Array.isArray(authority)) {
|
|
12
|
+
required = authority
|
|
13
|
+
} else if (typeof authority === 'object') {
|
|
14
|
+
required = authority.permission
|
|
15
|
+
}
|
|
16
|
+
return required === '*' || hasAnyItem(required, permissions, (r, t) => !!(r === t || r === t.id))
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 判断是否有路由需要的角色
|
|
21
|
+
* @param authority 路由权限配置
|
|
22
|
+
* @param roles 用户角色集合
|
|
23
|
+
*/
|
|
24
|
+
function hasRole (authority, roles) {
|
|
25
|
+
let required
|
|
26
|
+
if (typeof authority === 'object') {
|
|
27
|
+
required = authority.role
|
|
28
|
+
}
|
|
29
|
+
return authority === '*' || hasAnyItem(required, roles, (r, t) => !!(r === t || r === t.id))
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 判断目标数组是否有所需元素
|
|
34
|
+
* @param {String | String[]}required 所需元素,数组或单个元素
|
|
35
|
+
* @param {String[]|Object[]} source 目标数组
|
|
36
|
+
* @param {Function} filter 匹配条件
|
|
37
|
+
* (r: String, s: String|Object) => boolean
|
|
38
|
+
* @returns {boolean}
|
|
39
|
+
*/
|
|
40
|
+
function hasAnyItem (required, source, filter) {
|
|
41
|
+
if (!required) {
|
|
42
|
+
return false
|
|
43
|
+
}
|
|
44
|
+
const checkedList = Array.isArray(required) ? required : [required]
|
|
45
|
+
return !!source.find(s => checkedList.find(r => filter(r, s)))
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 路由权限校验
|
|
50
|
+
* @param route 路由
|
|
51
|
+
* @param permissions 用户权限集合
|
|
52
|
+
* @param roles 用户角色集合
|
|
53
|
+
* @returns {boolean}
|
|
54
|
+
*/
|
|
55
|
+
function hasAuthority (route, permissions, roles) {
|
|
56
|
+
const authorities = [...route.meta.pAuthorities, route.meta.authority]
|
|
57
|
+
for (const authority of authorities) {
|
|
58
|
+
if (!hasPermission(authority, permissions) && !hasRole(authority, roles)) {
|
|
59
|
+
return false
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return true
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* 根据权限配置过滤菜单数据
|
|
67
|
+
* @param menuData
|
|
68
|
+
* @param permissions
|
|
69
|
+
* @param roles
|
|
70
|
+
*/
|
|
71
|
+
function filterMenu (menuData, permissions, roles) {
|
|
72
|
+
return menuData.filter(menu => {
|
|
73
|
+
if (menu.meta && menu.meta.invisible === undefined) {
|
|
74
|
+
if (!hasAuthority(menu, permissions, roles)) {
|
|
75
|
+
return false
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (menu.children && menu.children.length > 0) {
|
|
79
|
+
menu.children = filterMenu(menu.children, permissions, roles)
|
|
80
|
+
}
|
|
81
|
+
return true
|
|
82
|
+
})
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export { filterMenu, hasAuthority }
|
package/src/utils/errorCode.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
401: '认证失败,无法访问系统资源',
|
|
3
|
-
403: '当前操作没有权限',
|
|
4
|
-
404: '访问资源不存在',
|
|
5
|
-
default: '系统未知错误,请反馈给管理员'
|
|
6
|
-
}
|
|
1
|
+
export default {
|
|
2
|
+
401: '认证失败,无法访问系统资源',
|
|
3
|
+
403: '当前操作没有权限',
|
|
4
|
+
404: '访问资源不存在',
|
|
5
|
+
default: '系统未知错误,请反馈给管理员'
|
|
6
|
+
}
|
package/src/utils/map-utils.js
CHANGED
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
import AMapLoader from '@amap/amap-jsapi-loader'
|
|
2
|
-
let Amap
|
|
3
|
-
async function GetGDMap (secretKey, key) {
|
|
4
|
-
if (!Amap) {
|
|
5
|
-
window._AMapSecurityConfig = {
|
|
6
|
-
securityJsCode: secretKey
|
|
7
|
-
}
|
|
8
|
-
// 解决高德地图加载报错 ---> 禁止多种API加载方式混用
|
|
9
|
-
AMapLoader.reset()
|
|
10
|
-
Amap = await AMapLoader.load({
|
|
11
|
-
key: key, // 申请好的Web端开发者Key,首次调用 load 时必填
|
|
12
|
-
version: '2.0', // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15
|
|
13
|
-
plugins: ['AMap.IndexCluster', 'AMP.MarkerCluster', 'AMap.InfoWindow', 'AMap.HeatMap', 'AMap.HawkEye', 'AMap.DistrictSearch',
|
|
14
|
-
'AMap.ToolBar', 'AMap.Geolocation', 'AMap.MouseTool',
|
|
15
|
-
'AMap.Geocoder', 'AMap.MarkerClusterer', 'AMap.AutoComplete', 'AMap.Scale'], // 需要使用的的插件列表,如比例尺'AMap.Scale'等
|
|
16
|
-
AMapUI: {
|
|
17
|
-
version: '1.1', // AMapUI 缺省 1.1
|
|
18
|
-
plugins: ['misc/PositionPicker'] // 需要加载的 AMapUI ui插件
|
|
19
|
-
}
|
|
20
|
-
})
|
|
21
|
-
}
|
|
22
|
-
return Amap
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
async function getGDMap (address) {
|
|
26
|
-
new (await GetGDMap()).Geocoder({
|
|
27
|
-
radius: 500 // 范围,默认:500
|
|
28
|
-
}).getLocation(address, function (status, result) {
|
|
29
|
-
if (status === 'complete' && result.geocodes.length) {
|
|
30
|
-
return ({ lng: result.geocodes[0].location.lng, lat: result.geocodes[0].location.lat })
|
|
31
|
-
} else {
|
|
32
|
-
// eslint-disable-next-line prefer-promise-reject-errors
|
|
33
|
-
throw new Error('根据经纬度查询地址失败')
|
|
34
|
-
}
|
|
35
|
-
})
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
async function GetLocation (address) {
|
|
39
|
-
return new Promise((resolve, reject) => {
|
|
40
|
-
try {
|
|
41
|
-
resolve(getGDMap(address))
|
|
42
|
-
} catch (e) {
|
|
43
|
-
reject(e)
|
|
44
|
-
}
|
|
45
|
-
})
|
|
46
|
-
}
|
|
47
|
-
export { GetGDMap, GetLocation }
|
|
1
|
+
import AMapLoader from '@amap/amap-jsapi-loader'
|
|
2
|
+
let Amap
|
|
3
|
+
async function GetGDMap (secretKey, key) {
|
|
4
|
+
if (!Amap) {
|
|
5
|
+
window._AMapSecurityConfig = {
|
|
6
|
+
securityJsCode: secretKey
|
|
7
|
+
}
|
|
8
|
+
// 解决高德地图加载报错 ---> 禁止多种API加载方式混用
|
|
9
|
+
AMapLoader.reset()
|
|
10
|
+
Amap = await AMapLoader.load({
|
|
11
|
+
key: key, // 申请好的Web端开发者Key,首次调用 load 时必填
|
|
12
|
+
version: '2.0', // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15
|
|
13
|
+
plugins: ['AMap.IndexCluster', 'AMP.MarkerCluster', 'AMap.InfoWindow', 'AMap.HeatMap', 'AMap.HawkEye', 'AMap.DistrictSearch',
|
|
14
|
+
'AMap.ToolBar', 'AMap.Geolocation', 'AMap.MouseTool',
|
|
15
|
+
'AMap.Geocoder', 'AMap.MarkerClusterer', 'AMap.AutoComplete', 'AMap.Scale'], // 需要使用的的插件列表,如比例尺'AMap.Scale'等
|
|
16
|
+
AMapUI: {
|
|
17
|
+
version: '1.1', // AMapUI 缺省 1.1
|
|
18
|
+
plugins: ['misc/PositionPicker'] // 需要加载的 AMapUI ui插件
|
|
19
|
+
}
|
|
20
|
+
})
|
|
21
|
+
}
|
|
22
|
+
return Amap
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async function getGDMap (address) {
|
|
26
|
+
new (await GetGDMap()).Geocoder({
|
|
27
|
+
radius: 500 // 范围,默认:500
|
|
28
|
+
}).getLocation(address, function (status, result) {
|
|
29
|
+
if (status === 'complete' && result.geocodes.length) {
|
|
30
|
+
return ({ lng: result.geocodes[0].location.lng, lat: result.geocodes[0].location.lat })
|
|
31
|
+
} else {
|
|
32
|
+
// eslint-disable-next-line prefer-promise-reject-errors
|
|
33
|
+
throw new Error('根据经纬度查询地址失败')
|
|
34
|
+
}
|
|
35
|
+
})
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function GetLocation (address) {
|
|
39
|
+
return new Promise((resolve, reject) => {
|
|
40
|
+
try {
|
|
41
|
+
resolve(getGDMap(address))
|
|
42
|
+
} catch (e) {
|
|
43
|
+
reject(e)
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
export { GetGDMap, GetLocation }
|
package/src/utils/request.js
CHANGED
|
@@ -12,9 +12,81 @@ import { logout, V4RefreshToken } from '@vue2-client/services/user'
|
|
|
12
12
|
import { LOGIN, SEARCH, V4_LOGIN } from '@vue2-client/services/apiService'
|
|
13
13
|
import { setV4AccessToken } from '@vue2-client/utils/login'
|
|
14
14
|
import EncryptUtil from '@vue2-client/utils/EncryptUtil'
|
|
15
|
+
|
|
15
16
|
// 是否显示重新登录
|
|
16
17
|
let isReloginShow
|
|
17
18
|
|
|
19
|
+
// ============ 请求去重管理 ============
|
|
20
|
+
// 存储进行中的请求 Map<requestKey, { promise, controller }>
|
|
21
|
+
const pendingRequests = new Map()
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 生成请求唯一标识
|
|
25
|
+
* @param {object} config - axios 请求配置
|
|
26
|
+
* @returns {string} 请求标识
|
|
27
|
+
*/
|
|
28
|
+
function generateRequestKey (config) {
|
|
29
|
+
const { method, url, data, params } = config
|
|
30
|
+
let dataStr = ''
|
|
31
|
+
let paramsStr = ''
|
|
32
|
+
try {
|
|
33
|
+
dataStr = data ? JSON.stringify(data) : ''
|
|
34
|
+
paramsStr = params ? JSON.stringify(params) : ''
|
|
35
|
+
} catch (e) {
|
|
36
|
+
// 循环引用或其他序列化问题,使用时间戳保证唯一性
|
|
37
|
+
console.warn('[请求去重] 参数序列化失败,跳过去重')
|
|
38
|
+
dataStr = `_${Date.now()}_${Math.random()}`
|
|
39
|
+
}
|
|
40
|
+
return `${method}:${url}:${dataStr}:${paramsStr}`
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* 添加请求到 pending 列表
|
|
45
|
+
* @param {object} config - axios 请求配置
|
|
46
|
+
*/
|
|
47
|
+
function addPendingRequest (config) {
|
|
48
|
+
const requestKey = generateRequestKey(config)
|
|
49
|
+
config._requestKey = requestKey
|
|
50
|
+
|
|
51
|
+
if (!pendingRequests.has(requestKey)) {
|
|
52
|
+
// 创建 AbortController 用于取消请求
|
|
53
|
+
const controller = new AbortController()
|
|
54
|
+
config.signal = controller.signal
|
|
55
|
+
pendingRequests.set(requestKey, { controller, config })
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* 移除已完成的请求
|
|
61
|
+
* @param {object} config - axios 请求配置
|
|
62
|
+
*/
|
|
63
|
+
function removePendingRequest (config) {
|
|
64
|
+
const requestKey = config._requestKey || generateRequestKey(config)
|
|
65
|
+
if (pendingRequests.has(requestKey)) {
|
|
66
|
+
pendingRequests.delete(requestKey)
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* 检查是否有相同的请求正在进行
|
|
72
|
+
* @param {object} config - axios 请求配置
|
|
73
|
+
* @returns {boolean}
|
|
74
|
+
*/
|
|
75
|
+
function hasPendingRequest (config) {
|
|
76
|
+
const requestKey = generateRequestKey(config)
|
|
77
|
+
return pendingRequests.has(requestKey)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* 清空所有 pending 请求
|
|
82
|
+
*/
|
|
83
|
+
export function clearPendingRequests () {
|
|
84
|
+
pendingRequests.forEach(({ controller }) => {
|
|
85
|
+
controller.abort()
|
|
86
|
+
})
|
|
87
|
+
pendingRequests.clear()
|
|
88
|
+
}
|
|
89
|
+
|
|
18
90
|
axios.defaults.timeout = 50000
|
|
19
91
|
axios.defaults.withCredentials = true
|
|
20
92
|
// 如果是microapp
|
|
@@ -145,6 +217,24 @@ function checkAuthorization (authType = AUTH_TYPE.BEARER) {
|
|
|
145
217
|
function loadInterceptors () {
|
|
146
218
|
// 加载请求拦截器
|
|
147
219
|
axios.interceptors.request.use(config => {
|
|
220
|
+
// ============ 请求去重逻辑 ============
|
|
221
|
+
// POST 请求默认开启去重,可通过 config.dedupe = false 关闭
|
|
222
|
+
const shouldDedupe = config.method?.toLowerCase() === 'post' && config.dedupe !== false
|
|
223
|
+
|
|
224
|
+
if (shouldDedupe && hasPendingRequest(config)) {
|
|
225
|
+
// 相同请求正在进行中,直接拒绝,不发起请求
|
|
226
|
+
console.warn(`重复请求被拦截: ${config.url}`)
|
|
227
|
+
const error = new Error('重复请求被取消')
|
|
228
|
+
error.code = 'ERR_DUPLICATE_REQUEST'
|
|
229
|
+
error.config = config
|
|
230
|
+
return Promise.reject(error)
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (shouldDedupe) {
|
|
234
|
+
addPendingRequest(config)
|
|
235
|
+
}
|
|
236
|
+
// ============ 去重逻辑结束 ============
|
|
237
|
+
|
|
148
238
|
const token = localStorage.getItem(ACCESS_TOKEN)
|
|
149
239
|
// 如果 token 存在
|
|
150
240
|
// 让每个请求携带自定义 token 请根据实际情况自行修改
|
|
@@ -189,6 +279,9 @@ function loadInterceptors () {
|
|
|
189
279
|
}, errorHandler)
|
|
190
280
|
// 加载响应拦截器
|
|
191
281
|
axios.interceptors.response.use((res) => {
|
|
282
|
+
// 请求完成,移除 pending 记录
|
|
283
|
+
removePendingRequest(res.config)
|
|
284
|
+
|
|
192
285
|
// 判断是否需要解密
|
|
193
286
|
if (res.headers && res.headers['x-encrypted'] === '1') {
|
|
194
287
|
const v4SessionKey = localStorage.getItem('v4-session-key')
|
|
@@ -315,6 +408,16 @@ function loginExpire () {
|
|
|
315
408
|
}
|
|
316
409
|
// 异常拦截处理器
|
|
317
410
|
const errorHandler = (error) => {
|
|
411
|
+
// 请求失败,移除 pending 记录
|
|
412
|
+
if (error.config) {
|
|
413
|
+
removePendingRequest(error.config)
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
// 如果是被取消的请求(去重导致或 AbortController),静默处理
|
|
417
|
+
if (error.name === 'CanceledError' || error.code === 'ERR_CANCELED' || error.code === 'ERR_DUPLICATE_REQUEST') {
|
|
418
|
+
return Promise.reject(error)
|
|
419
|
+
}
|
|
420
|
+
|
|
318
421
|
if (error.response) {
|
|
319
422
|
const data = error.response.data
|
|
320
423
|
// 从 localstorage 获取 token
|
package/vue.config.js
CHANGED
|
@@ -53,13 +53,18 @@ module.exports = {
|
|
|
53
53
|
changeOrigin: true
|
|
54
54
|
},
|
|
55
55
|
'/api/af-linepatrol/': {
|
|
56
|
-
|
|
57
|
-
target:
|
|
56
|
+
pathRewrite: { '^/api/af-linepatrol/': '/' },
|
|
57
|
+
target: 'http://127.0.0.1:9012',
|
|
58
58
|
changeOrigin: true
|
|
59
59
|
},
|
|
60
60
|
'/api/linepatrol/': {
|
|
61
|
-
|
|
62
|
-
target:
|
|
61
|
+
pathRewrite: { '^/api/linepatrol/': '/' },
|
|
62
|
+
target: 'http://127.0.0.1:9012',
|
|
63
|
+
changeOrigin: true
|
|
64
|
+
},
|
|
65
|
+
'/api/af-revenue/': {
|
|
66
|
+
pathRewrite: { '^/api/af-revenue/': '/' },
|
|
67
|
+
target: 'http://127.0.0.1:9026',
|
|
63
68
|
changeOrigin: true
|
|
64
69
|
},
|
|
65
70
|
// '/api/af-system/resource': {
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
# vue2迁移vue3
|
|
2
|
-
|
|
3
|
-
1. 完成vue-cli,webpack,babel,eslint的升级
|
|
4
|
-
- core-js 3.30.1 -> 3.33.0
|
|
5
|
-
- add regenerator-runtime
|
|
6
|
-
- @babel/core 7.21.4 -> 7.22.20
|
|
7
|
-
- babel-eslint 10.1.0 -> @babel/eslint-parser 7.22.15
|
|
8
|
-
- @vue/cli 4.5.19 -> 5.0.8
|
|
9
|
-
- babel-jest 25.5.1 -> 26.6.3
|
|
10
|
-
- eslint 6.8.0 -> 7.32.0
|
|
11
|
-
- jest 24.0.0 -> 26.6.3
|
|
12
|
-
- webpack 4.46.0 -> 5.88.2
|
|
13
|
-
2. 完成vue2的2.7升级
|
|
14
|
-
- vue 2.6.14 -> 2.7.14
|
|
15
|
-
- eslint 7.32.0 -> 8.51.0
|
|
1
|
+
# vue2迁移vue3
|
|
2
|
+
|
|
3
|
+
1. 完成vue-cli,webpack,babel,eslint的升级
|
|
4
|
+
- core-js 3.30.1 -> 3.33.0
|
|
5
|
+
- add regenerator-runtime
|
|
6
|
+
- @babel/core 7.21.4 -> 7.22.20
|
|
7
|
+
- babel-eslint 10.1.0 -> @babel/eslint-parser 7.22.15
|
|
8
|
+
- @vue/cli 4.5.19 -> 5.0.8
|
|
9
|
+
- babel-jest 25.5.1 -> 26.6.3
|
|
10
|
+
- eslint 6.8.0 -> 7.32.0
|
|
11
|
+
- jest 24.0.0 -> 26.6.3
|
|
12
|
+
- webpack 4.46.0 -> 5.88.2
|
|
13
|
+
2. 完成vue2的2.7升级
|
|
14
|
+
- vue 2.6.14 -> 2.7.14
|
|
15
|
+
- eslint 7.32.0 -> 8.51.0
|