diff --git a/src/assets/images/link-outer.png b/src/assets/images/link-outer.png new file mode 100644 index 0000000..ef72943 Binary files /dev/null and b/src/assets/images/link-outer.png differ diff --git a/src/utils/useWebTitle.ts b/src/utils/useWebTitle.ts deleted file mode 100644 index 5bf7367..0000000 --- a/src/utils/useWebTitle.ts +++ /dev/null @@ -1,92 +0,0 @@ -import { ref } from 'vue' - -export const useWebsiteTitle = () => { - const titles = ref>(new Map()) - const loading = ref(new Set()) - const errors = ref(new Map()) - - // 新增:重试配置 - const MAX_RETRY = 3 - const BASE_DELAY = 800 // 毫秒 - - const getCache = (url: string) => { - const cached = sessionStorage.getItem(`title_cache_${url}`) - if (!cached) return null - const { title, expire } = JSON.parse(cached) - return Date.now() < expire ? title : null - } - - const setCache = (url: string, title: string) => { - const data = { title, expire: Date.now() + 7 * 24 * 60 * 60 * 1000 } - sessionStorage.setItem(`title_cache_${url}`, JSON.stringify(data)) - } - - const fetchWithRetry = async (url: string, retryCount = 0): Promise => { - const proxyUrl = `https://api.allorigins.win/raw?url=${encodeURIComponent(url)}` - - try { - const res = await fetch(proxyUrl) - - if (!res.ok) { - throw new Error(`HTTP ${res.status}`) - } - - const html = await res.text() - const parser = new DOMParser() - const doc = parser.parseFromString(html, 'text/html') - const title = - doc.querySelector('title')?.textContent?.trim() || new URL(url).hostname || '无标题' - - return title - } catch (err) { - if (retryCount >= MAX_RETRY) { - throw err // 达到最大重试次数,抛出错误 - } - - // 第1次等800ms,第2次等1600ms,第3次等3200ms - const delay = BASE_DELAY * Math.pow(2, retryCount) - console.warn( - `获取标题失败,${retryCount + 1}/${MAX_RETRY} 次重试,等待 ${delay}ms`, - url - ) - - await new Promise((resolve) => setTimeout(resolve, delay)) - return fetchWithRetry(url, retryCount + 1) - } - } - - const fetchTitle = async (url: string): Promise => { - if (titles.value.has(url)) return titles.value.get(url)! - - const cached = getCache(url) - if (cached) { - titles.value.set(url, cached) - return cached - } - - if (loading.value.has(url)) return '' - - loading.value.add(url) - errors.value.delete(url) - - try { - const title = await fetchWithRetry(url) - titles.value.set(url, title) - setCache(url, title) - return title - } catch (err) { - const msg = `获取标题失败(已重试 ${MAX_RETRY} 次)` - errors.value.set(url, msg) - console.error(err) - return msg - } finally { - loading.value.delete(url) - } - } - - const fetchAll = async (urls: string[]) => { - await Promise.allSettled(urls.map(fetchTitle)) - } - - return { titles, loading, errors, fetchTitle, fetchAll } -} diff --git a/src/views/home/agent/components/Agent.vue b/src/views/home/agent/components/Agent.vue index 41f7c62..7933695 100644 --- a/src/views/home/agent/components/Agent.vue +++ b/src/views/home/agent/components/Agent.vue @@ -146,7 +146,7 @@ id: messageList.value.length + 1, text: '', isUser: false, - sessionId: 'projectStore.state.id', + sessionId: projectStore.state.id, loading: true, thinking: false, thinkingText: '', @@ -258,7 +258,7 @@ reportsContent.value ) { isGeneratingReport.value = false - localStorage.setItem( + sessionStorage.setItem( 'reportsContent_' + projectStore.state.id, reportsContent.value ) @@ -297,6 +297,7 @@ } // if (eventName === 'webAddress') { // console.log('webAddress111111111111111', eventName, dataLines) + // debugger // } if (eventName === 'tool') { @@ -311,17 +312,17 @@ // console.log('jsonData', jsonData) if (jsonData.webAddress) { aiMessage.webAddress = JSON.parse(jsonData.webAddress) + contentBody += `123` } if (jsonData.title) { emits('setTitle', jsonData.title) } if (hasSketch) { - console.log('sketch事件-----', jsonData); - sketchList.value.push({ [Object.keys(jsonData)[0]]: jsonData[Object.keys(jsonData)[0]] }) + MyEvent.emit('OpenSketch') } if (eventName === 'report') { reportsContent.value += jsonData.report @@ -438,10 +439,6 @@ while (i < dialogue.length) { const item = dialogue[i] - if (item.webAddress?.length > 0) { - console.log('item.webAddress-----', item.webAddress) - debugger - } if (item.role === 'user') { // user 角色直接添加 result.push({ @@ -513,7 +510,7 @@ } }) if (reportStr && session.id) { - localStorage.setItem(`reportsContent_${session.id}`, reportStr) + sessionStorage.setItem(`reportsContent_${session.id}`, reportStr) } // 3. 收集 sketchIDAndUrl 到 imgList diff --git a/src/views/home/agent/components/Item.vue b/src/views/home/agent/components/Item.vue index 8ab6681..a4079c3 100644 --- a/src/views/home/agent/components/Item.vue +++ b/src/views/home/agent/components/Item.vue @@ -40,11 +40,10 @@ - +