fix(#73): speed up SYB purchase preview
This commit is contained in:
+21
-15
@@ -78,20 +78,24 @@ service.interceptors.response.use(
|
||||
})
|
||||
return false
|
||||
} else if (code === 400 || code === 403) {
|
||||
ElMessage({
|
||||
message: response.data.msg,
|
||||
type: 'error',
|
||||
duration: 5 * 1000
|
||||
})
|
||||
if (!response.config?.suppressErrorMessage) {
|
||||
ElMessage({
|
||||
message: response.data.msg,
|
||||
type: 'error',
|
||||
duration: 5 * 1000
|
||||
})
|
||||
}
|
||||
return Promise.reject(new Error(response.data.msg))
|
||||
} else if (code !== 200) {
|
||||
// Notification.error({
|
||||
// title: response.data.msg
|
||||
// })
|
||||
ElMessage({
|
||||
message: response.data.msg,
|
||||
type: 'error'
|
||||
})
|
||||
if (!response.config?.suppressErrorMessage) {
|
||||
ElMessage({
|
||||
message: response.data.msg,
|
||||
type: 'error'
|
||||
})
|
||||
}
|
||||
return Promise.reject('error')
|
||||
} else {
|
||||
return response.data
|
||||
@@ -99,7 +103,7 @@ service.interceptors.response.use(
|
||||
},
|
||||
error => {
|
||||
if (error.message === 'Network Error') {
|
||||
if (!error.config?.suppressNetworkError) {
|
||||
if (!error.config?.suppressNetworkError && !error.config?.suppressErrorMessage) {
|
||||
ElMessage({
|
||||
message: '服务器连接异常,请检查服务器!',
|
||||
type: 'error',
|
||||
@@ -112,11 +116,13 @@ service.interceptors.response.use(
|
||||
|
||||
const message = error.response?.data?.message || error.response?.data?.msg || error.message
|
||||
|
||||
ElMessage({
|
||||
message,
|
||||
type: 'error',
|
||||
duration: 5 * 1000
|
||||
})
|
||||
if (!error.config?.suppressErrorMessage) {
|
||||
ElMessage({
|
||||
message,
|
||||
type: 'error',
|
||||
duration: 5 * 1000
|
||||
})
|
||||
}
|
||||
|
||||
return Promise.reject(error)
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ export default {
|
||||
data() {
|
||||
return {
|
||||
loading: false, products: [], selectedProducts: [], total: 0,
|
||||
purchaseReadiness: {}, purchaseReadinessLoading: false,
|
||||
purchaseReadiness: {}, purchaseReadinessLoading: false, loadGeneration: 0,
|
||||
purchaseDevices: [],
|
||||
purchaseDialog: { open: false, loading: false, saving: false, ids: [], deviceId: null, items: [], eligibleCount: 0, skippedCount: 0 },
|
||||
purchaseResult: { open: false, items: [], createdCount: 0, failedCount: 0 },
|
||||
@@ -185,23 +185,28 @@ export default {
|
||||
beforeUnmount() { this.stopSyncPolling() },
|
||||
methods: {
|
||||
async load(allowNetworkRetry = true) {
|
||||
const generation = ++this.loadGeneration
|
||||
this.loading = true
|
||||
this.selectedProducts = []
|
||||
this.$refs.productTable?.clearSelection()
|
||||
const requestOptions = allowNetworkRetry ? { suppressNetworkError: true } : {}
|
||||
try {
|
||||
const r = await listSybProducts(this.query, requestOptions)
|
||||
if (generation !== this.loadGeneration) return
|
||||
this.products = r.data.items
|
||||
this.total = r.data.total
|
||||
await this.loadPurchaseReadiness(requestOptions)
|
||||
this.loading = false
|
||||
void this.loadPurchaseReadiness(this.products.map(item => item.id), requestOptions, generation)
|
||||
} catch (error) {
|
||||
if (generation !== this.loadGeneration) return
|
||||
if (allowNetworkRetry && error?.message === 'Network Error' && !error?.response) {
|
||||
await new Promise(resolve => setTimeout(resolve, 1000))
|
||||
if (generation !== this.loadGeneration) return
|
||||
return this.load(false)
|
||||
}
|
||||
throw error
|
||||
} finally {
|
||||
this.loading = false
|
||||
if (generation === this.loadGeneration) this.loading = false
|
||||
}
|
||||
},
|
||||
search() { this.query.page = 1; this.load() },
|
||||
@@ -211,14 +216,21 @@ export default {
|
||||
purchaseReady(row) { return this.purchaseReadiness[row.id] || { sybProductId: row.id, eligible: false, reason: this.purchaseReadinessLoading ? '正在检查' : '请刷新后重试' } },
|
||||
purchasePriceText(item) { if (item.minUnitPriceCent === undefined || item.maxUnitPriceCent === undefined) return ''; return `允许单价 ¥${(item.minUnitPriceCent / 100).toFixed(2)}~¥${(item.maxUnitPriceCent / 100).toFixed(2)}` },
|
||||
purchaseActionLabel(item) { return { open_mapping: '去匹配', open_shopee: '查看蝦皮商品', open_pdd: '查看 PDD 商品', open_task: '查看任务', reparse: '查看并处理', select_device: '重新选择设备', refresh: '刷新' }[item.nextAction] || '' },
|
||||
async loadPurchaseReadiness(requestOptions = {}) {
|
||||
async loadPurchaseReadiness(ids, requestOptions = {}, generation = this.loadGeneration) {
|
||||
if (generation !== this.loadGeneration) return
|
||||
this.purchaseReadiness = {}
|
||||
if (!this.canPurchase || !this.products.length) return
|
||||
if (!this.canPurchase || !ids.length) { this.purchaseReadinessLoading = false; return }
|
||||
this.purchaseReadinessLoading = true
|
||||
try {
|
||||
const r = await previewPurchaseTasks({ sybProductIds: this.products.map(item => item.id) }, requestOptions)
|
||||
const r = await previewPurchaseTasks({ sybProductIds: ids }, { ...requestOptions, suppressErrorMessage: true })
|
||||
if (generation !== this.loadGeneration) return
|
||||
this.purchaseReadiness = Object.fromEntries(r.data.items.map(item => [item.sybProductId, item]))
|
||||
} finally { this.purchaseReadinessLoading = false }
|
||||
} catch {
|
||||
if (generation !== this.loadGeneration) return
|
||||
this.purchaseReadiness = Object.fromEntries(ids.map(id => [id, { sybProductId: id, eligible: false, reason: '采购准备检查失败,请点击刷新重试', nextAction: 'refresh' }]))
|
||||
} finally {
|
||||
if (generation === this.loadGeneration) this.purchaseReadinessLoading = false
|
||||
}
|
||||
},
|
||||
priceText(row) { if (row.unitPriceCent === null || row.unitPriceCent === undefined) return '—'; return `¥${(row.unitPriceCent / 100).toFixed(2)}` },
|
||||
parseMeta(status) { return { success: { label: '成功', type: 'success' }, uncertain: { label: '存疑', type: 'warning' }, failed: { label: '失败', type: 'danger' }}[status] || { label: status || '-', type: 'info' } },
|
||||
|
||||
Reference in New Issue
Block a user