lion 3 months ago
commit 863f8b36a9

@ -16,28 +16,44 @@
</div>
<div v-if="subjectObj.course_content_status===0">
<el-button type="primary" size="small" @click="changeContentStatus(true)"></el-button>
</div>
<div v-if="subjectObj.course_content_status===1">
<el-button type="primary" size="small" @click="changeContentStatus(false)"></el-button>
</div>
<div v-if="subjectObj.course_content_status===1">
<el-button type="primary" size="small" @click="isSendMessage"></el-button>
</div>
<div>
<el-button type="primary" size="small" v-print="'#print'"></el-button>
</div>
</div>
<div v-if="subjectObj.course_content_status===1">
<el-button type="primary" size="small" @click="changeContentStatus(false)"></el-button>
</div>
<div v-if="subjectObj.course_content_status===1">
<el-button type="primary" size="small" @click="isSendMessage"></el-button>
</div>
<div>
<el-button type="primary" size="small" v-print="'#print'"></el-button>
</div>
</div>
<div class="schedule" id="print">
<el-table :data="list" border style="width: 100%;height:300px;overflow: scroll;">
<el-table-column v-for="item in table_item" :prop="item.prop" :label="item.label"
<el-table-column v-for="item in table_item" :key="item.prop" :prop="item.prop" :label="item.label"
:width="item.width?item.width:''" :align="item.align">
</el-table-column>
<el-table-column label="操作" :width="180" align="center">
<!-- 课件列使用自定义模板 -->
<el-table-column label="课件" width="200" align="center">
<template slot-scope="scope">
<div v-if="scope.row.files && scope.row.files.length > 0">
<div v-for="file in scope.row.files" :key="file.id" class="file-item">
<el-link type="primary" @click="downloadFile(file)" :underline="false">
<i class="el-icon-document"></i>
{{ file.original_name }}
</el-link>
</div>
</div>
<span v-else class="no-files">暂无课件</span>
</template>
</el-table-column>
<el-table-column label="操作" :width="220" align="center">
<template slot-scope="scope">
<el-button type="primary" size="small" style='margin-left:5px;margin-bottom:5px;'
@click="editClass('editor',scope.row.id)">编辑</el-button>
<el-button type="success" size="small" style='margin-left:5px;margin-bottom:5px;'
@click="uploadMaterial(scope.row)">上传课件</el-button>
<el-popconfirm style="margin:0 10px" @confirm="deleteList(scope.row.id)" title="确定删除吗?">
<el-button type="danger" size="small" slot="reference">删除</el-button>
</el-popconfirm>
@ -52,6 +68,65 @@
</Modal>
<imports ref="imports" :table-name="'course_contents'" :course_id="id+''" @refresh="refreshData"></imports>
<editClass ref="editClass" @refresh="getCousreContent"></editClass>
<!-- 上传课件模态框 -->
<el-dialog title="上传课件" :visible.sync="materialDialogVisible" width="600px" center>
<div class="material-upload-container">
<div class="course-info">
<h4>课程信息</h4>
<p><strong>日期</strong>{{ selectedCourse.date }}</p>
<p><strong>时间</strong>{{ selectedCourse.period }}</p>
<p><strong>主题</strong>{{ selectedCourse.theme }}</p>
<p><strong>老师</strong>{{ selectedCourse.teacher ? selectedCourse.teacher.name : '' }}</p>
</div>
<div class="upload-section">
<h4>课件上传</h4>
<el-upload
ref="materialUpload"
:action="uploadAction"
:headers="uploadHeaders"
:file-list="materialFileList"
:on-success="handleMaterialUploadSuccess"
:on-remove="handleMaterialUploadRemove"
:on-error="handleMaterialUploadError"
:before-upload="beforeMaterialUpload"
multiple
drag
accept=".pdf,.doc,.docx,.ppt,.pptx,.xls,.xlsx,.zip,.rar,.txt,.jpg,.jpeg,.png,.gif">
<i class="el-icon-upload"></i>
<div class="el-upload__text">将文件拖到此处<em>点击上传</em></div>
<div class="el-upload__tip" slot="tip">
支持 PDFWordPPTExcel压缩包图片等格式单个文件不超过50MB
</div>
</el-upload>
</div>
<div class="material-list" v-if="materialFileList.length > 0">
<h4>已上传课件</h4>
<el-table :data="materialFileList" size="small" style="width: 100%">
<el-table-column prop="name" label="文件名" min-width="150"></el-table-column>
<el-table-column prop="size" label="大小" width="100" align="center">
<template slot-scope="scope">
{{ formatFileSize(scope.row.size) }}
</template>
</el-table-column>
<el-table-column label="操作" width="120" align="center">
<template slot-scope="scope">
<el-button type="text" size="small" @click="downloadMaterial(scope.row)">
<i class="el-icon-download"></i> 下载
</el-button>
</template>
</el-table-column>
</el-table>
</div>
</div>
<div slot="footer" class="dialog-footer">
<el-button @click="materialDialogVisible = false">取消</el-button>
<el-button type="primary" @click="saveMaterialFiles" :loading="saving">保存课件</el-button>
</div>
</el-dialog>
</div>
</template>
@ -60,15 +135,17 @@
import {
index,
sendSms,
destroy
} from '@/api/course/courseContent.js'
import {
index as teacherIndex
destroy,
save as saveContent
} from '@/api/course/courseContent.js'
import {
index as teacherIndex
} from "@/api/info/teachers.js"
import {
show,
save
} from "@/api/course/index.js"
import { uploads } from '@/api/uploads.js'
import imports from "@/views/component/imports.vue"
import editClass from "../components/editClass.vue"
export default {
@ -116,7 +193,15 @@
prop: 'teacher.introduce',
label: '老师简介',
align: 'left'
}]
}],
materialDialogVisible: false, //
selectedCourse: {}, //
uploadAction: `${process.env.VUE_APP_UPLOAD_API}`, // URL
uploadHeaders: {
Authorization: `Bearer ${this.$store.getters.token}`
}, //
materialFileList: [], //
saving: false //
}
},
methods: {
@ -145,13 +230,13 @@
show_relation: ['teacher', 'type_detail']
})
this.subjectObj = {}
this.subjectObj = this.base.deepCopy(res)
let teacher = []
if(res.teacher_detail.length>0){
res.teacher_detail.map(item=>{
teacher.push(item.name)
})
}
this.subjectObj = this.base.deepCopy(res)
let teacher = []
if(res.teacher_detail.length>0){
res.teacher_detail.map(item=>{
teacher.push(item.name)
})
}
this.subjectObj.teacherList = teacher.join(",")
},
//
@ -159,7 +244,7 @@
this.$refs.imports.show()
},
refreshData() {
this.$emit('refresh')
this.$emit('refresh')
this.getTeachers()
this.getCourseDetail()
this.getCousreContent()
@ -169,18 +254,18 @@
if (this.list.length === 0) {
this.$Message.warning("请先导入课表")
return
}
if(flag){
this.subjectObj.course_content_status = 1
}else{
this.subjectObj.course_content_status = 0
}
if(flag){
this.subjectObj.course_content_status = 1
}else{
this.subjectObj.course_content_status = 0
}
save(this.subjectObj).then(res => {
this.$Message.success(flag?"发布成功":'已取消发布')
this.$emit('refresh')
this.getCourseDetail()
if(flag){
this.isSendMessage()
this.getCourseDetail()
if(flag){
this.isSendMessage()
}
})
},
@ -211,13 +296,13 @@
this.$refs.editClass.id = id
this.$refs.editClass.setTeachers(this.teacher_options)
this.$refs.editClass.isShow = true
},
async getTeachers() {
const res = await teacherIndex({
page: 1,
page_size: 999
})
this.teacher_options = res.data
},
async getTeachers() {
const res = await teacherIndex({
page: 1,
page_size: 999
})
this.teacher_options = res.data
},
deleteList(id) {
var that = this;
@ -231,6 +316,80 @@
reject(error)
})
},
uploadMaterial(row) {
this.selectedCourse = row;
this.materialFileList = []; //
this.materialDialogVisible = true;
this.$nextTick(() => {
this.$refs.materialUpload.clearFiles(); //
});
},
handleMaterialUploadSuccess(response, file, fileList) {
this.$message.success('课件上传成功');
this.materialFileList = fileList;
},
handleMaterialUploadRemove(file, fileList) {
this.materialFileList = fileList;
},
handleMaterialUploadError(err, file, fileList) {
this.$message.error('课件上传失败: ' + err);
},
beforeMaterialUpload(file) {
const isLt50M = file.size / 1024 / 1024 < 50;
if (!isLt50M) {
this.$message.error('上传文件大小不能超过 50MB!');
}
return isLt50M;
},
downloadMaterial(file) {
window.open(file.url);
},
formatFileSize(size) {
if (size === 0) return '0 Bytes';
const k = 1024;
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
const i = Math.floor(Math.log(size) / Math.log(k));
return parseFloat((size / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
},
downloadFile(file) {
// a
const link = document.createElement('a');
link.href = file.url;
link.download = file.original_name;
link.target = '_blank';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
},
async saveMaterialFiles() {
if (this.materialFileList.length === 0) {
this.$message.warning('请先上传课件文件');
return;
}
this.saving = true;
try {
// ID
const fileIds = this.materialFileList.map(file => {
return file.response ? file.response.id : file.id;
});
// IDID
const updateData = {
id: this.selectedCourse.id,
file_ids: fileIds
};
await saveContent(updateData);
this.$message.success('课件保存成功');
this.materialDialogVisible = false;
this.getCousreContent(); //
} catch (error) {
this.$message.error('保存失败: ' + error.message);
} finally {
this.saving = false;
}
}
},
watch: {
isShow(newVal) {
@ -259,11 +418,11 @@
html,
div {
height: auto !important;
}
table th:last-child,
table th:last-child {
display: none;
}
}
table th:last-child,
table th:last-child {
display: none;
}
}
@ -302,4 +461,60 @@
margin-right: 10px;
}
}
</style>
.material-upload-container {
.course-info {
background: #f5f7fa;
padding: 15px;
border-radius: 4px;
margin-bottom: 20px;
h4 {
margin: 0 0 10px 0;
color: #303133;
}
p {
margin: 5px 0;
color: #606266;
}
}
.upload-section {
margin-bottom: 20px;
h4 {
margin: 0 0 10px 0;
color: #303133;
}
}
.material-list {
h4 {
margin: 0 0 10px 0;
color: #303133;
}
}
}
.file-item {
margin-bottom: 5px;
&:last-child {
margin-bottom: 0;
}
.el-link {
font-size: 12px;
i {
margin-right: 4px;
}
}
}
.no-files {
color: #909399;
font-size: 12px;
}
</style>

