多媒体信息发布平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

624 lines
20 KiB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  1. <template>
  2. <div>
  3. <div v-if="isToFolder" class="material_crumbs">
  4. <el-breadcrumb separator-class="el-icon-arrow-right">
  5. <el-breadcrumb-item><a href="/content">素材库</a></el-breadcrumb-item>
  6. <el-breadcrumb-item>{{ currentFolder }}</el-breadcrumb-item>
  7. </el-breadcrumb>
  8. </div>
  9. <div class="material_content">
  10. <!-- 上传 / 创建文件夹 -->
  11. <div class="material_item cont_upload">
  12. <Upload ref="uploadMaterial" @saveMaterial="saveMaterial" />
  13. <el-button v-if="!isToFolder" class="mkdir_btn" round type="primary" @click="handleMkdir(0)">创建文件夹</el-button>
  14. <el-button v-else class="return_btn" round type="primary"><a href="/content">返回</a></el-button>
  15. </div>
  16. <!-- 文件夹list -->
  17. <div v-for="(item,index) in materialFolders" :key="item.id" :class="['material_item', 'folder', { 'item_multi': folderChecked == index }]" @click.stop="editFolder(item,index)" @dblclick="floderDbClick(item,index)">
  18. <div class="icon_bg">
  19. <svg v-if="!item.imgPath" class="font-icon icon" aria-hidden="true">
  20. <use xlink:href="#icon-wenjianjia" />
  21. </svg>
  22. <img v-else :src="item.imgPath" />
  23. </div>
  24. <p class="file_name">{{ item.name }}</p>
  25. <span v-if="folderChecked == index" class="checked_btn"></span>
  26. </div>
  27. <!-- 素材库list -->
  28. <div v-for="(item, index) in materialList" :key="'list-'+index" :class="['material_item', 'item_cont', { 'item_multi': selectedListId.includes(item.material_id) }]">
  29. <img v-if="item.img_path || item.material_type == 1" :src="item.img_path" :onerror="defaultImg" alt />
  30. <div v-if="!item.img_path && item.material_type == 2" class="radio_img"></div>
  31. <div class="item_format">
  32. <span class="item_type">{{ item.deposit_url | getFileFormat }}</span>
  33. <span v-if="item.material_type !== '0'" class="item_time">{{ item.duration | getSeconds }}</span>
  34. </div>
  35. <div class="file_name">{{ item.material_name }}</div>
  36. <span v-if="isMultiSelected" class="checked_btn" @click="selectedItem(item)"></span>
  37. </div>
  38. </div>
  39. <!-- 创建文件夹layer / 编辑 -->
  40. <div class="publish_layer">
  41. <el-dialog :title="layerTitle" :close-on-click-modal="false" :show-close="false" :visible.sync="mkdirVisible" width="616px">
  42. <el-form ref="folderForm" :inline="true" :model="folderForm" size="small" label-width="100px">
  43. <el-form-item
  44. :label="labelTxt"
  45. prop="name"
  46. :rules="[
  47. { required: true, message: '请输入名称', trigger: 'blur' }
  48. ]"
  49. >
  50. <el-input v-model="folderForm.name" style="width: 336px" />
  51. </el-form-item>
  52. <el-form-item v-if="formatType != 0" label="封面">
  53. <UploadCover ref="childUpload" />
  54. </el-form-item>
  55. </el-form>
  56. <div slot="footer" class="dialog-footer">
  57. <el-button v-if="!isEditMaterial" type="primary" round @click="submitForm('folderForm')"> </el-button>
  58. <el-button v-else type="primary" round @click="saveMaterial"> </el-button>
  59. <el-button round @click="resetForm()"> </el-button>
  60. </div>
  61. </el-dialog>
  62. </div>
  63. <!-- 多选操作 -->
  64. <div v-if="selectedListId.length != 0 || folderChecked != -1" class="multi_handle">
  65. <div v-if="!isEditFolder && folderChecked == -1 && isMultiSelected">
  66. <el-button type="button" class="mulit_btn" @click="publishHandle(0)">即时发布</el-button>
  67. <el-button type="button" class="mulit_btn" @click="publishHandle(1)">定时发布</el-button>
  68. <el-button type="button" class="mulit_btn" :disabled="selectedListId.length > 1" @click="editContent()">编辑</el-button>
  69. <el-button type="button" class="mulit_btn">下载</el-button>
  70. <el-button type="button" class="mulit_btn" @click="moveingTo()">移动</el-button>
  71. <el-button type="button" class="mulit_btn mulit_delt_btn" @click="deleteMyMaterial">删除</el-button>
  72. </div>
  73. <div v-else>
  74. <el-button type="button" class="mulit_btn" @click="handleMkdir(1)">编辑</el-button>
  75. <el-button type="button" class="mulit_btn mulit_delt_btn" @click="deleteMaterialFolder">删除</el-button>
  76. </div>
  77. </div>
  78. <!-- 移动至layer -->
  79. <div class="wjj_layer">
  80. <!-- width="736px" -->
  81. <el-dialog title="移动至" :close-on-click-modal="false" :show-close="false" :visible.sync="movingVisible" width="576px" height="384px">
  82. <div class="wjj_list">
  83. <div v-for="(item, index) in folderList" :key="index" :class="['wjj_item', { 'wjj_item_active': folderListChecked == index }]" @click="wjjSelected(item,index)">
  84. <svg class="font-icon icon" aria-hidden="true">
  85. <use xlink:href="#icon-wenjianjia" />
  86. </svg>
  87. <p class="wjj_name">{{ item.name }}</p>
  88. </div>
  89. </div>
  90. <div slot="footer" class="dialog-footer">
  91. <el-button type="primary" round @click="moveFile">确定</el-button>
  92. <el-button round @click="movingVisible=false">取消</el-button>
  93. </div>
  94. </el-dialog>
  95. </div>
  96. </div>
  97. </template>
  98. <script>
  99. import { getMaterialList, saveMaterialFolder, deleteMaterialFolder, saveMaterial, deleteMyMaterial, moveMyMaterial } from '@/api/material/material'
  100. import Upload from '../../components/upload'
  101. import UploadCover from '../../components/upload_cover'
  102. import { getSeconds, getFileFormat } from '@/utils/index.js'
  103. export default {
  104. name: 'Material',
  105. components: { Upload, UploadCover },
  106. filters: {
  107. getSeconds(s) {
  108. return getSeconds(s)
  109. },
  110. getFileFormat(s) {
  111. return getFileFormat(s)
  112. }
  113. },
  114. props: {
  115. isMultiSelected: {
  116. type: Boolean,
  117. required: true
  118. }
  119. },
  120. data() {
  121. return {
  122. orga_id: '133221333123111', // 机构ID
  123. rootFolderId: null, // 根目录文件夹ID
  124. thisFoldId: null, // 当前父文件夹ID
  125. folderList: [], // 文件夹list
  126. materialFolders: [], // 文件夹list
  127. folderForm: { // form
  128. fid: '',
  129. id: '',
  130. img_path: '',
  131. name: '',
  132. orga_id: ''
  133. },
  134. isEditFolder: false, // 是否编辑文件夹
  135. mkdirVisible: false, // 新建编辑layer
  136. folderChecked: -1, // 文件夹是否单击选中
  137. materialList: [], // 素材库list
  138. isEditMaterial: false, // 是否是编辑素材
  139. formatType: null, // 上传素材类型 0 img 1 video 2 audio
  140. materialId: null, // 编辑时需要参数 id
  141. materialImgPath: '', // 素材封面
  142. materialDuration: 0, // 时长
  143. materialName: '', // 素材名称
  144. uploadFileUrl: null, // 素材保存路径
  145. selectedMaterial: [], // 素材选中
  146. selectedListId: [], // 素材选中的material_id
  147. selectinFolderid: [], // 素材选中的和文件关联表id -- in_folder_id
  148. layerTitle: '创建文件夹', // 文件夹/素材编辑框title
  149. labelTxt: '文件夹名称',
  150. isToFolder: false, // 是否进入文件夹
  151. currentFolder: '', // 当前进入的文件夹名
  152. currentFolderId: null,
  153. movingVisible: false,
  154. uploadListData: [ // 上传列表
  155. ],
  156. folderListChecked: -1,
  157. wjjList: []
  158. }
  159. },
  160. computed: {
  161. defaultImg() {
  162. return 'this.src="' + require('@/assets/images/menu_bg_02.png') + '"'
  163. }
  164. },
  165. watch: {
  166. isMultiSelected(newName, oldName) {
  167. console.log('newName', newName)
  168. if (newName === false) {
  169. this.selectedListId = []
  170. }
  171. },
  172. '$route.query.folderTag'(Val) {
  173. console.log(Val)
  174. }
  175. },
  176. mounted: function() {
  177. console.log(this.$route.query.folderTag)
  178. this.getMaterialList()
  179. document.addEventListener('click', this.hiddenFolderActiveClick)
  180. },
  181. methods: {
  182. // 获取素材库list
  183. getMaterialList() {
  184. let params
  185. if (this.$route.query.folderTag) {
  186. console.log('文件夹内')
  187. this.isToFolder = true
  188. this.currentFolder = localStorage.getItem('currentFolder')
  189. this.currentFolderId = localStorage.getItem('currentFolderId')
  190. params = {
  191. 'folder_id': this.currentFolderId,
  192. 'material_name': null,
  193. 'material_type': null,
  194. 'orga_id': this.orga_id
  195. }
  196. } else {
  197. console.log('文件夹外')
  198. this.isToFolder = false
  199. localStorage.removeItem('currentFolder')
  200. localStorage.removeItem('currentFolderId')
  201. params = {
  202. 'folder_id': null,
  203. 'material_name': null,
  204. 'material_type': null,
  205. 'material_type_not': null,
  206. 'orga_id': this.orga_id
  207. }
  208. }
  209. getMaterialList(params).then(res => {
  210. if (!this.$route.query.folderTag) {
  211. localStorage.setItem('rootFolderId', res.data.thisFoldId)
  212. }
  213. this.materialFolders = res.data.materialFolders
  214. this.materialList = res.data.pageThemeVO
  215. // 创建文件夹获取data
  216. this.thisFoldId = res.data.thisFoldId
  217. })
  218. },
  219. // 新建 / 编辑 文件夹
  220. handleMkdir(mkdirType) {
  221. this.mkdirVisible = true
  222. this.folderForm.fid = this.thisFoldId
  223. this.folderForm.orga_id = this.orga_id
  224. if (mkdirType === 0) {
  225. this.$nextTick(() => {
  226. this.$refs.childUpload.imageUrl = ''
  227. this.folderForm.img_path = ''
  228. this.folderForm.name = ''
  229. })
  230. delete this.folderForm.id
  231. } else {
  232. this.$nextTick(() => {
  233. this.$refs.childUpload.imageUrl = this.folderForm.img_path
  234. })
  235. }
  236. },
  237. // 文件夹双击操作
  238. floderDbClick(item, index) {
  239. this.isEditMaterial = false
  240. this.$router.replace(
  241. {
  242. path: '/content', query: { folderTag: 1 }
  243. }
  244. )
  245. this.currentFolder = item.name
  246. this.currentFolderId = item.id
  247. localStorage.setItem('currentFolder', this.currentFolder)
  248. localStorage.setItem('currentFolderId', this.currentFolderId)
  249. this.getMaterialList()
  250. this.selectedListId = []
  251. this.folderChecked = -1
  252. this.isEditFolder = false
  253. },
  254. // 点击其他区域选中的文件夹 去掉选中样式
  255. hiddenFolderActiveClick() {
  256. this.folderChecked = -1
  257. this.isEditFolder = false
  258. },
  259. // 选择 编辑 文件夹
  260. editFolder(item, index) {
  261. this.isEditMaterial = false
  262. this.selectedListId = []
  263. // 有选择中的文件夹时,同时存在素材多选操作时
  264. this.$emit('changedMultiSelected')
  265. if (index != this.folderChecked) {
  266. this.folderChecked = index
  267. this.isEditFolder = true
  268. this.folderForm = {
  269. fid: item.fid,
  270. id: item.id,
  271. name: item.name,
  272. img_path: item.imgPath,
  273. orga_id: item.orgaId
  274. }
  275. } else {
  276. this.folderChecked = -1
  277. this.isEditFolder = false
  278. }
  279. },
  280. // 删除 文件夹
  281. deleteMaterialFolder() {
  282. this.$confirm('此操作将永久删除该文件夹, 是否继续?', '提示', {
  283. confirmButtonText: '确定',
  284. cancelButtonText: '取消',
  285. type: 'warning'
  286. }).then(() => {
  287. const params = {
  288. id: this.folderForm.id
  289. }
  290. deleteMaterialFolder(params).then(res => {
  291. if (res.code === 200) {
  292. this.$message({
  293. message: '删除文件夹成功',
  294. type: 'success'
  295. })
  296. this.getMaterialList()
  297. this.folderChecked = -1
  298. this.isEditFolder = false
  299. }
  300. })
  301. }).catch(() => {
  302. this.$message({
  303. message: '已取消删除',
  304. type: 'info'
  305. })
  306. })
  307. },
  308. // 提交表单 - 新建/编辑
  309. submitForm(formName) {
  310. this.folderForm.img_path = this.$refs.childUpload.imageUrl
  311. this.$refs[formName].validate((valid) => {
  312. if (valid) {
  313. saveMaterialFolder(this.folderForm).then(res => {
  314. if (res.code === 200) {
  315. this.$message({
  316. message: '创建文件夹成功',
  317. duration: 2000,
  318. type: 'success'
  319. })
  320. this.mkdirVisible = false
  321. this.getMaterialList()
  322. } else {
  323. this.$message({
  324. message: '创建文件夹失败',
  325. duration: 2000,
  326. type: 'warning'
  327. })
  328. }
  329. })
  330. } else {
  331. console.log('error submit!!')
  332. return false
  333. }
  334. })
  335. },
  336. // 重置表单
  337. resetForm() {
  338. // 强制重置folderForm表单
  339. // Object.assign(this.$data.folderForm, this.$options.data.call(this).folderForm)
  340. this.mkdirVisible = false
  341. },
  342. // 选择素材 - to 即时发布/定时发布
  343. publishHandle(index) {
  344. this.$router.push(
  345. {
  346. path: '/release', query: { tag: index }
  347. }
  348. )
  349. localStorage.removeItem('selectedMaterial')
  350. localStorage.setItem('selectedMaterial', JSON.stringify(this.selectedMaterial))
  351. },
  352. // 素材 - 编辑
  353. editContent() {
  354. this.mkdirVisible = true
  355. this.labelTxt = '文件名称'
  356. this.isEditMaterial = true
  357. if (this.formatType == 1) {
  358. this.layerTitle = '视频编辑'
  359. } else if (this.formatType == 2) {
  360. this.layerTitle = '音频编辑'
  361. } else {
  362. this.layerTitle = '图片编辑'
  363. }
  364. const checkedMaterial = this.materialList.filter(item => {
  365. return item.material_id == this.selectedListId[0]
  366. })
  367. this.materialId = checkedMaterial[0].material_id
  368. this.folderForm.name = checkedMaterial[0].material_name
  369. this.materialDuration = checkedMaterial[0].duration
  370. this.uploadFileUrl = checkedMaterial[0].deposit_url
  371. this.materialImgPath = checkedMaterial[0].img_path
  372. },
  373. // 上传素材
  374. saveMaterial() {
  375. if (!this.isEditMaterial) {
  376. console.log('新增')
  377. console.log(this.$refs.uploadMaterial.fileSize)
  378. const formatType = this.$refs.uploadMaterial.formatType
  379. this.uploadFileUrl = this.$refs.uploadMaterial.uploadFileUrl
  380. // 视频和音频的时长
  381. const duration = this.$refs.uploadMaterial.duration
  382. this.materialName = this.$refs.uploadMaterial.fileNames
  383. switch (formatType) {
  384. case 'image':
  385. this.formatType = 0
  386. this.materialImgPath = this.uploadFileUrl
  387. this.materialDuration = 0
  388. break
  389. case 'video':
  390. this.formatType = 1
  391. this.materialDuration = duration
  392. break
  393. case 'audio':
  394. this.formatType = 2
  395. this.materialDuration = duration
  396. break
  397. }
  398. } else {
  399. this.materialName = this.folderForm.name
  400. this.$nextTick(() => {
  401. if (this.$refs.childUpload) {
  402. this.materialImgPath = this.$refs.childUpload.imageUrl
  403. }
  404. })
  405. }
  406. setTimeout(() => {
  407. const params = {
  408. 'class_ids': [
  409. // 素材类id集合
  410. ],
  411. 'deposit_url': this.uploadFileUrl, // 素材存放路径
  412. 'device_direction': 1, // 横竖屏 1.横屏 2.竖屏,
  413. 'duration': this.materialDuration, // 时长s
  414. 'material_id': this.materialId,
  415. 'folder_id': this.thisFoldId, // 文件夹id
  416. 'img_path': this.materialImgPath, // 封面图片id
  417. 'material_name': this.materialName, // 素材名称
  418. 'material_type': this.formatType, // 素材类别
  419. 'file_size': this.$refs.uploadMaterial.fileSize, // 文件大小
  420. 'orga_id': this.orga_id, // 机构id
  421. 'store_type': 1 // 库类型 1.素材库 2.主题库
  422. }
  423. console.log(params)
  424. if (!this.isEditMaterial) {
  425. // 新上传素材时不需要该字段
  426. delete params.material_id
  427. }
  428. saveMaterial(params).then(res => {
  429. if (res.code === 200) {
  430. this.$message({
  431. message: '上传素材成功',
  432. type: 'success'
  433. })
  434. this.mkdirVisible = false
  435. this.getMaterialList()
  436. this.materialImgPath = ''
  437. }
  438. })
  439. }, 200)
  440. },
  441. // 素材 - 多选
  442. selectedItem(item) {
  443. const id = item.material_id
  444. const inFolderId = item.in_folder_id
  445. const type = item.material_type
  446. const arr = this.selectedListId
  447. if (arr.includes(id)) {
  448. const index = arr.indexOf(id)
  449. if (index > -1) {
  450. arr.splice(index, 1)
  451. this.selectinFolderid.splice(index, 1)
  452. this.selectedMaterial.splice(index, 1)
  453. }
  454. } else {
  455. this.selectedListId.push(id)
  456. this.selectinFolderid.push(inFolderId)
  457. this.selectedMaterial.push(item)
  458. this.formatType = type
  459. }
  460. },
  461. // 素材 - 删除
  462. deleteMyMaterial() {
  463. this.$confirm('此操作将永久删除该素材, 是否继续?', '提示', {
  464. confirmButtonText: '确定',
  465. cancelButtonText: '取消',
  466. type: 'warning'
  467. }).then(() => {
  468. const params = {
  469. ids: this.selectedListId
  470. }
  471. deleteMyMaterial(params).then(res => {
  472. if (res.code === 200) {
  473. this.$message({
  474. message: '删除素材成功',
  475. type: 'success'
  476. })
  477. this.getMaterialList()
  478. this.selectedListId = []
  479. }
  480. })
  481. }).catch(() => {
  482. this.$message({
  483. message: '已取消删除',
  484. type: 'info'
  485. })
  486. })
  487. },
  488. UploadList() {
  489. this.uploadListVisible = true
  490. },
  491. // 点击-移动btn
  492. moveingTo(index) {
  493. this.folderList = []
  494. if (this.materialFolders.length > 0) {
  495. this.folderList = this.materialFolders.slice(0, this.materialFolders.length)
  496. }
  497. this.rootFolderId = localStorage.getItem('rootFolderId')
  498. const returnFolder = {
  499. id: this.rootFolderId,
  500. name: '返回上一级'
  501. }
  502. this.folderList.unshift(returnFolder)
  503. this.movingVisible = true
  504. },
  505. // 文件夹list - 选中操作
  506. wjjSelected(item, index) {
  507. this.folderListChecked = index
  508. this.thisFoldId = item.id
  509. },
  510. // 点击确定 - 移动素材
  511. moveFile() {
  512. if (this.materialFolders.length > 0) {
  513. if (this.thisFoldId == this.rootFolderId) {
  514. this.$message({
  515. message: '不能讲文件移动到自身目录下哦~',
  516. type: 'error'
  517. })
  518. return
  519. }
  520. } else {
  521. this.thisFoldId = this.rootFolderId
  522. }
  523. const params = {
  524. 'folder_id': this.thisFoldId,
  525. 'ids': this.selectinFolderid,
  526. 'material_ids': this.selectedListId
  527. }
  528. moveMyMaterial(params).then(res => {
  529. if (res.code === 200) {
  530. this.$message({
  531. message: '移动成功',
  532. type: 'success'
  533. })
  534. this.movingVisible = false
  535. this.getMaterialList()
  536. this.selectedListId = []
  537. }
  538. })
  539. },
  540. format(percentage) {
  541. return percentage === 100 ? '100%' : `${percentage}%`
  542. },
  543. start() {
  544. const that = this
  545. that.$nextTick(() => {
  546. that.progressLoading = true
  547. that.percentage = 0
  548. that.timeStart = setInterval(() => {
  549. if (that.percentage < 100) {
  550. that.percentage += 1
  551. }
  552. }, 100)
  553. })
  554. },
  555. // 进度条结束
  556. end() {
  557. this.loading_txt = '继续'
  558. // const that = this
  559. // that.percentage = 100
  560. clearInterval(this.timeStart)
  561. // setTimeout(() => {
  562. // that.progressLoading = false
  563. // }, 300)
  564. }
  565. }
  566. }
  567. </script>
  568. <style lang="scss" scoped>
  569. .material_crumbs {
  570. padding: 0 24px 15px 24px;
  571. ::v-deep .el-breadcrumb {
  572. font-size: 12px;
  573. color: #999999;
  574. }
  575. }
  576. .material_content {
  577. display: flex;
  578. flex-wrap: wrap;
  579. margin-left: 24px;
  580. .material_item {
  581. position: relative;
  582. width: 174px;
  583. height: 182px;
  584. border-radius: 4px;
  585. margin: 0 20px 20px 0;
  586. overflow: hidden;
  587. }
  588. .item_cont {
  589. border-color: #dcdde3;
  590. img {
  591. width: 100%;
  592. height: 148px;
  593. }
  594. .radio_img {
  595. width: 100%;
  596. height: 148px;
  597. }
  598. }
  599. }
  600. .upload_layer {
  601. ::v-deep .el-dialog__body {
  602. padding: 0 20px 30px 20px;
  603. }
  604. }
  605. ::v-deep .el-table {
  606. .el-button {
  607. padding: 0 10px;
  608. height: 24px;
  609. &.upload_delt {
  610. background-color: #f76b6b;
  611. }
  612. }
  613. }
  614. .multi_handle {
  615. div {
  616. display: flex;
  617. }
  618. }
  619. </style>