123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- import axios from "axios";
- import qs from "qs";
- axios.defaults.baseURL = window.location.href.split('://')[0]+'://' +process.env.VUE_APP_BASE_API //测试
- //获取后台浏览器跳转过来的地址携带的token
- let afterUrl = window.location.search.substring(1);
- let identity = afterUrl.substr(9, afterUrl.length);
- if(identity.length>0){
- //Authorization
- localStorage.setItem('Authorization',identity)
- localStorage.setItem('deptLevel','2')////这个是登陆后,刘波给你的院校的类型
- }
- //post请求头
- axios.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded;charset=UTF-8";
- // 表示跨域请求时是否需要使用凭证 允许跨域携带cookie信息
- axios.defaults.withCredentials = false;
- // 允许跨域
- axios.defaults.headers.post["Access-Control-Allow-Origin-Type"] = "*";
- //axios.defaults.headers.common["Authorization"] = 'Bearer f49d7770-515a-4661-8d07-fc07256c8165';//`Bearer ${localStorage.getItem('access_token')`;
- axios.defaults.headers.common["Authorization"] = 'Bearer '+localStorage.getItem('Authorization')+''
- //设置超时
- axios.defaults.timeout = 15000;
- axios.interceptors.request.use(
- config => {
- return config;
- },
- error => {
- return Promise.reject(error);
- }
- );
- axios.interceptors.response.use(
- response => {
- if (response.status == 200) {
- return Promise.resolve(response);
- } else {
- return Promise.reject(response);
- }
- },
- error => {
- console.log(JSON.stringify(error), '请求异常', {
- confirmButtonText: '确定',
- callback: (action) => {
- console.log(action)
- }
- });
- }
- );
- export default {
- /**
- * @param {String} url
- * @param {Object} data
- * @returns Promise
- */
- post(url, data) {
- return new Promise((resolve, reject) => {
- axios({
- method: 'post',
- url,
- data: qs.stringify(data),
- })
- .then(res => {
- resolve(res.data)
- })
- .catch(err => {
- reject(err)
- });
- })
- },
- get(url, data,type) {
- if(type=='video'){
- axios.defaults.baseURL =localStorage.getItem('cameraExtranetAgent')
- }else{
- axios.defaults.baseURL = window.location.href.split('://')[0]+'://' +process.env.VUE_APP_BASE_API
- }
- return new Promise((resolve, reject) => {
- axios({
- method: 'get',
- url,
- params: data,
- })
- .then(res => {
- resolve(res.data)
- })
- .catch(err => {
- reject(err)
- })
- })
- },
- baseUrl: window.location.href.split('://')[0]+'://' +process.env.VUE_APP_BASE_API
- };
|