Commit a503ee83 by limin

1.4.2

1 parent 54b5e8b2
...@@ -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 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?"); 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 = 'code', errId = 'errId', code_success_value = '0', data_key = 'data' },\r\n alert\r\n } = this.customer\r\n if (returnAll || !alert) {\r\n return res\r\n }\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 }\r\n break\r\n }\r\n return 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?");
/***/ }), /***/ }),
...@@ -558,7 +558,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac ...@@ -558,7 +558,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac
/***/ ((__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 */ \"Http\": () => (/* reexport safe */ _http__WEBPACK_IMPORTED_MODULE_0__[\"default\"]),\n/* harmony export */ \"utils\": () => (/* binding */ utils),\n/* harmony export */ \"Postmate\": () => (/* reexport safe */ _postmate__WEBPACK_IMPORTED_MODULE_4__[\"default\"])\n/* harmony export */ });\n/* harmony import */ var _http__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./http */ \"./src/http.js\");\n/* harmony import */ var _util_array__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./util.array */ \"./src/util.array.js\");\n/* harmony import */ var _util__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./util */ \"./src/util.js\");\n/* harmony import */ var _storage__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./storage */ \"./src/storage.js\");\n/* harmony import */ var _postmate__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./postmate */ \"./src/postmate.js\");\n/*\r\n * @Descripttion:\r\n * @version: 1.0.0\r\n * @Author: limin\r\n * @Date: 2021-09-06 11:12:07\r\n * @LastEditors: limin\r\n * @LastEditTime: 2021-09-21 14:36:51\r\n * @FilePath: \\npm\\glsx-common\\src\\index.js\r\n */\r\n\r\n\r\n\r\n// import qiankun from \"./qiankun\";\r\n\r\n\r\nconst utils = { ..._util__WEBPACK_IMPORTED_MODULE_2__[\"default\"], array: _util_array__WEBPACK_IMPORTED_MODULE_1__[\"default\"], storage: _storage__WEBPACK_IMPORTED_MODULE_3__[\"default\"] };\r\n\r\n\n\n//# sourceURL=webpack://glsx-common/./src/index.js?"); eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"Http\": () => (/* reexport safe */ _http__WEBPACK_IMPORTED_MODULE_0__[\"default\"]),\n/* harmony export */ \"utils\": () => (/* binding */ utils),\n/* harmony export */ \"Postmate\": () => (/* reexport safe */ _postmate__WEBPACK_IMPORTED_MODULE_4__[\"default\"])\n/* harmony export */ });\n/* harmony import */ var _http__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./http */ \"./src/http.js\");\n/* harmony import */ var _util_array__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./util.array */ \"./src/util.array.js\");\n/* harmony import */ var _util__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./util */ \"./src/util.js\");\n/* harmony import */ var _storage__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./storage */ \"./src/storage.js\");\n/* harmony import */ var _postmate__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./postmate */ \"./src/postmate.js\");\n/*\r\n * @Descripttion:\r\n * @version: 1.0.0\r\n * @Author: limin\r\n * @Date: 2021-09-06 11:12:07\r\n * @LastEditors: limin\r\n * @LastEditTime: 2021-10-11 14:13:52\r\n * @FilePath: \\glsx-common\\src\\index.js\r\n */\r\n\r\n\r\n\r\n\r\n\r\nconst utils = { ..._util__WEBPACK_IMPORTED_MODULE_2__[\"default\"], array: _util_array__WEBPACK_IMPORTED_MODULE_1__[\"default\"], storage: _storage__WEBPACK_IMPORTED_MODULE_3__[\"default\"] }\r\n\r\n\n\n//# sourceURL=webpack://glsx-common/./src/index.js?");
/***/ }), /***/ }),
...@@ -602,7 +602,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac ...@@ -602,7 +602,7 @@ eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpac
/***/ ((__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 */ \"Util\": () => (/* binding */ Util),\n/* harmony export */ \"createSign\": () => (/* binding */ createSign),\n/* harmony export */ \"default\": () => (__WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\n/* harmony import */ var md5__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! md5 */ \"./node_modules/md5/md5.js\");\n/* harmony import */ var md5__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(md5__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var sha1__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! sha1 */ \"./node_modules/sha1/sha1.js\");\n/* harmony import */ var sha1__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(sha1__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\r\n\r\nconst Util = {\r\n /**\r\n * 校验手机号码格式\r\n */\r\n checkPhone: function (mobile) {\r\n let myreg = /^(13[0-9]|15[0-9]|16[0-9]|17[0-9]|18[0-9]|19[0-9]|14[0-9])[0-9]{8}$/\r\n return myreg.test(mobile)\r\n },\r\n\r\n /**\r\n * 校验固定电话\r\n */\r\n validationTel: function (tel) {\r\n let reg = /^0[\\d]{2,3}-[\\d]{7,8}$/\r\n return reg.test(tel)\r\n },\r\n\r\n /**\r\n * 是否特殊字符\r\n */\r\n isSpecialLetter: function (str) {\r\n let reg = new RegExp(\"[`~!@#$^&*=|{}':;',\\\\[\\\\]<>?~!@#¥……&*——|{}【】‘;:”“'。,、? ]\")\r\n return reg.test(str)\r\n },\r\n\r\n /**\r\n * 获取当前时间\r\n */\r\n getCurrentDate: function () {\r\n let time = new Date()\r\n let y = time.getFullYear()\r\n let m = time.getMonth() + 1\r\n let d = time.getDate()\r\n\r\n return {\r\n date: y + '/' + m + '/' + d\r\n }\r\n },\r\n\r\n /**\r\n * 获取浏览器参数\r\n */\r\n getUrlParams: function (name) {\r\n let vars = [],\r\n hash\r\n let oParams = {}\r\n let hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&')\r\n for (let i = 0; i < hashes.length; i++) {\r\n hash = hashes[i].split('=')\r\n vars.push(hash[0])\r\n oParams[hash[0]] = hash[1]\r\n }\r\n console.log(vars)\r\n if (name) {\r\n return oParams[name]\r\n } else {\r\n return oParams\r\n }\r\n },\r\n\r\n /**\r\n * 根据当前时间,计算往后30天的日期\r\n */\r\n getAfterDate: function (day) {\r\n let date1 = new Date()\r\n let date2 = new Date(date1)\r\n let time = 30\r\n if (day) {\r\n time = day\r\n }\r\n date2.setDate(date1.getDate() + time)\r\n\r\n let _date = date2.getFullYear() + '-' + (date2.getMonth() + 1) + '-' + date2.getDate()\r\n\r\n return {\r\n date: _date,\r\n year: date2.getFullYear(),\r\n month: date2.getMonth() + 1,\r\n day: date2.getDate()\r\n }\r\n },\r\n\r\n /**\r\n * 字段截取\r\n */\r\n cutStr: function (str, num) {\r\n if (!str) {\r\n return ''\r\n }\r\n\r\n let m = 10\r\n let n = str\r\n if (num) {\r\n m = num\r\n }\r\n if (str.length > m) {\r\n n = str.slice(0, m) + '...'\r\n }\r\n\r\n return n\r\n },\r\n\r\n /**\r\n * 深克隆 所有原型链上的对象和属性\r\n * 例: const bar=deepClone(foo)\r\n * console.log(bar===foo) false\r\n * @param {*} obj\r\n */\r\n deepClone: function (obj) {\r\n // Handle the 3 simple types, and null or undefined or function\r\n if (obj == null || typeof obj !== 'object') return obj\r\n // Handle Date\r\n if (obj instanceof Date) {\r\n const copy = new Date()\r\n copy.setTime(obj.getTime())\r\n return copy\r\n }\r\n // Handle Array or Object\r\n if ((obj instanceof Array) | (obj instanceof Object)) {\r\n const copy = obj instanceof Array ? [] : {}\r\n for (var attr in obj) {\r\n if (obj.hasOwnProperty(attr)) {\r\n copy[attr] = Util.deepClone(obj[attr])\r\n }\r\n }\r\n return copy\r\n }\r\n throw new Error(\"Unable to clone obj! Its type isn't supported.\")\r\n },\r\n\r\n genUrlParams: function (param, key, encode) {\r\n // if (!param || layui.$.isEmptyObject(param)) return ''\r\n var params = []\r\n var t = typeof param\r\n if (t == 'string' || t == 'number' || t == 'boolean') {\r\n params.push(key + '=' + (encode == null || encode ? encodeURIComponent(param) : param))\r\n } else {\r\n for (var i in param) {\r\n var k = key == null ? i : key + (param instanceof Array ? '[' + i + ']' : '.' + i)\r\n params.push(Util.genUrlParams(param[i], k, encode))\r\n }\r\n }\r\n return params.join('&')\r\n },\r\n\r\n isEmptyObject: function (obj) {\r\n return !obj || JSON.stringify(obj) == '{}'\r\n },\r\n\r\n debounce: function (fn, timer) {\r\n var t = null\r\n return function () {\r\n if (t) {\r\n clearTimeout(t)\r\n }\r\n if (t == null) {\r\n fn.apply(this, arguments)\r\n }\r\n t = setTimeout(() => {\r\n t = null\r\n }, timer)\r\n }\r\n },\r\n\r\n throttle: function (fn, delay) {\r\n var t = null\r\n var begin = 0\r\n return function () {\r\n var cur = new Date().getTime()\r\n if (t) {\r\n clearTimeout(t)\r\n }\r\n if (cur - begin > delay) {\r\n fn.apply(this, arguments)\r\n begin = cur\r\n } else {\r\n t = setTimeout(() => {\r\n fn.apply(this, arguments)\r\n }, delay)\r\n }\r\n }\r\n },\r\n\r\n // 创建签名\r\n createSign: function (params, secret, noSignAttr = [], way = 'sha1') {\r\n delete params.sign\r\n params.timestamp = new Date().getTime()\r\n var strQs = qs__WEBPACK_IMPORTED_MODULE_2___default().stringify(params, { arrayFormat: 'indices', encode: false, allowDots: true })\r\n const objQs = strQs.split('&')\r\n const collect = objQs.reduce((collect, item) => {\r\n const [key, value] = item.split('=')\r\n if (value === null) {\r\n value = ''\r\n } else if (typeof obj === 'object') {\r\n value = JSON.stringify(value)\r\n }\r\n collect[key] = value\r\n return collect\r\n }, {})\r\n const keys = Object.keys(collect).sort()\r\n const str = keys.reduce((col, key) => {\r\n if (!noSignAttr.includes(key)) {\r\n col.push(key, collect[key])\r\n }\r\n return col\r\n }, [])\r\n collect.sign = { sha1: (sha1__WEBPACK_IMPORTED_MODULE_1___default()), md5: (md5__WEBPACK_IMPORTED_MODULE_0___default()) }[way](secret + str.join('') + secret).toUpperCase()\r\n return collect\r\n }\r\n}\r\nconst createSign = Util.createSign\r\n/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (Util);\r\n\n\n//# sourceURL=webpack://glsx-common/./src/util.js?"); eval("__webpack_require__.r(__webpack_exports__);\n/* harmony export */ __webpack_require__.d(__webpack_exports__, {\n/* harmony export */ \"Util\": () => (/* binding */ Util),\n/* harmony export */ \"createSign\": () => (/* binding */ createSign),\n/* harmony export */ \"default\": () => (__WEBPACK_DEFAULT_EXPORT__)\n/* harmony export */ });\n/* harmony import */ var md5__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! md5 */ \"./node_modules/md5/md5.js\");\n/* harmony import */ var md5__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(md5__WEBPACK_IMPORTED_MODULE_0__);\n/* harmony import */ var sha1__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! sha1 */ \"./node_modules/sha1/sha1.js\");\n/* harmony import */ var sha1__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(sha1__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\r\n\r\nconst Util = {\r\n /**\r\n * 校验手机号码格式\r\n */\r\n checkPhone: function (mobile) {\r\n let myreg = /^(13[0-9]|15[0-9]|16[0-9]|17[0-9]|18[0-9]|19[0-9]|14[0-9])[0-9]{8}$/\r\n return myreg.test(mobile)\r\n },\r\n\r\n /**\r\n * 校验固定电话\r\n */\r\n validationTel: function (tel) {\r\n let reg = /^0[\\d]{2,3}-[\\d]{7,8}$/\r\n return reg.test(tel)\r\n },\r\n\r\n /**\r\n * 是否特殊字符\r\n */\r\n isSpecialLetter: function (str) {\r\n let reg = new RegExp(\"[`~!@#$^&*=|{}':;',\\\\[\\\\]<>?~!@#¥……&*——|{}【】‘;:”“'。,、? ]\")\r\n return reg.test(str)\r\n },\r\n\r\n /**\r\n * 获取浏览器参数\r\n */\r\n getUrlParams: function (name) {\r\n let vars = [],\r\n hash\r\n let oParams = {}\r\n let hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&')\r\n for (let i = 0; i < hashes.length; i++) {\r\n hash = hashes[i].split('=')\r\n vars.push(hash[0])\r\n oParams[hash[0]] = hash[1]\r\n }\r\n console.log(vars)\r\n if (name) {\r\n return oParams[name]\r\n } else {\r\n return oParams\r\n }\r\n },\r\n\r\n /**\r\n * 字段截取\r\n */\r\n cutStr: function (str, num) {\r\n if (!str) {\r\n return ''\r\n }\r\n\r\n let m = 10\r\n let n = str\r\n if (num) {\r\n m = num\r\n }\r\n if (str.length > m) {\r\n n = str.slice(0, m) + '...'\r\n }\r\n\r\n return n\r\n },\r\n\r\n /**\r\n * 深克隆 所有原型链上的对象和属性\r\n * 例: const bar=deepClone(foo)\r\n * console.log(bar===foo) false\r\n * @param {*} obj\r\n */\r\n deepClone: function (obj) {\r\n // Handle the 3 simple types, and null or undefined or function\r\n if (obj == null || typeof obj !== 'object') return obj\r\n // Handle Date\r\n if (obj instanceof Date) {\r\n const copy = new Date()\r\n copy.setTime(obj.getTime())\r\n return copy\r\n }\r\n // Handle Array or Object\r\n if ((obj instanceof Array) | (obj instanceof Object)) {\r\n const copy = obj instanceof Array ? [] : {}\r\n for (var attr in obj) {\r\n if (obj.hasOwnProperty(attr)) {\r\n copy[attr] = Util.deepClone(obj[attr])\r\n }\r\n }\r\n return copy\r\n }\r\n throw new Error(\"Unable to clone obj! Its type isn't supported.\")\r\n },\r\n\r\n genUrlParams: function (param, key, encode) {\r\n // if (!param || layui.$.isEmptyObject(param)) return ''\r\n var params = []\r\n var t = typeof param\r\n if (t == 'string' || t == 'number' || t == 'boolean') {\r\n params.push(key + '=' + (encode == null || encode ? encodeURIComponent(param) : param))\r\n } else {\r\n for (var i in param) {\r\n var k = key == null ? i : key + (param instanceof Array ? '[' + i + ']' : '.' + i)\r\n params.push(Util.genUrlParams(param[i], k, encode))\r\n }\r\n }\r\n return params.join('&')\r\n },\r\n\r\n isEmptyObject: function (obj) {\r\n return !obj || JSON.stringify(obj) == '{}'\r\n },\r\n\r\n debounce: function (fn, timer) {\r\n var t = null\r\n return function () {\r\n if (t) {\r\n clearTimeout(t)\r\n }\r\n if (t == null) {\r\n fn.apply(this, arguments)\r\n }\r\n t = setTimeout(() => {\r\n t = null\r\n }, timer)\r\n }\r\n },\r\n\r\n throttle: function (fn, delay) {\r\n var t = null\r\n var begin = 0\r\n return function () {\r\n var cur = new Date().getTime()\r\n if (t) {\r\n clearTimeout(t)\r\n }\r\n if (cur - begin > delay) {\r\n fn.apply(this, arguments)\r\n begin = cur\r\n } else {\r\n t = setTimeout(() => {\r\n fn.apply(this, arguments)\r\n }, delay)\r\n }\r\n }\r\n },\r\n\r\n // 创建签名\r\n createSign: function (params, secret, noSignAttr = [], way = 'sha1') {\r\n delete params.sign\r\n params.timestamp = new Date().getTime()\r\n var strQs = qs__WEBPACK_IMPORTED_MODULE_2___default().stringify(params, { arrayFormat: 'indices', encode: false, allowDots: true })\r\n const objQs = strQs.split('&')\r\n const collect = objQs.reduce((collect, item) => {\r\n const [key, value] = item.split('=')\r\n if (value === null) {\r\n value = ''\r\n } else if (typeof obj === 'object') {\r\n value = JSON.stringify(value)\r\n }\r\n collect[key] = value\r\n return collect\r\n }, {})\r\n const keys = Object.keys(collect).sort()\r\n const str = keys.reduce((col, key) => {\r\n if (!noSignAttr.includes(key)) {\r\n col.push(key, collect[key])\r\n }\r\n return col\r\n }, [])\r\n collect.sign = { sha1: (sha1__WEBPACK_IMPORTED_MODULE_1___default()), md5: (md5__WEBPACK_IMPORTED_MODULE_0___default()) }[way](secret + str.join('') + secret).toUpperCase()\r\n return collect\r\n }\r\n}\r\nconst createSign = Util.createSign\r\n/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (Util);\r\n\n\n//# sourceURL=webpack://glsx-common/./src/util.js?");
/***/ }), /***/ }),
......
{ {
"name": "glsx-common", "name": "glsx-common",
"version": "1.4.0", "version": "1.4.2",
"description": "glsx common", "description": "glsx common",
"main": "./dist/glsx-common.js", "main": "./dist/glsx-common.js",
"private": false, "private": false,
......
...@@ -45,9 +45,12 @@ Http.prototype.create = function () { ...@@ -45,9 +45,12 @@ Http.prototype.create = function () {
this.service.interceptors.response.use( this.service.interceptors.response.use(
({ data: res, config: { returnAll } }) => { ({ data: res, config: { returnAll } }) => {
const { const {
response: { code_key = 'returnCode', errId = 'errId', code_success_value = '0', data_key = 'data' }, response: { code_key = 'code', errId = 'errId', code_success_value = '0', data_key = 'data' },
alert alert
} = this.customer } = this.customer
if (returnAll || !alert) {
return res
}
let code = res[code_key] let code = res[code_key]
// let errId = res[errId] // let errId = res[errId]
// 特殊的code处理,可以增加 // 特殊的code处理,可以增加
...@@ -58,12 +61,10 @@ Http.prototype.create = function () { ...@@ -58,12 +61,10 @@ Http.prototype.create = function () {
default: default:
if (alert) { if (alert) {
alert(res.message || res.msg || '出错了,请联系管理员') alert(res.message || res.msg || '出错了,请联系管理员')
} else {
returnAll = true
} }
break break
} }
return returnAll ? res : res[data_key] return res[data_key]
}, },
error => { error => {
const { alert } = this.customer const { alert } = this.customer
......
...@@ -4,14 +4,13 @@ ...@@ -4,14 +4,13 @@
* @Author: limin * @Author: limin
* @Date: 2021-09-06 11:12:07 * @Date: 2021-09-06 11:12:07
* @LastEditors: limin * @LastEditors: limin
* @LastEditTime: 2021-09-21 14:36:51 * @LastEditTime: 2021-10-11 14:13:52
* @FilePath: \npm\glsx-common\src\index.js * @FilePath: \glsx-common\src\index.js
*/ */
import Http from "./http"; import Http from './http'
import array from "./util.array"; import array from './util.array'
import util from "./util"; import util from './util'
// import qiankun from "./qiankun"; import storage from './storage'
import storage from "./storage"; import Postmate from './postmate'
import Postmate from "./postmate"; const utils = { ...util, array, storage }
const utils = { ...util, array, storage }; export { Http, utils, Postmate }
export { Http, utils, Postmate };
...@@ -27,20 +27,6 @@ export const Util = { ...@@ -27,20 +27,6 @@ export const Util = {
}, },
/** /**
* 获取当前时间
*/
getCurrentDate: function () {
let time = new Date()
let y = time.getFullYear()
let m = time.getMonth() + 1
let d = time.getDate()
return {
date: y + '/' + m + '/' + d
}
},
/**
* 获取浏览器参数 * 获取浏览器参数
*/ */
getUrlParams: function (name) { getUrlParams: function (name) {
...@@ -62,28 +48,6 @@ export const Util = { ...@@ -62,28 +48,6 @@ export const Util = {
}, },
/** /**
* 根据当前时间,计算往后30天的日期
*/
getAfterDate: function (day) {
let date1 = new Date()
let date2 = new Date(date1)
let time = 30
if (day) {
time = day
}
date2.setDate(date1.getDate() + time)
let _date = date2.getFullYear() + '-' + (date2.getMonth() + 1) + '-' + date2.getDate()
return {
date: _date,
year: date2.getFullYear(),
month: date2.getMonth() + 1,
day: date2.getDate()
}
},
/**
* 字段截取 * 字段截取
*/ */
cutStr: function (str, num) { cutStr: function (str, num) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!