/**
* 函数节流 方法封装
* @param fn
* @param interval
* @returns {Function}
* @constructor
*/
Throttle (fn, t) {
let last
let timer
let interval = t || 500
return function () {
let args = arguments
let now = +new Date()
if (last && now - last < interval) {
clearTimeout(timer)
timer = setTimeout(() => {
last = now
fn.apply(this, args)
}, interval)
} else {
last = now
fn.apply(this, args)
}
}
}
// 方法使用:
EG: (外加二次弹框确认)
fluteBeputin: util.Throttle(function () {
let arr = []
arr.push(arg0.productId)
this.$confirm('操作将选中的产品加入产品库,请确认是否执行?', '确认信息', {
distinguishCancelAndClose: true,
confirmButtonText: '确认',
cancelButtonText: '取消'
})
.then(() => {
let params = {
productIdList:arr,
}
util.request({
method: 'post',
interface: 'aaaaa',
data: params
}).then(res => {
if (res.result.success == '1') {
this.$message.success(res.result.message)
} else {
this.$message.error(res.result.message)
}
})
})
.catch(action => {
this.$message({
type: 'info',
message: action === 'cancel'
? '您已取消入库'
: '停留在当前页面'
})
});
// },
}, 3000),
网友评论