Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
npm
/
glsx-common
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 6574ea23
authored
Oct 03, 2021
by
limin
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
新增 防抖节流方法 http默认post
1 parent
80bb979a
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
40 additions
and
5 deletions
dist/glsx-common.js
package.json
src/http.js
src/util.js
dist/glsx-common.js
View file @
6574ea2
...
@@ -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 })\r\n const {\r\n response = {},\r\n request: { baseURL, timeout = 3000, withCredentials = true, responseType = 'json' },\r\n headers,\r\n alert,\r\n sign,\r\n signWay = 'sha1',\r\n secret\r\n } = options\r\n this.customer = {\r\n response,\r\n alert,\r\n sign,\r\n secret,\r\n signWay\r\n }\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 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 {\r\n response = {},\r\n request: { baseURL, timeout = 3000, withCredentials = true, responseType = 'json' },\r\n headers,\r\n alert,\r\n sign,\r\n signWay = 'sha1',\r\n secret\r\n } = options\r\n this.customer = {\r\n response,\r\n alert,\r\n sign,\r\n secret,\r\n signWay\r\n }\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 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?"
);
/***/
}),
/***/
}),
...
@@ -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
// 创建签名\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 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?"
);
/***/
}),
/***/
}),
...
...
package.json
View file @
6574ea2
{
{
"name"
:
"glsx-common"
,
"name"
:
"glsx-common"
,
"version"
:
"1.3.
7
"
,
"version"
:
"1.3.
8
"
,
"description"
:
"glsx common"
,
"description"
:
"glsx common"
,
"main"
:
"./dist/glsx-common.js"
,
"main"
:
"./dist/glsx-common.js"
,
"private"
:
false
,
"private"
:
false
,
...
...
src/http.js
View file @
6574ea2
...
@@ -9,7 +9,8 @@ import axios from 'axios'
...
@@ -9,7 +9,8 @@ import axios from 'axios'
import
qs
from
'qs'
import
qs
from
'qs'
function
Http
(
options
=
{})
{
function
Http
(
options
=
{})
{
this
.
service
=
axios
.
create
({
this
.
service
=
axios
.
create
({
withCredentials
:
true
withCredentials
:
true
,
method
:
'POST'
})
})
const
{
const
{
response
=
{},
response
=
{},
...
...
src/util.js
View file @
6574ea2
...
@@ -150,6 +150,40 @@ export const Util = {
...
@@ -150,6 +150,40 @@ export const Util = {
return
!
obj
||
JSON
.
stringify
(
obj
)
==
'{}'
return
!
obj
||
JSON
.
stringify
(
obj
)
==
'{}'
},
},
debounce
:
function
(
fn
,
timer
)
{
var
t
=
null
return
function
()
{
if
(
t
)
{
clearTimeout
(
t
)
}
if
(
t
==
null
)
{
fn
.
apply
(
this
,
arguments
)
}
t
=
setTimeout
(()
=>
{
t
=
null
},
timer
)
}
},
throttle
:
function
(
fn
,
delay
)
{
var
t
=
null
var
begin
=
0
return
function
()
{
var
cur
=
new
Date
().
getTime
()
if
(
t
)
{
clearTimeout
(
t
)
}
if
(
cur
-
begin
>
delay
)
{
fn
.
apply
(
this
,
arguments
)
begin
=
cur
}
else
{
t
=
setTimeout
(()
=>
{
fn
.
apply
(
this
,
arguments
)
},
delay
)
}
}
},
// 创建签名
// 创建签名
createSign
:
function
(
params
,
secret
,
noSignAttr
=
[],
way
=
'sha1'
)
{
createSign
:
function
(
params
,
secret
,
noSignAttr
=
[],
way
=
'sha1'
)
{
delete
params
.
sign
delete
params
.
sign
...
@@ -158,7 +192,7 @@ export const Util = {
...
@@ -158,7 +192,7 @@ export const Util = {
const
objQs
=
strQs
.
split
(
'&'
)
const
objQs
=
strQs
.
split
(
'&'
)
const
collect
=
objQs
.
reduce
((
collect
,
item
)
=>
{
const
collect
=
objQs
.
reduce
((
collect
,
item
)
=>
{
const
[
key
,
value
]
=
item
.
split
(
'='
)
const
[
key
,
value
]
=
item
.
split
(
'='
)
if
(
!
value
===
null
)
{
if
(
value
===
null
)
{
value
=
''
value
=
''
}
else
if
(
typeof
obj
===
'object'
)
{
}
else
if
(
typeof
obj
===
'object'
)
{
value
=
JSON
.
stringify
(
value
)
value
=
JSON
.
stringify
(
value
)
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment