ProductionResourceManage.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609
  1. <template>
  2. <div class="production-resource">
  3. <MenuPage cur-key="project" />
  4. <div class="production-resource-main">
  5. <div class="textbook-container">
  6. <MenuTree :id="select_node" :node-list="node_list" @selectNode="selectNode" />
  7. </div>
  8. <div class="textbook-chapter">
  9. <div class="textbook-chapter__header">
  10. <div class="courseware">
  11. <div class="operator flex">
  12. <span class="link" @click="handleAdd">上传</span>
  13. <span class="link" @click="handleDelete">删除</span>
  14. <span class="link" @click="handleSetInfo">设置信息</span>
  15. <span class="link" @click="handleChangeFile">更换文件</span>
  16. <span class="link" @click="handleMoveFile">移动文件</span>
  17. <span class="link" @click="handlePersonal">设置项目成员资源使用权限</span>
  18. <span class="link" @click="$router.push({ path: `/personal_workbench/project` })">返回项目列表</span>
  19. </div>
  20. </div>
  21. </div>
  22. <div class="search-box">
  23. <div class="search-left">
  24. <label
  25. class="label-btn"
  26. :class="[type_index === index ? 'active' : '']"
  27. v-for="(item, index) in type_list"
  28. :key="index"
  29. @click="changeType(index)"
  30. >{{ item.label }}</label
  31. >
  32. <el-input v-model="search_content"></el-input>
  33. <el-button type="primary" @click="queryList('')">查询</el-button>
  34. </div>
  35. <div class="search-right">
  36. <label>排序:</label>
  37. <el-select v-model="sort_value" placeholder="请选择"
  38. ><el-option v-for="item in sort_list" :key="item.value" :label="item.label" :value="item.value">
  39. </el-option
  40. ></el-select>
  41. <SvgIcon
  42. :icon-class="isDesc ? 'sort-down' : 'sort-up'"
  43. size="16"
  44. style="cursor: pointer"
  45. @click="changeSort"
  46. />
  47. </div>
  48. </div>
  49. <div class="sources-box" :style="{ height: height + 'px' }" v-if="height > 0" v-loading="boxLoading">
  50. <div
  51. v-for="(item, index) in list"
  52. :key="index"
  53. @click="selectSourceNode(item)"
  54. class="sources-item"
  55. :class="[select_sources_id === item.id ? 'active' : '']"
  56. >
  57. <template v-if="type_index === 0"> <el-image :src="item.file_url" fit="contain"></el-image></template>
  58. <template v-if="type_index === 1">
  59. <AudioLine
  60. ref="audioLine"
  61. :audio-id="'resource-audio-' + index"
  62. :mp3="item.file_url"
  63. :get-cur-time="getCurTime"
  64. :width="200"
  65. />
  66. </template>
  67. <template v-if="type_index === 2">
  68. <video controls :src="item.file_url" width="100%" height="140px"></video>
  69. </template>
  70. <p class="name">{{ item.name }}</p>
  71. <b class="label">{{ item.label }}</b>
  72. </div>
  73. </div>
  74. <PaginationPage ref="pagination" :total="total" @getList="queryList" />
  75. </div>
  76. </div>
  77. <!-- 上传 -->
  78. <el-dialog
  79. :visible.sync="sourceAddFlag"
  80. width="500px"
  81. append-to-body
  82. :show-close="true"
  83. title="上传资源"
  84. :close-on-click-modal="false"
  85. class="module-content"
  86. >
  87. <UploadFile
  88. key="upload_resources"
  89. :type="'upload_resources_manager'"
  90. :total-size="20000"
  91. :file-list="file_list"
  92. :file-id-list="file_id_list"
  93. :label-text="labelText"
  94. :accept-file-type="acceptFileType"
  95. :icon-class="iconClass"
  96. :limit="limit"
  97. :single-size="200"
  98. :uploadTip="uploadTip"
  99. @updateFileList="updateFileList"
  100. />
  101. <footer style="text-align: right">
  102. <el-button @click="handleCancle">取 消</el-button>
  103. <el-button :loading="loading" type="primary" @click="submitAdd">确 定</el-button>
  104. </footer>
  105. </el-dialog>
  106. <!-- 更新信息 -->
  107. <el-dialog
  108. :visible.sync="sourceInfoFlag"
  109. width="500px"
  110. append-to-body
  111. :show-close="true"
  112. title="设置资源"
  113. :close-on-click-modal="false"
  114. >
  115. <el-form ref="form" label-width="80px" :model="sourceInfo">
  116. <el-form-item prop="name" label="名称">
  117. <el-input v-model="sourceInfo.name" />
  118. </el-form-item>
  119. <el-form-item prop="label" label="标签">
  120. <el-input v-model="sourceInfo.label" />
  121. </el-form-item>
  122. <el-form-item prop="intro" label="简介">
  123. <el-input v-model="sourceInfo.intro" type="textarea" />
  124. </el-form-item>
  125. <el-form-item>
  126. <el-button @click="sourceInfoFlag = false">取 消</el-button>
  127. <el-button :loading="loading" type="primary" @click="submitSourceInfo">确 定</el-button>
  128. </el-form-item>
  129. </el-form>
  130. </el-dialog>
  131. </div>
  132. </template>
  133. <script>
  134. import MenuPage from '../common/menu.vue';
  135. import MenuTree from './components/MenuTree.vue';
  136. import {
  137. ChapterGetBookChapterStruct,
  138. MangerAddResource,
  139. MangerDeleteResource,
  140. MangerUpdateResourceFile,
  141. MangerUpdateResourceInfo,
  142. } from '@/api/book';
  143. import { GetProjectBaseInfo } from '@/api/project';
  144. import PaginationPage from '@/components/PaginationPage.vue';
  145. import { PageQueryProjectResourceList } from '@/api/list';
  146. import UploadFile from './components/UploadFile.vue';
  147. import AudioLine from './components/AudioLine.vue';
  148. export default {
  149. name: 'ProjectResourceManager',
  150. components: { MenuPage, MenuTree, PaginationPage, UploadFile, AudioLine },
  151. data() {
  152. return {
  153. book_id: this.$route.params.id,
  154. node_list: [],
  155. select_node: '',
  156. project_info: {}, // 项目基本信息
  157. type_list: [
  158. {
  159. value: 0,
  160. label: '图片',
  161. },
  162. {
  163. value: 1,
  164. label: '音频',
  165. },
  166. {
  167. value: 2,
  168. label: '视频',
  169. },
  170. {
  171. value: 3,
  172. label: 'H5 游戏',
  173. },
  174. {
  175. value: 4,
  176. label: '3D 模型',
  177. },
  178. ], // 类型分类
  179. type_index: 0, // 类型索引
  180. sort_list: [
  181. {
  182. value: 'name',
  183. label: '名称',
  184. },
  185. {
  186. value: 'label',
  187. label: '标签',
  188. },
  189. {
  190. value: 'last_modify_time',
  191. label: '修改时间',
  192. },
  193. {
  194. value: 'file_size',
  195. label: '文件大小',
  196. },
  197. ], // 排序分类
  198. sort_value: '', // 排序值
  199. isDesc: false, // 排序是否为倒序
  200. select_sources_id: '', // 选中的资源id
  201. list: [],
  202. total: 0,
  203. search_content: '', // 查询内容
  204. height: 0,
  205. page_capacity: 10,
  206. cur_page: 1,
  207. sourceAddFlag: false, // 新增flag
  208. labelText: '资源',
  209. acceptFileType: '.jpg,.png,.jpeg',
  210. iconClass: '',
  211. file_id_list: [],
  212. file_list: [],
  213. loading: false,
  214. acceptFileTypeList: ['.jpg,.png,.jpeg', '.mp3', '.mp4', '*', '*', '*'],
  215. limit: 10,
  216. uploadTip: '',
  217. boxLoading: false,
  218. sourceInfoFlag: false, // 设置信息
  219. sourceInfo: {
  220. name: '',
  221. label: '',
  222. intro: '',
  223. },
  224. };
  225. },
  226. created() {
  227. this.getProjectBaseInfo();
  228. },
  229. mounted() {
  230. this.height =
  231. document.getElementsByClassName('app-container')[0].clientHeight -
  232. document.getElementsByClassName('menu')[0].clientHeight -
  233. document.getElementsByClassName('textbook-chapter__header')[0].clientHeight -
  234. document.getElementsByClassName('search-box')[0].clientHeight -
  235. document.getElementsByClassName('el-pagination')[0].clientHeight -
  236. 30;
  237. },
  238. methods: {
  239. selectNode(nodeId) {
  240. this.select_node = nodeId;
  241. this.queryList('');
  242. },
  243. /**
  244. * 获取项目基本信息
  245. * @param {string} id - 项目ID
  246. */
  247. getProjectBaseInfo() {
  248. GetProjectBaseInfo({ id: this.book_id }).then(({ project_info }) => {
  249. this.project_info = project_info;
  250. this.getBookChapterStructExpandList(project_info.name);
  251. });
  252. },
  253. /**
  254. * 得到教材章节结构展开列表
  255. */
  256. getBookChapterStructExpandList(name) {
  257. ChapterGetBookChapterStruct({
  258. book_id: this.book_id,
  259. node_deep_mode: 0,
  260. is_contain_producer: 'false',
  261. is_contain_auditor: 'false',
  262. }).then(({ nodes }) => {
  263. this.node_list = [
  264. {
  265. auditor_desc: '',
  266. deep: 1,
  267. id: '',
  268. is_courseware: 'false',
  269. is_leaf: 'false',
  270. is_leaf_chapter: 'false',
  271. level_index: '0',
  272. label: name,
  273. nodes: nodes,
  274. children: nodes,
  275. },
  276. ];
  277. this.handleData(this.node_list[0], 1);
  278. });
  279. },
  280. // 递归
  281. handleData(data, nodeIndex) {
  282. if (data.nodes) {
  283. data.nodes.forEach((item) => {
  284. item.label = item.name;
  285. item.pid = data.id;
  286. item.nodexIndex = nodeIndex;
  287. item.isLeaf = item.is_leaf === 'true';
  288. if (item.nodes) {
  289. item.children = item.nodes;
  290. item.lists = item.nodes;
  291. this.handleData(item, nodeIndex + 1);
  292. }
  293. });
  294. }
  295. },
  296. // 上传
  297. handleAdd() {
  298. this.limit = 10;
  299. this.uploadTip = '最多上传 10 个文件,多文件分批上传';
  300. this.sourceAddFlag = true;
  301. },
  302. // 删除
  303. handleDelete() {
  304. if (this.select_sources_id) {
  305. this.$confirm('确定要删除此条资源吗?', '提示', {
  306. confirmButtonText: '确定',
  307. cancelButtonText: '取消',
  308. type: 'warning',
  309. })
  310. .then(() => {
  311. MangerDeleteResource({ id: this.select_sources_id }).then(() => {
  312. this.$message.success('删除成功!');
  313. this.select_sources_id = '';
  314. this.queryList('');
  315. });
  316. })
  317. .catch(() => {});
  318. } else {
  319. this.$message.warning('请先选择文件');
  320. }
  321. },
  322. // 设置信息
  323. handleSetInfo() {
  324. if (this.select_sources_id) {
  325. this.sourceInfoFlag = true;
  326. } else {
  327. this.$message.warning('请先选择文件');
  328. }
  329. },
  330. // 更换文件
  331. handleChangeFile() {
  332. if (this.select_sources_id) {
  333. this.limit = 1;
  334. this.uploadTip = '只能上传 1 个文件';
  335. this.sourceAddFlag = true;
  336. } else {
  337. this.$message.warning('请先选择文件');
  338. }
  339. },
  340. // 设置项目成员资源使用权限
  341. handlePersonal() {},
  342. // 移动文件
  343. handleMoveFile() {},
  344. // 切换类型
  345. changeType(index) {
  346. this.type_index = index;
  347. this.select_sources_id = '';
  348. this.acceptFileType = this.acceptFileTypeList[index];
  349. this.queryList('');
  350. },
  351. // 查询列表
  352. queryList(data) {
  353. this.boxLoading = true;
  354. if (data) {
  355. this.page_capacity = data.page_capacity;
  356. this.cur_page = data.cur_page;
  357. } else {
  358. this.page_capacity = 10;
  359. this.cur_page = 1;
  360. }
  361. let order_column_list = [];
  362. if (this.sort_value) {
  363. order_column_list = [this.isDesc ? this.sort_value + ':desc' : this.sort_value];
  364. }
  365. let datas = {
  366. page_capacity: this.page_capacity,
  367. cur_page: this.cur_page,
  368. project_id: this.book_id,
  369. book_chapter_node_id: this.select_node,
  370. type: this.type_list[this.type_index].value,
  371. name_or_label: this.search_content,
  372. order_column_list: order_column_list,
  373. };
  374. PageQueryProjectResourceList(datas)
  375. .then(({ total_count, resource_list }) => {
  376. this.boxLoading = false;
  377. this.total = total_count;
  378. this.list = resource_list;
  379. })
  380. .catch(() => {
  381. this.boxLoading = false;
  382. });
  383. },
  384. // 切换排序升序降序
  385. changeSort() {
  386. this.isDesc = !this.isDesc;
  387. },
  388. updateFileList({ file_list, file_id_list }) {
  389. this.file_list = file_list;
  390. this.file_id_list = file_id_list;
  391. },
  392. handleCancle() {
  393. this.sourceAddFlag = false;
  394. this.file_list = [];
  395. this.file_id_list = [];
  396. },
  397. // 确定新增资源
  398. submitAdd() {
  399. this.loading = true;
  400. if (this.limit === 1) {
  401. // 更换文件
  402. let data = {
  403. id: this.select_sources_id,
  404. file_id: this.file_id_list[0],
  405. };
  406. MangerUpdateResourceFile(data)
  407. .then((res) => {
  408. this.loading = false;
  409. this.sourceAddFlag = false;
  410. if (res.status === 1) {
  411. this.$message.success('更换成功');
  412. this.queryList('');
  413. }
  414. })
  415. .catch(() => {
  416. this.loading = false;
  417. });
  418. } else {
  419. // 上传文件
  420. let data = {
  421. project_id: this.book_id,
  422. book_chapter_node_id: this.select_node,
  423. type: this.type_list[this.type_index].value,
  424. file_id_list: this.file_id_list,
  425. };
  426. MangerAddResource(data)
  427. .then((res) => {
  428. this.loading = false;
  429. this.sourceAddFlag = false;
  430. if (res.status === 1) {
  431. this.queryList('');
  432. }
  433. })
  434. .catch(() => {
  435. this.loading = false;
  436. });
  437. }
  438. },
  439. // 点击资源
  440. selectSourceNode(item) {
  441. this.select_sources_id = item.id;
  442. this.sourceInfo = {
  443. name: item.name,
  444. label: item.label,
  445. intro: item.intro,
  446. };
  447. },
  448. getCurTime() {},
  449. // 更新信息确定按钮
  450. submitSourceInfo() {
  451. this.loading = true;
  452. MangerUpdateResourceInfo({
  453. id: this.select_sources_id,
  454. resource_info: this.sourceInfo,
  455. })
  456. .then((res) => {
  457. this.loading = false;
  458. this.sourceInfoFlag = false;
  459. if (res.status === 1) {
  460. this.$message.success('设置成功');
  461. this.queryList('');
  462. }
  463. })
  464. .catch(() => {
  465. this.loading = false;
  466. });
  467. },
  468. },
  469. };
  470. </script>
  471. <style lang="scss" scoped>
  472. @use '@/styles/mixin.scss' as *;
  473. .production-resource {
  474. @include page-content(true);
  475. .production-resource-main {
  476. display: flex;
  477. flex: 1;
  478. width: 100%;
  479. height: 100%;
  480. background: #fff;
  481. border-top: $border;
  482. .textbook-container {
  483. display: flex;
  484. flex-direction: column;
  485. width: 320px;
  486. height: calc(100vh - 120px);
  487. overflow: auto;
  488. border-right: $border;
  489. }
  490. .textbook-chapter {
  491. display: flex;
  492. flex: 1;
  493. flex-direction: column;
  494. &__header {
  495. display: flex;
  496. align-items: center;
  497. justify-content: flex-end;
  498. height: 40px;
  499. padding: 6px 4px;
  500. margin-bottom: 5px;
  501. background-color: #fff;
  502. border-bottom: 1px solid #e5e6eb;
  503. .operator {
  504. display: flex;
  505. flex: 1;
  506. justify-content: flex-end;
  507. .link {
  508. + .link {
  509. &::before {
  510. margin-right: 8px;
  511. color: #999;
  512. content: '|';
  513. }
  514. }
  515. }
  516. }
  517. }
  518. .search-box {
  519. display: flex;
  520. justify-content: space-between;
  521. padding: 5px;
  522. .search-left {
  523. display: flex;
  524. flex-flow: wrap;
  525. gap: 5px;
  526. align-items: center;
  527. }
  528. .label-btn {
  529. padding: 5px 10px;
  530. cursor: pointer;
  531. background: #ebebeb;
  532. border-radius: 4px;
  533. &.active {
  534. color: #f90;
  535. background: #ffefd6;
  536. }
  537. }
  538. .el-input,
  539. .el-select {
  540. width: 120px;
  541. }
  542. }
  543. }
  544. .sources-box {
  545. display: flex;
  546. flex-flow: wrap;
  547. gap: 10px;
  548. place-content: start start;
  549. padding: 5px;
  550. overflow: auto;
  551. .sources-item {
  552. width: 200px;
  553. cursor: pointer;
  554. .el-image {
  555. width: 100%;
  556. height: 140px;
  557. border: 1px solid #ccc;
  558. }
  559. .name,
  560. .label {
  561. margin: 5px 0;
  562. font-size: 14px;
  563. line-height: 1.3;
  564. }
  565. :deep .audioLine {
  566. background: #f2f3f5;
  567. }
  568. &.active {
  569. .el-image {
  570. border-color: #f90;
  571. }
  572. .name,
  573. .label {
  574. color: #f90;
  575. }
  576. }
  577. }
  578. }
  579. }
  580. }
  581. </style>