增加进度条
This commit is contained in:
@@ -102,23 +102,29 @@ export function getLocalRebillTask(taskId) {
|
||||
})
|
||||
}
|
||||
|
||||
export function cancelLocalRebill(taskId) {
|
||||
return request({
|
||||
url: '/price/billing/orderBill/rebill/task/' + taskId + '/cancel',
|
||||
method: 'post'
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Async local rebill; poll until done.
|
||||
* @param {object} data LocalRebillRequest
|
||||
* Poll local rebill task until terminal status.
|
||||
* @param {string} taskId
|
||||
* @param {(task: object) => void} [onProgress]
|
||||
*/
|
||||
export async function localRebillAsync(data, onProgress) {
|
||||
const submitRes = await submitLocalRebill(data)
|
||||
const d = submitRes && submitRes.data
|
||||
const taskId = d && (d.taskId || d)
|
||||
if (!taskId) throw new Error('missing local rebill taskId')
|
||||
export async function pollLocalRebillTask(taskId, onProgress) {
|
||||
const id = String(taskId || '')
|
||||
if (!id) throw new Error('missing local rebill taskId')
|
||||
const started = Date.now()
|
||||
const maxMs = 30 * 60 * 1000
|
||||
while (Date.now() - started < maxMs) {
|
||||
const res = await getLocalRebillTask(String(taskId))
|
||||
const res = await getLocalRebillTask(id)
|
||||
const task = res.data || {}
|
||||
if (typeof onProgress === 'function') onProgress(task)
|
||||
if (task.status === 'SUCCESS') return { task }
|
||||
if (task.status === 'CANCELLED') return { task, cancelled: true }
|
||||
if (task.status === 'FAIL') {
|
||||
const err = new Error(task.error || task.message || 'local rebill failed')
|
||||
err.task = task
|
||||
@@ -129,6 +135,21 @@ export async function localRebillAsync(data, onProgress) {
|
||||
throw new Error('local rebill timeout')
|
||||
}
|
||||
|
||||
/**
|
||||
* Async local rebill; poll until done.
|
||||
* @param {object} data LocalRebillRequest
|
||||
* @param {(task: object) => void} [onProgress]
|
||||
* @param {{ getTaskId?: (taskId: string) => void }} [options]
|
||||
*/
|
||||
export async function localRebillAsync(data, onProgress, options) {
|
||||
const submitRes = await submitLocalRebill(data)
|
||||
const d = submitRes && submitRes.data
|
||||
const taskId = d && (d.taskId || d)
|
||||
if (!taskId) throw new Error('missing local rebill taskId')
|
||||
if (options && typeof options.getTaskId === 'function') options.getTaskId(String(taskId))
|
||||
return pollLocalRebillTask(String(taskId), onProgress)
|
||||
}
|
||||
|
||||
/** Receivable bill detail */
|
||||
export function getBill(billId) {
|
||||
return request({
|
||||
|
||||
Reference in New Issue
Block a user