index.vue 5.8 KB

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