audio.vue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. <template>
  2. <div class="images">
  3. <audio id="audioTag" class="noshow" autoplay :src="audioSrc"></audio>
  4. <div class="audiocon">
  5. <!-- 左侧按钮 -->
  6. <div class="leftBtn">
  7. <div class="left" @click="$emit('sonCutMu', 'left')"></div>
  8. <div class="play">
  9. <img
  10. @click="bofang"
  11. :src="
  12. require(`@/assets/images/tab4/${isPlay ? 'stop' : 'play'}.png`)
  13. "
  14. alt=""
  15. />
  16. </div>
  17. <div class="right" @click="$emit('sonCutMu', 'right')"></div>
  18. </div>
  19. <div class="adcon">
  20. <div class="titleTxt">{{ title }}</div>
  21. <div class="time">
  22. <span>{{ time }}</span
  23. ><span> / {{ allTime }}</span>
  24. </div>
  25. <div class="bar">
  26. <div class="activeLine" @click="seekTime"></div>
  27. <div :style="{ width: currentPosi + '%' }" class="dot"></div>
  28. </div>
  29. </div>
  30. </div>
  31. </div>
  32. </template>
  33. <script>
  34. export default {
  35. name: "Audio",
  36. props: {
  37. audioSrc: {
  38. type: String,
  39. },
  40. title: {
  41. type: String,
  42. },
  43. },
  44. data() {
  45. return {
  46. active: 0,
  47. time: 0,
  48. _audio: "",
  49. isPlay: this.isMobile,
  50. currentPosi: 0,
  51. allTime: 0,
  52. };
  53. },
  54. methods: {
  55. bofang() {
  56. if (this._audio.paused) {
  57. this._audio.play();
  58. this.isPlay = true;
  59. } else {
  60. this._audio.pause();
  61. this.isPlay = false;
  62. }
  63. // 传给父组件控制唱片样式
  64. this.$emit("musicCd", this.isPlay);
  65. },
  66. transTime(time) {
  67. var duration = parseInt(time);
  68. var minute = parseInt(duration / 60);
  69. var sec = (duration % 60) + "";
  70. var isM0 = ":";
  71. if (minute == 0) {
  72. minute = "00";
  73. } else if (minute < 10) {
  74. minute = "0" + minute;
  75. }
  76. if (sec.length == 1) {
  77. sec = "0" + sec;
  78. }
  79. return minute + isM0 + sec;
  80. },
  81. updateProgress() {
  82. this.currentPosi = (this._audio.currentTime / this._audio.duration) * 100;
  83. this.time = this.transTime(this._audio.currentTime);
  84. },
  85. audioEnded() {
  86. this._audio.currentTime = 0;
  87. this._audio.pause();
  88. this.isPlay = false;
  89. },
  90. seekTime(e) {
  91. var rate = e.offsetX / e.target.clientWidth;
  92. this._audio.currentTime = this._audio.duration * rate;
  93. this.updateProgress();
  94. },
  95. },
  96. mounted() {
  97. this.$nextTick(() => {
  98. this._audio = $("#audioTag")[0];
  99. $("#audioTag").on("loadedmetadata", (e) => {
  100. this.time = this.isMobile
  101. ? "00:00"
  102. : this.transTime(e.currentTarget.duration);
  103. this.allTime = this.transTime(e.currentTarget.duration);
  104. this._audio.play();
  105. this.isPlay = true;
  106. });
  107. document.addEventListener(
  108. "WeixinJSBridgeReady",
  109. function () {
  110. this._audio.play();
  111. },
  112. false
  113. );
  114. $("#audioTag").on("timeupdate", () => {
  115. this.updateProgress();
  116. });
  117. $("#audioTag").on("timeupdate", () => {
  118. this.updateProgress();
  119. });
  120. $("#audioTag").on("ended", () => {
  121. // console.log('音乐播放完毕');
  122. this.$emit("sonCutMu", "right");
  123. this.audioEnded();
  124. });
  125. });
  126. },
  127. activated() {
  128. this.isPlay = this.isMobile;
  129. // 传给父组件控制唱片样式
  130. this.$emit("musicCd", this.isPlay);
  131. },
  132. };
  133. </script>
  134. <style lang="less" scoped>
  135. .images {
  136. overflow: hidden;
  137. border-radius: 10px;
  138. width: 100%;
  139. height: 100%;
  140. background-repeat: no-repeat;
  141. background-position: center bottom;
  142. text-align: center;
  143. .title {
  144. padding: 0 80px;
  145. display: inline-block;
  146. color: #dba761;
  147. font-weight: bold;
  148. font-size: 36px;
  149. height: 70px;
  150. line-height: 70px;
  151. background: #bc1515;
  152. border-radius: 60px;
  153. margin: 45px auto;
  154. }
  155. .img-con {
  156. display: flex;
  157. justify-content: space-around;
  158. align-items: center;
  159. position: relative;
  160. padding-bottom: 40px;
  161. > img {
  162. max-width: 1000px;
  163. max-height: 600px;
  164. }
  165. }
  166. @color: #dba761;
  167. .audiocon {
  168. margin: 0 auto;
  169. position: relative;
  170. width: 70%;
  171. height: 100%;
  172. .adcon {
  173. .titleTxt {
  174. letter-spacing: 2px;
  175. position: absolute;
  176. left: 5px;
  177. top: -20px;
  178. color: #fff;
  179. font-size: 16px;
  180. }
  181. .time {
  182. position: absolute;
  183. right: -100px;
  184. top: 4px;
  185. }
  186. width: 85%;
  187. margin: 0 auto;
  188. position: absolute;
  189. bottom: 7px;
  190. right: 40px;
  191. display: flex;
  192. justify-content: space-between;
  193. align-items: center;
  194. .bar {
  195. flex: auto;
  196. position: relative;
  197. background: none;
  198. display: flex;
  199. width: 100%;
  200. height: 30px;
  201. overflow: visible;
  202. .activeLine {
  203. height: 5px;
  204. cursor: pointer;
  205. overflow: hidden;
  206. position: absolute;
  207. background-color: rgba(237, 211, 176, 0.5);
  208. top: 50%;
  209. transform: translateY(-50%);
  210. border-radius: 12px;
  211. width: 100%;
  212. }
  213. @wh: 20px;
  214. .dot {
  215. pointer-events: none;
  216. border-radius: 12px;
  217. position: absolute;
  218. top: 0;
  219. left: 0;
  220. height: 5px;
  221. cursor: pointer;
  222. background-color: #edd3b0;
  223. top: 50%;
  224. transform: translateY(-50%);
  225. // width: @wh;
  226. // height: @wh;
  227. // display: inline-block;
  228. // position: absolute;
  229. // z-index: 999;
  230. // background-color: #fff;
  231. // top: 50%;
  232. // transform: translate(-@wh*0.5, -50%);
  233. // border-radius: 50%;
  234. // cursor: pointer;
  235. }
  236. }
  237. > img {
  238. margin: 0 40px;
  239. cursor: pointer;
  240. width: 30px;
  241. height: 36px;
  242. }
  243. .time {
  244. width: 100px;
  245. text-align: center;
  246. > span {
  247. &:first-of-type {
  248. color: #fff;
  249. }
  250. &:last-of-type {
  251. color: #fff;
  252. }
  253. }
  254. }
  255. }
  256. .leftBtn {
  257. cursor: pointer;
  258. margin-left: 12px;
  259. height: 100%;
  260. display: flex;
  261. width: 120px;
  262. justify-content: space-around;
  263. align-items: center;
  264. & > div {
  265. width: 18px;
  266. height: 24px;
  267. }
  268. .left {
  269. background: url("../../assets/images/tab4/12.png");
  270. background-size: 100% 100%;
  271. }
  272. .left:hover {
  273. background: url("../../assets/images/tab4/13.png");
  274. background-size: 100% 100%;
  275. }
  276. .right {
  277. background: url("../../assets/images/tab4/14.png");
  278. background-size: 100% 100%;
  279. }
  280. .right:hover {
  281. background: url("../../assets/images/tab4/15.png");
  282. background-size: 100% 100%;
  283. }
  284. .play {
  285. width: 50px;
  286. height: 50px;
  287. & > img {
  288. width: 100%;
  289. height: 100%;
  290. }
  291. }
  292. }
  293. }
  294. }
  295. @position: 62px;
  296. .mbimages {
  297. width: 100%;
  298. height: 100%;
  299. background-repeat: no-repeat;
  300. background-size: 100% 100%;
  301. background-position: bottom -@position;
  302. text-align: center;
  303. .title {
  304. width: 90%;
  305. padding: 10px;
  306. display: inline-block;
  307. color: #dba761;
  308. font-weight: bold;
  309. font-size: 18px;
  310. background: #bc1515;
  311. border-radius: 60px;
  312. margin: 20px auto 0;
  313. }
  314. .img-con {
  315. width: 90%;
  316. margin: 0 auto;
  317. > img {
  318. width: 100%;
  319. }
  320. }
  321. @color: #bc1515;
  322. .audiocon {
  323. width: 90%;
  324. height: 80px;
  325. margin: 0 auto;
  326. .time {
  327. width: 100%;
  328. text-align: center;
  329. > span {
  330. &:first-of-type {
  331. color: rgba(112, 112, 112, 1);
  332. }
  333. &:last-of-type {
  334. color: @color;
  335. }
  336. }
  337. }
  338. .adcon {
  339. width: 94%;
  340. margin: 0 auto;
  341. display: flex;
  342. justify-content: space-between;
  343. align-items: center;
  344. .bar {
  345. flex: auto;
  346. position: relative;
  347. background: none;
  348. display: flex;
  349. width: 80%;
  350. height: 30px;
  351. overflow: visible;
  352. .activeLine {
  353. height: 10px;
  354. cursor: pointer;
  355. overflow: hidden;
  356. position: absolute;
  357. background-color: @color;
  358. top: 50%;
  359. transform: translateY(-50%);
  360. border-radius: 12px;
  361. width: 100%;
  362. }
  363. @wh: 20px;
  364. .dot {
  365. width: @wh;
  366. height: @wh;
  367. display: inline-block;
  368. position: absolute;
  369. z-index: 999;
  370. background-color: rgba(219, 167, 97, 1);
  371. top: 50%;
  372. transform: translate(-@wh*0.5, -50%);
  373. border-radius: 50%;
  374. cursor: pointer;
  375. border: 2px solid @color;
  376. }
  377. }
  378. @whh: 36px;
  379. .bfzt {
  380. width: @whh;
  381. height: @whh;
  382. position: relative;
  383. margin-left: 20px;
  384. .bg {
  385. width: 100%;
  386. height: 100%;
  387. }
  388. .btnggg {
  389. position: absolute;
  390. top: 50%;
  391. left: 50%;
  392. transform: translate(-50%, -50%);
  393. cursor: pointer;
  394. width: @whh*0.4;
  395. height: @whh*0.4;
  396. }
  397. }
  398. }
  399. }
  400. }
  401. .noshow {
  402. position: fixed;
  403. top: -100%;
  404. left: -100%;
  405. opacity: 0 !important;
  406. pointer-events: none !important;
  407. }
  408. </style>