Commit 54b5e8b2 by limin

1.4.0

1 parent 53c98f6d
...@@ -547,7 +547,7 @@ eval("\n\nvar GetIntrinsic = __webpack_require__(/*! get-intrinsic */ \"./node_m ...@@ -547,7 +547,7 @@ eval("\n\nvar GetIntrinsic = __webpack_require__(/*! get-intrinsic */ \"./node_m
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
"use strict"; "use strict";
eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (__WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\n/* harmony import */ var _util__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./util */ \"./src/util.js\");\n/* harmony import */ var axios__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! axios */ \"./node_modules/axios/index.js\");\n/* harmony import */ var axios__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(axios__WEBPACK_IMPORTED_MODULE_1__);\n/* harmony import */ var qs__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! qs */ \"./node_modules/qs/lib/index.js\");\n/* harmony import */ var qs__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(qs__WEBPACK_IMPORTED_MODULE_2__);\n/*\r\n * @Author: limin\r\n * @Date: 2018-06-25 10:28:18\r\n * @Last Modified by: huyue\r\n * @Last Modified time: 2021-07-16 18:02:05\r\n */\r\n\r\n\r\n\r\nfunction Http(options = {}) {\r\n this.service = axios__WEBPACK_IMPORTED_MODULE_1___default().create({\r\n withCredentials: true,\r\n method: 'POST'\r\n })\r\n const { response = {}, request = {}, headers, alert, sign, signWay = 'sha1', secret } = options\r\n this.customer = {\r\n response,\r\n alert,\r\n sign,\r\n secret,\r\n signWay\r\n }\r\n const { baseURL, timeout = 3000, withCredentials = true, responseType = 'json' } = request\r\n Object.assign(this.service.defaults, { headers: Object.assign({}, headers, { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' }) }, { baseURL, timeout, withCredentials, responseType })\r\n return this.create()\r\n}\r\nHttp.prototype.create = function () {\r\n this.service.interceptors.request.use(\r\n config => {\r\n let { data = {}, sign = true, noSignAttr = [] } = config\r\n if (sign) {\r\n let _configSign = this.customer.sign || {}\r\n data = (0,_util__WEBPACK_IMPORTED_MODULE_0__.createSign)(Object.assign({}, _configSign, data), this.customer.secret, noSignAttr, this.customer.signWay)\r\n }\r\n const method = config.method.toLocaleLowerCase()\r\n if (method == 'get') {\r\n config.params = data\r\n } else if (method == 'post') {\r\n config.data = qs__WEBPACK_IMPORTED_MODULE_2___default().stringify(data)\r\n }\r\n return config\r\n },\r\n error => Promise.reject(error)\r\n )\r\n this.service.interceptors.response.use(\r\n ({ data: res, config: { returnAll } }) => {\r\n const {\r\n response: { code_key = 'returnCode', errId = 'errId', code_success_value = '0', data_key = 'data' },\r\n alert\r\n } = this.customer\r\n let code = res[code_key]\r\n // let errId = res[errId]\r\n // 特殊的code处理,可以增加\r\n switch (code + '') {\r\n case code_success_value + '':\r\n // 请求成功,不弹提示框,成功code可以更改\r\n break\r\n default:\r\n alert && alert(res.message || res.msg || '出错了,请联系管理员')\r\n break\r\n }\r\n return returnAll ? res : res[data_key]\r\n },\r\n error => {\r\n const { alert } = this.customer\r\n alert && alert(error.message || '出错了,请联系管理员')\r\n // 返回接口返回的错误信息\r\n return Promise.reject(error)\r\n }\r\n )\r\n this.service.axios = (axios__WEBPACK_IMPORTED_MODULE_1___default())\r\n return this.service\r\n}\r\n/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (Http);\r\n\n\n//# sourceURL=webpack://glsx-common/./src/http.js?"); eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"default\": () => (__WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\n/* harmony import */ var _util__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./util */ \"./src/util.js\");\n/* harmony import */ var axios__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! axios */ \"./node_modules/axios/index.js\");\n/* harmony import */ var axios__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(axios__WEBPACK_IMPORTED_MODULE_1__);\n/* harmony import */ var qs__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! qs */ \"./node_modules/qs/lib/index.js\");\n/* harmony import */ var qs__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(qs__WEBPACK_IMPORTED_MODULE_2__);\n/*\r\n * @Author: limin\r\n * @Date: 2018-06-25 10:28:18\r\n * @Last Modified by: huyue\r\n * @Last Modified time: 2021-07-16 18:02:05\r\n */\r\n\r\n\r\n\r\nfunction Http(options = {}) {\r\n this.service = axios__WEBPACK_IMPORTED_MODULE_1___default().create({\r\n withCredentials: true,\r\n method: 'POST'\r\n })\r\n const { response = {}, request = {}, headers, alert, sign, signWay = 'sha1', secret } = options\r\n this.customer = {\r\n response,\r\n alert,\r\n sign,\r\n secret,\r\n signWay\r\n }\r\n const { baseURL, timeout = 3000, withCredentials = true, responseType = 'json' } = request\r\n Object.assign(this.service.defaults, { headers: Object.assign({}, headers, { 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8' }) }, { baseURL, timeout, withCredentials, responseType })\r\n return this.create()\r\n}\r\nHttp.prototype.create = function () {\r\n this.service.interceptors.request.use(\r\n config => {\r\n let { data = {}, sign = true, noSignAttr = [] } = config\r\n if (sign) {\r\n let _configSign = this.customer.sign || {}\r\n data = (0,_util__WEBPACK_IMPORTED_MODULE_0__.createSign)(Object.assign({}, _configSign, data), this.customer.secret, noSignAttr, this.customer.signWay)\r\n }\r\n const method = config.method.toLocaleLowerCase()\r\n if (method == 'get') {\r\n config.params = data\r\n } else if (method == 'post') {\r\n config.data = qs__WEBPACK_IMPORTED_MODULE_2___default().stringify(data)\r\n }\r\n return config\r\n },\r\n error => Promise.reject(error)\r\n )\r\n this.service.interceptors.response.use(\r\n ({ data: res, config: { returnAll } }) => {\r\n const {\r\n response: { code_key = 'returnCode', errId = 'errId', code_success_value = '0', data_key = 'data' },\r\n alert\r\n } = this.customer\r\n let code = res[code_key]\r\n // let errId = res[errId]\r\n // 特殊的code处理,可以增加\r\n switch (code + '') {\r\n case code_success_value + '':\r\n // 请求成功,不弹提示框,成功code可以更改\r\n break\r\n default:\r\n if (alert) {\r\n alert(res.message || res.msg || '出错了,请联系管理员')\r\n } else {\r\n returnAll = true\r\n }\r\n break\r\n }\r\n return returnAll ? res : res[data_key]\r\n },\r\n error => {\r\n const { alert } = this.customer\r\n alert && alert(error.message || '出错了,请联系管理员')\r\n // 返回接口返回的错误信息\r\n return Promise.reject(error)\r\n }\r\n )\r\n this.service.axios = (axios__WEBPACK_IMPORTED_MODULE_1___default())\r\n return this.service\r\n}\r\n/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (Http);\r\n\n\n//# sourceURL=webpack://glsx-common/./src/http.js?");
/***/ }), /***/ }),
......
{ {
"name": "glsx-common", "name": "glsx-common",
"version": "1.3.9", "version": "1.4.0",
"description": "glsx common", "description": "glsx common",
"main": "./dist/glsx-common.js", "main": "./dist/glsx-common.js",
"private": false, "private": false,
......
...@@ -56,7 +56,11 @@ Http.prototype.create = function () { ...@@ -56,7 +56,11 @@ Http.prototype.create = function () {
// 请求成功,不弹提示框,成功code可以更改 // 请求成功,不弹提示框,成功code可以更改
break break
default: default:
alert && alert(res.message || res.msg || '出错了,请联系管理员') if (alert) {
alert(res.message || res.msg || '出错了,请联系管理员')
} else {
returnAll = true
}
break break
} }
return returnAll ? res : res[data_key] return returnAll ? res : res[data_key]
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!