MusicRelax.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. <template>
  2. <div class="main_right_height">
  3. <el-row>
  4. <el-col :span="1">&nbsp;</el-col>
  5. <el-col :span="22">
  6. <div style="display: flex">
  7. <i
  8. class="el-icon-arrow-left"
  9. style="cursor: pointer; line-height: 1.5"
  10. @click="goBack()"
  11. ></i>
  12. <span class="musicTitle">音乐放松</span>
  13. </div>
  14. <!-- <el-divider></el-divider> -->
  15. </el-col>
  16. <el-col :span="1"> &nbsp; </el-col>
  17. </el-row>
  18. <el-row class="pagin_class">
  19. <el-col :span="1">&nbsp;</el-col>
  20. <el-col :span="22" style="border: 1px solid #e1e1e1; margin-bottom: 60px">
  21. <el-table
  22. :header-cell-style="{
  23. background: '#66B497',
  24. color: '#FFFFFF',
  25. 'letter-spacing': '4px',
  26. }"
  27. ref="filterTable"
  28. :data="tableData"
  29. style="width: 100%"
  30. :row-class-name="tableRowClassName"
  31. >
  32. <el-table-column
  33. prop="musicName"
  34. label="音乐名称"
  35. align="center"
  36. width="180px"
  37. >
  38. </el-table-column>
  39. <el-table-column prop="mood" label="情绪" align="center" width="160">
  40. <template slot-scope="scope">
  41. <span
  42. class="tag"
  43. v-for="item in scope.row.mood"
  44. :key="item.index"
  45. >
  46. {{ item }}
  47. </span>
  48. </template>
  49. </el-table-column>
  50. <el-table-column
  51. prop="musicStyle"
  52. label="曲风"
  53. align="center"
  54. width="160"
  55. >
  56. <template slot-scope="scope">
  57. <span
  58. class="tag"
  59. v-for="item in scope.row.musicStyle"
  60. :key="item.index"
  61. >
  62. {{ item }}
  63. </span>
  64. </template>
  65. </el-table-column>
  66. <el-table-column prop="keywords" label="关键词" align="center">
  67. <template slot-scope="scope">
  68. <el-popover
  69. trigger="hover"
  70. placement="top"
  71. width="200"
  72. transition="fade-in-linear"
  73. >
  74. <span
  75. class="tag"
  76. v-for="item in scope.row.keywords"
  77. :key="item.index"
  78. >
  79. <!-- {{ index }} -->
  80. {{ item }}
  81. </span>
  82. <div slot="reference" class="name-wrapper">
  83. <span
  84. class="tag"
  85. v-for="(item, index) in scope.row.keywords"
  86. :key="item.index"
  87. v-show="index < 4"
  88. >
  89. <!-- {{ index }} -->
  90. {{ item }}
  91. </span>
  92. </div>
  93. </el-popover>
  94. </template>
  95. </el-table-column>
  96. <el-table-column
  97. prop="musicLength"
  98. label="时长"
  99. align="center"
  100. width="80"
  101. >
  102. </el-table-column>
  103. <el-table-column label="操作" align="center">
  104. <template slot-scope="scope">
  105. <div
  106. v-show="scope.row.musicFlag"
  107. class="change-icon"
  108. @click="musicPlay(scope.$index, scope.row)"
  109. >
  110. <img src="../assets/play2.png" alt="" />
  111. </div>
  112. <div
  113. v-show="!scope.row.musicFlag"
  114. class="change-icon"
  115. @click="musicPlay(scope.$index, scope.row)"
  116. >
  117. <img src="../assets/play1.png" alt="" />
  118. </div>
  119. <p v-show="scope.row.musicFlag">
  120. {{ timeCo }}
  121. <el-progress
  122. :text-inside="true"
  123. :percentage="progressValue"
  124. :show-text="false"
  125. color="#656161"
  126. ></el-progress>
  127. </p>
  128. </template>
  129. </el-table-column>
  130. </el-table>
  131. </el-col>
  132. <el-col :span="1">&nbsp;</el-col>
  133. </el-row>
  134. </div>
  135. </template>
  136. <script>
  137. export default {
  138. data() {
  139. return {
  140. timeCo: "00:00",
  141. indexFlag: 0,
  142. progressValue: 0,
  143. progressValueFlag: null,
  144. tableData: [
  145. {
  146. audio: null,
  147. musicName: "Digitalized Waves Of Unspoken Distances",
  148. musicLength: "04:06",
  149. mood: ["史诗", "漂浮"],
  150. musicStyle: ["电子舞曲"],
  151. //做梦
  152. keywords: [
  153. "嗓音",
  154. "波形",
  155. "大厅",
  156. "气氛",
  157. "低保真",
  158. "音源",
  159. "冥想音乐",
  160. "平静",
  161. "氛围",
  162. "回忆",
  163. "豪华",
  164. "夜间",
  165. "柔软",
  166. ],
  167. //播放标志flag
  168. musicFlag: false,
  169. path: "/music/Digitalized Waves Of Unspoken Distances.mp3",
  170. },
  171. {
  172. audio: null,
  173. musicName: "The Everlast",
  174. musicLength: "02:47",
  175. mood: ["放松", "和平"],
  176. musicStyle: ["电子舞曲"],
  177. keywords: [
  178. "平静",
  179. "太阳升起",
  180. "漂流",
  181. "觉醒",
  182. "冥想",
  183. "瑜珈",
  184. "宗教",
  185. "梦想",
  186. "云",
  187. "星星",
  188. "空间",
  189. ],
  190. musicFlag: false,
  191. path: "/music/The Everlast.mp3",
  192. },
  193. {
  194. audio: null,
  195. musicName: "Vandring",
  196. musicLength: "03:13",
  197. mood: ["动感", "梦幻"],
  198. musicStyle: ["电子舞曲"],
  199. keywords: [
  200. "森林",
  201. "山脉",
  202. "马刺",
  203. "自然医学",
  204. "嗡鸣声",
  205. "到达",
  206. "极光",
  207. "冷杉木",
  208. "轨道",
  209. "罗斯拉根",
  210. "到达",
  211. "氛围",
  212. "流浪者",
  213. ],
  214. musicFlag: false,
  215. path: "/music/Vandring.mp3",
  216. },
  217. {
  218. audio: null,
  219. musicName: "Halcyon Daydream",
  220. musicLength: "03:56",
  221. mood: ["放松", "和平"],
  222. musicStyle: ["Drones"],
  223. keywords: [
  224. "睡觉",
  225. "双声拍",
  226. "深度浩室",
  227. "禅",
  228. "梦想",
  229. "冥想",
  230. "镇定",
  231. ],
  232. musicFlag: false,
  233. path: "/music/Halcyon Daydream.mp3",
  234. },
  235. {
  236. audio: null,
  237. musicName: "Crystal Creek",
  238. musicLength: "04:24",
  239. mood: ["和平", "梦幻"],
  240. musicStyle: ["Drones"],
  241. keywords: [
  242. "深度浩室",
  243. "禅",
  244. "双耳听觉",
  245. "节奏",
  246. "持续低音",
  247. "波",
  248. "睡觉",
  249. "冥想",
  250. "和平",
  251. "噪音",
  252. "伽玛",
  253. ],
  254. musicFlag: false,
  255. path: "/music/Crystal Creek.mp3",
  256. },
  257. {
  258. audio: null,
  259. musicName: "Focal Point",
  260. musicLength: "03:24",
  261. mood: ["放松", "和平"],
  262. musicStyle: ["Drones"],
  263. keywords: ["双声拍", "冥想", "焦点", "氛围音乐", "持续低音", "伽玛"],
  264. musicFlag: false,
  265. path: "/music/Focal Point",
  266. },
  267. {
  268. audio: null,
  269. musicName: "Aura",
  270. musicLength: "01:38",
  271. mood: ["梦幻", "漂浮"],
  272. musicStyle: ["电影"],
  273. keywords: ["睡觉", "平静", "自由", "天使", "精神", "小情绪"],
  274. musicFlag: false,
  275. path: "/music/Aura.mp3",
  276. },
  277. {
  278. audio: null,
  279. musicName: "Plan B",
  280. musicLength: "01:50",
  281. mood: ["科幻", "梦幻空间"],
  282. musicStyle: ["抒情音乐"],
  283. keywords: ["睡觉", "镇定", "飞行", "宇航员", "水下"],
  284. musicFlag: false,
  285. path: "/music/Plan B.mp3",
  286. },
  287. {
  288. audio: null,
  289. musicName: "A New Beginning",
  290. musicLength: "04:37",
  291. mood: ["放松", "和平"],
  292. musicStyle: ["Drones"],
  293. keywords: [
  294. "睡觉",
  295. "432赫兹",
  296. "双声拍",
  297. "内心平静",
  298. "冥想",
  299. "氛围音乐",
  300. "持续低音",
  301. ],
  302. musicFlag: false,
  303. path: "/music/A New Beginning.mp3",
  304. },
  305. {
  306. audio: null,
  307. musicName: "Dissonant Love",
  308. musicLength: "03:59",
  309. mood: ["放松", "梦幻"],
  310. musicStyle: ["电子舞曲"],
  311. keywords: ["睡觉", "沙发音乐", "氛围音乐", "持续低音", "和平"],
  312. musicFlag: false,
  313. path: "/music/Dissonant Love.mp3",
  314. },
  315. {
  316. audio: null,
  317. musicName: "In the Arms of Great Despair",
  318. musicLength: "02:08",
  319. mood: ["放松", "希望"],
  320. musicStyle: ["抒情音乐"],
  321. keywords: ["波形", "水", "鲸鱼"],
  322. musicFlag: false,
  323. path: "/music/In the Arms of Great Despair.mp3",
  324. },
  325. {
  326. audio: null,
  327. musicName: "Dream Simulation",
  328. musicLength: "04:10",
  329. mood: ["和平", "梦幻"],
  330. musicStyle: ["电子舞曲"],
  331. keywords: ["睡觉", "沉睡", "冥想", "瑜珈", "焦点", "专心"],
  332. musicFlag: false,
  333. path: "/music/Dream Simulation.mp3",
  334. },
  335. {
  336. audio: null,
  337. musicName: "Love Returns",
  338. musicLength: "01:57",
  339. mood: ["和平", "梦幻"],
  340. musicStyle: ["电影", "抒情音乐"],
  341. keywords: ["平静", "宁静", "催眠曲"],
  342. musicFlag: false,
  343. path: "/music/Love Returns.mp3",
  344. },
  345. {
  346. audio: null,
  347. musicName: "Tones",
  348. musicLength: "02:18",
  349. mood: ["放松"],
  350. musicStyle: ["电子舞曲"],
  351. keywords: ["宏大", "巨大", "天使", "和谐", "环境音乐"],
  352. musicFlag: false,
  353. path: "/music/Tones.mp3",
  354. },
  355. {
  356. audio: null,
  357. musicName: "Gradation",
  358. musicLength: "02:15",
  359. mood: ["放松", "梦幻"],
  360. musicStyle: ["电影", "Drones"],
  361. keywords: ["魔法", "气氛", "深蓝海", "海洋", "联系", "害怕"],
  362. musicFlag: false,
  363. path: "/music/Gradation.mp3",
  364. },
  365. {
  366. audio: null,
  367. musicName: "Right to Roam.mp3",
  368. musicLength: "01:49",
  369. mood: ["黑暗", "漂浮"],
  370. musicStyle: ["Drones"],
  371. keywords: ["洞穴", "不祥", "隧道", "风"],
  372. musicFlag: false,
  373. path: "/music/Right to Roam.mp3",
  374. },
  375. {
  376. audio: null,
  377. musicName: "Fell Asleep.mp3",
  378. musicLength: "01:59",
  379. mood: ["放松", "梦幻"],
  380. musicStyle: ["电影", "Drones"],
  381. keywords: ["森林", "寺庙", "昆虫"],
  382. musicFlag: false,
  383. path: "/music/Fell Asleep.mp3",
  384. },
  385. {
  386. audio: null,
  387. musicName: "Jungle Explorer",
  388. musicLength: "02:06",
  389. mood: ["黑暗"],
  390. musicStyle: ["Drones"],
  391. keywords: ["热带", "不祥", "昆虫", "生物", "薄雾", "未知数"],
  392. musicFlag: false,
  393. path: "/music/Jungle Explorer.mp3",
  394. },
  395. {
  396. audio: null,
  397. musicName: "Near Dawn",
  398. musicLength: "02:47",
  399. mood: ["放松", "和平"],
  400. musicStyle: ["电影"],
  401. keywords: ["沉睡", "禅", "氛围", "温泉", "冥想", "氛围音乐"],
  402. musicFlag: false,
  403. path: "/music/Near Dawn.mp3",
  404. },
  405. {
  406. audio: null,
  407. musicName: "Wren",
  408. musicLength: "03:36",
  409. mood: ["放松", "和平"],
  410. musicStyle: ["电子舞曲"],
  411. keywords: [
  412. "沉睡",
  413. "禅",
  414. "自然",
  415. "温泉",
  416. "放松",
  417. "瑜珈",
  418. "氛围音乐",
  419. "生成",
  420. "睡觉",
  421. "随机",
  422. "机遇音乐",
  423. "冥想",
  424. "和平",
  425. ],
  426. musicFlag: false,
  427. path: "/music/Wren.mp3",
  428. },
  429. {
  430. audio: null,
  431. musicName: "Pure",
  432. musicLength: "01:56",
  433. mood: ["放松", "和平"],
  434. musicStyle: ["轻音乐", "抒情音乐"],
  435. keywords: ["美丽", "雨", "弦乐", "窗户", "思维"],
  436. musicFlag: false,
  437. path: "/music/Pure.mp3",
  438. },
  439. {
  440. audio: null,
  441. musicName: "Moonrise",
  442. musicLength: "03:07",
  443. mood: ["和平", "漂浮"],
  444. musicStyle: ["电影"],
  445. keywords: [
  446. "气氛",
  447. "睡觉",
  448. "叙事",
  449. "延音",
  450. "焦点",
  451. "氛围音乐",
  452. "混响",
  453. "吉他",
  454. ],
  455. musicFlag: false,
  456. path: "/music/Moonrise.mp3",
  457. },
  458. ],
  459. };
  460. },
  461. destroyed() {
  462. this.tableData[this.indexFlag].audio.pause();
  463. clearInterval(this.progressValueFlag);
  464. },
  465. methods: {
  466. goBack() {
  467. for (let i = 0; i < this.tableData.length; i++) {
  468. if (this.tableData[i].audio !== null) {
  469. this.tableData[i].audio.pause();
  470. this.tableData[i].audio = null;
  471. this.tableData[i].musicFlag = true;
  472. }
  473. }
  474. this.$router.go(-1);
  475. },
  476. musicPlay(index, row) {
  477. this.indexFlag = index;
  478. this.tableData[index].musicFlag = !row.musicFlag;
  479. let mp3 = __static + row.path;
  480. let list = [];
  481. //刚进来时需要循环是否有正在运行的音乐 //没有的话启动当前的音乐
  482. for (let i = 0; i < this.tableData.length; i++) {
  483. if (this.tableData[i].audio !== null) {
  484. list.push(i);
  485. }
  486. if (i !== index) {
  487. this.tableData[i].musicFlag = false;
  488. }
  489. }
  490. if (list.length == 0) {
  491. this.tableData[index].audio = new Audio();
  492. this.tableData[index].audio.src = mp3;
  493. this.tableData[index].audio.play();
  494. console.log("当前时长" + this.tableData[index].audio.currentTime);
  495. console.log("总时长" + this.tableData[index].audio.duration);
  496. this.computerProcess(index);
  497. } else if (list.length == 1) {
  498. //当list等于1时
  499. //有两种情况,是自身的,和不是自身的
  500. //是自身的情况下则播放
  501. //不是自身
  502. if (list[0] === index) {
  503. if (this.tableData[index].audio.paused) {
  504. //this.tableData[index].audio.src = mp3;
  505. this.tableData[index].audio.play();
  506. console.log("当前时长" + this.tableData[index].audio.currentTime);
  507. console.log("总时长" + this.tableData[index].audio.duration);
  508. this.computerProcess(index);
  509. } else {
  510. // this.tableData[index].audio.src = mp3;
  511. this.tableData[index].audio.pause();
  512. }
  513. } else {
  514. // this.tableData[list[0]].audio.pause();
  515. this.tableData[list[0]].audio.pause();
  516. this.tableData[list[0]].audio = null;
  517. this.tableData[index].audio = new Audio();
  518. this.tableData[index].audio.src = mp3;
  519. this.tableData[index].audio.play();
  520. this.computerProcess(index);
  521. console.log("当前时长" + this.tableData[index].audio.currentTime);
  522. console.log("总时长" + this.tableData[index].audio.duration);
  523. }
  524. }
  525. },
  526. computerProcess(i) {
  527. this.timeCo = "00:00";
  528. this.progressValue = 0;
  529. clearInterval(this.progressValueFlag);
  530. this.progressValueFlag = setInterval(() => {
  531. let a = this.tableData[i].audio.currentTime;
  532. let b = this.tableData[i].audio.duration;
  533. this.timeCo = this.formatterTimeFun(Math.ceil(a));
  534. this.progressValue = (a / b) * 100;
  535. console.log(this.progressValue);
  536. if (this.progressValue == 100) {
  537. this.tableData[i].musicFlag = false;
  538. clearInterval(this.progressValueFlag);
  539. }
  540. }, 1000);
  541. },
  542. formatterTimeFun(val) {
  543. let min = Math.floor(val / 60);
  544. min = this.formatterSs(min);
  545. let ss = val % 60;
  546. ss = this.formatterSs(ss);
  547. return min + ":" + ss;
  548. },
  549. formatterSs(val) {
  550. if (val < 10) {
  551. return "0" + val;
  552. } else {
  553. return val + "";
  554. }
  555. },
  556. tableRowClassName({ rowIndex }) {
  557. if (rowIndex % 2 === 0) {
  558. return "warning-row";
  559. } else if (rowIndex % 2 === 1) {
  560. return "success-row";
  561. }
  562. return "success-row";
  563. },
  564. },
  565. };
  566. </script>
  567. <style>
  568. .el-table .warning-row {
  569. background: #f5f5f5;
  570. }
  571. .el-table .success-row {
  572. background: #ffffff;
  573. }
  574. .el-table--enable-row-hover
  575. /deep/
  576. .el-table__body
  577. tr:hover
  578. > td.el-table__cell {
  579. background: rgba(223, 246, 237, 1) !important;
  580. }
  581. </style>
  582. <style scoped>
  583. /* .icon_style {
  584. width: 100px;
  585. height: 100px;
  586. } */
  587. .el-icon-video-pause {
  588. cursor: pointer;
  589. color: #57acbb;
  590. }
  591. .icon-pointer-music {
  592. cursor: pointer;
  593. color: #57acbb;
  594. }
  595. .change-icon {
  596. /* cursor: pointer; */
  597. text-align: center;
  598. font-size: 40px;
  599. }
  600. .change-icon img {
  601. width: 44px;
  602. height: auto;
  603. }
  604. .moodStyle {
  605. margin-bottom: 10px;
  606. margin-right: 10px;
  607. }
  608. .musicTitle {
  609. display: block;
  610. font-size: 18px;
  611. color: #57acbb;
  612. margin-bottom: 5px;
  613. }
  614. .main_right_height {
  615. height: 95vh !important;
  616. display: block !important;
  617. overflow-y: auto !important;
  618. }
  619. .el-table {
  620. border-radius: 16px 16px 0px 0px;
  621. border: none;
  622. }
  623. .el-table .el-table__cell {
  624. padding: 6px;
  625. }
  626. .tag {
  627. display: inline-block;
  628. background: #ffffff;
  629. border-radius: 40px 40px 40px 40px;
  630. opacity: 1;
  631. border: 1px solid #0fb577;
  632. font-size: 14px;
  633. font-family: Source Han Sans CN-Regular, Source Han Sans CN;
  634. font-weight: 400;
  635. color: #0fb577;
  636. padding: 2px 8px;
  637. margin: 0 5px;
  638. }
  639. </style>