1 |
- {"remainingRequest":"/Users/lihai/jolijoli/pad_spa/node_modules/babel-loader/lib/index.js!/Users/lihai/jolijoli/pad_spa/node_modules/eslint-loader/index.js??ref--13-0!/Users/lihai/jolijoli/pad_spa/src/common/http.js","dependencies":[{"path":"/Users/lihai/jolijoli/pad_spa/src/common/http.js","mtime":1652164298878},{"path":"/Users/lihai/jolijoli/pad_spa/babel.config.js","mtime":1649813268617},{"path":"/Users/lihai/jolijoli/pad_spa/node_modules/cache-loader/dist/cjs.js","mtime":499162500000},{"path":"/Users/lihai/jolijoli/pad_spa/node_modules/babel-loader/lib/index.js","mtime":315532800000},{"path":"/Users/lihai/jolijoli/pad_spa/node_modules/eslint-loader/index.js","mtime":499162500000}],"contextDependencies":[],"result":["var _this = this;\n\n// 封装axios请求\n\n/**axios封装\n * 请求拦截、相应拦截、错误统一处理\n */\nimport axios from 'axios';\nimport QS from 'qs';\nimport store from '../store/index'; // 环境的切换\n\nif (process.env.NODE_ENV == 'development') {\n axios.defaults.baseURL = '/api';\n} else if (process.env.NODE_ENV == 'debug') {\n axios.defaults.baseURL = '';\n} else if (process.env.NODE_ENV == 'production') {\n axios.defaults.baseURL = 'http://api.123dailu.com/';\n} // 请求超时时间\n\n\naxios.defaults.timeout = 10000; // post请求头\n\naxios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8'; // 请求拦截器\n\naxios.interceptors.request.use(function (config) {\n // 每次发送请求之前判断是否存在token,如果存在,则统一在http请求的header都加上token,不用每次请求都手动添加了\n // 即使本地存在token,也有可能token是过期的,所以在响应拦截器中要对返回状态进行判断\n var token = store.state.token;\n token && (config.headers.Authorization = token);\n return config;\n}, function (error) {\n return Promise.error(error);\n}); // 响应拦截器\n\naxios.interceptors.response.use(function (response) {\n if (response.status === 200) {\n return Promise.resolve(response);\n } else {\n return Promise.reject(response);\n }\n}, // 服务器状态码不是200的情况\nfunction (error) {\n if (error.response.status) {\n switch (error.response.status) {\n // 401: 未登录\n // 未登录则跳转登录页面,并携带当前页面的路径\n // 在登录成功后返回当前页面,这一步需要在登录页操作。\n case 401:\n router.replace({\n path: '/login',\n query: {\n redirect: router.currentRoute.fullPath\n }\n });\n break;\n // 403 token过期\n // 登录过期对用户进行提示\n // 清除本地token和清空vuex中token对象\n // 跳转登录页面\n\n case 403:\n _this.$message.error('登录过期,请重新登录'); // 清除token\n\n\n localStorage.removeItem('token');\n store.commit('loginSuccess', null); // 跳转登录页面,并将要浏览的页面fullPath传过去,登录成功后跳转需要访问的页面\n\n setTimeout(function () {\n router.replace({\n path: '/login',\n query: {\n redirect: router.currentRoute.fullPath\n }\n });\n }, 1000);\n break;\n // 404请求不存在\n\n case 404:\n _this.$message.error('网络请求不存在');\n\n break;\n // 其他错误,直接抛出错误提示\n\n default:\n _this.$message.error(error.response.data.message);\n\n }\n\n return Promise.reject(error.response);\n }\n});\n/**\n * get方法,对应get请求\n * @param {String} url [请求的url地址]\n * @param {Object} params [请求时携带的参数]\n */\n\nfunction get(url, params) {\n return new Promise(function (resolve, reject) {\n axios.get(url, {\n params: params\n }).then(function (res) {\n resolve(res.data);\n }).catch(function (err) {\n reject(err.data);\n });\n });\n}\n/**\n * post方法,对应post请求\n * @param {String} url [请求的url地址]\n * @param {Object} params [请求时携带的参数]\n */\n\n\nfunction post(url, params) {\n return new Promise(function (resolve, reject) {\n axios.post(url, QS.stringify(params)).then(function (res) {\n resolve(res.data);\n }).catch(function (err) {\n reject(err.data);\n });\n });\n}\n\nexport default (function () {\n if (typeof window.$http == 'undefined') {\n window.$http = {\n post: post,\n get: get\n };\n }\n});",{"version":3,"sources":["/Users/lihai/jolijoli/pad_spa/src/common/http.js"],"names":["axios","QS","store","process","env","NODE_ENV","defaults","baseURL","timeout","headers","post","interceptors","request","use","config","token","state","Authorization","error","Promise","response","status","resolve","reject","router","replace","path","query","redirect","currentRoute","fullPath","$message","localStorage","removeItem","commit","setTimeout","data","message","get","url","params","then","res","catch","err","stringify","window","$http"],"mappings":";;AAAA;;AACA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B,SAAO,IAAIrB,OAAJ,CAAY,UAACG,OAAD,EAAUC,MAAV,EAAoB;AACtCvB,IAAAA,KAAK,CAACsC,GAAN,CAAUC,GAAV,EAAe;AACdC,MAAAA,MAAM,EAAEA;AADM,KAAf,EAGEC,IAHF,CAGO,UAAAC,GAAG,EAAI;AACZpB,MAAAA,OAAO,CAACoB,GAAG,CAACN,IAAL,CAAP;AACA,KALF,EAMEO,KANF,CAMQ,UAAAC,GAAG,EAAI;AACbrB,MAAAA,MAAM,CAACqB,GAAG,CAACR,IAAL,CAAN;AACA,KARF;AASA,GAVM,CAAP;AAWA;AACD;;;;;;;AAKA,SAAS1B,IAAT,CAAc6B,GAAd,EAAmBC,MAAnB,EAA2B;AAC1B,SAAO,IAAIrB,OAAJ,CAAY,UAACG,OAAD,EAAUC,MAAV,EAAqB;AACvCvB,IAAAA,KAAK,CAACU,IAAN,CAAW6B,GAAX,EAAgBtC,EAAE,CAAC4C,SAAH,CAAaL,MAAb,CAAhB,EACEC,IADF,CACO,UAAAC,GAAG,EAAI;AACZpB,MAAAA,OAAO,CAACoB,GAAG,CAACN,IAAL,CAAP;AACA,KAHF,EAIEO,KAJF,CAIQ,UAAAC,GAAG,EAAI;AACbrB,MAAAA,MAAM,CAACqB,GAAG,CAACR,IAAL,CAAN;AACA,KANF;AAOA,GARM,CAAP;AASA;;AAID,gBAAe,YAAM;AACpB,MAAI,OAAOU,MAAM,CAACC,KAAd,IAAuB,WAA3B,EAAwC;AACvCD,IAAAA,MAAM,CAACC,KAAP,GAAe;AACdrC,MAAAA,IAAI,EAAEA,IADQ;AAEd4B,MAAAA,GAAG,EAAEA;AAFS,KAAf;AAIA;AACD,CAPD","sourcesContent":["// 封装axios请求\n/**axios封装\n * 请求拦截、相应拦截、错误统一处理\n */\nimport axios from 'axios';\nimport QS from 'qs';\nimport store from '../store/index'\n\n// 环境的切换\nif (process.env.NODE_ENV == 'development') {\n\taxios.defaults.baseURL = '/api';\n} else if (process.env.NODE_ENV == 'debug') {\n\taxios.defaults.baseURL = '';\n} else if (process.env.NODE_ENV == 'production') {\n\taxios.defaults.baseURL = 'http://api.123dailu.com/';\n}\n\n// 请求超时时间\naxios.defaults.timeout = 10000;\n\n// post请求头\naxios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8';\n\n// 请求拦截器\naxios.interceptors.request.use(\n\tconfig => {\n\t\t// 每次发送请求之前判断是否存在token,如果存在,则统一在http请求的header都加上token,不用每次请求都手动添加了\n\t\t// 即使本地存在token,也有可能token是过期的,所以在响应拦截器中要对返回状态进行判断\n\t\tconst token = store.state.token;\n\t\ttoken && (config.headers.Authorization = token);\n\t\treturn config;\n\t},\n\terror => {\n\t\treturn Promise.error(error);\n\t})\n\n// 响应拦截器\naxios.interceptors.response.use(\n\tresponse => {\n\t\tif (response.status === 200) {\n\t\t\treturn Promise.resolve(response);\n\t\t} else {\n\t\t\treturn Promise.reject(response);\n\t\t}\n\t},\n\t// 服务器状态码不是200的情况\n\terror => {\n\t\tif (error.response.status) {\n\t\t\tswitch (error.response.status) {\n\t\t\t\t// 401: 未登录\n\t\t\t\t// 未登录则跳转登录页面,并携带当前页面的路径\n\t\t\t\t// 在登录成功后返回当前页面,这一步需要在登录页操作。\n\t\t\t\tcase 401:\n\t\t\t\t\trouter.replace({\n\t\t\t\t\t\tpath: '/login',\n\t\t\t\t\t\tquery: { redirect: router.currentRoute.fullPath }\n\t\t\t\t\t});\n\t\t\t\t\tbreak;\n\t\t\t\t// 403 token过期\n\t\t\t\t// 登录过期对用户进行提示\n\t\t\t\t// 清除本地token和清空vuex中token对象\n\t\t\t\t// 跳转登录页面\n\t\t\t\tcase 403:\n\t\t\t\t\tthis.$message.error('登录过期,请重新登录');\n\t\t\t\t\t// 清除token\n\t\t\t\t\tlocalStorage.removeItem('token');\n\t\t\t\t\tstore.commit('loginSuccess', null);\n\t\t\t\t\t// 跳转登录页面,并将要浏览的页面fullPath传过去,登录成功后跳转需要访问的页面\n\t\t\t\t\tsetTimeout(() => {\n\t\t\t\t\t\trouter.replace({\n\t\t\t\t\t\t\tpath: '/login',\n\t\t\t\t\t\t\tquery: {\n\t\t\t\t\t\t\t\tredirect: router.currentRoute.fullPath\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t}, 1000);\n\t\t\t\t\tbreak;\n\t\t\t\t// 404请求不存在\n\t\t\t\tcase 404:\n\t\t\t\t\tthis.$message.error('网络请求不存在');\n\t\t\t\t\tbreak;\n\t\t\t\t// 其他错误,直接抛出错误提示\n\t\t\t\tdefault:\n\t\t\t\t\tthis.$message.error(error.response.data.message);\n\t\t\t}\n\t\t\treturn Promise.reject(error.response);\n\t\t}\n\t}\n)\n\t/**\n\t * get方法,对应get请求\n\t * @param {String} url [请求的url地址]\n\t * @param {Object} params [请求时携带的参数]\n\t */\nfunction get(url, params){\n\treturn new Promise((resolve, reject) =>{\n\t\taxios.get(url, {\n\t\t\tparams: params\n\t\t})\n\t\t\t.then(res => {\n\t\t\t\tresolve(res.data);\n\t\t\t})\n\t\t\t.catch(err => {\n\t\t\t\treject(err.data)\n\t\t\t})\n\t});\n}\n/**\n * post方法,对应post请求\n * @param {String} url [请求的url地址]\n * @param {Object} params [请求时携带的参数]\n */\nfunction post(url, params) {\n\treturn new Promise((resolve, reject) => {\n\t\taxios.post(url, QS.stringify(params))\n\t\t\t.then(res => {\n\t\t\t\tresolve(res.data);\n\t\t\t})\n\t\t\t.catch(err => {\n\t\t\t\treject(err.data)\n\t\t\t})\n\t});\n}\n\n\n\nexport default () => {\n\tif (typeof window.$http == 'undefined') {\n\t\twindow.$http = {\n\t\t\tpost: post,\n\t\t\tget: get\n\t\t}\n\t}\n}\n\n"]}]}
|