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