This commit is contained in:
2025-11-05 15:42:51 +08:00
parent 855d22f448
commit 283cfbbfc8
4 changed files with 382 additions and 25 deletions

View File

@@ -1,3 +1,9 @@
# WebSocket连接升级映射必须在server块之前定义
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
# 80端口仅处理HTTP请求自动重定向到HTTPS
server {
@@ -46,21 +52,33 @@ server {
# 注意:这里的路径需要与前端 VUE_APP_BASE_API 配置一致
location /dev-api/ {
proxy_pass http://127.0.0.1:30313/; # 后端服务地址
# 请求头设置
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $server_name;
# WebSocket支持如果需要
# 请求体相关配置重要支持POST请求
proxy_set_header Content-Type $content_type;
proxy_set_header Content-Length $content_length;
proxy_pass_request_headers on;
proxy_pass_request_body on;
# HTTP版本和WebSocket支持
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Connection $connection_upgrade;
# 超时设置
proxy_connect_timeout 600s;
proxy_send_timeout 600s;
proxy_read_timeout 600s;
# 请求缓冲设置(对大文件上传有用)
proxy_request_buffering on;1
client_max_body_size 100M;
}

View File

@@ -165,4 +165,13 @@ export function delJDOrder(ids) {
url: `/system/jdorder/${idPath}`,
method: 'delete'
})
}
// 手动获取物流信息(用于调试)
export function fetchLogisticsManually(data) {
return request({
url: '/jarvis/jdorder/fetchLogisticsManually',
method: 'post',
data
})
}

View File

@@ -0,0 +1,169 @@
<template>
<div style="padding: 40px; text-align: center; font-family: Arial, sans-serif;">
<div v-if="loading" style="margin-top: 100px;">
<i class="el-icon-loading" style="font-size: 48px; color: #409EFF;"></i>
<p style="margin-top: 20px; font-size: 16px; color: #666;">正在处理授权...</p>
</div>
<div v-else-if="success" style="margin-top: 100px;">
<i class="el-icon-success" style="font-size: 64px; color: #67C23A;"></i>
<h2 style="margin-top: 20px; color: #67C23A;">授权成功</h2>
<div style="margin-top: 30px; padding: 20px; background: #f5f7fa; border-radius: 8px; max-width: 600px; margin-left: auto; margin-right: auto;">
<p style="margin-bottom: 15px; font-size: 14px; color: #666;">请复制以下访问令牌</p>
<el-input
:value="accessToken"
readonly
style="margin-bottom: 15px;"
>
<template slot="append">
<el-button @click="copyToken" icon="el-icon-document-copy">复制</el-button>
</template>
</el-input>
<p style="font-size: 12px; color: #999; margin-top: 10px;">
访问令牌有效期{{ expiresIn }}
</p>
</div>
<div style="margin-top: 30px;">
<el-button type="primary" @click="closeWindow">关闭窗口</el-button>
</div>
</div>
<div v-else style="margin-top: 100px;">
<i class="el-icon-error" style="font-size: 64px; color: #F56C6C;"></i>
<h2 style="margin-top: 20px; color: #F56C6C;">授权失败</h2>
<p style="margin-top: 20px; color: #666;">{{ errorMessage }}</p>
<div style="margin-top: 30px;">
<el-button type="primary" @click="closeWindow">关闭窗口</el-button>
</div>
</div>
</div>
</template>
<script>
import { getTencentDocAccessToken } from '@/api/jarvis/tendoc'
export default {
name: 'TencentDocCallback',
data() {
return {
loading: true,
success: false,
accessToken: '',
refreshToken: '',
expiresIn: 0,
errorMessage: ''
}
},
created() {
this.handleCallback()
},
methods: {
async handleCallback() {
// 从URL参数中获取code和state
const urlParams = new URLSearchParams(window.location.search)
const code = urlParams.get('code')
const state = urlParams.get('state')
const error = urlParams.get('error')
const errorDescription = urlParams.get('error_description')
// 处理授权错误
if (error) {
this.loading = false
this.errorMessage = errorDescription || error || '授权失败'
return
}
// 验证授权码
if (!code) {
this.loading = false
this.errorMessage = '未收到授权码,请重新授权'
return
}
try {
// 调用后端接口获取访问令牌
const res = await getTencentDocAccessToken(code)
if (res.code === 200 && res.data) {
const data = res.data
this.accessToken = data.access_token || data.accessToken || ''
this.refreshToken = data.refresh_token || data.refreshToken || ''
this.expiresIn = data.expires_in || data.expiresIn || 0
// 保存到localStorage供主窗口使用
if (this.accessToken) {
localStorage.setItem('tendoc_access_token', this.accessToken)
if (this.refreshToken) {
localStorage.setItem('tendoc_refresh_token', this.refreshToken)
}
// 通知父窗口(如果是从弹窗打开的)
if (window.opener) {
window.opener.postMessage({
type: 'tendoc_auth_success',
access_token: this.accessToken,
refresh_token: this.refreshToken,
expires_in: this.expiresIn
}, '*')
}
}
this.success = true
} else {
this.errorMessage = res.msg || '获取访问令牌失败'
}
} catch (e) {
console.error('获取访问令牌失败', e)
this.errorMessage = e.message || '获取访问令牌失败,请稍后重试'
} finally {
this.loading = false
}
},
copyToken() {
if (this.accessToken) {
if (navigator.clipboard) {
navigator.clipboard.writeText(this.accessToken).then(() => {
this.$message.success('访问令牌已复制到剪贴板')
}).catch(() => {
this.fallbackCopy(this.accessToken)
})
} else {
this.fallbackCopy(this.accessToken)
}
}
},
fallbackCopy(text) {
const textArea = document.createElement('textarea')
textArea.value = text
textArea.style.position = 'fixed'
textArea.style.left = '-999999px'
textArea.style.top = '-999999px'
document.body.appendChild(textArea)
textArea.focus()
textArea.select()
try {
document.execCommand('copy')
this.$message.success('访问令牌已复制到剪贴板')
} catch (err) {
this.$message.error('复制失败,请手动复制')
}
document.body.removeChild(textArea)
},
closeWindow() {
if (window.opener) {
window.close()
} else {
// 如果不是弹窗,跳转到订单列表页面
this.$router.push('/system/jdorder/orderList')
}
}
}
}
</script>
<style scoped>
</style>

