1.0.0 • Published 4 years ago
npm-promisepoller v1.0.0
组件简介
1.使用方式
安装组件
mnpm install  promisePoller2.使用示例
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 | -- | 是 | 
| taskDelay | taskFn再次触发的延迟时间。防止taskFn操作太频繁 | Number | 300ms|否 | |
| |shouldContinue | 是否再次进行taskFn |()=>boolean | -- | 是 | ||
| masterTimeout | 主线程超时时间,超时结束轮询 | Number | 12000ms|否 | 
1.0.0
4 years ago