diff --git a/src/pages/index/index.vue b/src/pages/index/index.vue index 6c5cdda..9fe16ac 100644 --- a/src/pages/index/index.vue +++ b/src/pages/index/index.vue @@ -97,33 +97,27 @@ > - +{{ msg.content.length - 4 }} + + {{ msg.content.length - 4 }} @@ -219,55 +213,56 @@ transition: 'transform 0.3s ease', }" > -
- - - - - {{ item.name }} - - - +
- × -
+ + - - - ↻ - + + {{ item.name }} + - -
- - - + +
+ × +
+ + + + ↻ + + + +
+ + + +
@@ -423,7 +418,7 @@ interface IMessage { timestamp: Date } const userAvatar = ref('') -const chatMode = ref('tongyi-app') +const chatMode = ref('qwen-vl-plus') const baseUrl = getEnvBaseUrl() const messages = reactive([]) @@ -529,7 +524,7 @@ async function fetchHistoryList() { method: 'POST', data: { page: 1, - pageSize: 30, + pageSize: 9990, }, header: { Authorization: token.value, @@ -539,9 +534,7 @@ async function fetchHistoryList() { rawList.value = resp.data.data.data console.log('fetchHistoryList →', rawList.value) } - } catch (err) { - console.error('fetchHistoryList error:', err) - } + } catch (err) {} } /** 3. 拉取历史记录详情 */ @@ -558,16 +551,16 @@ async function fetchHistoryDiets(value) { Authorization: token.value, }, }) - console.log(resp, '/**************resp*********************/') + if (resp && resp.data) { const rawList = resp.data.data // 假设后端直接返回消息数组 + listUuid.value = resp.data.data[0].listUuid + const newMessages = parseBackendMessages(rawList) // 用解析后的消息替换当前消息列表 messages.splice(0, messages.length, ...newMessages) } - } catch (err) { - console.error('fetchHistoryList error:', err) - } + } catch (err) {} } function parseBackendMessages(rawList: any[]): IMessage[] { @@ -584,15 +577,20 @@ function parseBackendMessages(rawList: any[]): IMessage[] { const arr = JSON.parse(rawContent) as Array<{ text: string; type: string }> if (Array.isArray(arr)) { parts = arr.map((el) => { - if (el.type === 'text') { - return { type: 'text', content: el.text } - } - if (el.type === 'image_url' || el.type === 'image') { + if (el.type === 'file_url') { + return { + type: 'video', + content: [{ url: el.text, uploadFileType: 'video' }], + } + } else if (el.type === 'image_url' || el.type === 'image') { return { type: 'image', content: [{ url: el.text, uploadFileType: 'image' }], } + } else if (el.type === 'text') { + return { type: 'text', content: el.text } } + // 其他类型按需扩展 return { type: el.type, content: el.text } }) @@ -699,7 +697,6 @@ const mask = ref('') onMounted(() => { // 1. 定义一个 init 函数,拿 Extras 并依次调用接口 - const init = async () => { const wv = plus.webview.currentWebview() // token.value = wv.token || uni.getStorageSync('token') || import.meta.env.VITE_DEV_TOKEN @@ -718,7 +715,6 @@ function scrollToBottom() { const el = scrollEl.value! nextTick(() => { // el.scrollTo({ top: el.scrollHeight, behavior: 'smooth' }) - console.log(el.scrollHeight, 'el.scrollHeight') el.scrollTo({ top: el.scrollHeight, behavior: 'smooth' }) }) } @@ -778,9 +774,13 @@ async function newChat() { } const rotation = ref(0) function toggleActions() { - closeKeyboard() - showActions.value = !showActions.value + uni.hideKeyboard() + rotation.value += 45 + + console.log(rotation.value, '2') + showActions.value = !showActions.value + scrollToBottom() } @@ -791,10 +791,10 @@ const uploadFileTypeEm = { file: 'file', text: 'text', } - +// const url=baseUrl // 上传配置 const uploadConfig = reactive({ - url: 'http://114.218.158.24:9020/upload/img', + url: `${baseUrl}/upload/img`, formData: { source: 'chat', mask: mask.value, @@ -1032,11 +1032,51 @@ function previewImage(url: string) { } // 预览文件 +// 统一替换掉原来的 previewFile const previewFile = (url: string) => { - //跳转到webview打开 - uni.navigateTo({ - url: '/pages/webview/index?link=' + encodeURIComponent(url), + if (typeof plus !== 'undefined') { + // 在 App 里直接用原生下载 + 打开 + downloadAndOpenFile(url) + } else { + // H5 或者调试环境回退到 WebView + uni.navigateTo({ + url: '/pages/webview/index?link=' + encodeURIComponent(url), + }) + } +} + +const downloadAndOpenFile = (downloadUrl: string) => { + uni.showLoading({ title: '加载中...', mask: true }) + + if (!downloadUrl) { + uni.hideLoading() + return uni.showToast({ title: '文件路径无效', icon: 'none' }) + } + + // 将文件存放到应用私有下载目录,保证权限可读可写 + const options = { + // “_downloads/” 会自动映射到应用的 Documents/download 目录 + filename: '_downloads/', + } + + const dtask = plus.downloader.createDownload(downloadUrl, options, (d, status) => { + uni.hideLoading() + if (status === 200) { + const savedPath = d.filename + if (savedPath) { + // 用系统默认的方式打开任意类型文件(PDF/Word/Excel/图片/视频 都通用) + plus.runtime.openFile(savedPath, {}, () => { + // 打开失败的回调可选 + }) + } else { + uni.showToast({ title: '文件保存失败', icon: 'none' }) + } + } else { + uni.showToast({ title: '下载失败', icon: 'error' }) + } }) + + dtask.start() } const msgLoading = ref(true) // 发送消息 @@ -1226,10 +1266,10 @@ function refreshText() { const knowledgeOpen = ref(false) function toggleKnowledge() { console.error('44444', chatMode.value) - if (chatMode.value == 'tongyi-app') { - chatMode.value = 'qwen-vl-plus' - } else { + if (chatMode.value == 'qwen-vl-plus') { chatMode.value = 'tongyi-app' + } else { + chatMode.value = 'qwen-vl-plus' } knowledgeOpen.value = !knowledgeOpen.value showActions.value = false @@ -1310,7 +1350,7 @@ const onFocus = () => { border-radius: 12rpx 12rpx 0 0; } .popup.fullscreen { - height: 100%; + height: 90%; border-radius: 0; } /* Header */ @@ -1355,4 +1395,7 @@ const onFocus = () => { .tops { padding-top: var(--status-bar-height); } +.flex-i { + display: flex !important; +} diff --git a/src/pages/preview/index.vue b/src/pages/preview/index.vue index 21d3b8b..b3fbe70 100644 --- a/src/pages/preview/index.vue +++ b/src/pages/preview/index.vue @@ -1,5 +1,5 @@