AI销管
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

zaudio.vue 9.9 KiB

2 anos atrás
2 anos atrás
2 anos atrás
2 anos atrás
2 anos atrás
2 anos atrás
2 anos atrás
2 anos atrás
2 anos atrás
2 anos atrás
2 anos atrás
2 anos atrás
2 anos atrás
2 anos atrás
2 anos atrás
2 anos atrás
2 anos atrás
2 anos atrás
2 anos atrás
2 anos atrás
2 anos atrás
2 anos atrás
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. <template>
  2. <view class="imt-audio" :class="[`${theme}`]" v-if="audiolist.length > 0">
  3. <template v-if="theme == 'theme4'">
  4. <view class="imt-audios">
  5. <view class="top">
  6. <view class="audio-control-wrapper">
  7. <image :src="require('./static/loading.png')" v-if="loading" class="play loading"></image>
  8. <template v-else>
  9. <image :src="require('./static/pausebtn.png')" alt="" @click="operate" class="play"
  10. v-if="renderData('paused')"></image>
  11. <image :src="require('./static/playbtn.png')" alt="" @click="operate" class="play" v-else>
  12. </image>
  13. </template>
  14. </view>
  15. </view>
  16. <view class="audio-wrapper">
  17. <view class="audio-flex">
  18. <text>
  19. {{renderData('current')}}
  20. </text>
  21. <slider class="audio-slider" :activeColor="themeColor" block-size="16"
  22. :value="renderData('current_value')" :max="renderData('duration_value')" @change="change"
  23. :disabled="!renderIsPlay"></slider>
  24. <text v-if="!duration">
  25. {{renderData('duration')}}
  26. </text>
  27. <text v-else>{{ duration }}</text>
  28. </view>
  29. </view>
  30. </view>
  31. </template>
  32. <template v-if="theme == 'theme3'">
  33. <slider class="audio-slider" :activeColor="themeColor" block-size="0" :value="renderData('current_value')"
  34. :max="renderData('duration_value')" @change="change" :disabled="!renderIsPlay"></slider>
  35. <view class="top">
  36. <view class="audio-control-wrapper">
  37. <image :src="renderData('coverImgUrl')" mode="aspectFill" class="cover"
  38. :class="{ on: !renderData('paused') }"></image>
  39. <image :src="require('./static/loading.png')" v-if="loading" class="play loading"></image>
  40. <template v-else>
  41. <image :src="require('./static/pausebtn.png')" alt="" @click="operate" class="play"
  42. v-if="renderData('paused')"></image>
  43. <image :src="require('./static/playbtn.png')" alt="" @click="operate" class="play" v-else>
  44. </image>
  45. </template>
  46. </view>
  47. </view>
  48. <view class="audio-wrapper">
  49. <view class="titlebox">
  50. <view class="title">{{ renderData('title') }}</view>
  51. <view class="singer">{{ renderData('singer') }}</view>
  52. </view>
  53. <view class="slidebox">
  54. <view>{{ renderData('current') }}/ {{ renderData('duration') }}</view>
  55. <view>
  56. <text @click="changeplay(-1)">上一首</text>
  57. <text @click="changeplay(1)">下一首</text>
  58. </view>
  59. </view>
  60. </view>
  61. </template>
  62. <template v-if="theme == 'theme2'">
  63. <view class="top">
  64. <view class="audio-control-wrapper" :style="{backgroundImage: `url(${renderData('coverImgUrl')})`}">
  65. <image :src="require('./static/loading.png')" v-if="loading" class="play loading"></image>
  66. <template v-else>
  67. <image :src="require('./static/pausebtn.png')" alt="" @click="operate" class="play"
  68. v-if="renderData('paused')"></image>
  69. <image :src="require('./static/playbtn.png')" alt="" @click="operate" class="play" v-else>
  70. </image>
  71. </template>
  72. </view>
  73. <view>
  74. <view class="title">
  75. <text>{{ renderData('title') }}</text>
  76. <view class="audio-number">{{ renderData('current') }}/{{ renderData('duration') }}</view>
  77. </view>
  78. <view class="singer">{{ renderData('singer') }}</view>
  79. </view>
  80. </view>
  81. </template>
  82. <template v-if="theme == 'theme1'">
  83. <view class="top">
  84. <view class="audio-control-wrapper">
  85. <image :src="renderData('coverImgUrl')" mode="aspectFill" class="cover"
  86. :class="{ on: !renderData('paused') }"></image>
  87. </view>
  88. <view>
  89. <view class="title">{{ renderData('title') }}</view>
  90. <view class="singer">{{ renderData('singer') }}</view>
  91. </view>
  92. </view>
  93. <view class="audio-wrapper">
  94. <view class="audio-number">{{ renderData('current') }}</view>
  95. <slider class="audio-slider" :activeColor="themeColor" block-size="16"
  96. :value="renderData('current_value')" :max="renderData('duration_value')" @change="change"
  97. :disabled="!renderIsPlay"></slider>
  98. <view class="audio-number">{{ renderData('duration') }}</view>
  99. </view>
  100. <view class="audio-button-box">
  101. <!-- 块退15s -->
  102. <image :src="require('./static/prev.png')" class="prevbtn" @click="stepPlay(-15)" mode="widthFix">
  103. </image>
  104. <!-- 上一首 -->
  105. <image :src="require('./static/go.png')" class="prevplay" @click="changeplay(-1)" mode="widthFix">
  106. </image>
  107. <div class="playbox">
  108. <image :src="require('./static/loading2.png')" v-if="loading" class="play loading"></image>
  109. <template v-else>
  110. <!-- 播放 -->
  111. <image :src="require('./static/playbtn2.png')" alt="" @click="operate" class="play"
  112. v-if="renderData('paused')"></image>
  113. <!-- 暂停 -->
  114. <image :src="require('./static/pausebtn2.png')" alt="" @click="operate" class="pause" v-else>
  115. </image>
  116. </template>
  117. </div>
  118. <!-- 下一首 -->
  119. <image :src="require('./static/go.png')" class="nextplay" @click="changeplay(1)" mode="widthFix">
  120. </image>
  121. <!-- 快进15s -->
  122. <image :src="require('./static/next.png')" class="nextbtn" @click="stepPlay(15)" mode="widthFix">
  123. </image>
  124. </view>
  125. </template>
  126. </view>
  127. </template>
  128. <script>
  129. export default {
  130. props: {
  131. theme: {
  132. type: String, // 主题 'theme1' or 'theme2'
  133. default: 'theme1'
  134. },
  135. themeColor: {
  136. type: String,
  137. default: '#2671E2'
  138. },
  139. duration: {
  140. type: String,
  141. default: ""
  142. }
  143. },
  144. data() {
  145. return {
  146. playinfo: this.$zaudio.playinfo,
  147. audiolist: this.$zaudio.audiolist,
  148. paused: this.$zaudio.paused,
  149. renderIsPlay: this.$zaudio.renderIsPlay,
  150. audio: this.$zaudio.renderinfo,
  151. loading: this.$zaudio.loading,
  152. action: Symbol('zaudio')
  153. };
  154. },
  155. computed: {
  156. renderData() {
  157. return name => {
  158. if (!this.renderIsPlay) {
  159. if (name == 'paused') {
  160. return true;
  161. }
  162. return this.audio[name];
  163. } else {
  164. if (name == 'paused') {
  165. return this.paused;
  166. }
  167. return this.playinfo[name];
  168. }
  169. };
  170. }
  171. },
  172. mounted() {
  173. this.$nextTick(() => {
  174. let action = this.action;
  175. this.$zaudio.syncStateOn(action, ({
  176. audiolist,
  177. paused,
  178. playinfo,
  179. renderIsPlay,
  180. renderinfo,
  181. loading,
  182. }) => {
  183. this.audiolist = audiolist;
  184. this.paused = paused;
  185. this.playinfo = playinfo;
  186. this.renderIsPlay = renderIsPlay;
  187. this.audio = renderinfo;
  188. this.loading = loading;
  189. console.log(this.playinfo)
  190. });
  191. this.$zaudio.syncRender()
  192. });
  193. },
  194. methods: {
  195. // 转换时间
  196. formatSeconds(seconds) {
  197. var result = typeof seconds === "string" ? parseFloat(seconds) : seconds;
  198. if (isNaN(result)) return "";
  199. let h = Math.floor(result / 3600) < 10 ?
  200. "0" + Math.floor(result / 3600) :
  201. Math.floor(result / 3600);
  202. let m = Math.floor((result / 60) % 60) < 10 ?
  203. "0" + Math.floor((result / 60) % 60) :
  204. Math.floor((result / 60) % 60) + h * 60;
  205. let s = Math.floor(result % 60) < 10 ?
  206. "0" + Math.floor(result % 60) :
  207. Math.floor(result % 60);
  208. return `${h}:${m}:${s}`;
  209. },
  210. //播放or暂停
  211. operate() {
  212. this.$zaudio.operate();
  213. },
  214. //进度拖到
  215. change(event) {
  216. if (this.renderIsPlay) {
  217. console.log(event)
  218. this.$zaudio.seek(event.detail.value);
  219. }
  220. },
  221. //快进
  222. stepPlay(value) {
  223. this.$zaudio.stepPlay(value);
  224. },
  225. //切歌
  226. changeplay(count) {
  227. this.$zaudio.changeplay(count);
  228. }
  229. },
  230. beforeDestroy() {
  231. this.$zaudio.playinfo.duration = '00:00:00'
  232. this.$zaudio.playinfo.duration_value = '00:00:00'
  233. //组件卸载时卸载业务逻辑
  234. let action = this.action;
  235. this.$zaudio.syncStateOff(action)
  236. this.$zaudio.stop()
  237. }
  238. };
  239. </script>
  240. <style scoped lang="scss">
  241. @import './index.scss';
  242. // #ifdef MP-WEIXIN
  243. .theme3 .audio-slider {
  244. margin-top: -8px !important;
  245. }
  246. // #endif
  247. @mixin textoverflow() {
  248. display: -webkit-box;
  249. overflow: hidden;
  250. text-overflow: ellipsis;
  251. -webkit-box-orient: vertical;
  252. -webkit-line-clamp: 1;
  253. }
  254. @keyframes rowup {
  255. 0% {
  256. -webkit-transform: translate(-50%, -50%) rotate(0deg);
  257. transform-origin: center center;
  258. }
  259. 100% {
  260. -webkit-transform: translate(-50%, -50%) rotate(360deg);
  261. transform-origin: center center;
  262. }
  263. }
  264. .imt-audios {
  265. position: relative;
  266. width: 100%;
  267. height: 81rpx;
  268. display: flex;
  269. box-sizing: border-box;
  270. background: #fff;
  271. .top {
  272. position: relative;
  273. width: 100rpx;
  274. }
  275. .audio-wrapper {
  276. position: relative;
  277. padding: 0 20rpx;
  278. display: flex;
  279. flex: 1;
  280. color: #fff;
  281. .popup {
  282. position: absolute;
  283. right: 32rpx;
  284. top: -122rpx;
  285. z-index: 100;
  286. width: 136rpx;
  287. height: 122rpx;
  288. display: flex;
  289. align-items: center;
  290. justify-content: center;
  291. flex-direction: column;
  292. background: #fff;
  293. border: 1rpx solid #E0E0E0;
  294. transition: all 0.25s linear;
  295. opacity: 0;
  296. image {
  297. width: 32rpx;
  298. height: 32rpx;
  299. }
  300. text {
  301. margin-top: 10rpx;
  302. color: #333;
  303. font-size: 24rpx;
  304. }
  305. .act-test {
  306. color: #2671E2;
  307. }
  308. }
  309. .close {
  310. opacity: 1;
  311. }
  312. }
  313. .slidebox {
  314. flex-shrink: 0;
  315. display: flex;
  316. align-items: center;
  317. .slide-img {
  318. width: 32rpx;
  319. height: 8rpx;
  320. }
  321. }
  322. /deep/ .uni-slider-tap-area {
  323. padding: 0;
  324. }
  325. /deep/ .uni-slider-wrapper {
  326. min-height: 0;
  327. }
  328. /deep/ .uni-slider-handle-wrapper {
  329. height: 6px;
  330. }
  331. .audio-slider {
  332. flex-grow: 1;
  333. }
  334. .play {
  335. width: 44rpx;
  336. height: 44rpx;
  337. z-index: 99;
  338. border-radius: 50%;
  339. position: absolute;
  340. top: 50%;
  341. left: 50%;
  342. transform: translate(-50%, -50%);
  343. &.loading {
  344. width: 48rpx;
  345. height: 48rpx;
  346. animation: rotating_theme3 2s linear infinite;
  347. }
  348. }
  349. }
  350. .audio-flex {
  351. padding: 0 32rpx 0 0;
  352. flex-grow: 1;
  353. display: flex;
  354. align-items: center;
  355. text {
  356. color: #70798D;
  357. }
  358. }
  359. @keyframes rotating {
  360. 0% {
  361. transform: rotateZ(0deg)
  362. }
  363. 100% {
  364. transform: rotateZ(360deg)
  365. }
  366. }
  367. @keyframes rotating_theme3 {
  368. 0% {
  369. transform: translate(-50%, -50%) rotateZ(0deg)
  370. }
  371. 100% {
  372. transform: translate(-50%, -50%) rotateZ(360deg)
  373. }
  374. }
  375. </style>