Skip to content

Commit 98db08d

Browse files
fix: 上传文件对话增加文件下载功能
1 parent a96b0c1 commit 98db08d

File tree

3 files changed

+48
-14
lines changed

3 files changed

+48
-14
lines changed

ui/src/components/ai-chat/component/chat-input-operate/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<el-icon><CircleCloseFilled /></el-icon>
2525
</div>
2626
<img :src="getImgUrl(item && item?.name)" alt="" width="24" />
27-
<div class="ml-4 ellipsis" :title="item && item?.name">
27+
<div class="ml-4 ellipsis" style="max-width: 160px" :title="item && item?.name">
2828
{{ item && item?.name }}
2929
</div>
3030
</div>

ui/src/components/ai-chat/component/question-content/index.vue

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@
1818
<div class="mb-8" v-if="document_list.length">
1919
<el-space wrap>
2020
<template v-for="(item, index) in document_list" :key="index">
21-
<el-card shadow="never" style="--el-card-padding: 8px" class="file cursor">
22-
<div class="flex align-center">
21+
<el-card shadow="never" style="--el-card-padding: 8px" class="download-file cursor">
22+
<div class="download-button flex align-center" @click="downloadFile(item)">
23+
<el-icon class="mr-4"><Download /></el-icon>点击下载文件
24+
</div>
25+
<div class="show flex align-center">
2326
<img :src="getImgUrl(item && item?.name)" alt="" width="24" />
24-
<div class="ml-4 ellipsis" :title="item && item?.name">
27+
<div class="ml-4 ellipsis" style="max-width: 150px" :title="item && item?.name">
2528
{{ item && item?.name }}
2629
</div>
2730
</div>
@@ -55,7 +58,7 @@
5558
</template>
5659
<script setup lang="ts">
5760
import { type chatType } from '@/api/type/application'
58-
import { getImgUrl, getAttrsArray } from '@/utils/utils'
61+
import { getImgUrl, getAttrsArray, downloadByURL } from '@/utils/utils'
5962
import { onMounted, computed } from 'vue'
6063
const props = defineProps<{
6164
application: any
@@ -80,13 +83,33 @@ const image_list = computed(() => {
8083
}
8184
})
8285
83-
onMounted(() => {
84-
// console.log(props.chatRecord.execution_details)
85-
// if (props.chatRecord.execution_details?.length > 0) {
86-
// props.chatRecord.execution_details[0].image_list?.forEach((image: any) => {
87-
// console.log('image', image.name, image.url)
88-
// })
89-
// }
90-
})
86+
function downloadFile(item: any) {
87+
downloadByURL(item.url, item.name)
88+
}
89+
90+
onMounted(() => {})
9191
</script>
92-
<style lang="scss" scoped></style>
92+
<style lang="scss" scoped>
93+
.download-file {
94+
width: 200px;
95+
height: 43px;
96+
&:hover {
97+
color: var(--el-color-primary);
98+
border: 1px solid var(--el-color-primary);
99+
.download-button {
100+
display: block;
101+
text-align: center;
102+
line-height: 26px;
103+
}
104+
.show {
105+
display: none;
106+
}
107+
}
108+
.show {
109+
display: block;
110+
}
111+
.download-button {
112+
display: none;
113+
}
114+
}
115+
</style>

ui/src/utils/utils.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,14 @@ export function getAttrsArray(array: Array<any>, attr: string) {
8888
export function getSum(array: Array<any>) {
8989
return array.reduce((total, item) => total + item, 0)
9090
}
91+
92+
// 下载
93+
export function downloadByURL(url: string, name: string) {
94+
const a = document.createElement('a')
95+
a.setAttribute('href', url)
96+
a.setAttribute('target', '_blank')
97+
a.setAttribute('download', name)
98+
document.body.appendChild(a)
99+
a.click()
100+
document.body.removeChild(a)
101+
}

0 commit comments

Comments
 (0)