@ -66,6 +66,51 @@
</div>
</div>
</template>
<template v-slot:files>
<div class="xy-table-item">
<div class="xy-table-item-label" style="font-weight: bold">
<span style="color: red;font-weight: bold;padding-right: 4px;"></span>课件管理
</div>
<div class="xy-table-item-content">
<!-- 现有课件列表 -->
<div v-if="form.files && form.files.length > 0" class="existing-files">
<h5>现有课件</h5>
<div v-for="file in form.files" :key="file.id" class="file-item">
<el-link type="primary" @click="downloadFile(file)" :underline="false">
<i class="el-icon-document"></i>
{{ file.original_name }}
</el-link>
<el-button type="danger" size="mini" @click="removeFile(file)" style="margin-left: 10px;">
<i class="el-icon-delete"></i> 删除
</el-button>
</div>
</div>
<!-- 上传新课件 -->
<div class="upload-section">
<h5>上传新课件</h5>
<el-upload
ref="fileUpload"
:action="uploadAction"
:headers="uploadHeaders"
:file-list="newFileList"
:on-success="handleFileUploadSuccess"
:on-remove="handleFileUploadRemove"
:on-error="handleFileUploadError"
:before-upload="beforeFileUpload"
multiple
accept=".pdf,.doc,.docx,.ppt,.pptx,.xls,.xlsx,.zip,.rar,.txt,.jpg,.jpeg,.png,.gif">
<el-button size="small" type="primary">
<i class="el-icon-upload"></i> 点击上传
</el-button>
<div slot="tip" class="el-upload__tip">
支持 PDFWordPPTExcel压缩包图片等格式单个文件不超过50MB
</div>
</el-upload>
</div>
</div>
</div>
</template>
</xy-dialog>
</div>
</template>
@ -95,10 +140,17 @@
theme: '',
address: '',
introduce: '',
files: [], //
},
rules: {
},
uploadAction: `${process.env.VUE_APP_UPLOAD_API}`, // URL
uploadHeaders: {
Authorization: `Bearer ${this.$store.getters.token}`
}, //
newFileList: [], //
removedFileIds: [], // ID
}
},
created() {},
@ -120,27 +172,41 @@
submit() {
if (this.id) {
this.form.id = this.id
}else{
this.form.id = ''
}else{
this.form.id = ''
}
save({
...this.form
}).then(res => {
// ID
const existingFileIds = this.form.files.map(file => file.id);
const newFileIds = this.newFileList.map(file => {
return file.response ? file.response.id : file.id;
});
// IDIDID
const finalFileIds = [...existingFileIds, ...newFileIds].filter(id =>
!this.removedFileIds.includes(id)
);
const submitData = {
...this.form,
file_ids: finalFileIds
};
save(submitData).then(res => {
this.$message({
type: 'success',
message: '保存课表成功'
})
saveTeacher({
id: this.form.teacher_id,
introduce: this.form.introduce
}).then(res => {
})
saveTeacher({
id: this.form.teacher_id,
introduce: this.form.introduce
}).then(res => {
})
this.isShow = false
this.$emit('refresh')
// this.active = 1
})
})
},
getDetail() {
@ -152,6 +218,53 @@
this.form.introduce = res.teacher.introduce
})
},
//
downloadFile(file) {
const link = document.createElement('a');
link.href = file.url;
link.download = file.original_name;
link.target = '_blank';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
},
//
removeFile(file) {
this.$confirm(`确定要删除课件"${file.original_name}"吗?`, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
//
this.form.files = this.form.files.filter(f => f.id !== file.id);
// ID
this.removedFileIds.push(file.id);
this.$message.success('课件删除成功');
}).catch(() => {
//
});
},
//
handleFileUploadSuccess(response, file, fileList) {
this.$message.success('课件上传成功');
this.newFileList = fileList;
},
//
handleFileUploadRemove(file, fileList) {
this.newFileList = fileList;
},
//
handleFileUploadError(err, file, fileList) {
this.$message.error('课件上传失败: ' + err);
},
//
beforeFileUpload(file) {
const isLt50M = file.size / 1024 / 1024 < 50;
if (!isLt50M) {
this.$message.error('上传文件大小不能超过 50MB!');
}
return isLt50M;
},
},
@ -162,15 +275,18 @@
this.getDetail()
}
} else {
this.id = ''
this.form = {
date: '',
period: '',
teacher_id: "",
theme: '',
address: '',
introduce: '',
this.id = ''
this.form = {
date: '',
period: '',
teacher_id: "",
theme: '',
address: '',
introduce: '',
files: [], //
}
this.newFileList = [] //
this.removedFileIds = [] // ID
this.$refs['dialog'].reset()
}
},
@ -180,5 +296,49 @@
</script>
<style scoped lang="scss">
</style>
.existing-files {
margin-bottom: 20px;
h5 {
margin: 0 0 10px 0;
color: #303133;
font-size: 14px;
}
.file-item {
display: flex;
align-items: center;
margin-bottom: 8px;
padding: 8px;
background: #f5f7fa;
border-radius: 4px;
&:last-child {
margin-bottom: 0;
}
.el-link {
flex: 1;
font-size: 12px;
i {
margin-right: 4px;
}
}
}
}
.upload-section {
h5 {
margin: 0 0 10px 0;
color: #303133;
font-size: 14px;
}
.el-upload__tip {
font-size: 12px;
color: #909399;
margin-top: 5px;
}
}
</style>

Loading…
Cancel
Save