瀏覽代碼

需求表

wangxy 1 月之前
父節點
當前提交
70346ae602

+ 10 - 0
src/api/course/courseWatchComment.js

@@ -44,6 +44,7 @@ export function updateBarrageStatus(data) {
     data: data
   })
 }
+
 // 删除看课评论
 export function delCourseWatchComment(commentId) {
   return request({
@@ -78,3 +79,12 @@ export function clearBlack(query) {
     params: query
   })
 }
+
+//下载导入模板
+export function template(query) {
+  return request({
+    url: '/course/courseWatchComment/template',
+    method: 'get'
+    , params: query
+  })
+}

+ 146 - 4
src/views/course/courseComment/index.vue

@@ -54,6 +54,24 @@
           v-hasPermi="['course:courseWatchComment:remove']"
         >删除</el-button>
       </el-col>
+      <el-col :span="1.5">
+        <el-button
+          type="warning"
+          plain
+          icon="el-icon-download"
+          size="mini"
+          @click="handleExport"
+        >下载模板</el-button>
+      </el-col>
+      <el-col :span="1.5">
+        <el-button
+          type="info"
+          plain
+          icon="el-icon-upload2"
+          size="mini"
+          @click="handleImport"
+        >导入</el-button>
+      </el-col>
       <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
     </el-row>
 
@@ -182,6 +200,32 @@
         <el-button type="primary" @click="submitForm">确 定</el-button>
       </div>
     </el-dialog>
+    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body  @close="closeUploadDialog">
+      <el-upload
+        ref="upload"
+        :limit="1"
+        accept=".xlsx, .xls"
+        :headers="upload.headers"
+        :action="upload.url"
+        :disabled="upload.isUploading"
+        :on-progress="handleFileUploadProgress"
+        :on-success="handleFileSuccess"
+        :on-error="handleFileError"
+        auto-upload="false"
+        :data="uploadData"
+      >
+        <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
+        <el-button      style="margin-left: 10px;"
+                        type="success"
+                        size="small"
+                        :loading="upload.isUploading"
+                        @click="submitFileForm"
+        >上传到服务器</el-button>
+        <div slot="tip" class="el-upload__tip">
+          仅允许导入 xls、xlsx 格式文件,且不超过 10MB
+        </div>
+      </el-upload>
+    </el-dialog>
   </div>
 </template>
 
@@ -194,9 +238,10 @@ import {
   clearBlack,
   updateBarrageStatus,
   getCourseWatchComment,
-  updateCourseWatchComment, addCourseWatchComment
+  updateCourseWatchComment, addCourseWatchComment,template
 } from "@/api/course/courseWatchComment";
 import { addKeyword } from "@/api/system/keyword";
+import {getToken} from "@/utils/auth";
 
 export default {
   name: "CourseWatchComment",
@@ -231,6 +276,20 @@ export default {
         { dictValue: 0, dictLabel: "否" },
         { dictValue: 1, dictLabel: "是" }
       ],
+      upload: {
+        // 是否显示弹出层
+        open: false,
+        // 弹出层标题
+        title: "",
+        // 是否禁用上传
+        isUploading: false,
+        // 是否更新已经存在的用户数据
+        updateSupport: 0,
+        // 设置上传的请求头部
+        headers: { Authorization: "Bearer " + getToken() },
+        // 上传的地址
+        url: process.env.VUE_APP_BASE_API + "/course/courseWatchComment/import"
+      },
       //下拉状态
       statusOptions:[],
       // 弹出层标题
@@ -267,6 +326,11 @@ export default {
   },
 
   computed: {
+    uploadData() {
+      return {
+        type: this.activeTab === 'course' ? 0 : 1
+      };
+    },
     // 计算属性:根据当前tab返回搜索框提示文字
     searchPlaceholder() {
       return this.activeTab === 'course'
@@ -489,18 +553,96 @@ export default {
     },
     /** 导出按钮操作 */
     handleExport() {
-      const queryParams = this.queryParams;
-      this.$confirm('是否确认导出当前看课评论数据项?', "警告", {
+      this.$confirm('是否确认下载导入模板?', "警告", {
         confirmButtonText: "确定",
         cancelButtonText: "取消",
         type: "warning"
       }).then(() => {
         this.exportLoading = true;
-        return exportCourseWatchComment(queryParams);
+        const params = {
+          type: this.activeTab === 'course' ? 0 : 1
+        };
+        return template(params);
       }).then(response => {
         this.download(response.msg);
         this.exportLoading = false;
       }).catch(() => {});
+    },
+    /** 文件上传中处理 */
+    handleFileUploadProgress(event, file, fileList) {
+      this.upload.isUploading = true;
+    },
+
+    /** 文件上传成功处理 */
+    handleFileSuccess(response, file, fileList) {
+      if (response.code === 200) {
+        this.upload.open = false;
+        this.$refs.upload.clearFiles();
+        this.$message.success(response.msg || "导入成功");
+        this.getList();
+      } else {
+        // 业务错误,显示错误信息
+        this.$message.error(response.msg || "导入失败");
+        if (this.$refs.upload) {
+          this.$refs.upload.clearFiles();
+        }
+      }
+    },
+
+    /** 文件上传失败处理 */
+    handleFileError(err, file, fileList) {
+      this.upload.isUploading = false;
+      console.error('上传失败:', err);
+      if (this.$refs.upload) {
+        this.$refs.upload.clearFiles();
+      }
+      let errorMsg = "上传失败,请重试";
+      if (err.message) {
+        errorMsg = err.message;
+      }
+
+      // 如果错误响应有数据
+      if (err.response && err.response.data) {
+        const data = err.response.data;
+        if (data.msg) {
+          errorMsg = data.msg;
+        } else if (data.message) {
+          errorMsg = data.message;
+        }
+      }
+
+      this.$message.error(errorMsg);
+    },
+
+    /** 提交上传文件 */
+    submitFileForm() {
+      // 清空之前的错误文件
+      if (this.$refs.upload) {
+        this.$refs.upload.clearFiles();
+      }
+
+      if (!this.$refs.upload.uploadFiles.length) {
+        this.$message.warning('请先选择文件');
+        return;
+      }
+
+      this.upload.isUploading = true;
+      this.$refs.upload.submit();
+    },
+    /** 导入模板 */
+    handleImport() {
+      if (this.$refs.upload) {
+        this.$refs.upload.clearFiles();
+      }
+      this.upload.title = `导入${this.activeTab === 'course' ? '课程' : '视频'}评论`;
+      this.upload.open = true;
+    },
+    closeUploadDialog() {
+      this.upload.open = false;
+      if (this.$refs.upload) {
+        this.$refs.upload.clearFiles();
+      }
+      this.upload.isUploading = false;
     }
   }
 };

+ 4 - 6
src/views/course/courseTrafficLog/index.vue

@@ -2,7 +2,6 @@
   <div class="app-container">
     <!-- Tab 切换 -->
     <el-tabs v-model="activeTab" @tab-click="handleTabClick">
-      <el-tab-pane label="公司" name="company"></el-tab-pane>
       <el-tab-pane label="项目" name="project"></el-tab-pane>
       <el-tab-pane label="课程" name="course"></el-tab-pane>
       <el-tab-pane label="公开课" name="common"></el-tab-pane>
@@ -11,7 +10,7 @@
     <!-- 查询条件 -->
     <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
       <!-- 公司选择 -->
-      <el-form-item label="公司" v-if="activeTab === 'all' || activeTab === 'company'">
+      <el-form-item label="公司">
         <el-select v-model="queryParams.companyId" placeholder="请选择公司" filterable clearable size="small">
           <el-option v-for="(option, index) in companyList" :key="index" :value="option.dictValue" :label="option.dictLabel"></el-option>
         </el-select>
@@ -76,7 +75,7 @@
     <el-table border v-loading="loading" :data="courseTrafficLogList" @selection-change="handleSelectionChange" show-summary :summary-method="getSummaries">
       <el-table-column type="selection" width="55" align="center" />
       <!-- 公司列 -->
-      <el-table-column label="公司" align="center" prop="companyName" v-if="activeTab === 'all' || activeTab === 'company'" />
+      <el-table-column label="公司" align="center" prop="companyName" />
       <!-- 项目列 -->
       <el-table-column label="项目" align="center" prop="projectName" v-if="activeTab === 'all' || activeTab === 'project'" />
       <!-- 课程列 -->
@@ -108,7 +107,7 @@ import { allList } from "@/api/company/company";
 export default {
   data() {
     return {
-      activeTab: "company", // 默认 tab
+      activeTab: "project", // 默认 tab
       timeRange: null, // 时间范围单独绑定
       companyList: [],
       projectOptions: [],
@@ -171,6 +170,7 @@ export default {
     };
   },
   created() {
+    this.queryParams.tabType = "project";
     courseList().then(res => this.courseLists = res.list);
     this.getDicts("sys_course_project").then(res => this.projectOptions = res.data);
     this.getAllCompany();
@@ -209,8 +209,6 @@ export default {
       // 清理互斥参数
       if (tab.name !== "project") this.queryParams.project = null;
       if (tab.name !== "course") this.queryParams.courseId = null;
-      if (tab.name !== "company") this.queryParams.companyId = null;
-
       this.getList();
     },