topic.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <template>
  2. <app-layout>
  3. <view class="u-topic">
  4. <view class="topic" v-if="topic">
  5. <view class="title">{{topic.title}}</view>
  6. <view class="time plr-24">{{topic.read_count}}</view>
  7. <block v-for="(temp, index) in topic.detail" :key="index">
  8. <template v-if="temp.id === 'image-text'">
  9. <view class="plr-24">
  10. <app-rich-text :content="temp.data.content"></app-rich-text>
  11. </view>
  12. </template>
  13. <template v-else-if="temp.id === 'rubik'">
  14. <view style="position: relative">
  15. <app-image-ad :image-style="temp.data.style" :list="temp.data.list"
  16. :height="temp.data.height"></app-image-ad>
  17. <block v-for="(hotspot, hotspot_index) in temp.data.hotspot" :key="hotspot_index">
  18. <view>
  19. <app-hotspot :hotspot="rubikHotspot(hotspot)"></app-hotspot>
  20. </view>
  21. </block>
  22. </view>
  23. </template>
  24. <template v-else-if="temp.id === 'video'">
  25. <view>
  26. <app-video :pic-url="temp.data.pic_url"
  27. :url="temp.data.url"
  28. ></app-video>
  29. </view>
  30. </template>
  31. </block>
  32. </view>
  33. <view>
  34. <app-empty-bottom :height="Number(96)"></app-empty-bottom>
  35. </view>
  36. <view>
  37. <app-iphone-x>
  38. <view class="bar dir-left-nowrap cross-center" slot="empty-area">
  39. <view class="box-grow-1 dir-top-wrap cross-center" v-if="topic.is_favorite === 'love'" @click="favorite">
  40. <image src="/static/image/icon/icon-favorite-active.png"></image>
  41. <view>已收藏</view>
  42. </view>
  43. <view class="box-grow-1 dir-top-wrap cross-center" v-else @click="favorite">
  44. <image src="/static/image/icon/icon-favorite.png"></image>
  45. <view>收藏</view>
  46. </view>
  47. <view class="box-grow-1 dir-top-wrap cross-center" @click="shareClick">
  48. <image src="/static/image/icon/icon-share-gray.png"></image>
  49. <view>分享</view>
  50. </view>
  51. </view>
  52. </app-iphone-x>
  53. <app-share-qr-code-poster @share="hShareAppMessage" :theme="getTheme" v-model="shareShow" :url="poster" title="生成海报"></app-share-qr-code-poster>
  54. </view>
  55. </view>
  56. </app-layout>
  57. </template>
  58. <script>
  59. import {mapGetters, mapState} from "vuex";
  60. import appRichText from "../../components/basic-component/app-rich/parse";
  61. import appShareQrCodePoster from "../../components/page-component/app-share-qr-code-poster/app-share-qr-code-poster.vue";
  62. import appIphoneX from '../../components/basic-component/app-iphone-x/app-iphone-x.vue';
  63. import appEmptyBottom from'../../components/basic-component/app-empty-bottom/app-empty-bottom.vue';
  64. import appVideo from "../../components/page-component/app-video/app-video.vue";
  65. import appImageAd from "../../components/page-component/app-image-ad/app-image-ad.vue";
  66. import appHotspot from "../../components/basic-component/app-hotspot/app-hotspot.vue";
  67. export default {
  68. name: "topic",
  69. components: {
  70. 'app-rich-text': appRichText,
  71. 'app-share-qr-code-poster': appShareQrCodePoster,
  72. appIphoneX,
  73. appEmptyBottom,
  74. 'app-video': appVideo,
  75. 'app-image-ad': appImageAd,
  76. 'app-hotspot': appHotspot,
  77. },
  78. computed: {
  79. ...mapState({
  80. gConfig: state => state.gConfig,
  81. }),
  82. ...mapGetters('mallConfig', {
  83. getTheme: 'getTheme',
  84. }),
  85. },
  86. data() {
  87. return {
  88. topic: {},
  89. is_loading: false,
  90. shareShow: false,
  91. poster: null,
  92. id: null
  93. };
  94. },
  95. onLoad(options) { this.$commonLoad.onload(options);
  96. this.id = options.id;
  97. this.loadData(options.id);
  98. this.poster = this.$api.poster.topic + '&id=' + options.id
  99. // #ifdef MP-WEIXIN
  100. wx.showShareMenu({
  101. menus: ['shareAppMessage', 'shareTimeline']
  102. })
  103. // #endif
  104. },
  105. // #ifdef MP-WEIXIN
  106. onShareTimeline() {
  107. // 分享朋友圈beta
  108. return this.$shareTimeline({
  109. title: this.topic.app_share_title ? this.topic.app_share_title : this.topic.name,
  110. imageUrl: this.topic.qrcode_pic,
  111. query: {
  112. id: this.id
  113. }
  114. });
  115. },
  116. // #endif
  117. // #ifdef MP
  118. onShareAppMessage() {
  119. return this.hShareAppMessage();
  120. },
  121. // #endif
  122. methods: {
  123. hShareAppMessage(s = false) {
  124. return this.$shareAppMessage({
  125. title: this.topic.app_share_title ? this.topic.app_share_title : this.topic.title,
  126. imageUrl: this.topic.qrcode_pic ? this.topic.qrcode_pic : '',
  127. path: '/pages/topic/topic',
  128. params: {
  129. id: this.topic.id
  130. }
  131. }, s);
  132. },
  133. loadData(id) {
  134. this.$showLoading();
  135. this.$request({
  136. url: this.$api.topic.detail,
  137. data: {
  138. id: id
  139. }
  140. }).then(response => {
  141. this.$hideLoading();
  142. if (response.code === 0) {
  143. this.topic = response.data.list
  144. uni.setNavigationBarTitle({
  145. title: this.topic.app_share_title ? this.topic.app_share_title : this.topic.title
  146. })
  147. }
  148. }).catch(e => {
  149. this.$hideLoading();
  150. });
  151. },
  152. favorite() {
  153. if (this.is_loading) {
  154. return;
  155. }
  156. uni.showLoading({
  157. mark: true,
  158. title: '正在请求'
  159. });
  160. this.is_loading = true;
  161. let is_favorite = this.topic.is_favorite === 'no_love' ? 'love' : 'no_love';
  162. this.$request({
  163. url: this.$api.topic.favorite,
  164. data: {
  165. id: this.topic.id,
  166. is_favorite: is_favorite
  167. },
  168. method: 'post'
  169. }).then(response => {
  170. uni.hideLoading();
  171. this.is_loading = false;
  172. if (response.code === 0) {
  173. this.topic.is_favorite = is_favorite;
  174. uni.showToast({
  175. title: response.msg,
  176. mask: false
  177. })
  178. } else {
  179. uni.showModal({
  180. title: '提示',
  181. content: response.msg,
  182. showCancel: false,
  183. });
  184. }
  185. }).catch(e => {
  186. uni.hideLoading();
  187. this.is_loading = false;
  188. });
  189. },
  190. shareClick() {
  191. this.shareShow = true;
  192. },
  193. rubikHotspot(hotspot) {
  194. if (hotspot && hotspot.link) {
  195. hotspot.link.url = hotspot.link.new_link_url;
  196. hotspot.link.openType = hotspot.link.open_type;
  197. }
  198. return hotspot;
  199. },
  200. }
  201. }
  202. </script>
  203. <style scoped lang="scss">
  204. .topic {
  205. background-color: #ffffff;
  206. .title {
  207. padding: #{28rpx} #{24rpx} #{44rpx} #{24rpx};
  208. font-size: #{42rpx};
  209. }
  210. .time {
  211. margin-bottom: #{32rpx};
  212. font-size: $uni-font-size-general-two;
  213. color: $uni-general-color-two;
  214. }
  215. }
  216. .plr-24 {
  217. padding: 0 #{24rpx};
  218. }
  219. .bar {
  220. background-color: #ffffff;
  221. height: #{96rpx};
  222. width: 100%;
  223. border-top: #{1rpx} solid #e2e2e2;
  224. font-size: $uni-font-size-weak-one;
  225. color: $uni-general-color-two;
  226. image {
  227. width: #{40rpx};
  228. height: #{40rpx};
  229. }
  230. &>view.box-grow-1 {
  231. width: 50%;
  232. }
  233. }
  234. .u-topic {
  235. min-height: 100vh;
  236. background-color: #ffffff;
  237. }
  238. </style>