swagger文档管理改为API接口文档管理
This commit is contained in:
7
zyplayer-doc-ui/api-ui/src/api/custom.js
Normal file
7
zyplayer-doc-ui/api-ui/src/api/custom.js
Normal file
@@ -0,0 +1,7 @@
|
||||
import apiClient from './request/custom.js'
|
||||
|
||||
export const customApi = {
|
||||
get: (url, data) => apiClient({url: url, method: 'get', data: data}),
|
||||
post: (url, data) => apiClient({url: url, method: 'post', data: data}),
|
||||
};
|
||||
|
||||
4
zyplayer-doc-ui/api-ui/src/api/index.js
Normal file
4
zyplayer-doc-ui/api-ui/src/api/index.js
Normal file
@@ -0,0 +1,4 @@
|
||||
export { zyplayerApi } from './zyplayer.js';
|
||||
export { customApi } from './custom.js';
|
||||
|
||||
|
||||
14
zyplayer-doc-ui/api-ui/src/api/request/custom.js
Normal file
14
zyplayer-doc-ui/api-ui/src/api/request/custom.js
Normal file
@@ -0,0 +1,14 @@
|
||||
import Axios from 'axios'
|
||||
import interceptors from './interceptorsCustom'
|
||||
import {getCustomApiBaseUrl} from "./utils";
|
||||
|
||||
const apiClient = Axios.create({
|
||||
baseURL: getCustomApiBaseUrl(),
|
||||
timeout: 20000,
|
||||
headers: {'Content-type': 'application/x-www-form-urlencoded'},
|
||||
withCredentials: true
|
||||
});
|
||||
interceptors(apiClient);
|
||||
|
||||
export default apiClient;
|
||||
|
||||
61
zyplayer-doc-ui/api-ui/src/api/request/interceptors.js
Normal file
61
zyplayer-doc-ui/api-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 = {
|
||||
"./swagger-resources": true,
|
||||
"/v2/api-docs": 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)
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
41
zyplayer-doc-ui/api-ui/src/api/request/interceptorsCustom.js
Normal file
41
zyplayer-doc-ui/api-ui/src/api/request/interceptorsCustom.js
Normal file
@@ -0,0 +1,41 @@
|
||||
import qs from 'qs'
|
||||
import { message } from 'ant-design-vue';
|
||||
|
||||
export default function (axios) {
|
||||
axios.interceptors.request.use(
|
||||
config => {
|
||||
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 {
|
||||
return response.data;
|
||||
}
|
||||
return Promise.reject('请求错误');
|
||||
},
|
||||
error => {
|
||||
console.log('err' + error);
|
||||
message.error('请求错误:' + error.message);
|
||||
return Promise.reject(error)
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
25
zyplayer-doc-ui/api-ui/src/api/request/utils.js
Normal file
25
zyplayer-doc-ui/api-ui/src/api/request/utils.js
Normal file
@@ -0,0 +1,25 @@
|
||||
|
||||
/**
|
||||
* 获取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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取custom后端域名
|
||||
*/
|
||||
export function getCustomApiBaseUrl() {
|
||||
let env = import.meta.env.VITE_APP_ENV;
|
||||
let baseUrl = import.meta.env.VITE_APP_CUSTOM_URL_ONLINE;
|
||||
if ("dev" === env) {
|
||||
baseUrl = import.meta.env.VITE_APP_CUSTOM_URL_DEV;
|
||||
}
|
||||
return baseUrl;
|
||||
}
|
||||
|
||||
14
zyplayer-doc-ui/api-ui/src/api/request/zyplayer.js
Normal file
14
zyplayer-doc-ui/api-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;
|
||||
|
||||
17
zyplayer-doc-ui/api-ui/src/api/zyplayer.js
Normal file
17
zyplayer-doc-ui/api-ui/src/api/zyplayer.js
Normal file
@@ -0,0 +1,17 @@
|
||||
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}),
|
||||
apiDocList: data => apiClient({url: '/doc-api/doc/list', method: 'post', data: data}),
|
||||
apiDocAdd: data => apiClient({url: '/doc-api/doc/add', method: 'post', data: data}),
|
||||
apiDocUpdate: data => apiClient({url: '/doc-api/doc/update', method: 'post', data: data}),
|
||||
apiDocDetail: data => apiClient({url: '/doc-api/doc/detail', method: 'post', data: data}),
|
||||
apiDocApis: data => apiClient({url: '/doc-api/doc/apis', method: 'post', data: data}),
|
||||
apiDocApisDetail: data => apiClient({url: '/doc-api/doc/apis/detail', method: 'post', data: data}),
|
||||
docApiGlobalParamList: data => apiClient({url: '/doc-api/global-param/list', method: 'post', data: data}),
|
||||
docApiGlobalParamUpdate: data => apiClient({url: '/doc-api/global-param/update', method: 'post', data: data}),
|
||||
requestUrl: data => apiClient({url: '/doc-api/proxy/request', method: 'post', data: data}),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user