topic.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. <template>
  2. <app-layout>
  3. <view class="topic">
  4. <view class="detail-head" v-if="start">
  5. <view class="detail-head-label">{{ detail.title }}</view>
  6. <view class="detail-head-show-title cross-center main-between">
  7. <view>{{ detail.read_number }}人浏览</view>
  8. </view>
  9. </view>
  10. <view class="detail-diy">
  11. <block v-for="(temp, index) in detail.detail" :key="index">
  12. <template v-if="temp.id === 'mch-goods'">
  13. <view :style="[
  14. {'background-color':`${temp.data.backgroundColor}`,
  15. 'padding': `${temp.data.c_padding_top}rpx ${temp.data.c_padding_lr}rpx ${temp.data.c_padding_bottom}rpx`,
  16. 'background-image': temp.data.backgroundPicUrl ? `url(${temp.data.backgroundPicUrl})` : `none`,
  17. 'background-size':`${temp.data.backgroundWidth + '% ' + temp.data.backgroundHeight + '%'}`,
  18. 'background-position':`${transLabelBackgroundPosition(temp.data.position)}`,
  19. 'background-repeat':`${transLabelBackgroundRepeat(temp.data.mode)}`}]"
  20. >
  21. <app-diy-list :temp="temp" :theme="getTheme"></app-diy-list>
  22. </view>
  23. </template>
  24. <template v-else-if="temp.id === 'rubik'">
  25. <view style="position: relative">
  26. <app-image-ad
  27. v-bind:image-style="temp.data.style"
  28. v-bind:list="temp.data.list"
  29. v-bind:height="temp.data.height"
  30. ></app-image-ad>
  31. <block v-for="(hotspot, hotspot_index) in temp.data.hotspot" v-bind:key="hotspot_index">
  32. <app-hotspot v-bind:hotspot="rubikHotspot(hotspot)"></app-hotspot>
  33. </block>
  34. </view>
  35. </template>
  36. <template v-else-if="temp.id === 'video'">
  37. <app-video
  38. v-bind:pic-url="temp.data.pic_url"
  39. v-bind:url="temp.data.url"
  40. v-bind:has-auto="temp.data.hasAuto"
  41. v-bind:has-cycle="temp.data.hasCycle"
  42. v-bind:bg-padding="temp.data.bg_padding"
  43. v-bind:c-border-bottom="temp.data.c_border_bottom"
  44. v-bind:c-border-top="temp.data.c_border_top"
  45. v-bind:c-padding-top="temp.data.c_padding_top"
  46. v-bind:c-padding-lr="temp.data.c_padding_lr"
  47. v-bind:c-padding-bottom="temp.data.c_padding_bottom"
  48. ></app-video>
  49. </template>
  50. <template v-else-if="temp.id === 'image-text'">
  51. <view style="padding: 1rpx 24rpx" :style="{backgroundColor: temp.data.bg || 'inherit'}">
  52. <app-rich :image-prop="imageProp" v-bind:content='temp.data.content'></app-rich>
  53. </view>
  54. </template>
  55. </block>
  56. </view>
  57. <view style="height: 111rpx"></view>
  58. <view class="detail-navbar dir-left-nowrap cross-center">
  59. <!-- <view v-if="detail.is_favorite == 1" class="box-grow-1 dir-left-nowrap cross-center main-center"
  60. @click="handleLove('no_love',detail)">
  61. <view>
  62. <image :style="{'background-color': getTheme.background}" src="./image/weitao-love-a.png"></image>
  63. <view class="hide"></view>
  64. </view>
  65. <view>已收藏</view>
  66. </view>
  67. <view v-else class="box-grow-1 dir-left-nowrap cross-center main-center"
  68. @click="handleLove('love',detail)">
  69. <image src="./image/weitao-love.png"></image>
  70. <view>收藏</view>
  71. </view>
  72. <view class="box-grow-0 line"></view> -->
  73. <view class="box-grow-1 dir-left-nowrap cross-center main-center" @click="isShare = true">
  74. <image src="./image/weitao-detail-share.png"></image>
  75. <view>分享</view>
  76. </view>
  77. </view>
  78. <mch-share v-model="isShare" @share="hShareAppMessage" type="detail" :detail="detail"></mch-share>
  79. </view>
  80. </app-layout>
  81. </template>
  82. <script>
  83. import mchShare from "./mch-share";
  84. import appDiyGoodsList from "./components/app-diy-goods-list.vue";
  85. import {mapGetters, mapState} from "vuex";
  86. import appRich from "../../components/basic-component/app-rich/parse";
  87. import appVideo from "../../components/page-component/app-video/app-video";
  88. import appImageAd from "../../components/page-component/app-image-ad/app-image-ad";
  89. import appHotspot from "../../components/basic-component/app-hotspot/app-hotspot";
  90. import appDiyList from "../../components/page-component/index/app-diy-list";
  91. export default {
  92. name: "topic",
  93. components: {
  94. appDiyList,
  95. mchShare,
  96. appDiyGoodsList,
  97. appRich,
  98. appVideo,
  99. appImageAd,
  100. appHotspot,
  101. },
  102. computed: {
  103. ...mapState({
  104. userInfo: state => state.user.info,
  105. }),
  106. ...mapGetters('mallConfig', {
  107. getTheme: 'getTheme',
  108. }),
  109. },
  110. data() {
  111. return {
  112. imageProp: {
  113. mode: 'aspectFit',
  114. padding: 0,
  115. lazyLoad: false,
  116. domain: '',
  117. paddinglimit: 48,
  118. },
  119. detail: {},
  120. params: {
  121. id: '',
  122. },
  123. start: false,
  124. temp: {
  125. data: {}
  126. },
  127. isShare: false
  128. }
  129. },
  130. onLoad(options) {
  131. this.$commonLoad.onload(options);
  132. // #ifdef MP-WEIXIN
  133. wx.showShareMenu({
  134. menus: ['shareAppMessage', 'shareTimeline']
  135. })
  136. // #endif
  137. Object.assign(this.params, options);
  138. this.loadData();
  139. },
  140. // #ifdef MP
  141. onShareAppMessage(object) {
  142. return this.hShareAppMessage();
  143. },
  144. // #endif
  145. methods: {
  146. handleLove(value,detail) {
  147. this.$request({
  148. url: this.$api.topic.favorite,
  149. method: 'POST',
  150. data: {
  151. id: this.detail.id,
  152. is_favorite: value
  153. },
  154. }).then(info => {
  155. if(info.code === 0){
  156. this.detail.is_favorite = value === 'love' ? 1 : 0;
  157. }
  158. uni.showToast({title: info.msg, icon: 'none'});
  159. })
  160. },
  161. transLabelBackgroundPosition(val) {
  162. val = Number(val);
  163. switch (val) {
  164. case 1:
  165. return 'left top';
  166. case 2:
  167. return 'center top';
  168. case 3:
  169. return 'right top';
  170. case 4:
  171. return 'left center';
  172. case 5:
  173. return 'center center';
  174. case 6:
  175. return 'right center';
  176. case 7:
  177. return 'left bottom';
  178. case 8:
  179. return 'center bottom';
  180. case 9:
  181. return 'right bottom';
  182. default:
  183. return 'center';
  184. }
  185. },
  186. transLabelBackgroundRepeat(val) {
  187. val = Number(val);
  188. switch (val) {
  189. case 1:
  190. return 'no-repeat';
  191. case 2:
  192. return 'repeat-x';
  193. case 3:
  194. return 'repeat-y';
  195. case 4:
  196. return 'repeat';
  197. default:
  198. return 'no-repeat';
  199. }
  200. },
  201. rubikHotspot(hotspot) {
  202. if (hotspot && hotspot.link) {
  203. hotspot.link.url = hotspot.link.value;
  204. hotspot.link.openType = hotspot.link.open_type;
  205. }
  206. return hotspot;
  207. },
  208. hShareAppMessage(s = false) {
  209. let {share_title, share_pic_url, title, pic_url, abstract} = this.detail;
  210. return this.$shareAppMessage({
  211. title: share_title || title,
  212. imageUrl: !share_pic_url ? pic_url.length ? pic_url[0].pic_url : '' : share_pic_url,
  213. path: '/pages/topic/topic',
  214. desc: abstract,
  215. params: this.params
  216. }, s);
  217. },
  218. loadData() {
  219. this.$showLoading({title: '加载中'});
  220. this.start = false;
  221. this.$request({
  222. url: this.$api.topic.detail,
  223. data: {
  224. id: this.params.id
  225. },
  226. }).then(info => {
  227. this.$hideLoading();
  228. if (info.code === 0) {
  229. this.detail = info.data.detail;
  230. this.start = true;
  231. this.shareTimelineData = {
  232. title: this.detail.share_title ? this.detail.share_title : this.detail.title,
  233. imageUrl: !this.detail.share_pic_url ? this.detail.pic_url.length ? this.detail.pic_url[0].pic_url : '' : this.detail.share_pic_url,
  234. query: this.params
  235. }
  236. // #ifdef H5
  237. this.hShareAppMessage();
  238. // #endif
  239. } else {
  240. uni.showToast({title: info.msg, icon: 'none'});
  241. }
  242. }).catch(info => {
  243. this.$hideLoading();
  244. })
  245. },
  246. }
  247. }
  248. </script>
  249. <style scoped lang="scss">
  250. .topic {
  251. background: white;
  252. min-height: 100vh;
  253. .detail-head {
  254. padding: 24#{rpx} 24#{rpx} 0;
  255. .detail-head-label {
  256. font-size: 40#{rpx};
  257. font-weight: bold;
  258. color: #333333;
  259. padding-bottom: 20#{rpx};
  260. }
  261. .detail-head-show-title {
  262. font-size: 28#{rpx};
  263. color: #999999;
  264. padding-bottom: #{20rpx};
  265. }
  266. .detail-head_share {
  267. margin-left: auto;
  268. > image {
  269. height: 40#{rpx};
  270. width: 40#{rpx};
  271. display: block;
  272. }
  273. > view {
  274. margin-left: 6#{rpx};
  275. font-size: 28#{rpx};
  276. color: #333333;
  277. }
  278. }
  279. }
  280. .detail-navbar {
  281. position: fixed;
  282. bottom: 0;
  283. z-index: 1001;
  284. width: 100%;
  285. height: 111#{rpx};
  286. background: white;
  287. > view {
  288. height: 100%;
  289. font-size: 28#{rpx};
  290. color: #333333;
  291. }
  292. .line {
  293. height: 40#{rpx};
  294. width: 1px;
  295. background: #cccccc;
  296. }
  297. .hide {
  298. height: 60#{rpx};
  299. width: 60#{rpx};
  300. border: 10#{rpx} solid #FFFFFF;
  301. position: absolute;
  302. z-index: 10;
  303. margin-left: -10#{rpx};
  304. top: 22#{rpx};
  305. }
  306. image {
  307. height: 40#{rpx};
  308. width: 40#{rpx};
  309. display: block;
  310. margin-right: 20#{rpx};
  311. }
  312. }
  313. }
  314. </style>