mirror of
https://github.com/ialley-workshop-open/uni-halo.git
synced 2026-06-11 12:49:30 +08:00
release: 发布 uni-halo beta-v2.0 版本
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
*/
|
||||
|
||||
import HaloConfig from '@/config/halo.config.js'
|
||||
import HaloTokenConfig from '@/config/token.config.js'
|
||||
import {
|
||||
setInterceptors
|
||||
} from "./interceptors.js";
|
||||
@@ -21,11 +22,10 @@ const http = new Request()
|
||||
http.setConfig((config) => {
|
||||
|
||||
// 如果是在外部浏览器调试或者编译为h5,请注释该行代码
|
||||
config.baseURL = HaloConfig.apiUrl;
|
||||
config.baseURL = HaloTokenConfig.BASE_API;
|
||||
|
||||
config.header = {
|
||||
...config.header,
|
||||
'api-authorization': HaloConfig.apiAuthorization,
|
||||
...config.header,
|
||||
ContentType: 'application/json',
|
||||
dataType: 'json'
|
||||
}
|
||||
|
||||
@@ -64,13 +64,15 @@ const showCategoryInputPasswordModal = (response, category) => {
|
||||
export const setInterceptors = (http) => {
|
||||
http.interceptors.request.use(
|
||||
(config) => {
|
||||
console.log("config", config)
|
||||
|
||||
// 可使用async await 做异步操作
|
||||
config.header = {
|
||||
...config.header
|
||||
// ... 可以直接加参数
|
||||
};
|
||||
if (getAdminAccessToken()) {
|
||||
config.header['admin-authorization'] = getAdminAccessToken()
|
||||
if (config.custom.systemToken) {
|
||||
config.header['Authorization'] = `Bearer ${config.custom.systemToken}`
|
||||
}
|
||||
return config;
|
||||
},
|
||||
@@ -138,12 +140,14 @@ export const setInterceptors = (http) => {
|
||||
})
|
||||
})
|
||||
}
|
||||
return Promise.reject(response.data);
|
||||
} else if (response.data.status == 403) {
|
||||
// 如果报403是请求分类文章接口(您没有该分类的访问权限)的话说明是私密分类,需要输入密码请求
|
||||
if (response.config.url.indexOf('/api/content/categories') >= 0) {
|
||||
const category = getCategoryNameByUrl(response.config.url);
|
||||
showCategoryInputPasswordModal(response, category);
|
||||
}
|
||||
return Promise.reject(response.data);
|
||||
} else {
|
||||
return Promise.reject(response.data);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user