index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
  4. <el-form-item label="主题" prop="title">
  5. <el-input
  6. v-model="queryParams.title"
  7. placeholder="请输入主题"
  8. clearable
  9. size="small"
  10. @keyup.enter.native="handleQuery"
  11. />
  12. </el-form-item>
  13. <el-form-item label="备注" prop="remarks">
  14. <el-input
  15. v-model="queryParams.remarks"
  16. placeholder="请输入备注"
  17. clearable
  18. size="small"
  19. @keyup.enter.native="handleQuery"
  20. />
  21. </el-form-item>
  22. <el-form-item>
  23. <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  24. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  25. </el-form-item>
  26. </el-form>
  27. <el-row :gutter="10" class="mb8">
  28. <el-col :span="1.5">
  29. <el-button
  30. type="primary"
  31. icon="el-icon-plus"
  32. size="mini"
  33. @click="handleAdd"
  34. v-hasPermi="['elearn:resource:add']"
  35. >新增</el-button>
  36. </el-col>
  37. <el-col :span="1.5">
  38. <el-button
  39. type="success"
  40. icon="el-icon-edit"
  41. size="mini"
  42. :disabled="single"
  43. @click="handleUpdate"
  44. v-hasPermi="['elearn:resource:edit']"
  45. >修改</el-button>
  46. </el-col>
  47. <el-col :span="1.5">
  48. <el-button
  49. type="danger"
  50. icon="el-icon-delete"
  51. size="mini"
  52. :disabled="multiple"
  53. @click="handleDelete"
  54. v-hasPermi="['elearn:resource:remove']"
  55. >删除</el-button>
  56. </el-col>
  57. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  58. </el-row>
  59. <el-table v-loading="loading" :data="resourceList" @selection-change="handleSelectionChange" :height="clientHeight" border>
  60. <el-table-column type="selection" width="55" align="center" />
  61. <el-table-column label="主题" align="center" prop="title" :show-overflow-tooltip="true"/>
  62. <el-table-column label="课件" align="center">
  63. <template slot-scope="scope">
  64. <el-button
  65. size="mini"
  66. type="text"
  67. icon="el-icon-folder"
  68. @click="handleDoc(scope.row)"
  69. >上传课件
  70. </el-button>
  71. </template>
  72. </el-table-column>
  73. <el-table-column label="备注" align="center" prop="remarks" :show-overflow-tooltip="true"/>
  74. <el-table-column label="上传人" align="center" prop="createBy" :show-overflow-tooltip="true"/>
  75. <el-table-column label="操作" align="center" fixed="right" width="120" class-name="small-padding fixed-width">
  76. <template slot-scope="scope">
  77. <el-button
  78. size="mini"
  79. type="text"
  80. icon="el-icon-edit"
  81. @click="handleUpdate(scope.row)"
  82. v-hasPermi="['elearn:resource:edit']"
  83. >修改</el-button>
  84. <el-button
  85. size="mini"
  86. type="text"
  87. icon="el-icon-delete"
  88. @click="handleDelete(scope.row)"
  89. v-hasPermi="['elearn:resource:remove']"
  90. >删除</el-button>
  91. </template>
  92. </el-table-column>
  93. </el-table>
  94. <pagination
  95. v-show="total>0"
  96. :total="total"
  97. :page.sync="queryParams.pageNum"
  98. :limit.sync="queryParams.pageSize"
  99. @pagination="getList"
  100. />
  101. <!-- 添加或修改学习资料管理对话框 -->
  102. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  103. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  104. <el-form-item label="主题" prop="title">
  105. <el-input v-model="form.title" placeholder="请输入主题" />
  106. </el-form-item>
  107. <el-form-item label="备注" prop="remarks">
  108. <el-input v-model="form.remarks" placeholder="请输入备注" />
  109. </el-form-item>
  110. <el-form-item label="归属部门" prop="deptId">
  111. <treeselect v-model="form.deptId" :options="deptOptions" :show-count="true" placeholder="请选择归属部门" />
  112. </el-form-item>
  113. </el-form>
  114. <div slot="footer" class="dialog-footer">
  115. <el-button type="primary" @click="submitForm">确 定</el-button>
  116. <el-button @click="cancel">取 消</el-button>
  117. </div>
  118. </el-dialog>
  119. <!-- 课件附件 -->
  120. <el-dialog :close-on-click-modal="false" v-dialogDrag :title="doc.title" :visible.sync="doc.open" width="1000px" append-to-body >
  121. <el-upload ref="doc"
  122. :limit="1"
  123. :headers="doc.headers"
  124. :action="doc.url + '?pType=' + doc.pType + '&pId=' + doc.pId"
  125. :disabled="doc.isUploading"
  126. :on-progress="handleFileDocProgress"
  127. :on-success="handleFileDocSuccess"
  128. :auto-upload="true"
  129. drag
  130. >
  131. <i class="el-icon-upload"></i>
  132. <div class="el-upload__text">
  133. {{ $t('将文件拖到此处,或') }}
  134. <em>{{ $t('点击上传') }}</em>
  135. </div>
  136. </el-upload>
  137. <el-table :data="doc.commonfileList" border>
  138. <el-table-column :label="$t('文件名')" align="center" prop="fileName" :show-overflow-tooltip="true">
  139. <template slot-scope="scope">
  140. <a class="link-type" @click="handleDownload(scope.row)">
  141. <span>{{ scope.row.fileName }}</span>
  142. </a>
  143. </template>
  144. </el-table-column>
  145. <el-table-column :label="$t('大小(Kb)')" align="center" prop="fileSize" :show-overflow-tooltip="true" width="80" />
  146. <el-table-column :label="$t('上传人')" align="center" prop="creator" :show-overflow-tooltip="true" width="120"/>
  147. <el-table-column :label="$t('操作')" align="center" width="220" class-name="small-padding fixed-width">
  148. <template slot-scope="scope">
  149. <el-button
  150. v-if="scope.row.fileName.endsWith('pdf')"
  151. size="mini"
  152. type="text"
  153. icon="el-icon-view"
  154. @click="handleSee(scope.row)"
  155. >{{ $t('预览') }}</el-button>
  156. <el-button
  157. size="mini"
  158. type="text"
  159. icon="el-icon-download"
  160. @click="handleDownload(scope.row)"
  161. >{{ $t('下载') }}</el-button>
  162. <el-button
  163. size="mini"
  164. type="text"
  165. icon="el-icon-delete"
  166. @click="handleDeleteDoc(scope.row)"
  167. >{{ $t('删除') }}</el-button>
  168. </template>
  169. </el-table-column>
  170. </el-table>
  171. <el-dialog :close-on-click-modal="false" v-dialogDrag :title="pdf.title" :visible.sync="pdf.open" width="1300px" append-to-body>
  172. <div style="margin-top: -60px;float: right;margin-right: 40px;">
  173. <el-button size="mini" type="text" @click="openPdf">{{$t('新页面打开PDF')}}</el-button></div>
  174. <div style="margin-top: -30px">
  175. <iframe :src="pdf.pdfUrl" frameborder="0" width="100%" height="700px"></iframe>
  176. </div>
  177. </el-dialog>
  178. <div slot="footer" class="dialog-footer">
  179. <!-- <el-button type="primary" @click="submitFileForm">{{ $t('确 定') }}</el-button>-->
  180. <el-button @click="doc.open = false">{{ $t('返 回') }}</el-button>
  181. </div>
  182. </el-dialog>
  183. </div>
  184. </template>
  185. <script>
  186. import { listResource, getResource, delResource, addResource, updateResource, exportResource, importTemplate} from "@/api/training/elearn/resource";
  187. import { treeselect } from "@/api/system/dept";
  188. import { getToken } from "@/utils/auth";
  189. import Treeselect from "@riophae/vue-treeselect";
  190. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  191. import {addCommonfile, allFileList, delCommonfile, updateCommonfile} from "@/api/common/commonfile";
  192. export default {
  193. name: "Resource",
  194. components: { Treeselect },
  195. data() {
  196. return {
  197. doc: {
  198. file: "",
  199. // 是否显示弹出层(报告附件)
  200. open: false,
  201. // 弹出层标题(报告附件)
  202. title: "附件",
  203. // 是否禁用上传
  204. isUploading: false,
  205. // 是否更新已经存在的用户数据
  206. updateSupport: 0,
  207. // 报告附件上传位置编号
  208. ids: 0,
  209. // 设置上传的请求头部
  210. headers: { Authorization: "Bearer " + getToken() },
  211. // 上传的地址
  212. url: process.env.VUE_APP_BASE_API + "/common/commonfile/uploadFile",
  213. commonfileList: null,
  214. queryParams: {
  215. pId: null,
  216. pType: 'elearnResource'
  217. },
  218. pType: 'elearnResource',
  219. pId: null,
  220. form: {}
  221. },
  222. pdf : {
  223. title: '',
  224. pdfUrl: '',
  225. numPages: null,
  226. open: false,
  227. pageNum: 1,
  228. pageTotalNum: 1,
  229. loadedRatio: 0,
  230. },
  231. // 遮罩层
  232. loading: true,
  233. // 选中数组
  234. ids: [],
  235. // 非单个禁用
  236. single: true,
  237. // 非多个禁用
  238. multiple: true,
  239. // 显示搜索条件
  240. showSearch: false,
  241. // 总条数
  242. total: 0,
  243. // 学习资料管理表格数据
  244. resourceList: [],
  245. // 弹出层标题
  246. title: "",
  247. // 部门树选项
  248. deptOptions: undefined,
  249. clientHeight:300,
  250. // 是否显示弹出层
  251. open: false,
  252. // 用户导入参数
  253. upload: {
  254. // 是否显示弹出层(用户导入)
  255. open: false,
  256. // 弹出层标题(用户导入)
  257. title: "",
  258. // 是否禁用上传
  259. isUploading: false,
  260. // 是否更新已经存在的用户数据
  261. updateSupport: 0,
  262. // 设置上传的请求头部
  263. headers: { Authorization: "Bearer " + getToken() },
  264. // 上传的地址
  265. url: process.env.VUE_APP_BASE_API + "/elearn/resource/importData"
  266. },
  267. // 查询参数
  268. queryParams: {
  269. pageNum: 1,
  270. pageSize: 20,
  271. title: null,
  272. remarks: null,
  273. deptId: null
  274. },
  275. // 表单参数
  276. form: {},
  277. // 表单校验
  278. rules: {
  279. id: [
  280. { required: true, message: "主键id不能为空", trigger: "blur" }
  281. ],
  282. }
  283. };
  284. },
  285. watch: {
  286. // 根据名称筛选部门树
  287. deptName(val) {
  288. this.$refs.tree.filter(val);
  289. }
  290. },
  291. created() {
  292. //设置表格高度对应屏幕高度
  293. this.$nextTick(() => {
  294. this.clientHeight = document.body.clientHeight -250
  295. })
  296. this.getList();
  297. this.getTreeselect();
  298. },
  299. methods: {
  300. handleDoc(row) {
  301. this.doc.id = row.id;
  302. this.doc.title = "上传课件";
  303. this.doc.open = true;
  304. this.doc.queryParams.pId = row.id
  305. this.doc.pId = row.id
  306. this.doc.commonfileList = null;
  307. this.getFileList()
  308. },
  309. getFileList() {
  310. allFileList(this.doc.queryParams).then(response => {
  311. response.forEach(element => {
  312. element["isEdit"] = false
  313. });
  314. response.forEach(element => {
  315. element["isAdd"] = false
  316. });
  317. this.doc.commonfileList = response;
  318. });
  319. },
  320. //附件上传中处理
  321. handleFileDocProgress(event, file, fileList) {
  322. this.doc.file = file;
  323. this.doc.isUploading = true;
  324. },
  325. //附件上传成功处理
  326. handleFileDocSuccess(response, file, fileList) {
  327. this.doc.isUploading = false;
  328. this.$alert(response.msg, this.$t('导入结果'), {dangerouslyUseHTMLString: true});
  329. this.getFileList()
  330. },
  331. // 文件下载处理
  332. handleDownload(row) {
  333. var name = row.fileName;
  334. var url = row.fileUrl;
  335. var suffix = url.substring(url.lastIndexOf("."), url.length);
  336. const a = document.createElement('a')
  337. a.setAttribute('download', name)
  338. a.setAttribute('target', '_blank')
  339. a.setAttribute('href', process.env.VUE_APP_BASE_API + url)
  340. a.click()
  341. },
  342. openPdf() {
  343. window.open(this.pdf.pdfUrl);//path是文件的全路径地址
  344. },
  345. handleSee(row) {
  346. // window.open(process.env.VUE_APP_BASE_API +'/pdf/web/viewer.html?file=' + process.env.VUE_APP_BASE_API + row.fileUrl);//path是文件的全路径地址
  347. this.pdf.open = true
  348. this.pdf.title = row.fileName
  349. this.pdf.pdfUrl = process.env.VUE_APP_BASE_API + '/pdf/web/viewer.html?file=' + process.env.VUE_APP_BASE_API + row.fileUrl
  350. },
  351. // 上一页
  352. prePage() {
  353. let page = this.pdf.pageNum
  354. page = page > 1 ? page - 1 : this.pdf.pageTotalNum
  355. this.pdf.pageNum = page
  356. },
  357. // 下一页
  358. nextPage() {
  359. let page = this.pdf.pageNum
  360. page = page < this.pdf.pageTotalNum ? page + 1 : 1
  361. this.pdf.pageNum = page
  362. },
  363. // 取消
  364. cancelFile(row, index) {
  365. // 如果是新增的数据
  366. if (row.isAdd) {
  367. this.doc.commonfileList.splice(index, 1)
  368. } else {
  369. // 不是新增的数据 还原数据
  370. for (const i in row.oldRow) {
  371. row[i] = row.oldRow[i]
  372. }
  373. row.isEdit = false
  374. }
  375. },
  376. edit(row) {
  377. // 备份原始数据
  378. row['oldRow'] = JSON.parse(JSON.stringify(row));
  379. this.$nextTick(() => {
  380. row.isEdit = true;
  381. })
  382. },
  383. save(row) {
  384. row.isEdit = false;
  385. var that = this;
  386. that.loading = true;
  387. this.form = row;
  388. if (row.isAdd == true) {
  389. addCommonfile(this.form).then(response => {
  390. this.msgSuccess(this.$t('新增成功'));
  391. this.open = false;
  392. this.getList();
  393. });
  394. } else {
  395. updateCommonfile(this.form).then(response => {
  396. this.msgSuccess(this.$t('修改成功'));
  397. this.open = false;
  398. this.getList();
  399. });
  400. }
  401. },
  402. /** 删除按钮操作 */
  403. handleDeleteDoc(row) {
  404. const ids = row.id || this.ids;
  405. this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
  406. confirmButtonText: this.$t('确定'),
  407. cancelButtonText: this.$t('取消'),
  408. type: "warning"
  409. }).then(function () {
  410. return delCommonfile(ids);
  411. }).then(() => {
  412. this.getFileList()
  413. this.msgSuccess(this.$t('删除成功'));
  414. })
  415. },
  416. /** 查询学习资料管理列表 */
  417. getList() {
  418. this.loading = true;
  419. listResource(this.queryParams).then(response => {
  420. this.resourceList = response.rows;
  421. this.total = response.total;
  422. this.loading = false;
  423. });
  424. },
  425. /** 查询部门下拉树结构 */
  426. getTreeselect() {
  427. treeselect().then(response => {
  428. this.deptOptions = response.data;
  429. });
  430. },
  431. // 取消按钮
  432. cancel() {
  433. this.open = false;
  434. this.reset();
  435. },
  436. // 表单重置
  437. reset() {
  438. this.form = {
  439. id: null,
  440. title: null,
  441. remarks: null,
  442. delFlag: null,
  443. createBy: null,
  444. createTime: null,
  445. updateBy: null,
  446. updateTime: null,
  447. deptId: null
  448. };
  449. this.resetForm("form");
  450. },
  451. /** 搜索按钮操作 */
  452. handleQuery() {
  453. this.queryParams.pageNum = 1;
  454. this.getList();
  455. },
  456. /** 重置按钮操作 */
  457. resetQuery() {
  458. this.resetForm("queryForm");
  459. this.handleQuery();
  460. },
  461. // 多选框选中数据
  462. handleSelectionChange(selection) {
  463. this.ids = selection.map(item => item.id)
  464. this.single = selection.length !== 1
  465. this.multiple = !selection.length
  466. },
  467. /** 新增按钮操作 */
  468. handleAdd() {
  469. this.reset();
  470. this.open = true;
  471. this.title = "添加学习资料管理";
  472. },
  473. /** 修改按钮操作 */
  474. handleUpdate(row) {
  475. this.reset();
  476. const id = row.id || this.ids
  477. getResource(id).then(response => {
  478. this.form = response.data;
  479. this.open = true;
  480. this.title = "修改学习资料管理";
  481. });
  482. },
  483. /** 提交按钮 */
  484. submitForm() {
  485. this.$refs["form"].validate(valid => {
  486. if (valid) {
  487. if (this.form.id != null) {
  488. updateResource(this.form).then(response => {
  489. this.msgSuccess("修改成功");
  490. this.open = false;
  491. this.getList();
  492. });
  493. } else {
  494. addResource(this.form).then(response => {
  495. this.msgSuccess("新增成功");
  496. this.open = false;
  497. this.getList();
  498. });
  499. }
  500. }
  501. });
  502. },
  503. /** 删除按钮操作 */
  504. handleDelete(row) {
  505. const ids = row.id || this.ids;
  506. this.$confirm('是否确认删除?', "警告", {
  507. confirmButtonText: "确定",
  508. cancelButtonText: "取消",
  509. type: "warning"
  510. }).then(function () {
  511. return delResource(ids);
  512. }).then(() => {
  513. this.getList();
  514. this.msgSuccess("删除成功");
  515. })
  516. },
  517. }
  518. };
  519. </script>