index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. <template>
  2. <div class="app-container">
  3. <form-search :searchformShow="searchformShow" :validate-rules="searchRules" :extra-params="extraParams"
  4. @handleQuery="handleQuery" @resetQuery="resetQuery"></form-search>
  5. <el-card class="box-card" style="margin-bottom:30px">
  6. <el-row :gutter="24">
  7. <el-col :span="4">
  8. <h3 style="padding-left: 11px;border-left: 2px solid #e6a700;color: #e6a700;">章节目录</h3>
  9. <div class="head-container">
  10. <el-input v-model="deptName" placeholder="请输入部门名称" clearable size="small" prefix-icon="el-icon-search"
  11. style="margin-bottom: 20px"/>
  12. </div>
  13. <div class="head-container">
  14. <el-tree
  15. :data="deptOptions"
  16. :props="treeProps"
  17. :expand-on-click-node="false"
  18. :filter-node-method="filterNode"
  19. ref="tree"
  20. @node-click="handleNodeClick"
  21. />
  22. </div>
  23. </el-col>
  24. <el-col :span="20">
  25. <el-row :gutter="10" class="mb8">
  26. <el-col :span="1.5" v-hasPermi="['front:cloudResource:downloadToPersonResourse']">
  27. <el-button plain icon="el-icon-download" size="small" @click="downToPersonResourse" :disabled="multiple">
  28. 下载至个人资源库
  29. </el-button>
  30. </el-col>
  31. <el-table v-loading="loading" :data="resourcesList" @selection-change="handleSelectionChange">
  32. <el-table-column type="selection" width="55" align="center"/>
  33. <el-table-column label="文件" align="center" prop="resourcesName" v-if="viewName=='Index'">
  34. <template slot-scope="scope">
  35. <resource-preview-button :row="scope.row">
  36. <img style="width:130px;height:80px ;cursor:pointer" :src="img.ship" alt/>
  37. </resource-preview-button>
  38. </template>
  39. </el-table-column>
  40. <el-table-column label="文件名" align="center" prop="resourcesName"/>
  41. <el-table-column label="发布人" align="center" prop="createBy"/>
  42. <el-table-column label="时间" align="center" prop="createTime"/>
  43. <el-table-column label="操作" align="center" class-name="small-padding fixed-width"
  44. v-if="viewName!='Index'||isFrontMaster">
  45. <template slot-scope="scope">
  46. <resource-preview-button v-if="viewName!='Index'" :row="scope.row"/>
  47. <template v-if="isFrontMaster">
  48. <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
  49. :class="{'ml10':viewName!='Index'}">
  50. 修改
  51. </el-button>
  52. <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
  53. v-hasPermi="['system:resources:remove']">删除
  54. </el-button>
  55. </template>
  56. </template>
  57. </el-table-column>
  58. </el-table>
  59. <pagination v-show="total>0" :total="total" :page.sync="pageNum" :limit.sync="pageSize"
  60. @pagination="getList"/>
  61. </el-row>
  62. </el-col>
  63. </el-row>
  64. </el-card>
  65. <!-- 添加或修改云库对话框 -->
  66. <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
  67. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  68. <el-form-item label="资源名称" prop="resourcesName">
  69. <el-input v-model="form.resourcesName" placeholder="请输入资源名称"/>
  70. </el-form-item>
  71. </el-form>
  72. <div slot="footer" class="dialog-footer">
  73. <el-button type="primary" @click="submitForm">确 定</el-button>
  74. <el-button @click="cancel">取 消</el-button>
  75. </div>
  76. </el-dialog>
  77. <upload-dialog
  78. v-if="dialogVisible"
  79. :title="title"
  80. :page-name="queryParams.category"
  81. :dialogVisible.sync="dialogVisible"
  82. scene="下载"
  83. @handleClose="handleClose"
  84. @dialogVisibleClose="dialogVisibleClose"
  85. ></upload-dialog>
  86. </div>
  87. </template>
  88. <script>
  89. import {
  90. addCloudResource,
  91. deleteCloudResource,
  92. downToPersonResourse,
  93. downToSchoolResourse,
  94. getCloudResourceDetail,
  95. getCloudResources,
  96. modifyCloudResource
  97. } from '@/api/webApi/cloud'
  98. import { chapterTree } from '@/api/webApi/webQue.js'
  99. import { mapGetters } from 'vuex'
  100. import ResourcePreviewButton from '@/views/accurateTeaching/components/resource-preview-button'
  101. import consts from '@/common/mx-const'
  102. export default {
  103. components: { ResourcePreviewButton },
  104. data() {
  105. return {
  106. searchformShow: {},
  107. searchRules: {},
  108. extraParams: {},
  109. dialogVisible: false,
  110. img: {
  111. ship: require('@/assets/images/ship.png')
  112. },
  113. treeProps: {
  114. children: 'children',
  115. label: 'name',
  116. code: 'id'
  117. },
  118. deptOptions: undefined,
  119. deptName: '',
  120. // 遮罩层
  121. loading: true,
  122. // 导出遮罩层
  123. exportLoading: false,
  124. // 选中数组
  125. ids: [],
  126. // 非单个禁用
  127. single: true,
  128. // 非多个禁用
  129. multiple: true,
  130. // 显示搜索条件
  131. showSearch: true,
  132. // 总条数
  133. total: 0,
  134. pageNum: 1,
  135. pageSize: 10,
  136. // 云库表格数据
  137. resourcesList: [],
  138. // 弹出层标题
  139. title: '',
  140. // 是否显示弹出层
  141. open: false,
  142. // 资源类型字典
  143. typeOptions: [],
  144. // 资源分类字典
  145. categoryOptions: [],
  146. // 是否删除字典
  147. delFlagOptions: [],
  148. // 查询参数
  149. queryParams: {
  150. pageNum: 1,
  151. pageSize: 10,
  152. resourcesName: null,
  153. type: null,
  154. category: null,
  155. province: null,
  156. city: null,
  157. county: null,
  158. chapterId: null,
  159. resourcesUrl: null,
  160. bookId: null,
  161. subjectId: null
  162. },
  163. // 表单参数
  164. form: {},
  165. // 表单校验
  166. rules: {
  167. resourcesName: [
  168. { required: true, message: '资源名称不能为空', trigger: 'blur' }
  169. ],
  170. category: [
  171. { required: true, message: '资源分类不能为空', trigger: 'change' }
  172. ],
  173. chapterId: [
  174. { required: true, message: '章节不能为空', trigger: 'blur' }
  175. ],
  176. bookId: [{ required: true, message: '学册不能为空', trigger: 'blur' }],
  177. subjectId: [
  178. { required: true, message: '科目不能为空', trigger: 'blur' }
  179. ],
  180. delFlag: [
  181. { required: true, message: '是否删除不能为空', trigger: 'change' }
  182. ],
  183. createBy: [
  184. { required: true, message: '创建者Id不能为空', trigger: 'blur' }
  185. ]
  186. },
  187. viewName: ''
  188. }
  189. },
  190. computed: {
  191. ...mapGetters(['currentUser', 'isFrontMaster']),
  192. userInfo() {
  193. // TODO: hht 22.1.5 兼容历史写法,待清理
  194. return this.currentUser
  195. }
  196. },
  197. created() {
  198. this.viewName = this.$route.name
  199. if (this.viewName == 'Index') {
  200. this.searchformShow = {
  201. province: '',
  202. subjectid: '',
  203. edition: '',
  204. slipid: ''
  205. }
  206. this.searchRules = {}
  207. this.extraParams = {}
  208. } else if (this.viewName == 'Courseware') {
  209. this.searchformShow = {
  210. province: '',
  211. subjectid: '',
  212. edition: '',
  213. slipid: '',
  214. coursewareType: ''
  215. }
  216. this.searchRules = this.createCoursewareRules()
  217. this.extraParams = this.createCoursewareParams()
  218. }
  219. this.getList()
  220. this.getDicts('resource_type').then((response) => {
  221. this.typeOptions = response.data
  222. })
  223. this.getDicts('category').then((response) => {
  224. this.categoryOptions = response.data
  225. })
  226. this.getDicts('bool_flag').then((response) => {
  227. this.delFlagOptions = response.data
  228. })
  229. },
  230. methods: {
  231. createCoursewareRules() {
  232. return {
  233. subjectid: [{ required: true, message: '科目必选' }],
  234. edition: [{ required: true, message: '版本必选' }],
  235. slipid: [{ required: true, message: '学册必选' }]
  236. }
  237. },
  238. createCoursewareParams() {
  239. const sharedParams = { source: consts.enum.librarySource.courseware }
  240. return {
  241. subjectid: sharedParams,
  242. edition: sharedParams,
  243. slipid: sharedParams,
  244. tree: sharedParams
  245. }
  246. },
  247. /** 查询个人资源库列表 */
  248. getList() {
  249. this.loading = true
  250. if (this.viewName == 'Index') {
  251. this.queryParams.category = '微课视频'
  252. } else if (this.viewName == 'Courseware') {
  253. this.queryParams.category = '课件资源'
  254. }
  255. let Ajax = {
  256. subjectId: this.queryParams.subjectid, //科目
  257. bookId: this.queryParams.slipid, //学册
  258. chapterId: this.queryParams.chapterId, //章节
  259. coursewareType: this.queryParams.coursewareType,
  260. province: this.queryParams.province,
  261. city: this.queryParams.city,
  262. county: this.queryParams.area,
  263. schoolId: this.queryParams.schoolid,
  264. pageNum: this.pageNum,
  265. pageSize: this.pageSize,
  266. category: this.queryParams.category
  267. }
  268. getCloudResources(Ajax)
  269. .then((response) => {
  270. this.resourcesList = response.rows
  271. this.total = response.total
  272. this.loading = false
  273. })
  274. .catch((err) => {
  275. this.loading = false
  276. })
  277. },
  278. // 资源类型字典翻译
  279. typeFormat(row, column) {
  280. return this.selectDictLabel(this.typeOptions, row.type)
  281. },
  282. // 资源分类字典翻译
  283. categoryFormat(row, column) {
  284. return this.selectDictLabel(this.categoryOptions, row.category)
  285. },
  286. // 是否删除字典翻译
  287. delFlagFormat(row, column) {
  288. return this.selectDictLabel(this.delFlagOptions, row.delFlag)
  289. },
  290. handleClose(type, name) {
  291. let _this = this
  292. if (this.title == '下载至个人资源库') {
  293. _this.ids.forEach((item, index) => {
  294. let Ajax = {
  295. resourseId: item
  296. }
  297. if (name) {
  298. Ajax.resourcesName = name
  299. }
  300. downToPersonResourse(Ajax).then(() => {
  301. if (index == _this.ids.length - 1) {
  302. _this.msgSuccess('操作成功')
  303. _this.dialogVisible = false
  304. }
  305. })
  306. })
  307. } else {
  308. _this.ids.forEach((item, index) => {
  309. let Ajax = {
  310. resourseId: item
  311. }
  312. if (name) {
  313. Ajax.resourcesName = name
  314. }
  315. downToSchoolResourse(Ajax).then(() => {
  316. if (index == _this.ids.length - 1) {
  317. _this.msgSuccess('操作成功')
  318. _this.dialogVisible = false
  319. }
  320. })
  321. })
  322. }
  323. },
  324. downToPersonResourse() {
  325. let _this = this
  326. const resourcesIds = this.ids.join(',')
  327. this.title = '下载至个人资源库'
  328. this.dialogVisible = true
  329. },
  330. downToSchoolResourse() {
  331. let _this = this
  332. const resourcesIds = this.ids.join(',')
  333. this.title = '下载至校本资源库'
  334. this.dialogVisible = true
  335. },
  336. dialogVisibleClose() {
  337. this.dialogVisible = false
  338. },
  339. // 取消按钮
  340. cancel() {
  341. this.open = false
  342. this.reset()
  343. },
  344. // 表单重置
  345. reset() {
  346. this.form = {
  347. resourcesId: null,
  348. resourcesName: null,
  349. sourceId: null,
  350. category: null,
  351. chapterId: null,
  352. knowledgeBasicId: null,
  353. resourcesUrl: null,
  354. type: null,
  355. linkWay: null,
  356. bookId: null,
  357. customerId: null,
  358. subjectId: null,
  359. delFlag: null,
  360. createBy: null,
  361. createTime: null,
  362. remark: null
  363. }
  364. },
  365. /** 搜索按钮操作 */
  366. async handleQuery(data, type) {
  367. this.pageNum = 1
  368. this.queryParams = Object.assign(this.queryParams, data)
  369. await this.getTreeselect(type)
  370. this.getList()
  371. },
  372. /** 重置按钮操作 */
  373. resetQuery(data) {
  374. this.queryParams = data
  375. this.queryParams.chapterId = ''
  376. this.pageNum = 1
  377. this.getList()
  378. },
  379. // 多选框选中数据
  380. handleSelectionChange(selection) {
  381. this.ids = selection.map((item) => item.resourcesId)
  382. this.single = selection.length !== 1
  383. this.multiple = !selection.length
  384. },
  385. /** 新增按钮操作 */
  386. handleAdd() {
  387. this.reset()
  388. this.open = true
  389. this.title = '添加云库'
  390. },
  391. /** 修改按钮操作 */
  392. handleUpdate(row) {
  393. this.reset()
  394. getCloudResourceDetail({ resourcesId: row.resourcesId }).then(
  395. (response) => {
  396. this.form = response.data
  397. this.open = true
  398. this.title = '修改云库'
  399. }
  400. )
  401. },
  402. /** 提交按钮 */
  403. submitForm() {
  404. this.$refs['form'].validate((valid) => {
  405. if (valid) {
  406. if (this.form.resourcesId != null) {
  407. modifyCloudResource(this.form).then((response) => {
  408. this.msgSuccess('修改成功')
  409. this.open = false
  410. this.getList()
  411. })
  412. } else {
  413. addCloudResource(this.form).then((response) => {
  414. this.msgSuccess('新增成功')
  415. this.open = false
  416. this.getList()
  417. })
  418. }
  419. }
  420. })
  421. },
  422. /** 删除按钮操作 */
  423. handleDelete(row) {
  424. const resourcesIds = row.resourcesId || this.ids
  425. this.$confirm(
  426. '是否确认删除云库名称为"' + row.resourcesName + '"的数据项?',
  427. '警告',
  428. {
  429. confirmButtonText: '确定',
  430. cancelButtonText: '取消',
  431. type: 'warning'
  432. }
  433. )
  434. .then(function() {
  435. return deleteCloudResource(row.resourcesId)
  436. })
  437. .then(() => {
  438. this.getList()
  439. this.msgSuccess('删除成功')
  440. })
  441. },
  442. /** 导出按钮操作 */
  443. handleExport() {
  444. const queryParams = this.queryParams
  445. this.$confirm('是否确认导出所有云库数据项?', '警告', {
  446. confirmButtonText: '确定',
  447. cancelButtonText: '取消',
  448. type: 'warning'
  449. })
  450. .then(() => {
  451. this.exportLoading = true
  452. return exportList(queryParams)
  453. })
  454. .then((response) => {
  455. this.download(response.msg)
  456. this.exportLoading = false
  457. })
  458. },
  459. /** 查询部门下拉树结构 */
  460. async getTreeselect(type) {
  461. if (type == 'coursewareType') return
  462. if (!this.queryParams.slipid) {
  463. this.deptOptions = []
  464. this.queryParams.chapterId = ''
  465. return
  466. }
  467. if (type != 'slipid') {
  468. return
  469. }
  470. let Ajax = {
  471. editionId: this.queryParams.edition, //版本
  472. subjectId: this.queryParams.subjectid, //科目
  473. pharseId: this.queryParams.pharseId, //pharseId
  474. gradeId: this.queryParams.slipid, //学册
  475. ...this.extraParams.tree
  476. }
  477. this.treeLoading = true
  478. this.queryParams.chapterId = ''
  479. const resTree = await chapterTree(Ajax)
  480. this.deptOptions = resTree.data
  481. this.treeLoading = false
  482. },
  483. // 筛选节点
  484. filterNode(value, data) {
  485. if (!value) return true
  486. return data.label.indexOf(value) !== -1
  487. },
  488. // 节点单击事件
  489. handleNodeClick(data) {
  490. if (!data.children?.length) {
  491. this.pageNum = 1
  492. this.queryParams.chapterId = data.id
  493. this.getList()
  494. } else {
  495. this.queryParams.chapterId = ''
  496. }
  497. }
  498. }
  499. }
  500. </script>