1.0.0 • Published 2 years ago

npm-promisepoller v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

组件简介

1.使用方式

安装组件

mnpm install  promisePoller

2.使用示例

import promisePoller from 'promisePoller'
const params = {
    wmPoiId: poiId,
    acctId,
    preOrder,
    orderStatus
}
const taskFn = () => this.$http.get('/sc/order/retail/processing/...', { params })
const shouldContinue = (err, res) => {
    if (err) {
        return false;
    } else {
        if (!res || res.code !== 0) return false
        const { url, percent } = res.data || {}
        this.percent = percent || 0
        if (url) {
           window.open(url, '_blank')
            return false
        }
        return true
    }
}
promisePoller({
    taskFn,
    taskDelay: 300, // 延迟300ms去请求,一次接口请求完成速度太快了
    masterTimeout: 120000, // 线程超时120s
    shouldContinue
}).then(res => {
   //
}, () => {
    this.$Message.error('请重试')
})

3.组件属性

属性说明类型默认值是否必须
taskFn要执行操作function--
taskDelaytaskFn再次触发的延迟时间。防止taskFn操作太频繁Number300ms|否
|shouldContinue | 是否再次进行taskFn |()=>boolean--
masterTimeout主线程超时时间,超时结束轮询Number12000ms|否