mirror of
http://112.124.100.131/ebiz-ai/ebiz-ai-knowledge-manage.git
synced 2025-12-06 09:26:48 +08:00
feat(agent): 添加 token 定时刷新功能并优化代理图像显示- 在 workflow 组件中添加定时器,每 5 分钟刷新一次 token
- 优化智能代理卡片的图像显示,支持多种格式 - 新增 getAccessToken API调用
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
<script>
|
||||
import { DIFY_URL } from '@/config/base-url'
|
||||
import { agentAdd, agentDetail, agentEdit } from '@/api/intelligent-agent/list'
|
||||
import {
|
||||
agentAdd,
|
||||
agentDetail,
|
||||
agentEdit,
|
||||
getAccessToken
|
||||
} from '@/api/intelligent-agent/list'
|
||||
export default {
|
||||
name: 'workflow',
|
||||
props: {
|
||||
@@ -11,6 +16,7 @@ export default {
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
timer: null,
|
||||
agentDetail: {},
|
||||
|
||||
resetName: '',
|
||||
@@ -76,6 +82,15 @@ export default {
|
||||
this.worker.instance.postMessage('init-worker', [
|
||||
this.messageChannel.instance.port2
|
||||
])
|
||||
// 每 5 分钟执行一次
|
||||
// ✅ 先清理已有 timer,防止重复创建
|
||||
if (this.timer) {
|
||||
clearInterval(this.timer)
|
||||
this.timer = null
|
||||
}
|
||||
this.timer = setInterval(() => {
|
||||
this.initTokenRefresh()
|
||||
}, 1000 * 60 * 5)
|
||||
},
|
||||
destroyed() {
|
||||
// 组件销毁时清除 web worker 和 messageChannel
|
||||
@@ -83,6 +98,10 @@ export default {
|
||||
this.worker.instance = void 0
|
||||
this.messageChannel.instance.port1.close()
|
||||
this.messageChannel.instance = void 0
|
||||
if (this.timer) {
|
||||
clearInterval(this.timer)
|
||||
this.timer = null
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
'$route.query': {
|
||||
@@ -108,6 +127,21 @@ export default {
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
async initTokenRefresh() {
|
||||
try {
|
||||
const thirdContent = await getAccessToken()
|
||||
const { refreshToken, accessToken } = thirdContent.content.content
|
||||
|
||||
if (localStorage.getItem('refresh_token') !== refreshToken) {
|
||||
localStorage.setItem('refresh_token', refreshToken)
|
||||
}
|
||||
if (localStorage.getItem('console_token') !== accessToken) {
|
||||
localStorage.setItem('console_token', accessToken)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Token refresh failed:', error)
|
||||
}
|
||||
},
|
||||
handleAgentLoad() {
|
||||
// 把 messageChannel port1 的所有权传递给 iframe
|
||||
this.$refs.agent.contentWindow.postMessage('init-iframe', '*', [
|
||||
|
||||
@@ -236,15 +236,20 @@ export default {
|
||||
{{ dialog.agent.image }}
|
||||
</div>
|
||||
<div
|
||||
v-else
|
||||
v-else-if="dialog.agent.imageType === 'image'"
|
||||
style="width: 100%;height: 100%;overflow: hidden;border-radius: 8px"
|
||||
>
|
||||
<img
|
||||
v-if="dialog.agent.image"
|
||||
:src="dialog.agent.image"
|
||||
alt=""
|
||||
style="width: 100%;height: 100%"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div v-else style="font-size: 30px" class=" fw600 white">
|
||||
{{ dialog.agent.appName[0] }}
|
||||
</div>
|
||||
</div>
|
||||
</el-popover>
|
||||
</el-form-item>
|
||||
|
||||
Reference in New Issue
Block a user