Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
B
basic-vue-admin
概览
概览
详情
活动
周期分析
版本库
存储库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Basic
basic-vue-admin
Commits
e83cb06b
提交
e83cb06b
authored
10月 13, 2020
作者:
nebv
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: projectSetting add closeMessageOnSwitch and removeAllHttpPending
上级
4500214b
隐藏空白字符变更
内嵌
并排
正在显示
8 个修改的文件
包含
30 行增加
和
23 行删除
+30
-23
preview.ts
build/script/preview.ts
+0
-3
index.ts
src/router/guard/index.ts
+11
-6
projectSetting.ts
src/settings/projectSetting.ts
+7
-0
config.d.ts
src/types/config.d.ts
+4
-0
Axios.ts
src/utils/http/axios/Axios.ts
+3
-2
checkStatus.ts
src/utils/http/axios/checkStatus.ts
+2
-3
const.ts
src/utils/http/axios/const.ts
+1
-0
index.ts
src/utils/http/axios/index.ts
+2
-9
没有找到文件。
build/script/preview.ts
浏览文件 @
e83cb06b
...
@@ -16,9 +16,6 @@ const startApp = () => {
...
@@ -16,9 +16,6 @@ const startApp = () => {
const
port
=
9680
;
const
port
=
9680
;
portfinder
.
basePort
=
port
;
portfinder
.
basePort
=
port
;
const
app
=
new
Koa
();
const
app
=
new
Koa
();
// const connect = require('connect');
// const serveStatic = require('serve-static');
// const app = connect();
app
.
use
(
staticServer
(
resolve
(
process
.
cwd
(),
viteConfig
.
outDir
||
'dist'
)));
app
.
use
(
staticServer
(
resolve
(
process
.
cwd
(),
viteConfig
.
outDir
||
'dist'
)));
...
...
src/router/guard/index.ts
浏览文件 @
e83cb06b
...
@@ -11,22 +11,27 @@ import { getIsOpenTab } from '/@/utils/helper/routeHelper';
...
@@ -11,22 +11,27 @@ import { getIsOpenTab } from '/@/utils/helper/routeHelper';
const
{
projectSetting
}
=
useSetting
();
const
{
projectSetting
}
=
useSetting
();
export
function
createGuard
(
router
:
Router
)
{
export
function
createGuard
(
router
:
Router
)
{
const
axiosCanceler
=
new
AxiosCanceler
();
const
{
openNProgress
,
closeMessageOnSwitch
,
removeAllHttpPending
}
=
projectSetting
;
let
axiosCanceler
:
AxiosCanceler
|
null
;
if
(
removeAllHttpPending
)
{
axiosCanceler
=
new
AxiosCanceler
();
}
router
.
beforeEach
(
async
(
to
)
=>
{
router
.
beforeEach
(
async
(
to
)
=>
{
const
isOpen
=
getIsOpenTab
(
to
.
path
);
const
isOpen
=
getIsOpenTab
(
to
.
path
);
to
.
meta
.
inTab
=
isOpen
;
to
.
meta
.
inTab
=
isOpen
;
try
{
try
{
Modal
.
destroyAll
();
if
(
closeMessageOnSwitch
)
{
notification
.
destroy
();
Modal
.
destroyAll
();
notification
.
destroy
();
}
// TODO Some special interfaces require long connections
// TODO Some special interfaces require long connections
// Switching the route will delete the previous request
// Switching the route will delete the previous request
axiosCanceler
.
removeAllPending
();
removeAllHttpPending
&&
axiosCanceler
!
.
removeAllPending
();
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
warn
(
'basic guard error:'
+
error
);
console
.
warn
(
'basic guard error:'
+
error
);
}
}
});
});
projectSetting
.
openNProgress
&&
createProgressGuard
(
router
);
openNProgress
&&
createProgressGuard
(
router
);
createPermissionGuard
(
router
);
createPermissionGuard
(
router
);
createPageTitleGuard
(
router
);
createPageTitleGuard
(
router
);
createPageLoadingGuard
(
router
);
createPageLoadingGuard
(
router
);
...
...
src/settings/projectSetting.ts
浏览文件 @
e83cb06b
...
@@ -116,6 +116,13 @@ const setting: ProjectConfig = {
...
@@ -116,6 +116,13 @@ const setting: ProjectConfig = {
// 是否可以嵌入iframe页面
// 是否可以嵌入iframe页面
canEmbedIFramePage
:
true
,
canEmbedIFramePage
:
true
,
// 切换界面的时候是否删除未关闭的message及notify
closeMessageOnSwitch
:
true
,
// 切换界面的时候是否取消已经发送但是未响应的http请求。
// 如果开启,想对单独接口覆盖。可以在单独接口设置
removeAllHttpPending
:
true
,
};
};
export
default
setting
;
export
default
setting
;
src/types/config.d.ts
浏览文件 @
e83cb06b
...
@@ -102,6 +102,10 @@ export interface ProjectConfig {
...
@@ -102,6 +102,10 @@ export interface ProjectConfig {
openNProgress
:
boolean
;
openNProgress
:
boolean
;
// 是否可以嵌入iframe页面
// 是否可以嵌入iframe页面
canEmbedIFramePage
:
boolean
;
canEmbedIFramePage
:
boolean
;
// 切换界面的时候是否删除未关闭的message及notify
closeMessageOnSwitch
:
boolean
;
// 切换界面的时候是否取消已经发送但是未响应的http请求。
removeAllHttpPending
:
boolean
;
}
}
export
interface
GlobConfig
{
export
interface
GlobConfig
{
...
...
src/utils/http/axios/Axios.ts
浏览文件 @
e83cb06b
...
@@ -5,8 +5,9 @@ import { AxiosCanceler } from './axiosCancel';
...
@@ -5,8 +5,9 @@ import { AxiosCanceler } from './axiosCancel';
import
{
isFunction
}
from
'/@/utils/is'
;
import
{
isFunction
}
from
'/@/utils/is'
;
import
{
cloneDeep
}
from
'lodash-es'
;
import
{
cloneDeep
}
from
'lodash-es'
;
import
{
RequestOptions
,
CreateAxiosOptions
,
Result
}
from
'./types'
;
import
type
{
RequestOptions
,
CreateAxiosOptions
,
Result
}
from
'./types'
;
import
{
ContentTypeEnum
}
from
'/@/enums/httpEnum'
;
import
{
ContentTypeEnum
}
from
'/@/enums/httpEnum'
;
import
{
errorResult
}
from
'./const'
;
export
*
from
'./axiosTransform'
;
export
*
from
'./axiosTransform'
;
...
@@ -147,7 +148,7 @@ export class VAxios {
...
@@ -147,7 +148,7 @@ export class VAxios {
.
then
((
res
:
AxiosResponse
<
Result
>
)
=>
{
.
then
((
res
:
AxiosResponse
<
Result
>
)
=>
{
if
(
transformRequestData
&&
isFunction
(
transformRequestData
))
{
if
(
transformRequestData
&&
isFunction
(
transformRequestData
))
{
const
ret
=
transformRequestData
(
res
,
opt
);
const
ret
=
transformRequestData
(
res
,
opt
);
ret
!==
undefined
?
resolve
(
ret
)
:
reject
(
new
Error
(
'request error!'
));
ret
!==
errorResult
?
resolve
(
ret
)
:
reject
(
new
Error
(
'request error!'
));
return
;
return
;
}
}
resolve
((
res
as
unknown
)
as
Promise
<
T
>
);
resolve
((
res
as
unknown
)
as
Promise
<
T
>
);
...
...
src/utils/http/axios/checkStatus.ts
浏览文件 @
e83cb06b
import
{
useMessage
}
from
'/@/hooks/web/useMessage'
;
import
{
useMessage
}
from
'/@/hooks/web/useMessage'
;
import
{
userStore
}
from
'/@/store/modules/user'
;
const
{
createMessage
}
=
useMessage
();
const
{
createMessage
}
=
useMessage
();
const
error
=
createMessage
.
error
!
;
const
error
=
createMessage
.
error
!
;
...
@@ -12,9 +13,7 @@ export function checkStatus(status: number, msg: string): void {
...
@@ -12,9 +13,7 @@ export function checkStatus(status: number, msg: string): void {
// 在登录成功后返回当前页面,这一步需要在登录页操作。
// 在登录成功后返回当前页面,这一步需要在登录页操作。
case
401
:
case
401
:
error
(
'用户没有权限(令牌、用户名、密码错误)!'
);
error
(
'用户没有权限(令牌、用户名、密码错误)!'
);
// store.dispatch('user/loginOut', {
userStore
.
loginOut
(
true
);
// goLogin: true,
// });
break
;
break
;
case
403
:
case
403
:
error
(
'用户得到授权,但是访问是被禁止的。!'
);
error
(
'用户得到授权,但是访问是被禁止的。!'
);
...
...
src/utils/http/axios/const.ts
0 → 100644
浏览文件 @
e83cb06b
export
const
errorResult
=
'__ERROR_RESULT__'
;
src/utils/http/axios/index.ts
浏览文件 @
e83cb06b
...
@@ -20,6 +20,7 @@ import { formatRequestDate } from '/@/utils/dateUtil';
...
@@ -20,6 +20,7 @@ import { formatRequestDate } from '/@/utils/dateUtil';
import
{
setObjToUrlParams
,
deepMerge
}
from
'/@/utils'
;
import
{
setObjToUrlParams
,
deepMerge
}
from
'/@/utils'
;
import
{
errorStore
,
ErrorTypeEnum
,
ErrorInfo
}
from
'/@/store/modules/error'
;
import
{
errorStore
,
ErrorTypeEnum
,
ErrorInfo
}
from
'/@/store/modules/error'
;
import
{
appStore
}
from
'/@/store/modules/app'
;
import
{
appStore
}
from
'/@/store/modules/app'
;
import
{
errorResult
}
from
'./const'
;
const
{
globSetting
}
=
useSetting
();
const
{
globSetting
}
=
useSetting
();
const
prefix
=
globSetting
.
urlPrefix
;
const
prefix
=
globSetting
.
urlPrefix
;
...
@@ -62,7 +63,6 @@ const transform: AxiosTransform = {
...
@@ -62,7 +63,6 @@ const transform: AxiosTransform = {
return
res
.
data
;
return
res
.
data
;
}
}
// 错误的时候返回
// 错误的时候返回
const
errorResult
=
undefined
;
const
{
data
}
=
res
;
const
{
data
}
=
res
;
if
(
!
data
)
{
if
(
!
data
)
{
...
@@ -89,7 +89,7 @@ const transform: AxiosTransform = {
...
@@ -89,7 +89,7 @@ const transform: AxiosTransform = {
// 接口请求成功,直接返回结果
// 接口请求成功,直接返回结果
if
(
code
===
ResultEnum
.
SUCCESS
)
{
if
(
code
===
ResultEnum
.
SUCCESS
)
{
return
result
||
true
;
return
result
;
}
}
// 接口请求错误,统一提示错误信息
// 接口请求错误,统一提示错误信息
if
(
code
===
ResultEnum
.
ERROR
)
{
if
(
code
===
ResultEnum
.
ERROR
)
{
...
@@ -234,13 +234,6 @@ function createAxios(opt?: Partial<CreateAxiosOptions>) {
...
@@ -234,13 +234,6 @@ function createAxios(opt?: Partial<CreateAxiosOptions>) {
}
}
export
const
defHttp
=
createAxios
();
export
const
defHttp
=
createAxios
();
// var mock = new MockAdapter(axios);
// mock.onGet('/api/aaa').reply(200, {
// users: [{ id: 1, name: 'John Smith' }],
// });
// default
// other api url
// other api url
// export const otherHttp = createAxios({
// export const otherHttp = createAxios({
// requestOptions: {
// requestOptions: {
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论