index.vue 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047
  1. <!--课件资源-->
  2. <template>
  3. <div class="app-container el-resources">
  4. <div v-if="pageType == 1" class="list-max-big-box">
  5. <div class="top-max-box">
  6. <div class="left-max-box scrollbar-box">
  7. <div class="classify_btn" @click="clickPage(5,'')">管理分类 >></div>
  8. <el-tree
  9. :data="treeData"
  10. :props="defaultProps"
  11. :highlight-current="true"
  12. :expand-on-click-node="false"
  13. :filter-node-method="filterNode"
  14. node-key="id"
  15. ref="tree"
  16. default-expand-all
  17. @node-click="handleNodeClick"
  18. />
  19. </div>
  20. <div class="center-max-box" v-hasPermiRouter="['exam:el_category:list']"></div>
  21. <div class="right-max-box">
  22. <el-form :model="queryParams" ref="queryForm" :inline="true"
  23. style="height:60px;"
  24. v-show="showSearch" label-width="80px">
  25. <el-form-item label="" prop="title">
  26. <el-input
  27. v-model="queryParams.title"
  28. maxLength="20"
  29. placeholder="请输入课件名称"
  30. clearable
  31. size="small"
  32. />
  33. </el-form-item>
  34. <el-form-item label="" prop="type">
  35. <el-select v-model="queryParams.type" clearable placeholder="请选择课件类型">
  36. <el-option
  37. v-for="item in coursewareType"
  38. :key="item.dictValue"
  39. :label="item.dictLabel"
  40. :value="item.dictValue">
  41. </el-option>
  42. </el-select>
  43. </el-form-item>
  44. <el-form-item style="float: right;">
  45. <el-col :span="1.5">
  46. <p class="page-submit-common-style-button"
  47. @click="handleAdd"
  48. style="width:120px;"
  49. v-hasPermiRouter="['exam:elResources:add']"
  50. >新增文件课件</p>
  51. </el-col>
  52. <el-col :span="1.5">
  53. <p class="page-add-common-style-button"
  54. style="width:140px;margin-left:10px;"
  55. @click="richTextAddClick(1)"
  56. v-hasPermiRouter="['exam:elResources:add']"
  57. >新增富文本课件</p>
  58. </el-col>
  59. </el-form-item>
  60. <el-form-item>
  61. <p class="page-inquire-common-style-button" @click="handleQuery">查询</p>
  62. <p class="page-reset-common-style-button" @click="resetQuery">重置</p>
  63. </el-form-item>
  64. </el-form>
  65. <div class="min-list-box">
  66. <el-table class="table-box" v-loading="loading" border :data="el_resourcesList" @selection-change="handleSelectionChange">
  67. <el-table-column label="课件名称" align="left" prop="title" />
  68. <el-table-column label="分类" align="left" prop="cateTitle" width="160"/>
  69. <el-table-column label="类型" align="left" prop="type" width="110">
  70. <template slot-scope="scope">
  71. {{scope.row.type==1?'文档':(scope.row.type==2?'视频':(scope.row.type==3?'图片':(scope.row.type==4?'音频':(scope.row.type==5?'富文本':"其他"))))}}
  72. </template>
  73. </el-table-column>
  74. <el-table-column label="格式" align="left" prop="postfix" width="110"/>
  75. <el-table-column label="大小" align="left" prop="sizeStr" width="110"/>
  76. <el-table-column label="上传时间" align="left" prop="createTime" width="220"/>
  77. <el-table-column label="操作" align="left" class-name="small-padding fixed-width" width="160" v-if="tableButtonType">
  78. <template slot-scope="scope">
  79. <div class="table-button-box">
  80. <p class="table-button-null"></p>
  81. <p class="table-button-p"
  82. @click="handleUpdate(scope.row)"
  83. v-hasPermiRouter="['exam:elResources:add','exam:elResources:edit']"
  84. >修改</p>
  85. <p class="table-button-p"
  86. @click="handleDelete(scope.row)"
  87. v-hasPermiRouter="['exam:elResources:del']"
  88. >删除</p>
  89. <p class="table-button-null"></p>
  90. </div>
  91. </template>
  92. </el-table-column>
  93. </el-table>
  94. </div>
  95. </div>
  96. </div>
  97. <div class="bottom-max-box">
  98. <pagination :page-sizes="[20, 30, 40, 50]"
  99. v-show="total>0"
  100. :total="total"
  101. layout="total, prev, pager, next, sizes, jumper"
  102. :page.sync="queryParams.page"
  103. :limit.sync="queryParams.pageSize"
  104. @pagination="getList"
  105. />
  106. </div>
  107. <!-- 添加资源对话框 -->
  108. <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">
  109. <el-form ref="form" :model="form" v-loading="loading" :rules="rules" label-width="80px">
  110. <el-form-item label="分类" prop="title">
  111. <el-input
  112. style="width: 100%;"
  113. v-model="typeTitle"
  114. maxLength="25"
  115. placeholder=""
  116. disabled
  117. clearable
  118. size="small"
  119. />
  120. </el-form-item>
  121. <el-form-item label="课件名称" prop="name">
  122. <el-input
  123. disabled
  124. style="width: 100%;"
  125. v-model="coursewareName"
  126. maxLength="25"
  127. placeholder="课件名称"
  128. clearable
  129. size="small"
  130. />
  131. </el-form-item>
  132. <uploader
  133. :autoStart="false"
  134. :options="options"
  135. ref="uploader"
  136. :file-list="fileList"
  137. :file-status-text="statusText"
  138. class="uploader-example"
  139. @file-complete="fileComplete"
  140. @complete="complete"
  141. @file-success="fileSuccess"
  142. @files-added="filesAdded">
  143. <uploader-unsupport></uploader-unsupport>
  144. <uploader-drop>
  145. <i class="el-icon-upload"></i>
  146. <div class="el-upload__text">将文件拖到此处,或 <uploader-btn :attrs="attrs">点击上传</uploader-btn></div>
  147. </uploader-drop>
  148. <!-- <uploader-list></uploader-list> -->
  149. <uploader-files> </uploader-files>
  150. </uploader>
  151. <div class="up-text-box" style="margin-top:20px;max-height:400px;overflow-y: scroll">
  152. <div v-for="(item,index) in upTextList" :key="index" style="margin-left:30px;">
  153. <div style="display: flex">
  154. <p style="flex:1;font-size:14px;margin:0;">{{item.title}}.{{item.postfix}}</p>
  155. <p style="flex:1;font-size:14px;margin:0;text-align: right;margin-right:50px;">{{item.sizeStr}}</p>
  156. </div>
  157. <div>
  158. <el-progress :percentage="100" status="success"></el-progress>
  159. </div>
  160. </div>
  161. </div>
  162. <div class="up-data-box-text">
  163. <p>支持上传视频、图片、文件类型的课件</p>
  164. <p>图片请上传 png / jpeg / gif 格式</p>
  165. <p>视频请上传 mp4</p>
  166. <p>文件请上传 pdf / docx 格式</p>
  167. </div>
  168. </el-form>
  169. </el-dialog>
  170. <!--修改资源对话框-->
  171. <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">
  172. <el-form ref="editForm" :model="editForm" v-loading="loading" :rules="rules" label-width="80px">
  173. <el-form-item label="分类" prop="title">
  174. <el-input
  175. style="width: 100%;"
  176. v-model="editForm.cateTitle"
  177. maxLength="25"
  178. placeholder=""
  179. disabled
  180. clearable
  181. size="small"
  182. />
  183. </el-form-item>
  184. <el-form-item label="课件名称" prop="title">
  185. <el-input
  186. disabled
  187. v-model="editForm.title"
  188. maxLength="20"
  189. placeholder="请输入课件名称"
  190. clearable
  191. />
  192. </el-form-item>
  193. <div class="up-button-box">
  194. <uploader
  195. :autoStart="false"
  196. :options="options"
  197. ref="uploader"
  198. :file-list="fileList"
  199. :file-status-text="statusText"
  200. class="uploader-example"
  201. @file-complete="fileComplete"
  202. @complete="complete"
  203. @file-success="fileSuccess"
  204. @files-added="filesAdded">
  205. <uploader-unsupport></uploader-unsupport>
  206. <uploader-drop>
  207. <i class="el-icon-upload"></i>
  208. <div class="el-upload__text">将文件拖到此处,或 <uploader-btn :attrs="attrs">点击上传</uploader-btn></div>
  209. </uploader-drop>
  210. <!-- <uploader-list></uploader-list> -->
  211. <uploader-files> </uploader-files>
  212. </uploader>
  213. <div class="up-text-box" style="margin-top:20px;max-height:400px;overflow-y: scroll">
  214. <div v-for="(item,index) in upTextList" :key="index" style="margin-left:30px;">
  215. <div style="display: flex">
  216. <p style="flex:1;font-size:14px;margin:0;">{{item.title}}.{{item.postfix}}</p>
  217. <p style="flex:1;font-size:14px;margin:0;text-align: right;margin-right:50px;">{{item.sizeStr}}</p>
  218. </div>
  219. <div>
  220. <el-progress :percentage="100" status="success"></el-progress>
  221. </div>
  222. </div>
  223. </div>
  224. <div class="up-data-box-text">
  225. <p>支持上传视频、图片、文件类型的课件</p>
  226. <p>图片请上传 png / jpeg / gif 格式</p>
  227. <p>视频请上传 mp4 / WebM格式 </p>
  228. <p>文件请上传 pdf / docx 格式</p>
  229. </div>
  230. </div>
  231. </el-form>
  232. </el-dialog>
  233. <!--富文本新增课件-->
  234. <el-dialog class="el_resources_dialog" @close="handleClose" :title="title" :visible.sync="richTextAddType" :close-on-click-modal="false"
  235. v-if="richTextAddType" width="1100px" append-to-body :before-close="offUpPage">
  236. <el-form ref="richTextForm" :model="richTextForm" v-loading="loading" :rules="richTextRules" label-width="100px" style="flex-direction: column;display: flex;">
  237. <el-form-item label="分类">
  238. <el-input
  239. style="width: 100%;"
  240. v-model="typeTitle"
  241. maxLength="25"
  242. placeholder=""
  243. disabled
  244. clearable
  245. size="small"
  246. />
  247. </el-form-item>
  248. <el-form-item label="课件名称" prop="title">
  249. <el-input
  250. style="width: 100%;"
  251. v-model="richTextForm.title"
  252. maxLength="20"
  253. placeholder="请输入课件名称"
  254. clearable
  255. />
  256. </el-form-item>
  257. <el-form-item label="课件内容" prop="content" style="width:1000px;height:500px;overflow-y: scroll" class="scrollbar-box">
  258. <editor v-model="richTextForm.content" :min-height="192"/>
  259. </el-form-item>
  260. </el-form>
  261. <!--公共操作按钮-->
  262. <div slot="footer" class="dialog-footer dialog-footer-box">
  263. <p class="dialog-footer-button-null"></p >
  264. <p class="dialog-footer-button-info" @click="richTextCancel">取消</p >
  265. <p class="dialog-footer-button-primary" @click="richTextClick">提交</p >
  266. <p class="dialog-footer-button-null"></p >
  267. </div>
  268. </el-dialog>
  269. <!--富文本修改课件-->
  270. <el-dialog class="el_resources_dialog" @close="handleClose" :title="title" :visible.sync="richTextEditType" :close-on-click-modal="false"
  271. v-if="richTextEditType" width="1100px" append-to-body :before-close="offUpPage">
  272. <el-form ref="richTextForm" :model="richTextForm" v-loading="loading" :rules="richTextRules" label-width="80px">
  273. <el-form-item label="分类" prop="title">
  274. <el-input
  275. style="width: 100%;"
  276. v-model="typeTitle"
  277. maxLength="25"
  278. placeholder=""
  279. disabled
  280. clearable
  281. size="small"
  282. />
  283. </el-form-item>
  284. <el-form-item label="课件名称" prop="title">
  285. <el-input
  286. v-model="richTextForm.title"
  287. maxLength="20"
  288. placeholder="请输入课件名称"
  289. clearable
  290. />
  291. </el-form-item>
  292. <el-form-item label="课件内容" prop="content" style="width:1000px;height:500px;overflow-y: scroll" class="scrollbar-box">
  293. <editor v-model="richTextForm.content" :min-height="192"/>
  294. </el-form-item>
  295. </el-form>
  296. <!--公共操作按钮-->
  297. <div slot="footer" class="dialog-footer dialog-footer-box">
  298. <p class="dialog-footer-button-null"></p >
  299. <p class="dialog-footer-button-info" @click="richTextCancel">取消</p >
  300. <p class="dialog-footer-button-primary" @click="richTextClick">提交</p >
  301. <p class="dialog-footer-button-null"></p >
  302. </div>
  303. </el-dialog>
  304. </div>
  305. <!--管理分类-->
  306. <add-classify v-if="pageType == 5" :pageData="pageData"></add-classify>
  307. </div>
  308. </template>
  309. <script>
  310. import {
  311. examElCategoryTreeList,
  312. examElResourcesList,
  313. examElResourcesDel,
  314. examElResourcesAdd,
  315. examElResourcesUpdate,
  316. examElResourcesAddText,
  317. examElResourcesUpdateText
  318. } from "@/api/safetyEducationExam/index";
  319. import { getToken } from "@/utils/auth";
  320. import addClassify from "../el_category/index";
  321. import axios from "axios";
  322. import SparkMD5 from "spark-md5";
  323. let httpHeader=window.location.href.split('://')[0]+'://'
  324. export default {
  325. name: "El_resources",
  326. components: {
  327. addClassify
  328. },
  329. data() {
  330. let checkName = (rule, value, callback) => {
  331. let reg = /^\s+$/;
  332. if(reg.test(value)){
  333. return callback(new Error(''));
  334. }
  335. }
  336. return {
  337. tableButtonType:this.hasPermiDom(['exam:elResources:add','exam:elResources:edit','exam:elResources:del']),
  338. //页面状态
  339. pageType:1,
  340. pageData:{
  341. type:1,//1资源管理2课程管理
  342. },
  343. // 上传相关
  344. uploadImgUrl: "",
  345. headers: {
  346. Authorization: "Bearer " + getToken()
  347. },
  348. cateId:"",
  349. //树数据
  350. treeData:[],
  351. defaultProps: {
  352. children: "children",
  353. label: "title"
  354. },
  355. // 遮罩层
  356. loading: true,
  357. // 选中数组
  358. ids: [],
  359. // 非单个禁用
  360. single: true,
  361. // 非多个禁用
  362. multiple: true,
  363. // 显示搜索条件
  364. showSearch: true,
  365. // 总条数
  366. total: 0,
  367. // 课件资源表格数据
  368. el_resourcesList: [],
  369. // 弹出层标题
  370. title: "",
  371. // 是否显示弹出层
  372. open: false,
  373. //文件路径
  374. filePath:null,
  375. //文件名称
  376. fileName: null,
  377. //文件大小
  378. fileSize: null,
  379. // 查询参数
  380. queryParams: {
  381. page: 1,
  382. pageSize:20,
  383. cateId: "",
  384. title: null,
  385. type: null,
  386. },
  387. // 表单参数
  388. form: {},
  389. typeTitle:'',//点击的分类名称
  390. coursewareName:'',//课件名称
  391. // 表单校验
  392. rules: {
  393. cateId: [
  394. { required: true, message: "分类id不能为空", trigger: "blur" }
  395. ],
  396. },
  397. richTextRules: {
  398. title: [
  399. { required: true, message: "请输入课件名称", trigger: "blur" },
  400. { required: true, message: "请输入课件名称", validator: this.spaceJudgment, trigger: "blur" }
  401. ],
  402. content: [
  403. { required: true, message: "请输入课件内容", trigger: "blur" },
  404. { required: true, message: "请输入课件内容", validator: this.spaceJudgmentHTML, trigger: "blur" }
  405. ],
  406. },
  407. //课件类型
  408. coursewareType:[
  409. {dictLabel:"文档", dictValue:"1",},
  410. {dictLabel:"视频", dictValue:"2",},
  411. {dictLabel:"图片", dictValue:"3",},
  412. // {dictLabel:"音频", dictValue:"4",},
  413. {dictLabel:"富文本", dictValue:"5",}
  414. ],
  415. //上传成功展示列表
  416. upTextList:[],
  417. //修改页面
  418. openEdit:false,
  419. editForm:{
  420. id:'',
  421. },
  422. //修改上传
  423. editTree:[],
  424. fileList:[],
  425. //富文本数据
  426. richTextForm:{},
  427. //富文本课件状态
  428. richTextAddType:false,
  429. //富文本课件状态
  430. richTextEditType:false,
  431. skip: false,
  432. options: {
  433. target: httpHeader+this.judgmentNetworkReturnAddress()+"/system/file/upload/chunk2",
  434. // 开启服务端分片校验功能
  435. testChunks: true,
  436. single: true,
  437. fileParameterName: 'file',
  438. // testMethod: 'post',
  439. //uploadMethod: 'get',
  440. headers: {
  441. Authorization:getToken()
  442. },
  443. parseTimeRemaining: function (timeRemaining, parsedTimeRemaining) {
  444. return parsedTimeRemaining
  445. .replace(/\syears?/, "年")
  446. .replace(/\days?/, "天")
  447. .replace(/\shours?/, "小时")
  448. .replace(/\sminutes?/, "分钟")
  449. .replace(/\sseconds?/, "秒");
  450. },
  451. // // 服务器分片校验函数
  452. checkChunkUploadedByResponse: (chunk, message) => {
  453. const result = JSON.parse(message);
  454. if (result.data.skipUpload) {
  455. this.skip = true;
  456. return true;
  457. }
  458. return (result.data.uploaded || []).indexOf(chunk.offset + 1) >= 0;
  459. },
  460. },
  461. attrs: {
  462. accept: ["image/png","image/jpeg","image/gif","application/pdf","video/mp4","application/vnd.openxmlformats-officedocument.wordprocessingml.document"]
  463. },
  464. statusText: {
  465. success: "上传成功",
  466. error: "上传出错了",
  467. uploading: "上传中...",
  468. paused: "暂停中...",
  469. waiting: "等待中...",
  470. cmd5: "计算文件MD5中...",
  471. },
  472. disabled: true,
  473. };
  474. },
  475. watch: {
  476. fileList(o, n) {
  477. this.disabled = false;
  478. },
  479. },
  480. created() {
  481. this.getTreeData();
  482. },
  483. methods: {
  484. /*
  485. unescape(response.data.content) 解码
  486. escape(this.form.content) 编码
  487. */
  488. clickPage(type){
  489. if(type==1){
  490. this.pageType=1
  491. this.getTreeData();
  492. this.getList();
  493. }else if(type==5){
  494. this.pageType=5
  495. }
  496. },
  497. //监听弹窗关闭
  498. handleClose(){
  499. // this.typeTitle='';
  500. // this.coursewareName='';
  501. // this.queryParams.cateId='';
  502. // this.$refs.tree.setCurrentKey(null);
  503. },
  504. //富文本课件提交按钮
  505. richTextClick(){
  506. this.$refs["richTextForm"].validate(valid => {
  507. if (valid) {
  508. if(this.richTextAddType){
  509. //新增
  510. let obj = {
  511. cateId:this.richTextForm.cateId,
  512. title:this.richTextForm.title,
  513. content:escape(this.richTextForm.content),
  514. type:"5",
  515. }
  516. this.loading = true;
  517. examElResourcesAddText(obj).then( response => {
  518. this.msgSuccess("新增成功");
  519. this.loading = false;
  520. this.richTextCancel();
  521. this.getList();
  522. });
  523. }else if(this.richTextEditType){
  524. //修改
  525. let obj = {
  526. id:this.richTextForm.id,
  527. cateId:this.richTextForm.cateId,
  528. title:this.richTextForm.title,
  529. content:escape(this.richTextForm.content),
  530. type:"5",
  531. };
  532. examElResourcesUpdateText(obj).then( response => {
  533. this.msgSuccess("修改成功");
  534. this.loading = false;
  535. this.richTextCancel();
  536. this.getList();
  537. });
  538. }
  539. }
  540. });
  541. },
  542. //新增富文本按钮
  543. richTextAddClick(type,row){
  544. let self = this;
  545. if(type == 1){
  546. if(!this.queryParams.cateId){
  547. this.msgError('请在左侧列表选择分类')
  548. return
  549. }
  550. this.richTextForm = {};
  551. this.title = "新增课件"
  552. this.richTextForm.cateId = this.queryParams.cateId;
  553. this.richTextAddType = true;
  554. }else if(type == 2){
  555. this.title = "编辑课件"
  556. this.richTextForm = row;
  557. this.richTextForm.cateId = row.cateId;
  558. this.richTextForm.content = unescape(row.content);
  559. this.richTextEditType = true;
  560. }
  561. },
  562. //关闭富文本按钮
  563. richTextCancel(){
  564. this.richTextAddType = false;
  565. this.richTextEditType = false;
  566. },
  567. //关闭新增上传页面
  568. offUpPage(done){
  569. if(this.upTextList[0]){
  570. this.getList();
  571. }
  572. done();
  573. },
  574. /** 查询分类树 */
  575. getTreeData() {//type 1资源 2课程
  576. this.loading = true;
  577. examElCategoryTreeList({},1).then( response => {
  578. let list = [];
  579. let obj = {
  580. children:[],
  581. title:"所有分类",
  582. id:"",
  583. };
  584. list.push(obj);
  585. for(let i=0;i<response.data.length;i++){
  586. list.push(response.data[i]);
  587. }
  588. this.treeData = list;
  589. this.editTree = JSON.parse(JSON.stringify(response.data));
  590. this.getList();
  591. });
  592. },
  593. // 筛选节点
  594. filterNode(value, data) {
  595. if (!value) return true;
  596. return data.label.indexOf(value) !== -1;
  597. },
  598. // 节点单击事件
  599. handleNodeClick(data,node) {
  600. let self = this;
  601. this.queryParams.cateId = data.id;
  602. let text = '';
  603. for(let i=0;i<self.treeData.length;i++){
  604. if (data.id == self.treeData[i].id){
  605. text = self.treeData[i].title;
  606. break
  607. }
  608. for(let o=0;o<self.treeData[i].children.length;o++){
  609. if (data.id == self.treeData[i].children[o].id){
  610. text = self.treeData[i].title +'/'+ self.treeData[i].children[o].title;
  611. break
  612. }
  613. for(let x=0;x<self.treeData[i].children[o].children.length;x++){
  614. if (data.id == self.treeData[i].children[o].children[x].id){
  615. text = self.treeData[i].title +'/'+ self.treeData[i].children[o].title + '/' + self.treeData[i].children[o].children[x].title;
  616. break
  617. }
  618. }
  619. }
  620. }
  621. self.typeTitle=text
  622. //根据id查找父元素
  623. this.getList();
  624. },
  625. //根据id查找父元素
  626. familyTree (arr1, id) {
  627. var temp = []
  628. var forFn = function (arr, id) {
  629. for (var i = 0; i < arr.length; i++) {
  630. var item = arr[i]
  631. if (item.id === id) {
  632. temp.push(item)
  633. forFn(arr1, item.parentId)
  634. break
  635. } else {
  636. if (item.children) {
  637. forFn(item.children, id)
  638. }
  639. }
  640. }
  641. }
  642. forFn(arr1, id)
  643. return temp
  644. },
  645. /** 查询课件资源列表 */
  646. getList() {
  647. this.loading = true;
  648. examElResourcesList(this.queryParams).then( response => {
  649. this.el_resourcesList = response.data.records;
  650. this.total = response.data.total;
  651. this.loading = false;
  652. });
  653. },
  654. // 取消按钮
  655. cancel() {
  656. if(this.loading){
  657. return
  658. }
  659. this.editForm = {};
  660. this.fileList = [];
  661. this.upTextList = [];
  662. this.openEdit = false;
  663. this.reset();
  664. },
  665. // 表单重置
  666. reset() {
  667. this.form = {
  668. id: null,
  669. createBy: null,
  670. updateBy: null,
  671. createTime: null,
  672. updateTime: null,
  673. remark: null,
  674. cateId: null,
  675. title: null,
  676. type: null,
  677. };
  678. this.resetForm("form");
  679. },
  680. /** 搜索按钮操作 */
  681. handleQuery() {
  682. this.queryParams.page = 1;
  683. this.getList();
  684. },
  685. /** 重置按钮操作 */
  686. resetQuery() {
  687. // this.resetForm("queryForm");
  688. this.$set(this,'queryParams',{
  689. page: 1,
  690. pageSize:20,
  691. cateId:"",
  692. title: '',
  693. type:'',
  694. id:'',
  695. });
  696. this.$refs.tree.setCurrentKey();
  697. this.handleQuery();
  698. },
  699. // 多选框选中数据
  700. handleSelectionChange(selection) {
  701. this.ids = selection.map(item => item.id)
  702. this.single = selection.length!==1
  703. this.multiple = !selection.length
  704. },
  705. /** 新增按钮操作 */
  706. handleAdd() {
  707. if(!this.queryParams.cateId){
  708. this.msgError('请在左侧列表选择分类')
  709. return
  710. }
  711. this.reset();
  712. this.coursewareName='';
  713. this.editForm.cateId='';
  714. this.editForm.id='';
  715. this.uploadImgUrl = window.location.href.split('://')[0]+'://' + this.judgmentNetworkReturnAddress() + "/exam/el_resources?cateId=" + this.queryParams.cateId
  716. this.upTextList = [];
  717. this.open = true;
  718. this.title = "添加课件资源";
  719. },
  720. addResource(filePath){
  721. let _this=this;
  722. let obj={
  723. cateId:this.queryParams.cateId,
  724. id:this.queryParams.id,
  725. path:filePath,
  726. fileName:this.fileName,
  727. size:this.fileSize
  728. }
  729. examElResourcesAdd(obj).then( response => {
  730. this.msgSuccess("新增成功");
  731. this.coursewareName=response.data.fileName;//课件名称
  732. this.loading = false;
  733. setTimeout(function (){
  734. _this.open = false;
  735. },2000)
  736. this.richTextCancel();
  737. this.allRemove();
  738. this.getList();
  739. });
  740. },
  741. updateResource(filePath) {
  742. let _this=this;
  743. let obj = {
  744. id: this.editForm.id,
  745. cateId: this.editForm.cateId,
  746. title: this.editForm.title,
  747. path: filePath,
  748. fileName: this.fileName,
  749. size: this.fileSize
  750. }
  751. examElResourcesUpdate(obj).then(response => {
  752. this.msgSuccess("修改成功");
  753. this.loading = false;
  754. this.openEdit = false;
  755. this.coursewareName=response.data.fileName;//课件名称
  756. this.loading = false;
  757. setTimeout(function (){
  758. _this.open = false;
  759. },2000)
  760. this.allRemove();
  761. this.getList();
  762. });
  763. },
  764. /** 修改按钮操作 */
  765. handleUpdate(row) {
  766. let self = this;
  767. //根据id查找父元素
  768. let treeName=this.familyTree(this.treeData,row.cateId)
  769. let treeName1=treeName.reverse()
  770. let treeArr=[]
  771. treeName1.forEach(function (item){
  772. treeArr.push(item.title)
  773. })
  774. // self.typeTitle=treeArr.join('/')
  775. let text = '';
  776. for(let i=0;i<self.treeData.length;i++){
  777. if (row.cateId == self.treeData[i].id){
  778. text = self.treeData[i].title;
  779. break
  780. }
  781. for(let o=0;o<self.treeData[i].children.length;o++){
  782. if (row.cateId == self.treeData[i].children[o].id){
  783. text = self.treeData[i].title +'/'+ self.treeData[i].children[o].title;
  784. break
  785. }
  786. for(let x=0;x<self.treeData[i].children[o].children.length;x++){
  787. if (row.cateId == self.treeData[i].children[o].children[x].id){
  788. text = self.treeData[i].title +'/'+ self.treeData[i].children[o].title + '/' + self.treeData[i].children[o].children[x].title;
  789. break
  790. }
  791. }
  792. }
  793. }
  794. if(text[0]){
  795. self.typeTitle=text
  796. }else{
  797. self.typeTitle='该分类已删除'
  798. }
  799. if(row.type=='5'){
  800. this.richTextAddClick(2,row)
  801. return
  802. }
  803. this.coursewareName=row.title
  804. // this.queryParams.cateId=row.cateId
  805. //this.queryParams.id=row.id
  806. this.editForm.cateId=row.cateId
  807. this.editForm.id=row.id
  808. this.reset();
  809. this.uploadImgUrl = window.location.href.split('://')[0]+'://' + this.judgmentNetworkReturnAddress() + "/exam/el_resources?cateId=" + this.queryParams.cateId
  810. this.upTextList = [];
  811. this.open = true;
  812. this.title = "修改课件资源";
  813. },
  814. /** 删除按钮操作 */
  815. handleDelete(row) {
  816. const ids = row.id || this.ids;
  817. this.$confirm('是否确认删除?', "警告", {
  818. confirmButtonText: "确定",
  819. cancelButtonText: "取消",
  820. type: "warning"
  821. }).then(function() {
  822. return examElResourcesDel(ids);
  823. }).then(() => {
  824. this.getList();
  825. this.msgSuccess("删除成功");
  826. }).catch(() => {});
  827. },
  828. fileSuccess(rootFile, file, response, chunk) {
  829. const result = JSON.parse(response);
  830. if (result.code==200 && !this.skip) {
  831. axios.post(httpHeader+this.judgmentNetworkReturnAddress()+"/system/file/upload/merge", {
  832. identifier: file.uniqueIdentifier,
  833. filename: file.name,
  834. totalChunks: chunk.offset,
  835. },{
  836. headers: {
  837. Authorization:getToken()
  838. }
  839. }).then((res) => {
  840. if (res.data.code==200) {
  841. if(!this.editForm.id){//新增
  842. this.addResource(res.data.data);
  843. }else{//修改
  844. this.updateResource(res.data.data);
  845. }
  846. this.filePath=res.data.data;
  847. } else {
  848. }
  849. }).catch(function (error) {
  850. });
  851. } else {
  852. }
  853. if (this.skip) {
  854. this.skip = false;
  855. }
  856. },
  857. fileComplete(rootFile) {
  858. // 一个根文件(文件夹)成功上传完成。
  859. this.fileName=rootFile.name;
  860. this.fileSize=rootFile.size;
  861. },
  862. complete(file) {
  863. // 上传完毕。
  864. },
  865. filesAdded(file, fileList, event) {
  866. file.forEach((item)=>{
  867. if(["image/png","image/jpeg","image/gif",
  868. "application/pdf",
  869. "video/mp4",
  870. "application/vnd.openxmlformats-officedocument.wordprocessingml.document"].indexOf(item.fileType) === -1){
  871. this.$message.error("文件格式不支持,请上传正确的文件.");
  872. file.ignored = true;
  873. }else{
  874. this.fileList.push(item);
  875. this.computeMD5(item);
  876. }
  877. })
  878. },
  879. computeMD5(file) {
  880. let fileReader = new FileReader();
  881. let time = new Date().getTime();
  882. let blobSlice = File.prototype.slice || File.prototype.mozSlice || File.prototype.webkitSlice;
  883. let currentChunk = 0;
  884. const chunkSize = 1024 * 1024;
  885. let chunks = Math.ceil(file.size / chunkSize);
  886. let spark = new SparkMD5.ArrayBuffer();
  887. // 文件状态设为"计算MD5"
  888. file.cmd5 = true; //文件状态为“计算md5...”
  889. file.pause();
  890. loadNext();
  891. fileReader.onload = (e) => {
  892. spark.append(e.target.result);
  893. if (currentChunk < chunks) {
  894. currentChunk++;
  895. loadNext();
  896. // 实时展示MD5的计算进度
  897. } else {
  898. let md5 = spark.end();
  899. spark.destroy(); //释放缓存
  900. file.uniqueIdentifier = md5; //将文件md5赋值给文件唯一标识
  901. file.cmd5 = false; //取消计算md5状态
  902. file.resume(); //开始上传
  903. }
  904. };
  905. fileReader.onerror = function () {
  906. this.error(`文件${file.name}读取出错,请检查该文件`);
  907. file.cancel();
  908. };
  909. function loadNext() {
  910. let start = currentChunk * chunkSize;
  911. let end = start + chunkSize >= file.size ? file.size : start + chunkSize;
  912. fileReader.readAsArrayBuffer(blobSlice.call(file.file, start, end));
  913. }
  914. },
  915. allRemove() {
  916. this.fileList.map((e) => {
  917. e.cancel();
  918. });
  919. this.fileList = [];
  920. },
  921. }
  922. };
  923. </script>
  924. <style scoped lang="scss">
  925. .el-resources {
  926. display: flex!important;
  927. flex-direction: column;
  928. box-shadow: 0 0 8px 2px rgba(0, 0, 0, 0.1);
  929. /*padding:20px!important;*/
  930. .list-max-big-box{
  931. flex:1;
  932. display: flex!important;
  933. flex-direction: column;
  934. padding:20px!important;
  935. overflow: hidden;
  936. .top-max-box{
  937. flex:1;
  938. display: flex;
  939. overflow: hidden!important;
  940. .left-max-box{
  941. width:250px;
  942. .classify_btn{
  943. font-size: 14px;
  944. font-family: Microsoft YaHei;
  945. font-weight: 400;
  946. color: #0183FA;
  947. line-height: 70px;
  948. cursor: pointer;
  949. text-align: left;
  950. }
  951. }
  952. .center-max-box{
  953. border-right:2px dashed #E0E0E0;
  954. margin-right:30px;
  955. margin-top:20px;
  956. }
  957. .right-max-box{
  958. flex:1;
  959. display: flex;
  960. flex-direction: column;
  961. overflow: hidden!important;
  962. .min-list-box{
  963. flex: 1;
  964. overflow: hidden!important;
  965. display: flex;
  966. .button-box{
  967. width:190px;
  968. display: flex;
  969. }
  970. }
  971. }
  972. }
  973. .bottom-max-box{
  974. height:50px;
  975. }
  976. }
  977. }
  978. .uploader{
  979. .uploader-drop{
  980. height: 200px;
  981. background: #fff;
  982. border-radius: 6px;
  983. text-align: center;
  984. >i{
  985. width: 100px;
  986. height: 78px;
  987. font-size: 78px;
  988. color: #0183FA;
  989. margin-top: 20px;
  990. }
  991. .uploader-btn{
  992. padding: 0;
  993. color: #0183FA;
  994. border: 0;
  995. cursor: pointer;
  996. background: none;
  997. outline: none;
  998. font-size: 14px;
  999. }
  1000. }
  1001. }
  1002. .el_resources_dialog{
  1003. //上传描述
  1004. .up-data-box-text{
  1005. margin-bottom:20px;
  1006. p{
  1007. margin:0;
  1008. padding:0;
  1009. line-height:24px;
  1010. font-size:12px;
  1011. color:#999;
  1012. text-align: center;
  1013. }
  1014. }
  1015. }
  1016. </style>
  1017. <style lang="scss">
  1018. .el-resources{
  1019. .el-tree-node__label{
  1020. width: 188px;
  1021. display:block;
  1022. overflow:hidden;
  1023. text-overflow:ellipsis;
  1024. white-space:nowrap;
  1025. }
  1026. }
  1027. </style>