bookstore.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <template>
  2. <view class="content" :style="{paddingTop: content_paddingTop + 'px'}">
  3. <view class="content__bg-color"></view>
  4. <view class="content__container" v-for="(item,index) in data_list" :key="index">
  5. <templateSearch v-if="item.template_type==config.template_stype.SEARCH" ></templateSearch>
  6. <templateBanner v-if="item.template_type==config.template_stype.BANNER" :templateData='item' @clickBook='clickBook'></templateBanner>
  7. <templateBookH3 v-if="item.template_type==config.template_stype.H_3" :templateData='item' :dataList='H3_data_list' @clickBook='clickBook'></templateBookH3>
  8. <templateBookV3 v-if="item.template_type==config.template_stype.V_3" :templateData='item' @clickBook='clickBook'></templateBookV3>
  9. <templateBookList v-if="item.template_type==config.template_stype.LIST" :templateData='item' @clickBook='clickBook'></templateBookList>
  10. </view>
  11. </view>
  12. </template>
  13. <script setup lang="ts">
  14. import templateSearch from '../bookstore/template/template-book-Search.vue'
  15. import templateBanner from '../bookstore/template/template-book-Banner.vue'
  16. import templateBookH3 from '../bookstore/template/template-book-H-3.vue'
  17. import templateBookV3 from '../bookstore/template/template-book-V-3.vue'
  18. import templateBookList from '../bookstore/template/template-book-List.vue'
  19. import { bookstore_template_data, book_item_data } from '../../data/data';
  20. import { ref } from 'vue';
  21. import { tools } from '../../framework/tools';
  22. import { http } from '../../framework/http';
  23. import { config } from '../../config/config';
  24. import { log } from '../../framework/log';
  25. import { util } from '../../framework/util'
  26. import { onPullDownRefresh } from '@dcloudio/uni-app'
  27. let data_list = ref<Array<bookstore_template_data>>([])
  28. let H3_data_list = ref<Array<Array<book_item_data>>>([])
  29. let content_paddingTop = ref(0)
  30. if(tools.getCurPlatform() == config.Platform.WEIXIN) {
  31. content_paddingTop.value = uni.getSystemInfoSync().safeArea.top + 40
  32. }
  33. onPullDownRefresh(()=>{
  34. setTimeout(()=>{
  35. requestData(true)
  36. },500)
  37. })
  38. requestData()
  39. function requestData(isPullDown:boolean=false) {
  40. util.showLoading()
  41. http.StaticRequest(config.url_confg.Static.book_store,(err,data)=>{
  42. util.hideLoading()
  43. if(isPullDown){ uni.stopPullDownRefresh() }
  44. if(!err) {
  45. if(data.code==config.url_confg.StatesCode.SUCCESS){
  46. data_list.value = data.content
  47. for (let i = 0; i < data_list.value.length; i++) {
  48. let element = data_list.value[i]
  49. if(element.template_type==config.template_stype.H_3) {
  50. // 横-3分页数据
  51. for(var j=0; j<element.list.length; j+=3) {
  52. let pagingData = element.list.slice(j, j+3)
  53. H3_data_list.value.push(pagingData)
  54. }
  55. }
  56. }
  57. }
  58. } else {
  59. log.Error(err)
  60. }
  61. })
  62. }
  63. function clickBook(data:book_item_data) {
  64. tools.gotoBookdetails(data.book_id,data.wx_book_id)
  65. }
  66. function shareToTimeline() {
  67. wx.shareToTimeline({
  68. title: '分享到朋友圈',
  69. link: '你的小程序链接',
  70. imgUrl: '你的图片链接',
  71. success: function () {
  72. console.log('分享到朋友圈成功');
  73. },
  74. fail: function (err) {
  75. console.log('分享到朋友圈失败', err);
  76. }
  77. });
  78. }
  79. </script>
  80. <style lang="scss">
  81. .content{
  82. display: flex;
  83. flex-direction: column;
  84. width: 100%;
  85. &__bg-color {
  86. position: fixed;
  87. width: 100%;
  88. height: 100%;
  89. left: 0;
  90. top: 0;
  91. background-image: linear-gradient(to bottom, #fcd9e0, #ffffff);
  92. z-index: 9;
  93. }
  94. &__container{
  95. display: flex;
  96. flex-direction: column;
  97. z-index: 10;
  98. }
  99. }
  100. </style>