|
@@ -1,74 +0,0 @@
|
|
|
-import axios from 'axios';
|
|
|
-import dd from 'gdt-jsapi';
|
|
|
-import base from "./base.js"
|
|
|
-
|
|
|
-export default () => {
|
|
|
- axios.defaults.baseURL = base.httpUrl; // 配置axios请求的地址
|
|
|
- console.log("axios.defaults.baseURL-------", axios.defaults.baseURL);
|
|
|
- axios.defaults.headers.post['Content-Type'] = 'application/json; charset=UTF-8';
|
|
|
- axios.defaults.crossDomain = true;
|
|
|
- axios.defaults.withCredentials = true; //设置cross跨域 并设置访问权限 允许跨域携带cookie信息
|
|
|
-
|
|
|
- //配置发送请求前的拦截器 可以设置token信息
|
|
|
- axios.interceptors.request.use(config => {
|
|
|
- console.log("config---------",config);
|
|
|
- dd.showLoading({ text: "加载中" });
|
|
|
- if (config.url.indexOf('geoserver/PH_DEMO') == '-1' && config.url.indexOf('/ding/authLogin') == '-1' && config.url.indexOf('/pub/ding/login') == '-1') {
|
|
|
- // var token = localStorage.getItem('token');
|
|
|
- // console.log('token--------',token);
|
|
|
- // if (token) {
|
|
|
- // config.headers['token'] = token;
|
|
|
- // }
|
|
|
- } else {
|
|
|
- config.withCredentials = false;
|
|
|
- }
|
|
|
- return config;
|
|
|
- }, error => {
|
|
|
- return Promise.reject(error);
|
|
|
- });
|
|
|
- // 配置响应拦截器
|
|
|
- axios.interceptors.response.use(res => {
|
|
|
- const code = res.data.code;
|
|
|
- console.log('配置响应拦截器----', code);
|
|
|
- dd.hideLoading();
|
|
|
- //这里面写所需要的代码
|
|
|
- if (res.data.code == '401') {
|
|
|
- //全局登陆过滤,当判读token失效或者没有登录时 返回登陆页面
|
|
|
- dd.toast({
|
|
|
- text: '登录失效请重新登录'
|
|
|
- });
|
|
|
- var url = base.url + '/statistics'; //http://192.168.1.221:9081/api + '/login?isLogin=1'
|
|
|
- var appId = base.appId;
|
|
|
- dd.openSchemeUrl({
|
|
|
- url: "taurus://taurusclient/action/open_app?appId=" + appId + "&type=1&offline=false&url=" + encodeURIComponent(url)
|
|
|
- }).then(res => { }) //"taurus://taurusclient/action/open_app?appId=" + 'phwj_h5-IYwQFALfovb3Jh27vAz2qe' + "&type=1&offline=false&url=" + encodeURIComponent('http://192.168.1.221:9081/api + '/login?isLogin=1'')
|
|
|
- return false;
|
|
|
- } else if (code == 500) {
|
|
|
- dd.toast({
|
|
|
- text: res.data.msg
|
|
|
- });
|
|
|
- return Promise.reject(new Error(res.data.msg))
|
|
|
- } else {
|
|
|
- return Promise.resolve(res.data);
|
|
|
- };
|
|
|
- }, error => {
|
|
|
- let { message } = error;
|
|
|
- if (message == "Network Error") {
|
|
|
- message = "网络异常,请稍后重试";
|
|
|
- } else if (message.includes("timeout")) {
|
|
|
- message = "系统接口请求超时";
|
|
|
- } else {
|
|
|
- message = "未知异常,请联系管理员";
|
|
|
- }
|
|
|
- dd.toast({
|
|
|
- text: message
|
|
|
- });
|
|
|
- dd.hideLoading();
|
|
|
- return Promise.reject(error);
|
|
|
- })
|
|
|
- axios.imgUrl = (actionName) => {
|
|
|
- // 非生产环境 && 开启代理, 接口前缀统一使用[/proxyApi/]前缀做代理拦截!
|
|
|
- return (axios.defaults.baseURL) + `/auth/file/manage/show/${localStorage.getItem('token')}?url=${encodeURIComponent('/' + actionName)}`;
|
|
|
- }
|
|
|
- return axios
|
|
|
-}
|