|
|
@@ -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;
|
|
|
}
|
|
|
}
|
|
|
};
|