index.vue 38 KB

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