From 5c343b63fa9f64f16568a0b4d0d3a8538b1ed2b6 Mon Sep 17 00:00:00 2001 From: "97694732@qq.com" Date: Sat, 6 Jun 2026 11:15:20 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E6=97=A0ISBN=E4=B8=8A=E4=BC=A0=E5=90=AF?= =?UTF-8?q?=E7=94=A8=E6=8C=89=E9=92=AE,=E4=B8=8A=E4=BC=A0MinIO=E5=90=8E?= =?UTF-8?q?=E8=B0=83=E7=94=A8syncBook=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/upload/upload.vue | 108 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 104 insertions(+), 4 deletions(-) diff --git a/pages/upload/upload.vue b/pages/upload/upload.vue index 67bb016..89775e7 100644 --- a/pages/upload/upload.vue +++ b/pages/upload/upload.vue @@ -703,7 +703,7 @@ - + 确认上传 @@ -1900,8 +1900,6 @@ export default { // 提交上传 async submitUpload() { if (this.isSubmitting) return - // 无ISBN上传暂不可用 - if (this.currentTab === 'no-isbn') return const warehouseData = this.currentTab === 'isbn' ? this.isbnWarehouseData : this.noIsbnWarehouseData if (!warehouseData) { @@ -1951,7 +1949,11 @@ export default { console.log('【上传】MinIO图片URL列表:', imageUrls) // 图片上传完成后直接推送数据到接口 - await this.doSubmit(warehouseData, imageUrls) + if (this.currentTab === 'isbn') { + await this.doSubmit(warehouseData, imageUrls) + } else { + await this.doNoIsbnSyncBook(imageUrls) + } } catch (e) { uni.hideLoading() this.isSubmitting = false @@ -2123,6 +2125,104 @@ export default { } }, + // 无ISBN - 调用 syncBook 同步图书数据 + async doNoIsbnSyncBook(imageUrls) { + this.isSubmitting = true + uni.showLoading({ title: '上传中...', mask: true }) + try { + const token = uni.getStorageSync('token') || '' + + // 构建参数 + const params = { + fid: '0', + type: '4', + isbn: this.noIsbnIsbn || this.noIsbnUnifyIsbn || '', + f_isbn: '0', + book_name: this.noIsbnBookName || '', + f_book_name: '', + author: this.noIsbnAuthor || '', + publisher: this.noIsbnPublisher || '', + publication_time: this.noIsbnPrintTime || '', + binding_layout: '', + fix_price: this.noIsbnPrice ? String(Math.round(parseFloat(this.noIsbnPrice) * 100)) : '', + page_count: '0', + word_count: this.noIsbnWordCount || '', + book_format: '', + live_image: imageUrls.join(',') + } + + const apiUrl = 'https://psi.api.buzhiyushu.cn/api/syncBook' + console.log('【syncBook】请求地址:', apiUrl) + console.log('【syncBook】请求参数:', params) + + const res = await new Promise(function (resolve, reject) { + uni.request({ + url: apiUrl, + method: 'POST', + header: { + 'Content-Type': 'application/x-www-form-urlencoded', + 'Authorization': 'Bearer ' + token + }, + data: params, + success: function (r) { resolve(r) }, + fail: function (e) { reject(e) } + }) + }) + + console.log('【syncBook】返回值:', res.statusCode, res.data) + + uni.hideLoading() + + if (res.statusCode !== 200) { + throw new Error('API返回: HTTP ' + res.statusCode) + } + + var respData = res.data + if (typeof respData === 'string') { + try { respData = JSON.parse(respData) } catch (e) { respData = { code: 500, msg: respData } } + } + + if (respData && respData.code === 200) { + uni.showToast({ title: respData.msg || '上传成功', icon: 'success' }) + } else { + throw new Error(respData && respData.msg || '上传失败') + } + + // 保存上传记录到本地 + const uploadHistory = uni.getStorageSync('uploadHistory') || [] + uploadHistory.unshift({ + id: Date.now(), + time: new Date().toLocaleString(), + type: this.currentTab, + apiUrl: apiUrl, + apiResponse: res.data, + data: params + }) + uni.setStorageSync('uploadHistory', uploadHistory.slice(0, 100)) + + // 清空表单 + this.noIsbnPhotoList = [] + this.noIsbnBookName = '' + this.noIsbnPrice = '' + this.noIsbnStock = 1 + this.noIsbnAuthor = '' + this.noIsbnPublisher = '' + this.noIsbnOriginalPrice = '' + this.noIsbnIsbn = '' + this.noIsbnUnifyIsbn = '' + this.noIsbnPrintTime = '' + this.noIsbnFormat = '' + this.noIsbnBinding = '' + this.noIsbnProductList = [] + } catch (e) { + uni.hideLoading() + console.error('【syncBook】失败:', e) + uni.showToast({ title: e.message || '上传失败', icon: 'none', duration: 3000 }) + } finally { + this.isSubmitting = false + } + }, + // 无ISBN - 书名搜索(使用与ISBN相同的kongfz接口) searchNoIsbn() { if (!this.isLoggedIn) {