123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047 |
- <!--课件资源-->
- <template>
- <div class="app-container el-resources">
- <div v-if="pageType == 1" class="list-max-big-box">
- <div class="top-max-box">
- <div class="left-max-box scrollbar-box">
- <div class="classify_btn" @click="clickPage(5,'')">管理分类 >></div>
- <el-tree
- :data="treeData"
- :props="defaultProps"
- :highlight-current="true"
- :expand-on-click-node="false"
- :filter-node-method="filterNode"
- node-key="id"
- ref="tree"
- default-expand-all
- @node-click="handleNodeClick"
- />
- </div>
- <div class="center-max-box" v-hasPermiRouter="['exam:el_category:list']"></div>
- <div class="right-max-box">
- <el-form :model="queryParams" ref="queryForm" :inline="true"
- style="height:60px;"
- v-show="showSearch" label-width="80px">
- <el-form-item label="" prop="title">
- <el-input
- v-model="queryParams.title"
- maxLength="20"
- placeholder="请输入课件名称"
- clearable
- size="small"
- />
- </el-form-item>
- <el-form-item label="" prop="type">
- <el-select v-model="queryParams.type" clearable placeholder="请选择课件类型">
- <el-option
- v-for="item in coursewareType"
- :key="item.dictValue"
- :label="item.dictLabel"
- :value="item.dictValue">
- </el-option>
- </el-select>
- </el-form-item>
- <el-form-item style="float: right;">
- <el-col :span="1.5">
- <p class="page-submit-common-style-button"
- @click="handleAdd"
- style="width:120px;"
- v-hasPermiRouter="['exam:elResources:add']"
- >新增文件课件</p>
- </el-col>
- <el-col :span="1.5">
- <p class="page-add-common-style-button"
- style="width:140px;margin-left:10px;"
- @click="richTextAddClick(1)"
- v-hasPermiRouter="['exam:elResources:add']"
- >新增富文本课件</p>
- </el-col>
- </el-form-item>
- <el-form-item>
- <p class="page-inquire-common-style-button" @click="handleQuery">查询</p>
- <p class="page-reset-common-style-button" @click="resetQuery">重置</p>
- </el-form-item>
- </el-form>
- <div class="min-list-box">
- <el-table class="table-box" v-loading="loading" border :data="el_resourcesList" @selection-change="handleSelectionChange">
- <el-table-column label="课件名称" align="left" prop="title" />
- <el-table-column label="分类" align="left" prop="cateTitle" width="160"/>
- <el-table-column label="类型" align="left" prop="type" width="110">
- <template slot-scope="scope">
- {{scope.row.type==1?'文档':(scope.row.type==2?'视频':(scope.row.type==3?'图片':(scope.row.type==4?'音频':(scope.row.type==5?'富文本':"其他"))))}}
- </template>
- </el-table-column>
- <el-table-column label="格式" align="left" prop="postfix" width="110"/>
- <el-table-column label="大小" align="left" prop="sizeStr" width="110"/>
- <el-table-column label="上传时间" align="left" prop="createTime" width="220"/>
- <el-table-column label="操作" align="left" class-name="small-padding fixed-width" width="160" v-if="tableButtonType">
- <template slot-scope="scope">
- <div class="table-button-box">
- <p class="table-button-null"></p>
- <p class="table-button-p"
- @click="handleUpdate(scope.row)"
- v-hasPermiRouter="['exam:elResources:add','exam:elResources:edit']"
- >修改</p>
- <p class="table-button-p"
- @click="handleDelete(scope.row)"
- v-hasPermiRouter="['exam:elResources:del']"
- >删除</p>
- <p class="table-button-null"></p>
- </div>
- </template>
- </el-table-column>
- </el-table>
- </div>
- </div>
- </div>
- <div class="bottom-max-box">
- <pagination :page-sizes="[20, 30, 40, 50]"
- v-show="total>0"
- :total="total"
- layout="total, prev, pager, next, sizes, jumper"
- :page.sync="queryParams.page"
- :limit.sync="queryParams.pageSize"
- @pagination="getList"
- />
- </div>
- <!-- 添加资源对话框 -->
- <el-dialog class="el_resources_dialog" @close="handleClose" :title="title" :visible.sync="open" width="700px" append-to-body :before-close="offUpPage" :close-on-click-modal="false">
- <el-form ref="form" :model="form" v-loading="loading" :rules="rules" label-width="80px">
- <el-form-item label="分类" prop="title">
- <el-input
- style="width: 100%;"
- v-model="typeTitle"
- maxLength="25"
- placeholder=""
- disabled
- clearable
- size="small"
- />
- </el-form-item>
- <el-form-item label="课件名称" prop="name">
- <el-input
- disabled
- style="width: 100%;"
- v-model="coursewareName"
- maxLength="25"
- placeholder="课件名称"
- clearable
- size="small"
- />
- </el-form-item>
- <uploader
- :autoStart="false"
- :options="options"
- ref="uploader"
- :file-list="fileList"
- :file-status-text="statusText"
- class="uploader-example"
- @file-complete="fileComplete"
- @complete="complete"
- @file-success="fileSuccess"
- @files-added="filesAdded">
- <uploader-unsupport></uploader-unsupport>
- <uploader-drop>
- <i class="el-icon-upload"></i>
- <div class="el-upload__text">将文件拖到此处,或 <uploader-btn :attrs="attrs">点击上传</uploader-btn></div>
- </uploader-drop>
- <!-- <uploader-list></uploader-list> -->
- <uploader-files> </uploader-files>
- </uploader>
- <div class="up-text-box" style="margin-top:20px;max-height:400px;overflow-y: scroll">
- <div v-for="(item,index) in upTextList" :key="index" style="margin-left:30px;">
- <div style="display: flex">
- <p style="flex:1;font-size:14px;margin:0;">{{item.title}}.{{item.postfix}}</p>
- <p style="flex:1;font-size:14px;margin:0;text-align: right;margin-right:50px;">{{item.sizeStr}}</p>
- </div>
- <div>
- <el-progress :percentage="100" status="success"></el-progress>
- </div>
- </div>
- </div>
- <div class="up-data-box-text">
- <p>支持上传视频、图片、文件类型的课件</p>
- <p>图片请上传 png / jpeg / gif 格式</p>
- <p>视频请上传 mp4</p>
- <p>文件请上传 pdf / docx 格式</p>
- </div>
- </el-form>
- </el-dialog>
- <!--修改资源对话框-->
- <el-dialog class="el_resources_dialog" @close="handleClose" :title="title" :visible.sync="openEdit" width="700px" append-to-body :before-close="offUpPage" :close-on-click-modal="false">
- <el-form ref="editForm" :model="editForm" v-loading="loading" :rules="rules" label-width="80px">
- <el-form-item label="分类" prop="title">
- <el-input
- style="width: 100%;"
- v-model="editForm.cateTitle"
- maxLength="25"
- placeholder=""
- disabled
- clearable
- size="small"
- />
- </el-form-item>
- <el-form-item label="课件名称" prop="title">
- <el-input
- disabled
- v-model="editForm.title"
- maxLength="20"
- placeholder="请输入课件名称"
- clearable
- />
- </el-form-item>
- <div class="up-button-box">
- <uploader
- :autoStart="false"
- :options="options"
- ref="uploader"
- :file-list="fileList"
- :file-status-text="statusText"
- class="uploader-example"
- @file-complete="fileComplete"
- @complete="complete"
- @file-success="fileSuccess"
- @files-added="filesAdded">
- <uploader-unsupport></uploader-unsupport>
- <uploader-drop>
- <i class="el-icon-upload"></i>
- <div class="el-upload__text">将文件拖到此处,或 <uploader-btn :attrs="attrs">点击上传</uploader-btn></div>
- </uploader-drop>
- <!-- <uploader-list></uploader-list> -->
- <uploader-files> </uploader-files>
- </uploader>
- <div class="up-text-box" style="margin-top:20px;max-height:400px;overflow-y: scroll">
- <div v-for="(item,index) in upTextList" :key="index" style="margin-left:30px;">
- <div style="display: flex">
- <p style="flex:1;font-size:14px;margin:0;">{{item.title}}.{{item.postfix}}</p>
- <p style="flex:1;font-size:14px;margin:0;text-align: right;margin-right:50px;">{{item.sizeStr}}</p>
- </div>
- <div>
- <el-progress :percentage="100" status="success"></el-progress>
- </div>
- </div>
- </div>
- <div class="up-data-box-text">
- <p>支持上传视频、图片、文件类型的课件</p>
- <p>图片请上传 png / jpeg / gif 格式</p>
- <p>视频请上传 mp4 / WebM格式 </p>
- <p>文件请上传 pdf / docx 格式</p>
- </div>
- </div>
- </el-form>
- </el-dialog>
- <!--富文本新增课件-->
- <el-dialog class="el_resources_dialog" @close="handleClose" :title="title" :visible.sync="richTextAddType" :close-on-click-modal="false"
- v-if="richTextAddType" width="1100px" append-to-body :before-close="offUpPage">
- <el-form ref="richTextForm" :model="richTextForm" v-loading="loading" :rules="richTextRules" label-width="100px" style="flex-direction: column;display: flex;">
- <el-form-item label="分类">
- <el-input
- style="width: 100%;"
- v-model="typeTitle"
- maxLength="25"
- placeholder=""
- disabled
- clearable
- size="small"
- />
- </el-form-item>
- <el-form-item label="课件名称" prop="title">
- <el-input
- style="width: 100%;"
- v-model="richTextForm.title"
- maxLength="20"
- placeholder="请输入课件名称"
- clearable
- />
- </el-form-item>
- <el-form-item label="课件内容" prop="content" style="width:1000px;height:500px;overflow-y: scroll" class="scrollbar-box">
- <editor v-model="richTextForm.content" :min-height="192"/>
- </el-form-item>
- </el-form>
- <!--公共操作按钮-->
- <div slot="footer" class="dialog-footer dialog-footer-box">
- <p class="dialog-footer-button-null"></p >
- <p class="dialog-footer-button-info" @click="richTextCancel">取消</p >
- <p class="dialog-footer-button-primary" @click="richTextClick">提交</p >
- <p class="dialog-footer-button-null"></p >
- </div>
- </el-dialog>
- <!--富文本修改课件-->
- <el-dialog class="el_resources_dialog" @close="handleClose" :title="title" :visible.sync="richTextEditType" :close-on-click-modal="false"
- v-if="richTextEditType" width="1100px" append-to-body :before-close="offUpPage">
- <el-form ref="richTextForm" :model="richTextForm" v-loading="loading" :rules="richTextRules" label-width="80px">
- <el-form-item label="分类" prop="title">
- <el-input
- style="width: 100%;"
- v-model="typeTitle"
- maxLength="25"
- placeholder=""
- disabled
- clearable
- size="small"
- />
- </el-form-item>
- <el-form-item label="课件名称" prop="title">
- <el-input
- v-model="richTextForm.title"
- maxLength="20"
- placeholder="请输入课件名称"
- clearable
- />
- </el-form-item>
- <el-form-item label="课件内容" prop="content" style="width:1000px;height:500px;overflow-y: scroll" class="scrollbar-box">
- <editor v-model="richTextForm.content" :min-height="192"/>
- </el-form-item>
- </el-form>
- <!--公共操作按钮-->
- <div slot="footer" class="dialog-footer dialog-footer-box">
- <p class="dialog-footer-button-null"></p >
- <p class="dialog-footer-button-info" @click="richTextCancel">取消</p >
- <p class="dialog-footer-button-primary" @click="richTextClick">提交</p >
- <p class="dialog-footer-button-null"></p >
- </div>
- </el-dialog>
- </div>
- <!--管理分类-->
- <add-classify v-if="pageType == 5" :pageData="pageData"></add-classify>
- </div>
- </template>
- <script>
- import {
- examElCategoryTreeList,
- examElResourcesList,
- examElResourcesDel,
- examElResourcesAdd,
- examElResourcesUpdate,
- examElResourcesAddText,
- examElResourcesUpdateText
- } from "@/api/safetyEducationExam/index";
- import { getToken } from "@/utils/auth";
- import addClassify from "../el_category/index";
- import axios from "axios";
- import SparkMD5 from "spark-md5";
- let httpHeader=window.location.href.split('://')[0]+'://'
- export default {
- name: "El_resources",
- components: {
- addClassify
- },
- data() {
- let checkName = (rule, value, callback) => {
- let reg = /^\s+$/;
- if(reg.test(value)){
- return callback(new Error(''));
- }
- }
- return {
- tableButtonType:this.hasPermiDom(['exam:elResources:add','exam:elResources:edit','exam:elResources:del']),
- //页面状态
- pageType:1,
- pageData:{
- type:1,//1资源管理2课程管理
- },
- // 上传相关
- uploadImgUrl: "",
- headers: {
- Authorization: "Bearer " + getToken()
- },
- cateId:"",
- //树数据
- treeData:[],
- defaultProps: {
- children: "children",
- label: "title"
- },
- // 遮罩层
- loading: true,
- // 选中数组
- ids: [],
- // 非单个禁用
- single: true,
- // 非多个禁用
- multiple: true,
- // 显示搜索条件
- showSearch: true,
- // 总条数
- total: 0,
- // 课件资源表格数据
- el_resourcesList: [],
- // 弹出层标题
- title: "",
- // 是否显示弹出层
- open: false,
- //文件路径
- filePath:null,
- //文件名称
- fileName: null,
- //文件大小
- fileSize: null,
- // 查询参数
- queryParams: {
- page: 1,
- pageSize:20,
- cateId: "",
- title: null,
- type: null,
- },
- // 表单参数
- form: {},
- typeTitle:'',//点击的分类名称
- coursewareName:'',//课件名称
- // 表单校验
- rules: {
- cateId: [
- { required: true, message: "分类id不能为空", trigger: "blur" }
- ],
- },
- richTextRules: {
- title: [
- { required: true, message: "请输入课件名称", trigger: "blur" },
- { required: true, message: "请输入课件名称", validator: this.spaceJudgment, trigger: "blur" }
- ],
- content: [
- { required: true, message: "请输入课件内容", trigger: "blur" },
- { required: true, message: "请输入课件内容", validator: this.spaceJudgmentHTML, trigger: "blur" }
- ],
- },
- //课件类型
- coursewareType:[
- {dictLabel:"文档", dictValue:"1",},
- {dictLabel:"视频", dictValue:"2",},
- {dictLabel:"图片", dictValue:"3",},
- // {dictLabel:"音频", dictValue:"4",},
- {dictLabel:"富文本", dictValue:"5",}
- ],
- //上传成功展示列表
- upTextList:[],
- //修改页面
- openEdit:false,
- editForm:{
- id:'',
- },
- //修改上传
- editTree:[],
- fileList:[],
- //富文本数据
- richTextForm:{},
- //富文本课件状态
- richTextAddType:false,
- //富文本课件状态
- richTextEditType:false,
- skip: false,
- options: {
- target: httpHeader+this.judgmentNetworkReturnAddress()+"/system/file/upload/chunk2",
- // 开启服务端分片校验功能
- testChunks: true,
- single: true,
- fileParameterName: 'file',
- // testMethod: 'post',
- //uploadMethod: 'get',
- headers: {
- Authorization:getToken()
- },
- parseTimeRemaining: function (timeRemaining, parsedTimeRemaining) {
- return parsedTimeRemaining
- .replace(/\syears?/, "年")
- .replace(/\days?/, "天")
- .replace(/\shours?/, "小时")
- .replace(/\sminutes?/, "分钟")
- .replace(/\sseconds?/, "秒");
- },
- // // 服务器分片校验函数
- checkChunkUploadedByResponse: (chunk, message) => {
- const result = JSON.parse(message);
- if (result.data.skipUpload) {
- this.skip = true;
- return true;
- }
- return (result.data.uploaded || []).indexOf(chunk.offset + 1) >= 0;
- },
- },
- attrs: {
- accept: ["image/png","image/jpeg","image/gif","application/pdf","video/mp4","application/vnd.openxmlformats-officedocument.wordprocessingml.document"]
- },
- statusText: {
- success: "上传成功",
- error: "上传出错了",
- uploading: "上传中...",
- paused: "暂停中...",
- waiting: "等待中...",
- cmd5: "计算文件MD5中...",
- },
- disabled: true,
- };
- },
- watch: {
- fileList(o, n) {
- this.disabled = false;
- },
- },
- created() {
- this.getTreeData();
- },
- methods: {
- /*
- unescape(response.data.content) 解码
- escape(this.form.content) 编码
- */
- clickPage(type){
- if(type==1){
- this.pageType=1
- this.getTreeData();
- this.getList();
- }else if(type==5){
- this.pageType=5
- }
- },
- //监听弹窗关闭
- handleClose(){
- // this.typeTitle='';
- // this.coursewareName='';
- // this.queryParams.cateId='';
- // this.$refs.tree.setCurrentKey(null);
- },
- //富文本课件提交按钮
- richTextClick(){
- this.$refs["richTextForm"].validate(valid => {
- if (valid) {
- if(this.richTextAddType){
- //新增
- let obj = {
- cateId:this.richTextForm.cateId,
- title:this.richTextForm.title,
- content:escape(this.richTextForm.content),
- type:"5",
- }
- this.loading = true;
- examElResourcesAddText(obj).then( response => {
- this.msgSuccess("新增成功");
- this.loading = false;
- this.richTextCancel();
- this.getList();
- });
- }else if(this.richTextEditType){
- //修改
- let obj = {
- id:this.richTextForm.id,
- cateId:this.richTextForm.cateId,
- title:this.richTextForm.title,
- content:escape(this.richTextForm.content),
- type:"5",
- };
- examElResourcesUpdateText(obj).then( response => {
- this.msgSuccess("修改成功");
- this.loading = false;
- this.richTextCancel();
- this.getList();
- });
- }
- }
- });
- },
- //新增富文本按钮
- richTextAddClick(type,row){
- let self = this;
- if(type == 1){
- if(!this.queryParams.cateId){
- this.msgError('请在左侧列表选择分类')
- return
- }
- this.richTextForm = {};
- this.title = "新增课件"
- this.richTextForm.cateId = this.queryParams.cateId;
- this.richTextAddType = true;
- }else if(type == 2){
- this.title = "编辑课件"
- this.richTextForm = row;
- this.richTextForm.cateId = row.cateId;
- this.richTextForm.content = unescape(row.content);
- this.richTextEditType = true;
- }
- },
- //关闭富文本按钮
- richTextCancel(){
- this.richTextAddType = false;
- this.richTextEditType = false;
- },
- //关闭新增上传页面
- offUpPage(done){
- if(this.upTextList[0]){
- this.getList();
- }
- done();
- },
- /** 查询分类树 */
- getTreeData() {//type 1资源 2课程
- this.loading = true;
- examElCategoryTreeList({},1).then( response => {
- let list = [];
- let obj = {
- children:[],
- title:"所有分类",
- id:"",
- };
- list.push(obj);
- for(let i=0;i<response.data.length;i++){
- list.push(response.data[i]);
- }
- this.treeData = list;
- this.editTree = JSON.parse(JSON.stringify(response.data));
- this.getList();
- });
- },
- // 筛选节点
- filterNode(value, data) {
- if (!value) return true;
- return data.label.indexOf(value) !== -1;
- },
- // 节点单击事件
- handleNodeClick(data,node) {
- let self = this;
- this.queryParams.cateId = data.id;
- let text = '';
- for(let i=0;i<self.treeData.length;i++){
- if (data.id == self.treeData[i].id){
- text = self.treeData[i].title;
- break
- }
- for(let o=0;o<self.treeData[i].children.length;o++){
- if (data.id == self.treeData[i].children[o].id){
- text = self.treeData[i].title +'/'+ self.treeData[i].children[o].title;
- break
- }
- for(let x=0;x<self.treeData[i].children[o].children.length;x++){
- if (data.id == self.treeData[i].children[o].children[x].id){
- text = self.treeData[i].title +'/'+ self.treeData[i].children[o].title + '/' + self.treeData[i].children[o].children[x].title;
- break
- }
- }
- }
- }
- self.typeTitle=text
- //根据id查找父元素
- this.getList();
- },
- //根据id查找父元素
- familyTree (arr1, id) {
- var temp = []
- var forFn = function (arr, id) {
- for (var i = 0; i < arr.length; i++) {
- var item = arr[i]
- if (item.id === id) {
- temp.push(item)
- forFn(arr1, item.parentId)
- break
- } else {
- if (item.children) {
- forFn(item.children, id)
- }
- }
- }
- }
- forFn(arr1, id)
- return temp
- },
- /** 查询课件资源列表 */
- getList() {
- this.loading = true;
- examElResourcesList(this.queryParams).then( response => {
- this.el_resourcesList = response.data.records;
- this.total = response.data.total;
- this.loading = false;
- });
- },
- // 取消按钮
- cancel() {
- if(this.loading){
- return
- }
- this.editForm = {};
- this.fileList = [];
- this.upTextList = [];
- this.openEdit = false;
- this.reset();
- },
- // 表单重置
- reset() {
- this.form = {
- id: null,
- createBy: null,
- updateBy: null,
- createTime: null,
- updateTime: null,
- remark: null,
- cateId: null,
- title: null,
- type: null,
- };
- this.resetForm("form");
- },
- /** 搜索按钮操作 */
- handleQuery() {
- this.queryParams.page = 1;
- this.getList();
- },
- /** 重置按钮操作 */
- resetQuery() {
- // this.resetForm("queryForm");
- this.$set(this,'queryParams',{
- page: 1,
- pageSize:20,
- cateId:"",
- title: '',
- type:'',
- id:'',
- });
- this.$refs.tree.setCurrentKey();
- this.handleQuery();
- },
- // 多选框选中数据
- handleSelectionChange(selection) {
- this.ids = selection.map(item => item.id)
- this.single = selection.length!==1
- this.multiple = !selection.length
- },
- /** 新增按钮操作 */
- handleAdd() {
- if(!this.queryParams.cateId){
- this.msgError('请在左侧列表选择分类')
- return
- }
- this.reset();
- this.coursewareName='';
- this.editForm.cateId='';
- this.editForm.id='';
- this.uploadImgUrl = window.location.href.split('://')[0]+'://' + this.judgmentNetworkReturnAddress() + "/exam/el_resources?cateId=" + this.queryParams.cateId
- this.upTextList = [];
- this.open = true;
- this.title = "添加课件资源";
- },
- addResource(filePath){
- let _this=this;
- let obj={
- cateId:this.queryParams.cateId,
- id:this.queryParams.id,
- path:filePath,
- fileName:this.fileName,
- size:this.fileSize
- }
- examElResourcesAdd(obj).then( response => {
- this.msgSuccess("新增成功");
- this.coursewareName=response.data.fileName;//课件名称
- this.loading = false;
- setTimeout(function (){
- _this.open = false;
- },2000)
- this.richTextCancel();
- this.allRemove();
- this.getList();
- });
- },
- updateResource(filePath) {
- let _this=this;
- let obj = {
- id: this.editForm.id,
- cateId: this.editForm.cateId,
- title: this.editForm.title,
- path: filePath,
- fileName: this.fileName,
- size: this.fileSize
- }
- examElResourcesUpdate(obj).then(response => {
- this.msgSuccess("修改成功");
- this.loading = false;
- this.openEdit = false;
- this.coursewareName=response.data.fileName;//课件名称
- this.loading = false;
- setTimeout(function (){
- _this.open = false;
- },2000)
- this.allRemove();
- this.getList();
- });
- },
- /** 修改按钮操作 */
- handleUpdate(row) {
- let self = this;
- //根据id查找父元素
- let treeName=this.familyTree(this.treeData,row.cateId)
- let treeName1=treeName.reverse()
- let treeArr=[]
- treeName1.forEach(function (item){
- treeArr.push(item.title)
- })
- // self.typeTitle=treeArr.join('/')
- let text = '';
- for(let i=0;i<self.treeData.length;i++){
- if (row.cateId == self.treeData[i].id){
- text = self.treeData[i].title;
- break
- }
- for(let o=0;o<self.treeData[i].children.length;o++){
- if (row.cateId == self.treeData[i].children[o].id){
- text = self.treeData[i].title +'/'+ self.treeData[i].children[o].title;
- break
- }
- for(let x=0;x<self.treeData[i].children[o].children.length;x++){
- if (row.cateId == self.treeData[i].children[o].children[x].id){
- text = self.treeData[i].title +'/'+ self.treeData[i].children[o].title + '/' + self.treeData[i].children[o].children[x].title;
- break
- }
- }
- }
- }
- if(text[0]){
- self.typeTitle=text
- }else{
- self.typeTitle='该分类已删除'
- }
- if(row.type=='5'){
- this.richTextAddClick(2,row)
- return
- }
- this.coursewareName=row.title
- // this.queryParams.cateId=row.cateId
- //this.queryParams.id=row.id
- this.editForm.cateId=row.cateId
- this.editForm.id=row.id
- this.reset();
- this.uploadImgUrl = window.location.href.split('://')[0]+'://' + this.judgmentNetworkReturnAddress() + "/exam/el_resources?cateId=" + this.queryParams.cateId
- this.upTextList = [];
- this.open = true;
- this.title = "修改课件资源";
- },
- /** 删除按钮操作 */
- handleDelete(row) {
- const ids = row.id || this.ids;
- this.$confirm('是否确认删除?', "警告", {
- confirmButtonText: "确定",
- cancelButtonText: "取消",
- type: "warning"
- }).then(function() {
- return examElResourcesDel(ids);
- }).then(() => {
- this.getList();
- this.msgSuccess("删除成功");
- }).catch(() => {});
- },
- fileSuccess(rootFile, file, response, chunk) {
- const result = JSON.parse(response);
- if (result.code==200 && !this.skip) {
- axios.post(httpHeader+this.judgmentNetworkReturnAddress()+"/system/file/upload/merge", {
- identifier: file.uniqueIdentifier,
- filename: file.name,
- totalChunks: chunk.offset,
- },{
- headers: {
- Authorization:getToken()
- }
- }).then((res) => {
- if (res.data.code==200) {
- if(!this.editForm.id){//新增
- this.addResource(res.data.data);
- }else{//修改
- this.updateResource(res.data.data);
- }
- this.filePath=res.data.data;
- } else {
- }
- }).catch(function (error) {
- });
- } else {
- }
- if (this.skip) {
- this.skip = false;
- }
- },
- fileComplete(rootFile) {
- // 一个根文件(文件夹)成功上传完成。
- this.fileName=rootFile.name;
- this.fileSize=rootFile.size;
- },
- complete(file) {
- // 上传完毕。
- },
- filesAdded(file, fileList, event) {
- file.forEach((item)=>{
- if(["image/png","image/jpeg","image/gif",
- "application/pdf",
- "video/mp4",
- "application/vnd.openxmlformats-officedocument.wordprocessingml.document"].indexOf(item.fileType) === -1){
- this.$message.error("文件格式不支持,请上传正确的文件.");
- file.ignored = true;
- }else{
- this.fileList.push(item);
- this.computeMD5(item);
- }
- })
- },
- computeMD5(file) {
- let fileReader = new FileReader();
- let time = new Date().getTime();
- let blobSlice = File.prototype.slice || File.prototype.mozSlice || File.prototype.webkitSlice;
- let currentChunk = 0;
- const chunkSize = 1024 * 1024;
- let chunks = Math.ceil(file.size / chunkSize);
- let spark = new SparkMD5.ArrayBuffer();
- // 文件状态设为"计算MD5"
- file.cmd5 = true; //文件状态为“计算md5...”
- file.pause();
- loadNext();
- fileReader.onload = (e) => {
- spark.append(e.target.result);
- if (currentChunk < chunks) {
- currentChunk++;
- loadNext();
- // 实时展示MD5的计算进度
- } else {
- let md5 = spark.end();
- spark.destroy(); //释放缓存
- file.uniqueIdentifier = md5; //将文件md5赋值给文件唯一标识
- file.cmd5 = false; //取消计算md5状态
- file.resume(); //开始上传
- }
- };
- fileReader.onerror = function () {
- this.error(`文件${file.name}读取出错,请检查该文件`);
- file.cancel();
- };
- function loadNext() {
- let start = currentChunk * chunkSize;
- let end = start + chunkSize >= file.size ? file.size : start + chunkSize;
- fileReader.readAsArrayBuffer(blobSlice.call(file.file, start, end));
- }
- },
- allRemove() {
- this.fileList.map((e) => {
- e.cancel();
- });
- this.fileList = [];
- },
- }
- };
- </script>
- <style scoped lang="scss">
- .el-resources {
- display: flex!important;
- flex-direction: column;
- box-shadow: 0 0 8px 2px rgba(0, 0, 0, 0.1);
- /*padding:20px!important;*/
- .list-max-big-box{
- flex:1;
- display: flex!important;
- flex-direction: column;
- padding:20px!important;
- overflow: hidden;
- .top-max-box{
- flex:1;
- display: flex;
- overflow: hidden!important;
- .left-max-box{
- width:250px;
- .classify_btn{
- font-size: 14px;
- font-family: Microsoft YaHei;
- font-weight: 400;
- color: #0183FA;
- line-height: 70px;
- cursor: pointer;
- text-align: left;
- }
- }
- .center-max-box{
- border-right:2px dashed #E0E0E0;
- margin-right:30px;
- margin-top:20px;
- }
- .right-max-box{
- flex:1;
- display: flex;
- flex-direction: column;
- overflow: hidden!important;
- .min-list-box{
- flex: 1;
- overflow: hidden!important;
- display: flex;
- .button-box{
- width:190px;
- display: flex;
- }
- }
- }
- }
- .bottom-max-box{
- height:50px;
- }
- }
- }
- .uploader{
- .uploader-drop{
- height: 200px;
- background: #fff;
- border-radius: 6px;
- text-align: center;
- >i{
- width: 100px;
- height: 78px;
- font-size: 78px;
- color: #0183FA;
- margin-top: 20px;
- }
- .uploader-btn{
- padding: 0;
- color: #0183FA;
- border: 0;
- cursor: pointer;
- background: none;
- outline: none;
- font-size: 14px;
- }
- }
- }
- .el_resources_dialog{
- //上传描述
- .up-data-box-text{
- margin-bottom:20px;
- p{
- margin:0;
- padding:0;
- line-height:24px;
- font-size:12px;
- color:#999;
- text-align: center;
- }
- }
- }
- </style>
- <style lang="scss">
- .el-resources{
- .el-tree-node__label{
- width: 188px;
- display:block;
- overflow:hidden;
- text-overflow:ellipsis;
- white-space:nowrap;
- }
- }
- </style>
|