index.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <template>
  2. <view class='app-container' :style="{ background: `url(${form.backgroundImage}) no-repeat 100% / cover` }">
  3. <view class="content" :style="{ 'padding-bottom': form.buttonFixType === 0 ? '94px' : 0 }">
  4. <!-- 标题 -->
  5. <view class="title">{{ form.title }}</view>
  6. <!-- 页面布局 -->
  7. <view v-if="form.contentShareLayoutList">
  8. <view class="item" v-for="item in form.contentShareLayoutList" :key="item.id">
  9. <!-- 图片 -->
  10. <img v-if="item.layoutType === 0" mode="aspectFit" :src="item.contentPic" />
  11. <!-- 音频 -->
  12. <my-audio v-if="item.layoutType === 1" :ref="`video${item.sort}`" :bg="form.audioBackgroundImage"
  13. :pic="item.contentPic" :name="item.contentName" :status="item.playStatus" @click="getPlay($event, item)" />
  14. <!-- 歌单 、专辑 -->
  15. <my-list v-if="item.layoutType === 2" :pic="item.contentPic" :name="item.contentName" :data="item.contentInfo"
  16. :type="item.contentType" @click="getOpen(item)" />
  17. </view>
  18. </view>
  19. </view>
  20. <!-- 按钮 -->
  21. <view :class="['footer', form.buttonFixType === 0 ? 'fixed' : '']">
  22. <button class="left" @click="getClick(form.leftButtonForwardType, form, 'leftButton')"
  23. :style="{ background: form.leftButtonImg ? `url(${form.leftButtonImg}) no-repeat 100% / 100%` : '' }">
  24. <text>{{ form.leftButtonText }}</text>
  25. </button>
  26. <button class="right" @click="getClick(form.rightButtonForwardType, form, 'rightButton')"
  27. :style="{ background: form.rightButtonImg ? `url(${form.rightButtonImg}) no-repeat 100% / 100%` : '' }">
  28. <text>{{ form.rightButtonText }}</text>
  29. </button>
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. import { detail } from '@/api/content'
  35. export default {
  36. data() {
  37. return {
  38. // 表单
  39. form: {},
  40. // 是否显示底部按钮
  41. isShow: false,
  42. // 跳转地址
  43. audioOption: {
  44. 8: '/mobile/playAlbumPage',
  45. 10: '/mobile/playSongsPage',
  46. 15: '/mobile/playSongsPage'
  47. },
  48. activeAudio: {}
  49. }
  50. },
  51. onLoad(e) {
  52. if (e.articleId) {
  53. this.getDetail(e.articleId)
  54. }
  55. },
  56. methods: {
  57. getDetail(articleId) {
  58. detail({
  59. articleId: articleId
  60. }).then(res => {
  61. if (res.data.code === 0) {
  62. // 按sort从小到大排序
  63. res.data.data.contentShareLayoutList.sort(function (x, y) {
  64. return x.sort > y.sort ? 1 : -1
  65. })
  66. // 给单音频添加播放状态
  67. res.data.data.contentShareLayoutList.map(i => {
  68. if ([2, 6, 11].includes(i.contentType)) {
  69. i.playStatus = 2
  70. }
  71. })
  72. this.form = res.data.data
  73. // 检测当前是否有正在播放的音频
  74. this.getStatus()
  75. // 非APP内部H5底部按钮隐藏
  76. this.isShow = JSON.stringify(getApp().globalData.userInfo) == '{}' ? false : this.form.isButton === 1 ? true : false
  77. }
  78. })
  79. },
  80. // 获取播放状态
  81. getStatus() {
  82. playStatus.postMessage(`获取当前播放状态`)
  83. window['setOpenPage'] = res => {
  84. let e = JSON.parse(res)
  85. this.form.contentShareLayoutList.find(i => {
  86. if (i.contentId == e.audioId) {
  87. i.playStatus = e.status
  88. }
  89. })
  90. }
  91. },
  92. // 单个音频
  93. getPlay(e, item) {
  94. let status = e === 2 ? 1 : 2
  95. openPage.postMessage(`?page=/mobile/audioPage&audioId=${item.contentInfo.audioId}&audioType=${item.contentInfo.audioType}&platformId=${item.platformId}&openAudioPage=0&cmd=openPage&playStatus=${status}`)
  96. window['setOpenPage'] = res => {
  97. item.playStatus = JSON.parse(res).status
  98. }
  99. },
  100. // 歌单 、专辑
  101. getOpen(item) {
  102. openPage.postMessage(`?page=${this.audioOption[item.contentType]}&audioId=${item.contentInfo.audioId}&audioType=${item.contentInfo.audioType}&platformId=${item.platformId}&openAudioPage=1&cmd=openPage`)
  103. },
  104. // 底部按钮
  105. getClick(type, form, key) {
  106. if (type === 0) {
  107. // H5内链
  108. window.location.href = form[`${key}ForwardUrl`]
  109. } else if (type === 1) {
  110. // App跳转音频合集
  111. openPage.postMessage(`?page=${this.audioOption[form[`${key}ContentType`]]}&audioId=${form[`${key}ContentId`]}&audioType=${form[`${key}ContentType`]}&playformId=${form[`${key}PlatformId`]}&openAudioPage=1&cmd=openPage`)
  112. } else {
  113. // 分享
  114. openShare.postMessage(`?contentId=${form.id}&shareType=-4`)
  115. }
  116. }
  117. }
  118. }
  119. </script>
  120. <style lang="scss" scoped>
  121. .app-container {
  122. display: flex;
  123. flex-flow: column nowrap;
  124. word-break: break-all;
  125. padding: 0;
  126. font-weight: 100;
  127. min-height: 100%;
  128. .content {
  129. flex: 1;
  130. padding: 24px 16px;
  131. .title {
  132. margin-bottom: 24px;
  133. color: #FFF;
  134. font-weight: bold;
  135. }
  136. .item {
  137. margin-bottom: 24px;
  138. img {
  139. width: 100%;
  140. }
  141. }
  142. }
  143. .footer {
  144. width: 100%;
  145. height: 94px;
  146. background: #414141;
  147. display: flex;
  148. justify-content: space-around;
  149. padding-top: 24px;
  150. button {
  151. background: linear-gradient(180deg, #A4D099 0%, #78B06A 100%);
  152. height: 46px;
  153. line-height: 46px;
  154. font-size: 16px;
  155. border-radius: 25px;
  156. color: #FFF;
  157. font-weight: bold;
  158. }
  159. .left {
  160. width: 220px;
  161. }
  162. .right {
  163. width: 107px;
  164. }
  165. }
  166. }
  167. .fixed {
  168. position: fixed;
  169. bottom: 0;
  170. }
  171. </style>