| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428 |
- <template>
- <div class="images">
- <audio id="audioTag" class="noshow" autoplay :src="audioSrc"></audio>
- <div class="audiocon">
- <!-- 左侧按钮 -->
- <div class="leftBtn">
- <div class="left" @click="$emit('sonCutMu', 'left')"></div>
- <div class="play">
- <img
- @click="bofang"
- :src="
- require(`@/assets/images/tab4/${isPlay ? 'stop' : 'play'}.png`)
- "
- alt=""
- />
- </div>
- <div class="right" @click="$emit('sonCutMu', 'right')"></div>
- </div>
- <div class="adcon">
- <div class="titleTxt">{{ title }}</div>
- <div class="time">
- <span>{{ time }}</span
- ><span> / {{ allTime }}</span>
- </div>
- <div class="bar">
- <div class="activeLine" @click="seekTime"></div>
- <div :style="{ width: currentPosi + '%' }" class="dot"></div>
- </div>
- </div>
- </div>
- </div>
- </template>
- <script>
- export default {
- name: "Audio",
- props: {
- audioSrc: {
- type: String,
- },
- title: {
- type: String,
- },
- },
- data() {
- return {
- active: 0,
- time: 0,
- _audio: "",
- isPlay: this.isMobile,
- currentPosi: 0,
- allTime: 0,
- };
- },
- methods: {
- bofang() {
- if (this._audio.paused) {
- this._audio.play();
- this.isPlay = true;
- } else {
- this._audio.pause();
- this.isPlay = false;
- }
- // 传给父组件控制唱片样式
- this.$emit("musicCd", this.isPlay);
- },
- transTime(time) {
- var duration = parseInt(time);
- var minute = parseInt(duration / 60);
- var sec = (duration % 60) + "";
- var isM0 = ":";
- if (minute == 0) {
- minute = "00";
- } else if (minute < 10) {
- minute = "0" + minute;
- }
- if (sec.length == 1) {
- sec = "0" + sec;
- }
- return minute + isM0 + sec;
- },
- updateProgress() {
- this.currentPosi = (this._audio.currentTime / this._audio.duration) * 100;
- this.time = this.transTime(this._audio.currentTime);
- },
- audioEnded() {
- this._audio.currentTime = 0;
- this._audio.pause();
- this.isPlay = false;
- },
- seekTime(e) {
- var rate = e.offsetX / e.target.clientWidth;
- this._audio.currentTime = this._audio.duration * rate;
- this.updateProgress();
- },
- },
- mounted() {
- this.$nextTick(() => {
- this._audio = $("#audioTag")[0];
- $("#audioTag").on("loadedmetadata", (e) => {
- this.time = this.isMobile
- ? "00:00"
- : this.transTime(e.currentTarget.duration);
- this.allTime = this.transTime(e.currentTarget.duration);
- this._audio.play();
- this.isPlay = true;
- });
- document.addEventListener(
- "WeixinJSBridgeReady",
- function () {
- this._audio.play();
- },
- false
- );
- $("#audioTag").on("timeupdate", () => {
- this.updateProgress();
- });
- $("#audioTag").on("timeupdate", () => {
- this.updateProgress();
- });
- $("#audioTag").on("ended", () => {
- // console.log('音乐播放完毕');
- this.$emit("sonCutMu", "right");
- this.audioEnded();
- });
- });
- },
- activated() {
- this.isPlay = this.isMobile;
- // 传给父组件控制唱片样式
- this.$emit("musicCd", this.isPlay);
- },
- };
- </script>
- <style lang="less" scoped>
- .images {
- overflow: hidden;
- border-radius: 10px;
- width: 100%;
- height: 100%;
- background-repeat: no-repeat;
- background-position: center bottom;
- text-align: center;
- .title {
- padding: 0 80px;
- display: inline-block;
- color: #dba761;
- font-weight: bold;
- font-size: 36px;
- height: 70px;
- line-height: 70px;
- background: #bc1515;
- border-radius: 60px;
- margin: 45px auto;
- }
- .img-con {
- display: flex;
- justify-content: space-around;
- align-items: center;
- position: relative;
- padding-bottom: 40px;
- > img {
- max-width: 1000px;
- max-height: 600px;
- }
- }
- @color: #dba761;
- .audiocon {
- margin: 0 auto;
- position: relative;
- width: 70%;
- height: 100%;
- .adcon {
- .titleTxt {
- letter-spacing: 2px;
- position: absolute;
- left: 5px;
- top: -20px;
- color: #fff;
- font-size: 16px;
- }
- .time {
- position: absolute;
- right: -100px;
- top: 4px;
- }
- width: 85%;
- margin: 0 auto;
- position: absolute;
- bottom: 7px;
- right: 40px;
- display: flex;
- justify-content: space-between;
- align-items: center;
- .bar {
- flex: auto;
- position: relative;
- background: none;
- display: flex;
- width: 100%;
- height: 30px;
- overflow: visible;
- .activeLine {
- height: 5px;
- cursor: pointer;
- overflow: hidden;
- position: absolute;
- background-color: rgba(237, 211, 176, 0.5);
- top: 50%;
- transform: translateY(-50%);
- border-radius: 12px;
- width: 100%;
- }
- @wh: 20px;
- .dot {
- pointer-events: none;
- border-radius: 12px;
- position: absolute;
- top: 0;
- left: 0;
- height: 5px;
- cursor: pointer;
- background-color: #edd3b0;
- top: 50%;
- transform: translateY(-50%);
- // width: @wh;
- // height: @wh;
- // display: inline-block;
- // position: absolute;
- // z-index: 999;
- // background-color: #fff;
- // top: 50%;
- // transform: translate(-@wh*0.5, -50%);
- // border-radius: 50%;
- // cursor: pointer;
- }
- }
- > img {
- margin: 0 40px;
- cursor: pointer;
- width: 30px;
- height: 36px;
- }
- .time {
- width: 100px;
- text-align: center;
- > span {
- &:first-of-type {
- color: #fff;
- }
- &:last-of-type {
- color: #fff;
- }
- }
- }
- }
- .leftBtn {
- cursor: pointer;
- margin-left: 12px;
- height: 100%;
- display: flex;
- width: 120px;
- justify-content: space-around;
- align-items: center;
- & > div {
- width: 18px;
- height: 24px;
- }
- .left {
- background: url("../../assets/images/tab4/12.png");
- background-size: 100% 100%;
- }
- .left:hover {
- background: url("../../assets/images/tab4/13.png");
- background-size: 100% 100%;
- }
- .right {
- background: url("../../assets/images/tab4/14.png");
- background-size: 100% 100%;
- }
- .right:hover {
- background: url("../../assets/images/tab4/15.png");
- background-size: 100% 100%;
- }
- .play {
- width: 50px;
- height: 50px;
- & > img {
- width: 100%;
- height: 100%;
- }
- }
- }
- }
- }
- @position: 62px;
- .mbimages {
- width: 100%;
- height: 100%;
- background-repeat: no-repeat;
- background-size: 100% 100%;
- background-position: bottom -@position;
- text-align: center;
- .title {
- width: 90%;
- padding: 10px;
- display: inline-block;
- color: #dba761;
- font-weight: bold;
- font-size: 18px;
- background: #bc1515;
- border-radius: 60px;
- margin: 20px auto 0;
- }
- .img-con {
- width: 90%;
- margin: 0 auto;
- > img {
- width: 100%;
- }
- }
- @color: #bc1515;
- .audiocon {
- width: 90%;
- height: 80px;
- margin: 0 auto;
- .time {
- width: 100%;
- text-align: center;
- > span {
- &:first-of-type {
- color: rgba(112, 112, 112, 1);
- }
- &:last-of-type {
- color: @color;
- }
- }
- }
- .adcon {
- width: 94%;
- margin: 0 auto;
- display: flex;
- justify-content: space-between;
- align-items: center;
- .bar {
- flex: auto;
- position: relative;
- background: none;
- display: flex;
- width: 80%;
- height: 30px;
- overflow: visible;
- .activeLine {
- height: 10px;
- cursor: pointer;
- overflow: hidden;
- position: absolute;
- background-color: @color;
- top: 50%;
- transform: translateY(-50%);
- border-radius: 12px;
- width: 100%;
- }
- @wh: 20px;
- .dot {
- width: @wh;
- height: @wh;
- display: inline-block;
- position: absolute;
- z-index: 999;
- background-color: rgba(219, 167, 97, 1);
- top: 50%;
- transform: translate(-@wh*0.5, -50%);
- border-radius: 50%;
- cursor: pointer;
- border: 2px solid @color;
- }
- }
- @whh: 36px;
- .bfzt {
- width: @whh;
- height: @whh;
- position: relative;
- margin-left: 20px;
- .bg {
- width: 100%;
- height: 100%;
- }
- .btnggg {
- position: absolute;
- top: 50%;
- left: 50%;
- transform: translate(-50%, -50%);
- cursor: pointer;
- width: @whh*0.4;
- height: @whh*0.4;
- }
- }
- }
- }
- }
- .noshow {
- position: fixed;
- top: -100%;
- left: -100%;
- opacity: 0 !important;
- pointer-events: none !important;
- }
- </style>
|