123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- document.write("<script language='javascript' src='./static/js/appfunc.min.js'></script>");
- // 配置基地址
- var request = axios.create({
- // baseURL: 'http://192.168.9.85:22000'
- // 测试接口
- baseURL: 'http://test.ap.shuangkebang.com'
- // 模拟接口
- // baseURL: 'http://192.168.9.85:22000/mock/11'
- });
- // 数据响应防抖
- let requestflag = true;
- // 请求拦截器
- request.interceptors.request.use(
- config => {
- // 该处可以将config打印出来看一下,该部分将发送给后端(server端)
- // console.log(config);
- config.headers.Authorization = 'Bearer ' + PublicLib.getCookieInfo('token');;
- if(requestflag){
- // config.header = {"":""};
- if(config.method === 'post'){
- requestflag = false;
- }
- return config; // 对config处理完后返回,下一步将向后端发送请求
- }
-
- },
- error => { // 当发生错误时,执行该部分代码
- console.log(error); //调试用
- return Promise.reject(error)
- }
- );
- // 响应拦截器
- request.interceptors.response.use(
- response => { // 该处为后端返回整个内容
- // tips('登录失效');
- const res = response.data; // 该处可将后端数据取出,提前做一个处理
- requestflag = true;
- return res;
- },
- error => {
- console.log(error.response.status);
- if(error.response.status === 401) {
- PublicLib.GoBack({Level:0});
- };
- return Promise.reject(error);
- }
- );
- // 测试接口
- // const testInterface = (url) => {
- // return request.get(url);
- // };
- // GET请求
- const getRequest = (url,parameter) => {
- console.log(parameter)
- return request.get(url,{params:{value:encryption(parameter)}});
- };
- // POST请求
- const postRequest = (url,parameter) => {
- let param = new URLSearchParams();
- param.append('value', encryption(parameter));
- console.log(parameter);
- return request({
- url,
- method: 'post',
- headers: {
- // 'Access-Control-Allow-Origin':'*'
- 'Content-Type': 'application/x-www-form-urlencoded'
- },
- data: param,
- })
- };
- // let param = new URLSearchParams();
- // param.append('value', '{"Mobile":"' + Mobile + '","ReferenceCode":"' + ReferenceCode + '","LoginPwd":"' + LoginPwd + '","MobileCode":"' + MobileCode + '","MobileCode":"' + that.mobileCode + '"}');
- // param.append('token', getCookieInfo('Token'));
- document.write("<script language='javascript' src='./static/js/publicfn.js'></script>");
|