{"_rev":"38-643d967f07353f3dc8b0f6113f27fb1e","time":{"created":"2023-05-17T08:43:00.837Z","0.0.1":"2020-05-19T08:29:31.637Z","modified":"2023-05-17T08:43:01.367Z","0.0.1-alpha.1":"2020-05-19T08:55:34.238Z","0.0.1-alpha.2":"2020-05-19T08:56:44.214Z","0.0.1-alpha.3":"2020-05-20T05:56:21.329Z","0.2.0":"2020-05-20T06:25:36.734Z","0.2.0-alpha.1":"2020-05-20T07:43:40.740Z","0.2.0-alpha.2":"2020-05-20T07:54:16.975Z","0.2.0-alpha.3":"2020-05-20T08:04:08.088Z","0.2.0-alpha.4":"2020-05-20T08:13:24.063Z","0.2.0-alpha.5":"2020-05-20T08:17:42.714Z","0.2.0-alpha.6":"2020-05-20T08:23:08.884Z","0.2.0-alpha.7":"2020-05-20T08:35:46.300Z","0.2.0-alpha.8":"2020-05-20T08:44:17.052Z","0.2.0-alpha.9":"2020-05-20T08:54:09.487Z","0.2.0-alpha.10":"2020-05-20T08:57:17.991Z","0.2.0-alpha.11":"2020-05-20T09:00:19.228Z","0.2.0-alpha.12":"2020-05-20T09:09:15.668Z","0.2.0-alpha.13":"2020-05-20T09:21:53.203Z","0.2.0-alpha.14":"2020-05-20T09:48:03.669Z","0.2.0-alpha.15":"2020-05-20T10:02:04.021Z","0.2.1":"2020-05-20T10:05:35.940Z","0.3.1":"2020-08-06T07:44:53.912Z","0.3.2":"2020-08-06T09:05:29.425Z","0.3.3":"2020-08-17T08:16:24.608Z","0.3.4":"2020-09-18T06:31:41.888Z","0.3.5":"2020-10-21T06:55:26.116Z","0.3.6":"2020-10-21T07:44:44.468Z","0.3.7":"2020-12-28T15:53:10.594Z","0.3.8":"2021-01-13T09:02:14.611Z","0.3.9":"2021-01-13T09:21:27.033Z","0.3.10":"2021-01-13T09:24:05.483Z","0.3.11":"2021-01-14T03:03:10.885Z","0.3.12":"2021-01-14T03:25:21.521Z","0.3.13":"2021-01-14T05:58:25.134Z","0.3.14":"2021-01-14T06:01:07.590Z","0.3.16":"2023-05-17T08:43:01.178Z"},"_id":"luban-http","name":"luban-http","dist-tags":{"latest":"0.3.16"},"versions":{"0.3.16":{"name":"luban-http","version":"0.3.16","description":"基于axios二次封装的http模块","main":"./build/index.js","bin":{"swagger":"bin/swagger.js"},"scripts":{"build":"webpack --config webpack.config.js"},"keywords":["axios","luban"],"author":{"name":"anth7"},"license":"MIT","dependencies":{"axios":"^0.19.2","commander":"^5.1.0","core-js":"^3.6.5","fs-extra":"^9.0.0"},"devDependencies":{"@babel/core":"^7.9.6","@babel/preset-env":"^7.9.6","babel-loader":"^8.1.0","webpack":"^4.43.0","webpack-cli":"^3.3.12"},"gitHead":"d5b45e374efbb3688e24b4d10ba67d77eb38f3e5","_id":"luban-http@0.3.16","_nodeVersion":"16.19.0","_npmVersion":"8.19.3","dist":{"integrity":"sha512-Tt+3TX8cqf/VCSdpjspMPumRe/u1q2hzjzymutRDKYCo5NlpXzKlmHWIZPtSRvYSO9BpWFqPGWy+OSvtcAB+Cw==","shasum":"ec3bedcf704c9109100744e8f535d42c1b848d11","tarball":"https://registry.npmjs.org/luban-http/-/luban-http-0.3.16.tgz","fileCount":33,"unpackedSize":442999,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIDDBjLBLfn6J9WE8y17oiMOHqKeIZIH6t52vH0LuGWcoAiAC1Rk/eJu8JA5UbCIKDN6HV5Fl4LdmDSp+5AZU2YkL4A=="}]},"_npmUser":{"name":"anth7","email":"anthony7yan@gmail.com"},"directories":{},"maintainers":[{"name":"anth7","email":"anthony7yan@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/luban-http_0.3.16_1684312980921_0.309727322434449"},"_hasShrinkwrap":false}},"maintainers":[{"name":"anth7","email":"anthony7yan@gmail.com"}],"description":"基于axios二次封装的http模块","keywords":["axios","luban"],"author":{"name":"anth7"},"license":"MIT","readme":"# luban-http\n\n基于axios二次封装的http模块。\n\n1. 二次封装了`get`,`post`,`delete`,`put`请求方法。\n2. 封装了请求打断的方法，用于取消正在发送中的请求。\n3. 提供了根据swagger上的接口文档自动生成api文件的功能。\n4. 提供了`发送请求成功失败`和`请求响应成功失败`的回调函数以及`统一错误处理`的回调函数，你可以在这些回调函数里与`antd`,`element-ui`,`iview`等UI库的`Message`组件联合使用也可以与`nprogress`进度条组件联合使用。\n\n## 使用\n\n#### 安装\n```\nnpm install -S luban-http\n```\n#### 常规使用\n在你的api文件中使用`luban-http`\n```\nimport http from 'luban-http'\n\n// 参数 （url, params/query, config = {} , closeCommonErrorHandling = false）\n// url: 请求地址\n// params/query: 请求参数\n// config: 请求配置 参考axios文档\n// closeCommonErrorHandling：关闭请求错误统一处理\nhttp.$GET('./api/xxxxxx', { id: 123 })\nhttp.$POST('./api/xxxxxx', { page: 1 }, { responseType: 'json' })\nhttp.$DELETE('./api/xxxxxx', {}, {}, false).then(res => {\n  if (!res.status) {\n    Message.error(xxxxx)\n  }\n})\nhttp.$PUT('./api/xxxxxx', params)\n```\n取消所有处于`pending`状态的请求，以`vue-router`为例\n```\nimport Vue from 'vue'\nimport Router from 'vue-router'\nimport http from 'luban-http'\n\nVue.use(Router)\n\nconst router = new Router({\n  routes: []\n})\nrouter.beforeEach((to, from, next) => {\n  // 调用clearHttpRequestList方法在切换路由的时候取消掉所有pending状态的请求\n  http.clearHttpRequestList()\n  next()\n})\n\nexport default router\n\n```\n与组件联合使用\n```\n// vue main.js\n\nimport Vue from 'vue'\nimport NProgress from 'nprogress'\nimport { Message } from 'element-ui'\nimport http from 'luban-http'\n\nimport 'nprogress/nprogress.css'\n\n//与elment-ui Message组件和nprogress进度条组件使用，以及设置超时时长和请求的baseURL\n\nhttp.setOptions({\n  timeout: 30000, // 设置超时时长\n  baseURL: '', // 设置baseURL\n  statusName: 'status', // status字段名字\n  isAllErrorResponseByReject: false, // 是否所有的错误都从reject回调函数接收\n  requestInterceptor: (config) => { NProgress.start() }, //发送请求成功的回调\n  requestInterceptorError: (error) => { console.log(error); NProgress.done() }, // 发送请求失败的回调\n  responseInterceptor: (response) => { NProgress.done() }, // 请求响应成功的回调\n  responseInterceptorError: (error) => { console.log(error); NProgress.done() }, // 请求响应失败的回调\n  commonErrorHandling: (message, res) => { Message.error(message || '未知异常') } // 统一错误处理的回调\n})\n\n\n```\n#### 与Swagger使用\n\n在`package.json`文件 `scripts`属性中添加命令，如下所示：\n```\n\"scripts\": {\n   \"swagger\": \"swagger -u http://localhost:8191/v2/api-docs -d /\"\n  }\n```\n  参数解释所示:<br>\n    -u --swagger-doc-url [value]  swagger-doc访问地址<br>\n    -d --target-dir [value]       生成的api文件存放的文件夹地址（相对于项目的/目录）<br>\n    -n --api-dir-name [value]     保存api文件的目录名称<br>\n    -a --is-absolute              是否启用绝对路径: true(绝对路径)， false(相对路径） 默认是false<br>\n    -b --base-url [value]         生成的api的路由前缀\n\n`swagger-doc-url`可以通过swagger页面得到，配置好`swagger-doc-url`地址和文件输出位置后，执行`npm run swagger`命令。脚本将会把swagger-doc上所有的接口在指定目录下自动生成接口文件，生成的代码如下所示：\n```\n// xxxx.js\n'use strict'\n// 后台管理员管理\nimport http from 'luban-http'\n\n'use strict'\n// 学院部门\nimport http from 'luban-http'\n\n// 各学院学生数和师生比\nexport const ApiCollegeFindStudentAndTeacherScale = (query = {}, params = null) => http.$GET('api/college/findStudentAndTeacherScale', query, params, {}, false)\n// 各学院教师年龄分布\nexport const ApiCollegeFindTeacherAgeRange = (query = {}, params = null) => http.$GET('api/college/findTeacherAgeRange', query, params, {}, false)\n// 各级师资占比\nexport const ApiCollegeFindTeacherRatio = (params = null, query = null) => http.$POST('api/college/findTeacherRatio', params, query, {}, false)\n// 部门教职工数前5名\nexport const ApiCollegeFindDepartmentTeacherTop5 = (query = {}, params = null) => http.$GET('api/college/findDepartmentTeacherTop5', query, params, {}, false)\n// 各学院项目数和论文数的排名\nexport const ApiCollegeFindCollegeProjectAndPaperNum = (query = {}, params = null) => http.$GET('api/college/findCollegeProjectAndPaperNum', query, params, {}, false)\n\n\n\n```","readmeFilename":"README.md"}