musicLibraryUpdater.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. <template>
  2. <el-dialog :title="(modelType == 'add' ? '添加' : '编辑') + '音乐库'" width="1000px" :visible.sync="dialogVisible">
  3. <div class="brand-video-editor">
  4. <el-form :model="form" :rules="rules" ref="MusicLibraryForm">
  5. <div class="brand-video-editor__top">
  6. <div class="type-black">
  7. <div class="type-black__ul">
  8. <ul>
  9. <li>
  10. <el-form-item prop="parentId" label="选择现有音乐类型:">
  11. <div class="type-black__select">
  12. <el-select v-model="form.parentId" placeholder="请选择音乐类型">
  13. <el-option
  14. v-for="item in musicTypes"
  15. :key="item.id"
  16. :label="item.musicCategoryName"
  17. :value="item.id">
  18. </el-option>
  19. </el-select>
  20. </div>
  21. </el-form-item>
  22. </li>
  23. <li>
  24. <el-form-item prop="musicName" label="音乐库名称:">
  25. <div class="type-black__input">
  26. <el-input v-model="form.musicName" placeholder="音乐库名称"></el-input>
  27. </div>
  28. </el-form-item>
  29. </li>
  30. </ul>
  31. </div>
  32. </div>
  33. <div class="video-upload">
  34. <el-form-item prop="musicUrl" label="上传视频/音频文件:" required>
  35. <div class="upload-black">
  36. <!-- action必选参数, 上传的地址 -->
  37. <el-upload class="avatar-uploader el-upload--text"
  38. :action="action"
  39. :show-file-list="false"
  40. :headers="{
  41. 'Authorization': 'Bearer ' + token
  42. }"
  43. :disabled="videoFlag"
  44. accept="video/*,audio/*"
  45. :on-success="handleVideoSuccess"
  46. :before-upload="beforeUploadVideo"
  47. :on-progress="uploadVideoProcess">
  48. <div class="video-black__warp">
  49. <div class="music--black" v-if="form.musicUrl && !videoFlag">
  50. <span class="music--icon"><img src="../../assets/image/file-icon.svg" alt=""></span>
  51. <span class="music--title">{{ form.fileName }}</span>
  52. <span class="music--size">{{ form.size }}</span>
  53. <el-tooltip
  54. class="item"
  55. effect="dark"
  56. content="删除"
  57. placement="bottom-end">
  58. <i class="close el-icon-circle-close"
  59. @click.stop="imgUploadDel()"></i>
  60. </el-tooltip>
  61. </div>
  62. <p class="text-black" v-else-if="!form.musicUrl && !videoFlag">
  63. <span class="upload-icon"><img src="../../assets/image/upload-icon.svg" alt=""></span>
  64. <span class="_text_">选择文件或者拖拽上传视频/音频</span>
  65. <span class="subtext">支持MP4、MP3文件,最大200MB</span>
  66. <a href="javascript:;" class="file-btns">浏览文件</a>
  67. </p>
  68. <div class="progress-black" v-if="videoFlag">
  69. <div class="progress--text">上传中...</div>
  70. <el-progress color="#ae8877" :stroke-width="10" :percentage="videoUploadPercent" :show-text="false"></el-progress>
  71. </div>
  72. </div>
  73. </el-upload>
  74. </div>
  75. </el-form-item>
  76. </div>
  77. </div>
  78. <div class="music-library-btns">
  79. <el-button type="primary" :disabled="videoFlag" class="music-library__a" :loading="comfirmLoading" @click="handleConfirm">更新音乐库</el-button>
  80. </div>
  81. </el-form>
  82. </div>
  83. </el-dialog>
  84. </template>
  85. <script>
  86. import { api } from "@/api/api";
  87. import { getToken } from '@/utils/auth'
  88. import { addMusicConfigInfo, editMusicConfigInfo } from "@/api/musicLibraryManager";
  89. export default {
  90. name: "MusicLibraryUpdater",
  91. components: {
  92. },
  93. computed: {
  94. token() {
  95. return getToken();
  96. }
  97. },
  98. data() {
  99. var checkMusicUrl = (rule, value, callback) => {
  100. if (!value) {
  101. callback(new Error('请上传视频/音频文件'));
  102. } else {
  103. callback();
  104. }
  105. };
  106. return {
  107. action: api.fileUrl,
  108. form: {
  109. musicName: '',
  110. musicUrl: '',
  111. parentId: '',
  112. fileName: '',
  113. size: ''
  114. },
  115. modelType: 'add',
  116. dialogVisible: false,
  117. comfirmLoading: false,
  118. editId: '',
  119. videoFlag: false,
  120. videoUploadPercent: 0,
  121. musicTypes: [],
  122. rules: {
  123. musicName: [
  124. { required: true, message: "请输入音乐库名称", trigger: "blur" }
  125. ],
  126. parentId: [
  127. { required: true, message: "请选择音乐类目", trigger: "change" }
  128. ],
  129. musicUrl: [
  130. { validator: checkMusicUrl, trigger: "change" }
  131. ]
  132. },
  133. progressTimer: null
  134. };
  135. },
  136. watch: {
  137. dialogVisible(val) {
  138. if (!val) {
  139. this.form = {
  140. musicName: '',
  141. musicUrl: '',
  142. parentId: '',
  143. fileName: '',
  144. size: ''
  145. }
  146. this.modelType = 'add';
  147. this.comfirmLoading = false;
  148. this.editId = '';
  149. }
  150. }
  151. },
  152. methods: {
  153. show(rows, type, musicOptions) {
  154. this.dialogVisible = true;
  155. this.comfirmLoading = false;
  156. this.modelType = type;
  157. this.musicTypes = musicOptions;
  158. if (type == 'edit') {
  159. this.editId = rows.id;
  160. }
  161. this.$nextTick(() => {
  162. this.form = type == 'edit' ? {
  163. musicName: rows.musicName,
  164. musicUrl: rows.musicUrl,
  165. parentId: rows.parentId,
  166. fileName: rows.fileName,
  167. size: rows.size
  168. } : {
  169. musicName: '',
  170. musicUrl: '',
  171. parentId: '',
  172. fileName: '',
  173. size: ''
  174. }
  175. this.$refs.MusicLibraryForm.resetFields()
  176. })
  177. },
  178. handleConfirm() {
  179. this.$refs.MusicLibraryForm.validate(valid => {
  180. if (valid) {
  181. this.comfirmLoading = true;
  182. const params = this.form;
  183. if (this.modelType == 'add') {
  184. addMusicConfigInfo(params).then(res =>{
  185. this.dialogVisible = false;
  186. if(res.code == 200){
  187. this.$message.success(res.msg || "操作成功");
  188. this.$emit("confirm");
  189. }
  190. }).finally(()=>{
  191. this.comfirmLoading = false;
  192. })
  193. } else {
  194. params.id = this.editId;
  195. editMusicConfigInfo(params).then(res =>{
  196. this.dialogVisible = false;
  197. if(res.code == 200){
  198. this.$message.success(res.msg || "操作成功");
  199. this.$emit("confirm");
  200. }
  201. }).finally(()=>{
  202. this.comfirmLoading = false;
  203. })
  204. }
  205. } else {
  206. return false;
  207. }
  208. });
  209. },
  210. beforeUploadVideo(file) {
  211. const isLt10M = file.size / 1024 / 1024 < 200;
  212. const allowedTypes = [
  213. 'video/mp4', 'video/ogg', 'video/flv', 'video/avi', 'video/wmv', 'video/rmvb',
  214. 'audio/mp3', 'audio/mpeg', 'audio/wav', 'audio/ogg', 'audio/x-m4a'
  215. ];
  216. if (!allowedTypes.includes(file.type)) {
  217. this.$message.error('请上传正确的视频或音频格式');
  218. return false;
  219. }
  220. if (!isLt10M) {
  221. this.$message.error('上传文件大小不能超过200MB哦!');
  222. return false;
  223. }
  224. this.progressTimer = setInterval(() => {
  225. if (this.videoUploadPercent < 98) {
  226. this.videoUploadPercent += 5;
  227. } else {
  228. clearInterval(this.progressTimer);
  229. }
  230. }, 200);
  231. },
  232. uploadVideoProcess(event, file, fileList) {
  233. this.videoFlag = true;
  234. // this.videoUploadPercent = file.percentage;
  235. },
  236. handleVideoSuccess(res, file) {
  237. clearInterval(this.progressTimer);
  238. this.videoFlag = false;
  239. this.videoUploadPercent = 0;
  240. this.$refs.MusicLibraryForm.clearValidate(['musicUrl']);
  241. if (res.code == 200) {
  242. this.form.fileName = res.data.fileName;
  243. this.form.size = res.data.size;
  244. this.form.musicUrl = res.data.url;
  245. } else {
  246. this.$message.error('上传失败,请重新上传!');
  247. }
  248. },
  249. imgUploadDel() {
  250. //删除
  251. this.$confirm("确定要删除吗?", "提示", {
  252. confirmButtonText: "确定",
  253. cancelButtonText: "取消",
  254. type: "warning"
  255. }).then(() => {
  256. this.form.musicUrl = '';
  257. this.form.fileName = '';
  258. this.form.size = '';
  259. this.$notify({
  260. title: "成功",
  261. message: "删除成功",
  262. type: "success",
  263. duration: 3000
  264. });
  265. });
  266. }
  267. }
  268. };
  269. </script>
  270. <style lang="scss" scoped>
  271. .brand-video-editor {
  272. display: flex;
  273. flex-direction: column;
  274. justify-content: space-between;
  275. height: 100%;
  276. padding: 20px;
  277. .brand-video-editor__top {
  278. display: flex;
  279. justify-content: space-between;
  280. gap: 3.6vw;
  281. align-items: stretch;
  282. .video-upload {
  283. flex: 1;
  284. max-width: 700px;
  285. }
  286. .video-black__warp {
  287. width: 100%;
  288. max-width: 70%;
  289. display: flex;
  290. justify-content: center;
  291. .progress-black {
  292. width: 100%;
  293. }
  294. .music--black {
  295. position: relative;
  296. display: flex;
  297. flex-direction: column;
  298. align-items: center;
  299. width: 110px;
  300. .music--icon {
  301. width: 80px;
  302. img {
  303. display: block;
  304. max-width: 100%;
  305. }
  306. }
  307. .music--title {
  308. font-size: 14px;
  309. color: #232323;
  310. font-weight: bold;
  311. line-height: 1.5;
  312. margin: 10px 0;
  313. white-space: nowrap;
  314. overflow: hidden;
  315. max-width: 100%;
  316. text-overflow: ellipsis;
  317. }
  318. .music--size {
  319. font-size: 14px;
  320. font-weight: bold;
  321. color: #ae8877;
  322. line-height: 1.5;
  323. }
  324. .close {
  325. position: absolute;
  326. top: -20px;
  327. right: -20px;
  328. cursor: pointer;
  329. z-index: 999999;
  330. color: red;
  331. background-color: #fff;
  332. font-size: 30px;
  333. border-radius: 50%;
  334. outline: none;
  335. width: 20px;
  336. height: 20px;
  337. line-height: 20px;
  338. font-size: 20px;
  339. color: #8c939d;
  340. display: block;
  341. text-align: center;
  342. }
  343. }
  344. }
  345. .upload-black {
  346. width: 100%;
  347. .avatar-uploader {
  348. display: block;
  349. width: 100%;
  350. height: 100%;
  351. /deep/ .el-upload {
  352. display: flex;
  353. width: 100%;
  354. height: 100%;
  355. justify-content: center;
  356. align-items: center;
  357. padding: 50px 0;
  358. border: 1px dashed #d9d9d9;
  359. border-radius: 10px;
  360. min-height: 280px;
  361. }
  362. }
  363. .text-black {
  364. display: flex;
  365. flex-direction: column;
  366. align-items: center;
  367. margin: 0;
  368. gap: 10px;
  369. .upload-icon {
  370. width: 48px;
  371. height: 48px;
  372. img {
  373. display: block;
  374. width: 100%;
  375. }
  376. }
  377. ._text_ {
  378. font-size: 18px;
  379. color: #292D32;
  380. line-height: 1.5;
  381. }
  382. .subtext {
  383. font-size: 16px;
  384. color: #A9ACB4;
  385. line-height: 1.5;
  386. }
  387. a.file-btns {
  388. display: flex;
  389. font-size: 16px;
  390. justify-content: center;
  391. align-items: center;
  392. height: 40px;
  393. border-radius: 4px;
  394. border: 1px solid #CBD0DC;
  395. padding: 0 30px;
  396. color: #54575C;
  397. }
  398. }
  399. }
  400. .type-black {
  401. flex: 1;
  402. ul {
  403. padding: 0;
  404. margin: 0;
  405. }
  406. li {
  407. list-style: none;
  408. /deep/ .el-select {
  409. width: 100%;
  410. }
  411. }
  412. li + li {
  413. margin-top: 30px;
  414. }
  415. }
  416. }
  417. .music-library-btns {
  418. display: flex;
  419. align-items: center;
  420. justify-content: center;
  421. margin-top: 50px;
  422. /deep/ .music-library__a {
  423. font-size: 16px;
  424. background: #ae8877;
  425. color: #fff;
  426. padding: 15px 80px;
  427. border-radius: 4px;
  428. }
  429. }
  430. }
  431. </style>