48 lines
1.2 KiB
JavaScript
48 lines
1.2 KiB
JavaScript
const { request } = require('../../utils/request')
|
|
|
|
Page({
|
|
data: {
|
|
id: '',
|
|
timer: null
|
|
},
|
|
|
|
onLoad(query) {
|
|
this.setData({ id: query.id })
|
|
this.poll()
|
|
const timer = setInterval(() => this.poll(), 2500)
|
|
this.setData({ timer })
|
|
},
|
|
|
|
onUnload() {
|
|
if (this.data.timer) {
|
|
clearInterval(this.data.timer)
|
|
}
|
|
},
|
|
|
|
async poll() {
|
|
if (!this.data.id) return
|
|
try {
|
|
const report = await request({ url: `/reports/${this.data.id}` })
|
|
if (report.status === 'completed') {
|
|
clearInterval(this.data.timer)
|
|
wx.redirectTo({ url: `/pages/report/report?id=${this.data.id}` })
|
|
}
|
|
if (report.status === 'failed') {
|
|
clearInterval(this.data.timer)
|
|
wx.showModal({
|
|
title: '生成失败',
|
|
content: report.error_message || '照片暂时无法分析,请换一张更清晰的照片。',
|
|
showCancel: false,
|
|
success: () => wx.switchTab({ url: '/pages/index/index' })
|
|
})
|
|
}
|
|
} catch (error) {
|
|
wx.showToast({ title: error.message || '查询失败', icon: 'none' })
|
|
}
|
|
},
|
|
|
|
backHome() {
|
|
wx.switchTab({ url: '/pages/index/index' })
|
|
}
|
|
})
|