101 lines
2.7 KiB
JavaScript
101 lines
2.7 KiB
JavaScript
import axios from 'axios';
|
|
import { url, zoneUrl } from '../ssrUrl';
|
|
|
|
let baseUrl = `${url}/api`
|
|
let baseZoneUrl = `${zoneUrl}/api`
|
|
if (__CLIENT__ ) {
|
|
let settings = localStorage.chromesetting && localStorage.chromesetting !== 'undefined' &&JSON.parse(localStorage.chromesetting);
|
|
baseUrl = settings && settings.common && settings.common.main_site_url ? `${settings.common.main_site_url}/api` : baseUrl;
|
|
baseZoneUrl = settings ? `${settings && settings.common.zone}/api` : `${zoneUrl}/api`;
|
|
}
|
|
console.log("__CLIENT__",__CLIENT__,baseUrl);
|
|
|
|
const axiosInstance = axios.create({
|
|
withCredentials: true
|
|
});
|
|
axiosInstance.interceptors.request.use(
|
|
config => {
|
|
if (window.location.port === "3007") {
|
|
if (config.url.indexOf('?') === -1) {
|
|
config.url = `${config.url}?debug=admin`;
|
|
} else {
|
|
config.url = `${config.url}&debug=admin`;
|
|
}
|
|
}
|
|
return config;
|
|
},
|
|
err => {
|
|
return Promise.reject(err);
|
|
});
|
|
|
|
axiosInstance.interceptors.response.use(
|
|
response => {
|
|
return response;
|
|
},
|
|
error => {
|
|
console.log(error);
|
|
}
|
|
)
|
|
|
|
const setHead = () => {
|
|
if (__SERVER__) {
|
|
axiosInstance.defaults.headers.cookie = domObj.window.document.cookie
|
|
axiosInstance.defaults.headers.common['isServer'] = true
|
|
}
|
|
}
|
|
|
|
|
|
export async function getProjectFunc (owner, projectsId) {
|
|
setHead()
|
|
const url = `${baseUrl}/${owner}/${projectsId}/simple.json`;
|
|
return axiosInstance.get(url);
|
|
}
|
|
|
|
export async function getProjectDetailFunc (owner, projectsId) {
|
|
setHead()
|
|
const url = `${baseUrl}/${owner}/${projectsId}/detail.json`;
|
|
return axiosInstance.get(url);
|
|
}
|
|
|
|
export async function getProjectEntriesFunc (owner, projectsId, branch) {
|
|
setHead()
|
|
const url = `${baseUrl}/${owner}/${projectsId}/entries.json`;
|
|
return axiosInstance.get(url, {params: { ref: branch }});
|
|
}
|
|
|
|
export async function getBannerFunc (owner, projectsId) {
|
|
setHead()
|
|
const url = `${baseUrl}/${owner}/${projectsId}/menu_list.json`;
|
|
return axiosInstance.get(url);
|
|
}
|
|
|
|
export async function getProjectReadMe (owner, projectsId, branch) {
|
|
setHead()
|
|
const url = `${baseUrl}/${owner}/${projectsId}/readme.json`;
|
|
return axiosInstance.get(url, {params: { ref: branch }});
|
|
}
|
|
|
|
export async function getOwnerInfo (owner) {
|
|
setHead()
|
|
const url = `${baseUrl}/owners/${owner}.json`;
|
|
return axiosInstance.get(url);
|
|
}
|
|
|
|
|
|
export async function getMainInfos (deptId) {
|
|
setHead()
|
|
const url = `${baseZoneUrl}/zone/open/zoneKey/${deptId}`;
|
|
return axiosInstance.get(url);
|
|
}
|
|
|
|
export async function getNewsDetail (id) {
|
|
setHead()
|
|
const url = `${baseZoneUrl}/cms/doc/open/${id}`;
|
|
return axiosInstance.get(url);
|
|
}
|
|
|
|
export async function getSetting () {
|
|
const url = `${baseUrl}/setting.json`;
|
|
return axiosInstance.get(url);
|
|
}
|