index.vue 6.0 KB

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