Explorar o código

导出评论功能

yuhongqi hai 4 días
pai
achega
6a35079d07
Modificáronse 2 ficheiros con 66 adicións e 1 borrados
  1. 9 0
      src/api/live/liveMsg.js
  2. 57 1
      src/views/live/live/index.vue

+ 9 - 0
src/api/live/liveMsg.js

@@ -60,3 +60,12 @@ export function exportLiveMsg(query) {
     params: query
   })
 }
+
+// 导出直播评论
+export function exportLiveMsgComments(liveId) {
+  return request({
+    url: '/live/liveMsg/exportComments/' + liveId,
+    method: 'get',
+    responseType: 'blob'
+  })
+}

+ 57 - 1
src/views/live/live/index.vue

@@ -258,6 +258,12 @@
               >
                 <i class="el-icon-service"></i> 查看二维码
               </el-dropdown-item>
+<!--              <el-dropdown-item-->
+<!--                @click.native="handleExportComments(scope.row)"-->
+<!--                :disabled="exportingComments[scope.row.liveId]"-->
+<!--              >-->
+<!--                <i class="el-icon-download"></i> 导出评论-->
+<!--              </el-dropdown-item>-->
             </el-dropdown-menu>
           </el-dropdown>
 
@@ -433,6 +439,7 @@ import {
   finishLive,
   startLive, copyLive,generateCode
 } from "@/api/live/live";
+import { exportLiveMsgComments } from "@/api/live/liveMsg";
 import Editor from '@/components/Editor/wang';
 import user from '@/store/modules/user';
 import VideoUpload from "@/components/LiveVideoUpload/single.vue";
@@ -537,7 +544,9 @@ export default {
       videoUrl: "",
       qrcodeDialogVisible: false,  // 弹窗显示状态:默认隐藏
       currentQrcodeUrl: "",        // 当前要展示的二维码地址
-      defaultImg: "https://via.placeholder.com/400x400?text=二维码加载失败"  // 占位图
+      defaultImg: "https://via.placeholder.com/400x400?text=二维码加载失败",  // 占位图
+      // 导出评论状态:key为liveId,value为是否正在导出
+      exportingComments: {}
     };
   },
   created() {
@@ -988,7 +997,54 @@ export default {
         this.download(response.msg);
         this.exportLoading = false;
       }).catch(() => {});
+    },
+    /** 导出评论按钮操作 */
+    handleExportComments(row) {
+      const liveId = row.liveId;
+      // 检查是否正在导出
+      if (this.exportingComments[liveId]) {
+        this.$message.warning("正在导出中,请勿重复操作");
+        return;
+      }
+
+      // 检查是否有其他直播间正在导出
+      const hasExporting = Object.values(this.exportingComments).some(status => status === true);
+      if (hasExporting) {
+        this.$message.warning("当前已有导出任务进行中,请等待完成后再试");
+        return;
+      }
+
+      this.$confirm('是否确认导出该直播间的评论数据?', "提示", {
+        confirmButtonText: "确定",
+        cancelButtonText: "取消",
+        type: "info"
+      }).then(() => {
+        // 设置导出状态
+        this.$set(this.exportingComments, liveId, true);
+
+        exportLiveMsgComments(liveId).then(response => {
+          // 创建blob对象
+          const blob = new Blob([response], { type: 'application/vnd.ms-excel' });
+          // 创建下载链接
+          const url = window.URL.createObjectURL(blob);
+          const link = document.createElement('a');
+          link.href = url;
+          link.setAttribute('download', `直播评论_${row.liveName || liveId}_${new Date().getTime()}.xlsx`);
+          document.body.appendChild(link);
+          link.click();
+          document.body.removeChild(link);
+          window.URL.revokeObjectURL(url);
+
+          this.$message.success("导出成功");
+        }).catch(error => {
+          this.$message.error(error.msg || "导出失败");
+        }).finally(() => {
+          // 清除导出状态
+          this.$set(this.exportingComments, liveId, false);
+        });
+      }).catch(() => {});
     }
+
   }
 };
 </script>