View File

@@ -134,11 +134,21 @@
<el-table-column label="完成时间" prop="finishTime" width="160">
<template slot-scope="scope">{{ parseTime(scope.row.finishTime) }}</template>
</el-table-column>
<el-table-column label="操作" fixed="right" width="180">
<el-table-column label="操作" fixed="right" width="240">
<template slot-scope="scope">
<el-button type="text" size="mini" style="color: #409EFF;" @click="handleSyncLogistics(scope.row)">
同步物流
</el-button>
<el-button
type="text"
size="mini"
style="color: #67C23A;"
@click="handleFetchLogistics(scope.row)"
:disabled="scope.row.distributionMark !== 'F' && scope.row.distributionMark !== 'PDD'"
:title="(scope.row.distributionMark !== 'F' && scope.row.distributionMark !== 'PDD') ? '仅支持F或PDD分销标识' : '获取物流信息'"
>
获取物流
</el-button>
<el-button type="text" size="mini" style="color: #f56c6c;" @click="handleDelete(scope.row)">
删除
</el-button>
@@ -159,6 +169,89 @@
</template>
</list-layout>
<!-- 获取物流信息对话框 -->
<el-dialog
title="获取物流信息(调试)"
:visible.sync="fetchLogisticsDialogVisible"
width="800px"
:close-on-click-modal="false"
>
<div v-loading="fetchLogisticsLoading">
<el-alert
v-if="fetchLogisticsResult"
:title="fetchLogisticsResult.success ? '获取成功' : '获取失败'"
:type="fetchLogisticsResult.success ? 'success' : 'error'"
:closable="false"
style="margin-bottom: 20px;"
/>
<el-form label-width="120px" v-if="fetchLogisticsResult">
<el-form-item label="错误信息" v-if="fetchLogisticsResult.error">
<el-alert
:title="fetchLogisticsResult.error"
type="error"
:closable="false"
/>
</el-form-item>
<el-form-item label="订单ID" v-if="fetchLogisticsResult.orderId">
<span>{{ fetchLogisticsResult.orderId }}</span>
</el-form-item>
<el-form-item label="订单号" v-if="fetchLogisticsResult.orderNo">
<span>{{ fetchLogisticsResult.orderNo }}</span>
</el-form-item>
<el-form-item label="分销标识" v-if="fetchLogisticsResult.distributionMark">
<span>{{ fetchLogisticsResult.distributionMark }}</span>
</el-form-item>
<el-form-item label="物流链接" v-if="fetchLogisticsResult.logisticsLink">
<el-input
:value="fetchLogisticsResult.logisticsLink"
readonly
type="textarea"
:rows="2"
/>
</el-form-item>
<el-form-item label="请求URL" v-if="fetchLogisticsResult.requestUrl">
<el-input
:value="fetchLogisticsResult.requestUrl"
readonly
type="textarea"
:rows="2"
/>
</el-form-item>
<el-form-item label="返回数据(原始)" v-if="fetchLogisticsResult.responseRaw || fetchLogisticsResult.responseData">
<el-input
:value="fetchLogisticsResult.responseRaw || JSON.stringify(fetchLogisticsResult.responseData, null, 2)"
readonly
type="textarea"
:rows="10"
style="font-family: monospace; font-size: 12px;"
/>
</el-form-item>
<el-form-item label="返回数据(解析后)" v-if="fetchLogisticsResult.responseData">
<el-input
:value="JSON.stringify(fetchLogisticsResult.responseData, null, 2)"
readonly
type="textarea"
:rows="10"
style="font-family: monospace; font-size: 12px;"
/>
</el-form-item>
</el-form>
<div v-else style="text-align: center; padding: 40px;">
<span style="color: #999;">正在获取物流信息...</span>
</div>
</div>
<div slot="footer" class="dialog-footer">
<el-button @click="fetchLogisticsDialogVisible = false">关闭</el-button>
<el-button
type="primary"
@click="copyFetchLogisticsResult"
v-if="fetchLogisticsResult"
>
复制结果
</el-button>
</div>
</el-dialog>
<!-- 同步物流对话框 -->
<el-dialog
title="同步物流到腾讯文档"
@@ -252,7 +345,7 @@
</template>
<script>
import { listJDOrders, updateJDOrder, delJDOrder } from '@/api/system/jdorder'
import { listJDOrders, updateJDOrder, delJDOrder, fetchLogisticsManually } from '@/api/system/jdorder'
import { fillLogisticsByOrderNo, getTencentDocAuthUrl, getTencentDocAccessToken } from '@/api/jarvis/tendoc'
import ListLayout from '@/components/ListLayout'
@@ -295,7 +388,11 @@ export default {
orderNoColumn: null,
logisticsLinkColumn: null
},
currentOrder: null
currentOrder: null,
// 获取物流信息对话框
fetchLogisticsDialogVisible: false,
fetchLogisticsLoading: false,
fetchLogisticsResult: null
}
},
created() {
@@ -561,38 +658,48 @@ export default {
if (res.code === 200 && res.data) {
// 打开授权页面
const authUrl = res.data
this.$message.info('正在打开授权页面,授权完成后请将访问令牌复制到上方输入框')
const width = 600
const height = 700
const left = (window.screen.width - width) / 2
const top = (window.screen.height - height) / 2
window.open(
// 监听来自授权回调页面的消息
const messageHandler = (event) => {
if (event.data && event.data.type === 'tendoc_auth_success') {
window.removeEventListener('message', messageHandler)
this.syncLogisticsForm.accessToken = event.data.access_token
// 保存配置
localStorage.setItem('tendoc_sync_config', JSON.stringify(this.syncLogisticsForm))
this.$message.success('授权成功,访问令牌已自动保存')
}
}
window.addEventListener('message', messageHandler)
// 打开授权窗口
const authWindow = window.open(
authUrl,
'腾讯文档授权',
`width=${width},height=${height},left=${left},top=${top},resizable=yes,scrollbars=yes`
)
// 提示用户手动输入访问令牌
this.$prompt('授权完成后请从授权页面复制访问令牌access_token并粘贴到下方', '输入访问令牌', {
confirmButtonText: '确定',
cancelButtonText: '取消',
inputPlaceholder: '请输入访问令牌',
inputValidator: (value) => {
if (!value || !value.trim()) {
return '访问令牌不能为空'
// 如果窗口关闭检查localStorage是否有新的token
const checkWindow = setInterval(() => {
if (authWindow.closed) {
clearInterval(checkWindow)
window.removeEventListener('message', messageHandler)
// 检查localStorage是否有新的token
const token = localStorage.getItem('tendoc_access_token')
if (token && token !== this.syncLogisticsForm.accessToken) {
this.syncLogisticsForm.accessToken = token
localStorage.setItem('tendoc_sync_config', JSON.stringify(this.syncLogisticsForm))
this.$message.success('授权成功,访问令牌已自动保存')
}
return true
}
}).then(({ value }) => {
this.syncLogisticsForm.accessToken = value.trim()
// 保存配置
localStorage.setItem('tendoc_sync_config', JSON.stringify(this.syncLogisticsForm))
this.$message.success('访问令牌已保存')
}).catch(() => {
// 用户取消
})
}, 1000)
this.$message.info('请在授权页面完成授权,授权成功后会自动保存访问令牌')
} else {
this.$message.error(res.msg || '获取授权URL失败')
}
@@ -651,6 +758,60 @@ export default {
} finally {
this.syncLogisticsLoading = false
}
},
/** 手动获取物流信息 */
async handleFetchLogistics(row) {
// 检查分销标识
if (row.distributionMark !== 'F' && row.distributionMark !== 'PDD') {
this.$message.warning('该订单的分销标识不是F或PDD无需处理')
return
}
// 检查物流链接
if (!row.logisticsLink || !row.logisticsLink.trim()) {
this.$message.warning('该订单暂无物流链接')
return
}
this.fetchLogisticsDialogVisible = true
this.fetchLogisticsLoading = true
this.fetchLogisticsResult = null
try {
const res = await fetchLogisticsManually({ orderId: row.id })
if (res.code === 200) {
this.fetchLogisticsResult = {
success: true,
...res.data
}
this.$message.success('获取物流信息成功,数据已记录到日志文件')
} else {
this.fetchLogisticsResult = {
success: false,
error: res.msg || '获取失败'
}
this.$message.error(res.msg || '获取物流信息失败')
}
} catch (e) {
this.fetchLogisticsResult = {
success: false,
error: e.message || '请求异常'
}
this.$message.error('获取物流信息失败: ' + (e.message || '未知错误'))
console.error('获取物流信息失败', e)
} finally {
this.fetchLogisticsLoading = false
}
},
/** 复制获取物流信息的结果 */
copyFetchLogisticsResult() {
if (!this.fetchLogisticsResult) return
const resultText = JSON.stringify(this.fetchLogisticsResult, null, 2)
this.copyToClipboard(resultText)
}
}