使用vitejs+vue3+antdv重构swagger文档展示
This commit is contained in:
3
zyplayer-doc-ui/swagger-ui/src/api/index.js
Normal file
3
zyplayer-doc-ui/swagger-ui/src/api/index.js
Normal file
@@ -0,0 +1,3 @@
|
||||
export { zyplayerApi } from './zyplayer.js';
|
||||
|
||||
|
||||
61
zyplayer-doc-ui/swagger-ui/src/api/request/interceptors.js
Normal file
61
zyplayer-doc-ui/swagger-ui/src/api/request/interceptors.js
Normal file
@@ -0,0 +1,61 @@
|
||||
import qs from 'qs'
|
||||
import { message } from 'ant-design-vue';
|
||||
import {getZyplayerApiBaseUrl} from "./utils";
|
||||
|
||||
// 增加不需要验证结果的标记
|
||||
const noValidate = {
|
||||
"/zyplayer-doc-db/executor/execute": true,
|
||||
"/zyplayer-doc-db/datasource/test": true,
|
||||
};
|
||||
|
||||
export default function (axios) {
|
||||
axios.interceptors.request.use(
|
||||
config => {
|
||||
config.needValidateResult = true;
|
||||
// 增加不需要验证结果的标记
|
||||
if (noValidate[config.url]) {
|
||||
config.needValidateResult = false;
|
||||
}
|
||||
if (config.method === 'get') {
|
||||
config.params = config.params || {};
|
||||
config.params = {...config.params, _: (new Date()).getTime()}
|
||||
} else if (config.method === 'post') {
|
||||
config.data = config.data || {};
|
||||
if (config.data instanceof FormData) {
|
||||
// 表单,无需特殊处理
|
||||
} else if (config.data instanceof Object) {
|
||||
config.data = qs.stringify(config.data);
|
||||
}
|
||||
}
|
||||
return config;
|
||||
},
|
||||
error => {
|
||||
console.log(error);
|
||||
return Promise.reject(error);
|
||||
}
|
||||
);
|
||||
axios.interceptors.response.use(
|
||||
response => {
|
||||
if (!!response.message) {
|
||||
vue.$message.error('请求错误:' + response.message);
|
||||
}else {
|
||||
if (!response.config.needValidateResult || response.data.errCode === 200) {
|
||||
return response.data;
|
||||
} else if (response.data.errCode === 400) {
|
||||
message.error('请先登录');
|
||||
let href = encodeURIComponent(window.location.href);
|
||||
window.location = getZyplayerApiBaseUrl() + "#/user/login?redirect=" + href;
|
||||
} else {
|
||||
message.error(response.data.errMsg || "未知错误");
|
||||
}
|
||||
}
|
||||
return Promise.reject('请求错误');
|
||||
},
|
||||
error => {
|
||||
console.log('err' + error);
|
||||
message.error('请求错误:' + error.message);
|
||||
return Promise.reject(error)
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
13
zyplayer-doc-ui/swagger-ui/src/api/request/utils.js
Normal file
13
zyplayer-doc-ui/swagger-ui/src/api/request/utils.js
Normal file
@@ -0,0 +1,13 @@
|
||||
|
||||
/**
|
||||
* 获取zyplayer后端域名
|
||||
*/
|
||||
export function getZyplayerApiBaseUrl() {
|
||||
let env = import.meta.env.VITE_APP_ENV;
|
||||
let baseUrl = import.meta.env.VITE_APP_BASE_URL_ONLINE;
|
||||
if ("dev" === env) {
|
||||
baseUrl = import.meta.env.VITE_APP_BASE_URL_DEV;
|
||||
}
|
||||
return baseUrl;
|
||||
}
|
||||
|
||||
14
zyplayer-doc-ui/swagger-ui/src/api/request/zyplayer.js
Normal file
14
zyplayer-doc-ui/swagger-ui/src/api/request/zyplayer.js
Normal file
@@ -0,0 +1,14 @@
|
||||
import Axios from 'axios'
|
||||
import interceptors from './interceptors'
|
||||
import {getZyplayerApiBaseUrl} from "./utils";
|
||||
|
||||
const apiClient = Axios.create({
|
||||
baseURL: getZyplayerApiBaseUrl(),
|
||||
timeout: 20000,
|
||||
headers: {'Content-type': 'application/x-www-form-urlencoded'},
|
||||
withCredentials: true
|
||||
});
|
||||
interceptors(apiClient);
|
||||
|
||||
export default apiClient;
|
||||
|
||||
8
zyplayer-doc-ui/swagger-ui/src/api/zyplayer.js
Normal file
8
zyplayer-doc-ui/swagger-ui/src/api/zyplayer.js
Normal file
@@ -0,0 +1,8 @@
|
||||
import apiClient from './request/zyplayer.js'
|
||||
|
||||
export const zyplayerApi = {
|
||||
getSelfUserInfo: data => apiClient({url: '/user/info/selfInfo', method: 'post', data: data}),
|
||||
userLogout: data => apiClient({url: '/logout', method: 'post', data: data}),
|
||||
systemUpgradeInfo: data => apiClient({url: '/system/info/upgrade', method: 'post', data: data}),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user