Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Simoje丶
vue-vben-admin
提交
f646e377
V
vue-vben-admin
项目概览
Simoje丶
/
vue-vben-admin
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vue-vben-admin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
f646e377
编写于
12月 15, 2020
作者:
V
vben
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: axios add joinTime field
上级
c774a6d3
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
65 addition
and
35 deletion
+65
-35
CHANGELOG.zh_CN.md
CHANGELOG.zh_CN.md
+7
-1
src/components/Drawer/src/useDrawer.ts
src/components/Drawer/src/useDrawer.ts
+1
-1
src/components/Modal/src/useModal.ts
src/components/Modal/src/useModal.ts
+1
-1
src/utils/dateUtil.ts
src/utils/dateUtil.ts
+0
-24
src/utils/http/axios/helper.ts
src/utils/http/axios/helper.ts
+45
-0
src/utils/http/axios/index.ts
src/utils/http/axios/index.ts
+8
-8
src/utils/http/axios/types.ts
src/utils/http/axios/types.ts
+2
-0
vite.config.ts
vite.config.ts
+1
-0
未找到文件。
CHANGELOG.zh_CN.md
浏览文件 @
f646e377
...
...
@@ -3,7 +3,8 @@
### ✨ Features
-
移除左侧菜单搜索,新增顶部菜单搜索功能
-
layout 移动端适配。页面未适配
-
layout 移动端适配。业务页面未适配
-
axios 加入 joinTime 配置。控制响应是否加入时间戳
### ⚡ Performance Improvements
...
...
@@ -19,6 +20,10 @@
-
刷新按钮布局调整
-
`route.meta`
移除
`externalLink`
属性
### ✨ Refactor
-
`openModal`
与
`openDrawer`
第三个参数
`openOnSet`
默认设置为 true
### 🐛 Bug Fixes
-
修复多级路由缓存导致组件渲染多次的问题
...
...
@@ -31,6 +36,7 @@
-
修复
`Modal`
与
`Drawer`
组件在使用 emits 数据传递失效问题
-
修复菜单已知问题
-
修复上传组件 api 失效问题
-
修复菜单权限过滤失效问题
## 2.0.0-rc.13 (2020-12-10)
...
...
src/components/Drawer/src/useDrawer.ts
浏览文件 @
f646e377
...
...
@@ -56,7 +56,7 @@ export function useDrawer(): UseDrawerReturnType {
getInstance
().
setDrawerProps
(
props
);
},
openDrawer
:
<
T
=
any
>
(
visible
=
true
,
data
?:
T
,
openOnSet
=
fals
e
):
void
=>
{
openDrawer
:
<
T
=
any
>
(
visible
=
true
,
data
?:
T
,
openOnSet
=
tru
e
):
void
=>
{
getInstance
().
setDrawerProps
({
visible
:
visible
,
});
...
...
src/components/Modal/src/useModal.ts
浏览文件 @
f646e377
...
...
@@ -60,7 +60,7 @@ export function useModal(): UseModalReturnType {
getInstance
().
setModalProps
(
props
);
},
openModal
:
<
T
=
any
>
(
visible
=
true
,
data
?:
T
,
openOnSet
=
fals
e
):
void
=>
{
openModal
:
<
T
=
any
>
(
visible
=
true
,
data
?:
T
,
openOnSet
=
tru
e
):
void
=>
{
getInstance
().
setModalProps
({
visible
:
visible
,
});
...
...
src/utils/dateUtil.ts
浏览文件 @
f646e377
import
{
isObject
,
isString
}
from
'
/@/utils/is
'
;
import
moment
from
'
moment
'
;
const
DATE_TIME_FORMAT
=
'
YYYY-MM-DD HH:mm
'
;
...
...
@@ -34,28 +33,5 @@ export const formatAgo = (str: string | number) => {
return
parseInt
(
String
(
time
/
31536000000
))
+
'
年前
'
;
}
};
/**
* @description: 格式化请求参数时间
*/
export
function
formatRequestDate
(
params
:
any
)
{
for
(
const
key
in
params
)
{
if
(
params
[
key
]
&&
params
[
key
].
_isAMomentObject
)
{
params
[
key
]
=
params
[
key
].
format
(
DATE_TIME_FORMAT
);
}
if
(
isString
(
key
))
{
const
value
=
params
[
key
];
if
(
value
)
{
try
{
params
[
key
]
=
isString
(
value
)
?
value
.
trim
()
:
value
;
}
catch
(
error
)
{
throw
new
Error
(
error
);
}
}
}
if
(
isObject
(
params
[
key
]))
{
formatRequestDate
(
params
[
key
]);
}
}
}
export
const
dateUtil
=
moment
;
src/utils/http/axios/helper.ts
0 → 100644
浏览文件 @
f646e377
import
{
isObject
,
isString
}
from
'
/@/utils/is
'
;
export
function
createNow
<
T
extends
boolean
>
(
join
:
boolean
,
restful
:
T
):
T
extends
true
?
string
:
object
;
export
function
createNow
(
join
:
boolean
,
restful
=
false
):
string
|
object
{
if
(
!
join
)
{
return
restful
?
''
:
{};
}
const
now
=
new
Date
().
getTime
();
if
(
restful
)
{
return
`?_t=
${
now
}
`
;
}
return
{
_t
:
now
,
};
}
const
DATE_TIME_FORMAT
=
'
YYYY-MM-DD HH:mm
'
;
/**
* @description: 格式化请求参数时间
*/
export
function
formatRequestDate
(
params
:
any
)
{
for
(
const
key
in
params
)
{
if
(
params
[
key
]
&&
params
[
key
].
_isAMomentObject
)
{
params
[
key
]
=
params
[
key
].
format
(
DATE_TIME_FORMAT
);
}
if
(
isString
(
key
))
{
const
value
=
params
[
key
];
if
(
value
)
{
try
{
params
[
key
]
=
isString
(
value
)
?
value
.
trim
()
:
value
;
}
catch
(
error
)
{
throw
new
Error
(
error
);
}
}
}
if
(
isObject
(
params
[
key
]))
{
formatRequestDate
(
params
[
key
]);
}
}
}
src/utils/http/axios/index.ts
浏览文件 @
f646e377
...
...
@@ -3,7 +3,6 @@
import
type
{
AxiosResponse
}
from
'
axios
'
;
import
type
{
CreateAxiosOptions
,
RequestOptions
,
Result
}
from
'
./types
'
;
import
{
VAxios
}
from
'
./Axios
'
;
import
{
getToken
}
from
'
/@/utils/auth
'
;
import
{
AxiosTransform
}
from
'
./axiosTransform
'
;
...
...
@@ -16,11 +15,11 @@ import { useMessage } from '/@/hooks/web/useMessage';
import
{
RequestEnum
,
ResultEnum
,
ContentTypeEnum
}
from
'
/@/enums/httpEnum
'
;
import
{
isString
}
from
'
/@/utils/is
'
;
import
{
formatRequestDate
}
from
'
/@/utils/dateUtil
'
;
import
{
setObjToUrlParams
,
deepMerge
}
from
'
/@/utils
'
;
import
{
errorStore
}
from
'
/@/store/modules/error
'
;
import
{
errorResult
}
from
'
./const
'
;
import
{
useI18n
}
from
'
/@/hooks/web/useI18n
'
;
import
{
createNow
,
formatRequestDate
}
from
'
./helper
'
;
const
globSetting
=
useGlobSetting
();
const
prefix
=
globSetting
.
urlPrefix
;
...
...
@@ -97,7 +96,7 @@ const transform: AxiosTransform = {
// 请求之前处理config
beforeRequestHook
:
(
config
,
options
)
=>
{
const
{
apiUrl
,
joinPrefix
,
joinParamsToUrl
,
formatDate
}
=
options
;
const
{
apiUrl
,
joinPrefix
,
joinParamsToUrl
,
formatDate
,
joinTime
=
true
}
=
options
;
if
(
joinPrefix
)
{
config
.
url
=
`
${
prefix
}${
config
.
url
}
`
;
...
...
@@ -107,17 +106,14 @@ const transform: AxiosTransform = {
config
.
url
=
`
${
apiUrl
}${
config
.
url
}
`
;
}
if
(
config
.
method
?.
toUpperCase
()
===
RequestEnum
.
GET
)
{
const
now
=
new
Date
().
getTime
();
if
(
!
isString
(
config
.
params
))
{
config
.
data
=
{
// 给 get 请求加上时间戳参数,避免从缓存中拿数据。
params
:
Object
.
assign
(
config
.
params
||
{},
{
_t
:
now
,
}),
params
:
Object
.
assign
(
config
.
params
||
{},
createNow
(
joinTime
,
false
)),
};
}
else
{
// 兼容restful风格
config
.
url
=
config
.
url
+
config
.
params
+
`
?_t=
${
now
}
`
;
config
.
url
=
config
.
url
+
config
.
params
+
`
${
createNow
(
joinTime
,
true
)
}
`
;
config
.
params
=
undefined
;
}
}
else
{
...
...
@@ -187,6 +183,8 @@ function createAxios(opt?: Partial<CreateAxiosOptions>) {
// 接口可能会有通用的地址部分,可以统一抽取出来
prefixUrl
:
prefix
,
headers
:
{
'
Content-Type
'
:
ContentTypeEnum
.
JSON
},
// 如果是form-data格式
// headers: { 'Content-Type': ContentTypeEnum.FORM_URLENCODED },
// 数据处理方式
transform
,
// 配置项,下面的选项都可以在独立的接口请求中覆盖
...
...
@@ -203,6 +201,8 @@ function createAxios(opt?: Partial<CreateAxiosOptions>) {
errorMessageMode
:
'
message
'
,
// 接口地址
apiUrl
:
globSetting
.
apiUrl
,
// 是否加入时间戳
joinTime
:
true
,
},
},
opt
||
{}
...
...
src/utils/http/axios/types.ts
浏览文件 @
f646e377
...
...
@@ -16,6 +16,8 @@ export interface RequestOptions {
apiUrl
?:
string
;
// 错误消息提示类型
errorMessageMode
?:
ErrorMessageMode
;
// 是否加入时间戳
joinTime
?:
boolean
;
}
export
interface
CreateAxiosOptions
extends
AxiosRequestConfig
{
...
...
vite.config.ts
浏览文件 @
f646e377
...
...
@@ -78,6 +78,7 @@ const viteConfig: UserConfig = {
// The package will be recompiled using rollup, and the new package compiled into the esm module specification will be put into node_modules/.vite_opt_cache
optimizeDeps
:
{
include
:
[
'
qs
'
,
'
echarts/map/js/china
'
,
'
ant-design-vue/es/locale/zh_CN
'
,
'
ant-design-vue/es/locale/en_US
'
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录