This commit is contained in:
2025-11-06 16:34:26 +08:00
parent 41ed4f3f34
commit d4d4cc614b

View File

@@ -657,41 +657,37 @@ export default {
/** 同步物流到腾讯文档 */
async handleSyncLogistics(row) {
// 检查是否有物流链接
if (!row.logisticsLink || !row.logisticsLink.trim()) {
this.$message.warning('该订单暂无物流链接,无法同步')
try {
// 先检查配置是否完整
const configRes = await this.$http.get('/jarvis/tencentDoc/config')
if (configRes.code !== 200 || !configRes.data || !configRes.data.isConfigured) {
this.$confirm('检测到尚未完成H-TF自动写入配置是否现在配置', '提示', {
type: 'warning'
}).then(() => {
this.showAutoWriteConfig = true
})
return
}
this.currentOrder = row
// 确认同步
await this.$confirm(
`将从配置的腾讯文档中搜索并填充物流链接,是否继续?\n\n` +
`文档: ${configRes.data.fileId}\n` +
`工作表: ${configRes.data.sheetId}\n` +
`数据起始行: ${configRes.data.startRow}`,
'同步物流确认',
{ type: 'info' }
)
// 先检查token状态如果没有token则自动打开授权页面
try {
const tokenStatusRes = await getTokenStatus()
if (!tokenStatusRes.data || !tokenStatusRes.data.hasToken) {
// 没有token自动打开授权页面
await this.openAuthAndWait()
}
this.syncLogisticsLoading = true
// 直接同步,不需要打开对话框
await this.handleSyncLogisticsSubmit()
} catch (e) {
// 检查失败,也尝试打开授权
await this.openAuthAndWait()
}
// 打开配置对话框
this.syncLogisticsDialogVisible = true
// 从localStorage获取之前保存的配置
const savedConfig = localStorage.getItem('tendoc_sync_config')
if (savedConfig) {
try {
const config = JSON.parse(savedConfig)
this.syncLogisticsForm = {
...this.syncLogisticsForm,
...config
}
} catch (e) {
console.error('解析保存的配置失败', e)
if (e !== 'cancel') {
this.$message.error('操作失败:' + (e.message || '未知错误'))
}
} finally {
this.syncLogisticsLoading = false
}
},
@@ -794,59 +790,22 @@ export default {
/** 同步物流链接 */
async handleSyncLogisticsSubmit() {
if (!this.syncLogisticsForm.fileId || !this.syncLogisticsForm.sheetId) {
this.$message.warning('请填写文件ID和工作表ID')
return
}
// 保存配置到localStorage不包含accessToken
const configToSave = {
fileId: this.syncLogisticsForm.fileId,
sheetId: this.syncLogisticsForm.sheetId,
headerRow: this.syncLogisticsForm.headerRow,
orderNoColumn: this.syncLogisticsForm.orderNoColumn,
logisticsLinkColumn: this.syncLogisticsForm.logisticsLinkColumn
}
localStorage.setItem('tendoc_sync_config', JSON.stringify(configToSave))
this.syncLogisticsLoading = true
try {
const params = {
// 不再传递accessToken后端自动刷新token
fileId: this.syncLogisticsForm.fileId,
sheetId: this.syncLogisticsForm.sheetId,
headerRow: this.syncLogisticsForm.headerRow || 1
}
// 如果指定了列位置,则传递
if (this.syncLogisticsForm.orderNoColumn != null) {
params.orderNoColumn = this.syncLogisticsForm.orderNoColumn
}
if (this.syncLogisticsForm.logisticsLinkColumn != null) {
params.logisticsLinkColumn = this.syncLogisticsForm.logisticsLinkColumn
}
const res = await fillLogisticsByOrderNo(params)
// 后端会自动从配置中读取 fileId、sheetId、startRow 等参数
// 前端只需传递空对象即可
const res = await fillLogisticsByOrderNo({})
if (res.code === 200) {
const data = res.data || {}
this.$message.success(
`同步成功!成功填充 ${data.filledCount || 0} 条,跳过 ${data.skippedCount || 0} 条,错误 ${data.errorCount || 0}`
)
this.syncLogisticsDialogVisible = false
} else {
// 如果是因为token问题提示用户授权
if (res.msg && res.msg.includes('授权')) {
this.$message.error(res.msg + '。请访问: GET /jarvis/tendoc/authUrl 获取授权URL')
} else {
this.$message.error(res.msg || '同步失败')
}
}
} catch (e) {
this.$message.error('同步失败,请稍后重试: ' + (e.message || '未知错误'))
this.$message.error('同步失败' + (e.message || '未知错误'))
console.error('同步物流失败', e)
} finally {
this.syncLogisticsLoading = false
}
},