musicLibraryUpdater.vue 13 KB

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