wujingjing
2025-04-02 5fb58c10b2bb44b3f2d3bdab4d7a6619271e2bbf
src/components/chat/user/index.vue
@@ -10,9 +10,8 @@
                     <div
                        v-for="(item, index) in msg.attachList"
                        :key="index"
                        class="flex items-center gap-2 bg-[#e9e9e9] px-2 py-3 rounded-lg w-[220px] relative group"
                        class="flex items-center gap-2 bg-[#e9e9e9] px-2 py-3 rounded-lg w-[220px] relative group cursor-pointer"
                        @click="openAttachPreview(item)"
                        :class="{ 'cursor-pointer': item.type === 'table' }"
                     >
                        <template v-if="item.type === 'file'">
                           <el-image
@@ -29,12 +28,12 @@
                              <div v-if="item.model.type" class="text-info text-sm over-ellipsis w-full">
                                 {{ `${item.model.type ?? ''},${item.model.size ?? ''}` }}
                              </div>
                              <!-- <el-tooltip effect="dark" content="下载" placement="top">
                              <el-tooltip effect="dark" content="下载" placement="top">
                                 <span
                                    class="group-hover:visible invisible ywifont ywicon-quote absolute right-2"
                                    class="group-hover:visible invisible ywifont ywicon-download2 absolute right-2 cursor-pointer"
                                    @click.stop="downloadAttach(item)"
                                 ></span>
                              </el-tooltip> -->
                              </el-tooltip>
                           </div>
                        </template>
                        <template v-if="item.type === 'metric'">
@@ -45,7 +44,7 @@
                           </div>
                           <el-tooltip effect="dark" content="引用" placement="top">
                              <span
                                 class="group-hover:visible invisible ywifont ywicon-quote absolute right-2"
                                 class="group-hover:visible invisible ywifont ywicon-quote absolute right-2 cursor-pointer"
                                 @click.stop="quoteAttach(item)"
                              ></span>
                           </el-tooltip>
@@ -58,7 +57,7 @@
                           </div>
                           <el-tooltip effect="dark" content="引用" placement="top">
                              <span
                                 class="group-hover:visible invisible ywifont ywicon-quote absolute right-2"
                                 class="group-hover:visible invisible ywifont ywicon-quote absolute right-2 cursor-pointer"
                                 @click.stop="quoteAttach(item)"
                              ></span>
                           </el-tooltip>
@@ -71,8 +70,7 @@
      </div>
      <BusinessTablePreview :data="attachPreviewData" v-model="attachPreviewIsShow" />
      <MetricValuesPreview v-model="metricPreviewIsShow" :data="metricPreviewData"/>
      <MetricValuesPreview v-model="metricPreviewIsShow" :data="metricPreviewData" />
      <!-- #endregion -->
@@ -144,8 +142,8 @@
import { Attach } from '../components/playBar/hook/useAttach';
import MetricValuesPreview from '../components/playBar/metricValues/MetricValuesPreview.vue';
import emitter from '/@/utils/mitt';
import { downloadFileByPost } from '/@/api/file';
const emit = defineEmits<{
   (event: 'copyMsg', msgObj: ChatMessage): void;
@@ -184,8 +182,9 @@
const attachPreviewIsShow = ref(false);
const attachPreviewData = ref<Attach>();
const openAttachPreview = (item: Attach) => {
   if (item.type === 'file') return;
   if (item.type === 'table') {
   if (item.type === 'file') {
      openFileContent(item);
   } else if (item.type === 'table') {
      attachPreviewIsShow.value = true;
      attachPreviewData.value = item;
   } else if (item.type === 'metric') {
@@ -201,10 +200,32 @@
};
//#endregion
//#region ====================== 查看文件文本内容 ======================
const openFileContent = (item: Attach) => {
   emitter.emit('setFileContent', {
      title: item.title,
      content: item.model?.file_content ?? '',
   });
};
//#endregion
//#region ====================== 附件下载 ======================
const downloadAttach = (item: Attach) => {
const downloadAttach = async (item: Attach) => {
   const fileId = item.model?.file_id;
   if (!fileId) return;
   const res = await downloadFileByPost({
      file_id: fileId,
   });
   const url = window.URL.createObjectURL(res as any);
   const link = document.createElement('a');
   link.href = url;
   link.download = item.title || 'download'; // Use item title or fallback name
   document.body.appendChild(link);
   link.click();
   document.body.removeChild(link);
   window.URL.revokeObjectURL(url);
};
//#endregion
</script>