share.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <template>
  2. <view class="pageHome">
  3. <yx-navbar :isBack="false" title="分享给我"></yx-navbar>
  4. <view class="pageIndex">
  5. <view class="tabs">
  6. <view class="tab" :class="tabIndex == 0 ? 'active' : ''" @click="onClickTab(0)">
  7. <text>可视化大屏</text>
  8. </view>
  9. <view class="tab" :class="tabIndex == 1 ? 'active' : ''" @click="onClickTab(1)">
  10. <text>自助报表</text>
  11. </view>
  12. </view>
  13. <view class="search">
  14. <u-search
  15. :placeholder="placeholder" v-model="params.name" :show-action="false"
  16. bg-color="#f6f6f6" @change="onSearch" shape="square"
  17. ></u-search>
  18. </view>
  19. <scroll-view class="content" scroll-y @scrolltolower="getData(false)">
  20. <view class="main" v-if="dataList.length > 0">
  21. <view class="infoList" v-for="(item, index) in dataList" :key="index" @click="goDetail(item)">
  22. <img v-if="item.visualData.backgroundUrl" class="infoImg" :src="item.visualData.backgroundUrl" alt="">
  23. <img v-else class="infoImg" src="../../static/img/no-bg-img.jpg" alt="">
  24. <view class="info-box">
  25. <view class="name">{{ item.visualData.title }}</view>
  26. <view class="info">
  27. <view class="num"><i class="el-icon-view"></i> 访问量:{{ item.count }}</view>
  28. <view class="dateTime">{{ item.date }}</view>
  29. </view>
  30. </view>
  31. </view>
  32. </view>
  33. <template v-if="!loading&&!dataList.length">
  34. <image class="none" v-if="params.name" src="../../static/img/no-search.png" style="width: 100%" mode="aspectFit"></image>
  35. <image class="none" v-else src="../../static/img/no-data.png" style="width: 100%" mode="aspectFit"></image>
  36. </template>
  37. </scroll-view>
  38. <tab-bar tabbarValue='分享给我'></tab-bar>
  39. </view>
  40. </view>
  41. </template>
  42. <script>
  43. import {getShareList, getPv} from '@/common/api.js'
  44. import moment from 'moment'
  45. export default {
  46. data() {
  47. return {
  48. placeholder: "请输入大屏名称",
  49. tabIndex: 0,
  50. params: {
  51. size: 10,
  52. page: 1,
  53. name: "",
  54. },
  55. dataList: [],
  56. propsShow: false,
  57. loading: true,
  58. }
  59. },
  60. onShow() {
  61. this.getData(true)
  62. },
  63. methods: {
  64. getCount(data, type) {
  65. return new Promise((resolve, reject) => {
  66. if (!data.length) {
  67. resolve()
  68. } else {
  69. let visualIds = data.map(i => i.visualData.id)
  70. getPv({type, visualIds}).then(rr => {
  71. let counts = rr.data.reduce((r, i) => ({...r, [i.visualId]: i.viewCount}), {})
  72. data.forEach(item => item.count = counts[item.visualData.id] || 0)
  73. resolve()
  74. })
  75. }
  76. })
  77. },
  78. getData(reload) {
  79. if (reload) {
  80. this.params.page = 1
  81. }
  82. this.loading = true
  83. if (this.tabIndex === 0) {
  84. getShareList({...this.params, type: 0}).then(res => {
  85. let data = res.data.records
  86. this.getCount(data, 0).then(() => {
  87. data.forEach(item => {
  88. item.date = moment(item.visualData.createTime).format('YYYY-MM-DD')
  89. })
  90. if (data.length) this.params.page++
  91. this.dataList = reload ? data : this.dataList.concat(data)
  92. })
  93. }).finally(() => this.loading = false)
  94. }
  95. if (this.tabIndex === 1) {
  96. getShareList({...this.params, type: 1}).then(res => {
  97. let data = res.data.records
  98. this.getCount(data, 1).then(() => {
  99. data.forEach(item => {
  100. item.date = moment(item.visualData.createTime).format('YYYY-MM-DD')
  101. })
  102. if (data.length) this.params.page++
  103. this.dataList = reload ? data : this.dataList.concat(data)
  104. })
  105. }).finally(() => this.loading = false)
  106. }
  107. },
  108. onClickTab(index) {
  109. this.placeholder = index ? '请输入报表名称' : '请输入大屏名称'
  110. this.tabIndex = index
  111. this.params.name = ''
  112. this.getData(true)
  113. },
  114. onSearch(e) {
  115. this.getData(true)
  116. },
  117. goDetail(item) {
  118. uni.navigateTo({url: '/pages/detail/bigdata?id=' + item.visualData.id + '&title=' + item.visualData.title})
  119. },
  120. },
  121. }
  122. </script>
  123. <style lang="less">
  124. @import "./home.less";
  125. </style>