Commit 6574ea23 by limin

新增 防抖节流方法 http默认post

1 parent 80bb979a
{ {
"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,
......
...@@ -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 = {},
......
...@@ -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)
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!