| | |
| | | <div class="search"> |
| | | <el-form :inline="true" :model="searchForm" class="demo-form-inline"> |
| | | <el-form-item label="主题"> |
| | | <el-input v-model="searchForm.typeName" size="small" placeholder="主题内容" clearable @clear="page"></el-input> |
| | | <el-input v-model="searchForm.subject" size="small" placeholder="主题内容" clearable @clear="page"></el-input> |
| | | </el-form-item> |
| | | <el-form-item label="学习类型"> |
| | | <el-select v-model="searchForm.belongType" clearable @clear="page" @change="page" placeholder="学习类型"> |
| | | <el-option v-for="item in typeList" :key="item.id" :label="item.typeName" :value="item.id"> |
| | | </el-option> |
| | | </el-select> |
| | | </el-form-item> |
| | | <el-form-item> |
| | | <el-button type="primary" @click="page" size="small">查询</el-button> |
| | |
| | | </el-form> |
| | | <div> |
| | | <el-button type="primary" @click="handlerAdd" size="small">添加</el-button> |
| | | <el-button type="danger" @click="batchRemove" size="small" style="margin-left: 5px">删除</el-button> |
| | | </div> |
| | | </div> |
| | | <el-table |
| | | :data="tableData" |
| | | border |
| | | style="width: 100%"> |
| | | <el-table-column |
| | | fixed |
| | | prop="typeName" |
| | | label="分类名称"> |
| | | </el-table-column> |
| | | <el-table-column |
| | | prop="orderNum" |
| | | label="排序值"> |
| | | </el-table-column> |
| | | <el-table-column |
| | | prop="createTime" |
| | | label="创建时间"> |
| | | </el-table-column> |
| | | <el-table-column |
| | | fixed="right" |
| | | label="操作" |
| | | width="140"> |
| | | <template slot-scope="scope"> |
| | | <el-button @click="handleUpdate(scope.row)" type="primary" size="small" style="margin-right: 5px">修改</el-button> |
| | | |
| | | <el-popconfirm |
| | | :title="getTitle(scope.row.typeName)" |
| | | @confirm="remove(scope.row.id)" |
| | | > |
| | | |
| | | <el-table :data="tableData" border @selection-change="handleSelectionChange" style="width: 100%"> |
| | | <el-table-column type="selection" width="55"> |
| | | </el-table-column> |
| | | <el-table-column fixed prop="subject" label="主题 "> |
| | | </el-table-column> |
| | | <el-table-column prop="typeName" label="学习类型"> |
| | | </el-table-column> |
| | | <el-table-column prop="contentType" :formatter="typeFormatter" label="文件类型"> |
| | | </el-table-column> |
| | | <el-table-column label="文件内容" width="240"> |
| | | <template slot-scope="scope"> |
| | | <video controls v-if="scope.row.contentType === 'video'" :src="'/api/files/' + scope.row.contentUrl.url" |
| | | class="showContent" /> |
| | | <el-image v-if="scope.row.contentType === 'img'" :src="'/api/files/' + scope.row.contentUrl.url" |
| | | class="showContent"></el-image> |
| | | <!-- <img v-if="scope.row.contentType === 'img'" :src="'/api/files/' + scope.row.contentUrl.url" |
| | | class="showContent" /> --> |
| | | <el-link type="primary" v-if="scope.row.contentType === 'pdf'" class="showContent" |
| | | @click="checkPdf('/api/files/' + scope.row.contentUrl.url)">点击查看</el-link> |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column prop="attachment" label="附件"> |
| | | <template slot-scope="scope"> |
| | | <div v-for="item in scope.row.attachment" :key="item.url"> |
| | | <el-link type="primary" :href="'/api/upload/download?url=' + item.url +'&fileName=' + item.name" >{{ item.name }}</el-link> |
| | | </div> |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column fixed="right" label="操作" width="140"> |
| | | <template slot-scope="scope"> |
| | | <el-button @click="handleUpdate(scope.row)" type="primary" size="small" |
| | | style="margin-right: 5px">修改</el-button> |
| | | <el-popconfirm :title="getTitle(scope.row.typeName)" @confirm="remove(scope.row.id)"> |
| | | <el-button slot="reference" type="danger" size="small">删除</el-button> |
| | | </el-popconfirm> |
| | | </template> |
| | | </el-table-column> |
| | | </el-table> |
| | | |
| | | <el-dialog |
| | | title="添加文件" |
| | | :visible.sync="open" |
| | | width="600px" |
| | | <pagination v-show="total > 0" :total="total" :page.sync="searchForm.pageNum" :limit.sync="searchForm.pageSize" |
| | | @pagination="page" /> |
| | | |
| | | <el-dialog :title="dialogTitle" :visible.sync="open" width="600px" :close-on-click-modal="false" |
| | | :before-close="handleClose"> |
| | | <el-form label-position="top" label-width="80px" ref="form" :rules="rules" :model="form"> |
| | | <el-form label-position="left" label-width="120px" ref="form" :rules="rules" :model="form"> |
| | | <el-form-item label="主题" prop="subject"> |
| | | <el-input v-model="form.subject" placeholder="主题内容"></el-input> |
| | | </el-form-item> |
| | | <el-form-item label="所属类型" prop="belongType"> |
| | | <el-input v-model="form.belongType" placeholder="所属类型"></el-input> |
| | | <el-form-item label="学习类型" prop="belongType"> |
| | | <el-select v-model="form.belongType" placeholder="学习类型"> |
| | | <el-option v-for="item in typeList" :key="item.id" :label="item.typeName" :value="item.id"> |
| | | </el-option> |
| | | </el-select> |
| | | </el-form-item> |
| | | <el-form-item label="文件类型" prop="contentType"> |
| | | <el-input v-model="form.contentType" placeholder="不同类型的文件阅览方式不同,多余文件请以附件形式上传"></el-input> |
| | | <el-select v-model="form.contentType" placeholder="不同类型的文件阅览方式不同,多余文件请以附件形式上传" @change="fileChange"> |
| | | <el-option label="视频" value="video"></el-option> |
| | | <el-option label="PDF" value="pdf"></el-option> |
| | | <el-option label="图片" value="img"></el-option> |
| | | </el-select> |
| | | </el-form-item> |
| | | <el-form-item label="上传文件" prop="contentUrl"> |
| | | <upload :fileSizeLimitM="1024" :uploadNum="1" @getUploadUrl="getUploadUrl" /> |
| | | <el-form-item label="上传文件(一个)" prop="contentUrl"> |
| | | <upload v-show="form.contentType" ref="upload" :fileUrl="form.contentUrl" :fileType="form.contentType" |
| | | :fileSizeLimitM="1024" :uploadNum="1" @getUploadUrl="getUploadUrl" @removeFile="removeFile" /> |
| | | </el-form-item> |
| | | <el-form-item label="附件" prop="attachment"> |
| | | <upload :fileSizeLimitM="1024" :uploadNum="3" @getUploadUrl="getUploadAttachmentUrl" /> |
| | | <el-form-item label="附件(最多3个)" prop="attachment"> |
| | | <upload :fileSizeLimitM="1024" :uploadNum="3" :fileUrl="form.attachment" |
| | | @getUploadUrl="getUploadAttachmentUrl" @removeFile="removeAttachmentFile" /> |
| | | </el-form-item> |
| | | </el-form> |
| | | <span slot="footer" class="dialog-footer"> |
| | | <el-button @click="open = false">取 消</el-button> |
| | | <el-button type="primary" @click="handlerSubmit">添 加</el-button> |
| | | <el-button type="primary" @click="handlerSubmit">保 存</el-button> |
| | | </span> |
| | | </el-dialog> |
| | | |
| | | <el-dialog title="PDF查看" :visible.sync="pdfDialog" width="80%" :before-close="closePdfDialog"> |
| | | <vue-office-pdf :src="pdf" @rendered="rendered" /> |
| | | </el-dialog> |
| | | </div> |
| | | </template> |
| | | |
| | | <script> |
| | | import OnlineStudyAPI from '@/api/online-study' |
| | | import Upload from '@/components/UploadC' |
| | | import Pagination from '@/components/Pagination'; |
| | | import OnlineStudyAPI from '@/api/online-study'; |
| | | import StudyTypeAPI from '@/api/study-type'; |
| | | import Upload from '@/components/UploadC'; |
| | | |
| | | import VueOfficePdf from '@vue-office/pdf'; |
| | | export default { |
| | | name: 'type', |
| | | components: {Upload}, |
| | | data () { |
| | | components: { Upload, Pagination, VueOfficePdf }, |
| | | computed: { |
| | | fileContentUrl: () => { |
| | | return this.form ? this.form.contentUrl ? [this.form.contentUrl] : [] : []; |
| | | } |
| | | }, |
| | | data() { |
| | | return { |
| | | uploadAttachmentData: [], |
| | | uploadData: { |
| | | url: '', |
| | | originalFilename: '' |
| | | }, |
| | | pdf: '', |
| | | dialogTitle: '添加学习内容', |
| | | ids: [], |
| | | typeList: [], |
| | | searchForm: { |
| | | pageNum: 1, |
| | | pageSize: 10, |
| | | pageSize: 5, |
| | | typeName: '' |
| | | }, |
| | | total: 0, |
| | | tableData: [], |
| | | open: false, |
| | | pdfDialog: false, |
| | | form: { |
| | | typeName: '', |
| | | orderNum: null |
| | | contentType: 'video', |
| | | subject: '', |
| | | belongType: 2, |
| | | contentUrl: [], |
| | | attachment: [], |
| | | temp: [] |
| | | }, |
| | | rules: { |
| | | contentUrl: [ |
| | |
| | | { required: true, message: '请输入主题内容', trigger: 'blur' }, |
| | | ], |
| | | belongType: [ |
| | | { required: true, message: '请选择所属类型', trigger: 'change' } |
| | | { required: true, message: '请选择学习分类', trigger: 'change' } |
| | | ], |
| | | contentType: [ |
| | | { required: true, message: '请选择文件类型', trigger: 'change' } |
| | | ] |
| | | } |
| | | } |
| | | }; |
| | | }, |
| | | methods: { |
| | | getUploadAttachmentUrl (uploadData) { |
| | | this.form.attachment = uploadData.url |
| | | this.uploadAttachmentData = uploadData |
| | | checkPdf(url) { |
| | | this.pdf = url; |
| | | this.pdfDialog = true; |
| | | }, |
| | | closePdfDialog() { |
| | | this.pdfDialog = false; |
| | | }, |
| | | rendered() { |
| | | |
| | | }, |
| | | fileChange() { |
| | | this.form.contentUrl = []; |
| | | }, |
| | | handleSelectionChange(val) { |
| | | this.ids = val.map(item => item.id); |
| | | }, |
| | | typeFormatter(row) { |
| | | if (row.contentType === 'video') { |
| | | return "视频"; |
| | | } |
| | | if (row.contentType === 'img') { |
| | | return "图片"; |
| | | } |
| | | if (row.contentType === 'pdf') { |
| | | return "PDF"; |
| | | } |
| | | }, |
| | | clearFile() { |
| | | this.form.contentUrl = []; |
| | | this.$refs.upload.clearFile(); |
| | | }, |
| | | removeFile() { |
| | | this.form.contentUrl = []; |
| | | }, |
| | | removeAttachmentFile(fileList, fileName) { |
| | | this.form.attachment = fileList.filter(item => item.name !== fileName); |
| | | }, |
| | | getUploadAttachmentUrl(uploadData) { |
| | | this.form.attachment = uploadData; |
| | | }, |
| | | getUploadUrl(uploadData) { |
| | | this.form.contentUrl = uploadData.url |
| | | this.uploadData = uploadData |
| | | this.form.contentUrl = uploadData; |
| | | }, |
| | | remove (id) { |
| | | OnlineStudyAPI.remove(id).then(res => { |
| | | remove(id) { |
| | | OnlineStudyAPI.remove([id]).then(res => { |
| | | if (res.code === 1) { |
| | | this.$message.success('删除成功') |
| | | this.$message.success('删除成功'); |
| | | this.page() |
| | | } |
| | | }) |
| | | }); |
| | | }, |
| | | getTitle (typeName) { |
| | | return '确定要删除' + typeName + '这个分类吗?' |
| | | batchRemove() { |
| | | if (this.ids.length < 1) { |
| | | this.$message.warning("请选择要删除的数据"); |
| | | } |
| | | OnlineStudyAPI.remove(this.ids).then(res => { |
| | | if (res.code === 1) { |
| | | this.$message.success('删除成功'); |
| | | this.ids = []; |
| | | } |
| | | }); |
| | | }, |
| | | handlerSubmit () { |
| | | getTitle(typeName) { |
| | | return '确定要删除' + typeName + '这个文件吗?'; |
| | | }, |
| | | handlerSubmit() { |
| | | this.$refs['form'].validate((valid) => { |
| | | if (valid) { |
| | | if (this.form.id) { |
| | | OnlineStudyAPI.update(this.form).then(res => { |
| | | const temp = JSON.parse(JSON.stringify(this.form)); |
| | | // this.form.contentUrl = this.form.contentUrl[0] |
| | | temp.contentUrl = temp.contentUrl[0]; |
| | | if (temp.id) { |
| | | OnlineStudyAPI.update(temp).then(res => { |
| | | if (res.code === 1) { |
| | | this.$message.success('修改成功') |
| | | this.open = false |
| | | this.page() |
| | | this.$message.success('修改成功'); |
| | | this.open = false; |
| | | this.page(); |
| | | } |
| | | }) |
| | | }); |
| | | } else { |
| | | OnlineStudyAPI.add(this.form).then(res => { |
| | | OnlineStudyAPI.add(temp).then(res => { |
| | | if (res.code === 1) { |
| | | this.$message.success('添加成功') |
| | | this.open = false |
| | | this.page() |
| | | this.$message.success('添加成功'); |
| | | this.open = false; |
| | | this.page(); |
| | | } |
| | | }) |
| | | }); |
| | | } |
| | | } |
| | | }) |
| | | }); |
| | | }, |
| | | handleClose () { |
| | | this.open = false |
| | | resetForm() { |
| | | this.form = { |
| | | contentType: 'video', |
| | | subject: '', |
| | | belongType: 2, |
| | | contentUrl: [], |
| | | attachment: [], |
| | | temp: [] |
| | | }; |
| | | }, |
| | | handlerAdd () { |
| | | this.form = {} |
| | | this.open = true |
| | | handleClose() { |
| | | this.open = false; |
| | | this.resetForm(); |
| | | }, |
| | | page () { |
| | | handlerAdd() { |
| | | this.resetForm(); |
| | | this.open = true; |
| | | this.dialogTitle = '添加学习内容'; |
| | | }, |
| | | page() { |
| | | OnlineStudyAPI.page(this.searchForm).then(res => { |
| | | if (res.code === 1) { |
| | | this.tableData = res.response |
| | | this.tableData = res.response; |
| | | this.total = res.total; |
| | | } |
| | | }) |
| | | }); |
| | | }, |
| | | handleUpdate (row) { |
| | | this.form.typeName = row.typeName |
| | | this.form.orderNum = row.orderNum |
| | | this.form.id = row.id |
| | | this.open = true |
| | | handleUpdate(row) { |
| | | this.form.id = row.id; |
| | | this.form.contentType = row.contentType; |
| | | this.form.contentUrl = [row.contentUrl] || []; |
| | | this.form.attachment = row.attachment || []; |
| | | this.form.subject = row.subject; |
| | | this.form.belongType = row.belongType; |
| | | this.dialogTitle = '修改学习内容'; |
| | | this.open = true; |
| | | } |
| | | }, |
| | | mounted () { |
| | | this.page() |
| | | mounted() { |
| | | this.page(); |
| | | StudyTypeAPI.list().then(res => { |
| | | if (res.code === 1) { |
| | | this.typeList = res.response; |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | }; |
| | | </script> |
| | | |
| | | <style scoped> |
| | | .showContent { |
| | | width: 100%; |
| | | min-height: 80px; |
| | | object-fit: contain; |
| | | } |
| | | |
| | | .warp { |
| | | margin: 40px 10px; |
| | | } |
| | | |
| | | .search { |
| | | margin-top: 10px; |
| | | } |
| | | ::v-deep .el-image__error { |
| | | position: absolute; |
| | | top: 0; |
| | | bottom: 0; |
| | | } |
| | | </style> |