me.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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.title" :show-action="false"
  16. bg-color="#f6f6f6" @change="onSearch" shape="square"
  17. ></u-search>
  18. <img class="icon" src="../../static/img/cate.png" alt="" @click="showCategory=true">
  19. </view>
  20. <scroll-view class="content" scroll-y @scrolltolower="getData(false)">
  21. <view class="main" v-if="dataList.length > 0">
  22. <view class="infoList" v-for="(item, index) in dataList" :key="index" @click="goDetail(item)">
  23. <img v-if="item.backgroundUrl" class="infoImg" :src="item.backgroundUrl" alt="">
  24. <img v-else class="infoImg" src="../../static/img/no-bg-img.jpg" alt="">
  25. <view class="info-box">
  26. <view class="name">{{ item.title }}</view>
  27. <view class="describe">所属分类:{{ item.categoryName }}</view>
  28. <view class="info">
  29. <view class="num"><i class="el-icon-view"></i> 访问量:{{ item.count }}</view>
  30. <view class="dateTime">{{ item.date }}</view>
  31. </view>
  32. </view>
  33. </view>
  34. </view>
  35. <template v-if="!loading&&!dataList.length">
  36. <image v-if="params.title" src="../../static/img/no-search.png" style="width: 100%" mode="aspectFit"></image>
  37. <image v-else src="../../static/img/no-data.png" style="width: 100%" mode="aspectFit"></image>
  38. </template>
  39. </scroll-view>
  40. </view>
  41. <u-picker :show="showCategory" :columns="categoryList" confirmColor="#eb5a10" @cancel="showCategory=false"
  42. closeOnClickOverlay @close="showCategory=false" key-name="categoryValue" @change="onCategoryChange"
  43. @confirm="onSelectCategory"
  44. ></u-picker>
  45. <tab-bar tabbarValue='我的看板'></tab-bar>
  46. </view>
  47. </template>
  48. <script>
  49. import {bigdataList, reportList, classifyList, reportClassList, getPv} from '@/common/api.js'
  50. import moment from 'moment'
  51. import Cookies from 'js-cookie'
  52. export default {
  53. data() {
  54. return {
  55. placeholder: "请输入大屏名称",
  56. tabIndex: 0,
  57. params: {
  58. size: 10,
  59. current: 1,
  60. title: "",
  61. isMobile: 1,
  62. category: '',
  63. createUser: Cookies.get('user_id')
  64. },
  65. dataList: [],
  66. visualCategoryPlain: [],
  67. reportCategoryPlain: [],
  68. categoryList: [[], [], []],
  69. showCategory: false,
  70. propsShow: false,
  71. loading: true,
  72. lastCreateTime: '',
  73. }
  74. },
  75. onShow() {
  76. this.getCategory().then(() => {
  77. this.getData(true)
  78. })
  79. },
  80. methods: {
  81. getCount(data, type) {
  82. return new Promise((resolve, reject) => {
  83. if (!data.length) {
  84. resolve()
  85. } else {
  86. let visualIds = data.map(i => i.id)
  87. getPv({type, visualIds}).then(rr => {
  88. let counts = rr.data.reduce((r, i) => ({...r, [i.visualId]: i.viewCount}), {})
  89. data.forEach(item => item.count = counts[item.id] || 0)
  90. resolve()
  91. })
  92. }
  93. })
  94. },
  95. getData(reload) {
  96. if (reload) {
  97. this.params.current = 1
  98. this.lastCreateTime = moment(new Date()).format('YYYY-MM-DD HH:mm:ss')
  99. }
  100. let data = {...this.params, createTimeIndex: this.lastCreateTime}
  101. this.loading = true
  102. if (this.tabIndex === 0) {
  103. bigdataList(data).then(res => {
  104. let data = res.data
  105. this.getCount(data, 0).then(() => {
  106. data.forEach(item => {
  107. item.categoryName = this.visualCategoryPlain.find(i => i.id === item.category)?.categoryValue || ''
  108. item.date = moment(item.createTime).format('YYYY-MM-DD')
  109. })
  110. if (data.length) this.params.current++
  111. if (reload) {
  112. this.dataList = data
  113. } else {
  114. this.dataList = this.dataList.concat(data)
  115. }
  116. this.lastCreateTime = this.dataList[this.dataList.length - 1]?.createTime || ''
  117. })
  118. }).finally(() => this.loading = false)
  119. }
  120. if (this.tabIndex === 1) {
  121. reportList(data).then(res => {
  122. let data = res.data
  123. this.getCount(data, 1).then(() => {
  124. data.forEach(item => {
  125. item.categoryName = this.reportCategoryPlain.find(i => i.id === item.category)?.categoryValue || ''
  126. item.date = moment(item.createTime).format('YYYY-MM-DD')
  127. })
  128. if (data.length) this.params.current++
  129. if (reload) {
  130. this.dataList = data
  131. } else {
  132. this.dataList = this.dataList.concat(data)
  133. }
  134. this.lastCreateTime = this.dataList[this.dataList.length - 1]?.createTime || ''
  135. })
  136. }).finally(() => this.loading = false)
  137. }
  138. },
  139. onSelectCategory({value}) {
  140. this.params.category = value[2]?.id || ''
  141. this.getData(true)
  142. this.showCategory = false
  143. },
  144. onClickTab(index) {
  145. this.placeholder = index ? '请输入报表名称' : '请输入大屏名称'
  146. this.tabIndex = index
  147. this.params.category = ''
  148. this.params.title = ''
  149. this.countDefaultCategory()
  150. this.getData(true)
  151. },
  152. onSearch(e) {
  153. this.getData(true)
  154. },
  155. goDetail(item) {
  156. uni.navigateTo({url: '/pages/detail/bigdata?id=' + item.id + '&title=' + item.title})
  157. },
  158. getCategory() {
  159. return new Promise((resolve, reject) => {
  160. let task1 = classifyList()
  161. task1.then(res => {
  162. this.visualCategoryPlain = res.data
  163. this.visualCategoryPlain.unshift({id: '', categoryValue: '全部分类'})
  164. })
  165. let task2 = reportClassList()
  166. task2.then(res => {
  167. this.reportCategoryPlain = res.data
  168. this.reportCategoryPlain.unshift({id: '', categoryValue: '全部分类'})
  169. })
  170. Promise.all([task1, task2]).then(() => {
  171. this.countDefaultCategory()
  172. resolve()
  173. })
  174. })
  175. },
  176. countDefaultCategory() {
  177. let categories = this.tabIndex ? this.reportCategoryPlain : this.visualCategoryPlain
  178. let categories1 = categories.filter(i => !i.parentId)
  179. let categories2 = [{id: '', categoryValue: '全部'}]
  180. let categories3 = [{id: '', categoryValue: '全部'}]
  181. this.categoryList = [categories1, categories2, categories3]
  182. },
  183. onCategoryChange({columnIndex, index, picker, values}) {
  184. let now = values[columnIndex][index]
  185. let categories = this.tabIndex ? this.reportCategoryPlain : this.visualCategoryPlain
  186. if (columnIndex === 0) {
  187. if (!now.id) {
  188. picker.setColumnValues(1, [{id: '', categoryValue: '全部'}])
  189. picker.setColumnValues(2, [{id: '', categoryValue: '全部'}])
  190. } else {
  191. let column2 = categories.filter(i => i.parentId === now.id)
  192. column2.unshift({id: now.id, categoryValue: '全部', vir: true})
  193. picker.setColumnValues(1, column2)
  194. picker.setColumnValues(2, [{id: now.id, categoryValue: '全部'}])
  195. }
  196. }
  197. if (columnIndex === 1) {
  198. if (!now.id) {
  199. picker.setColumnValues(2, [{id: '', categoryValue: '全部'}])
  200. } else {
  201. if (now.vir) {
  202. picker.setColumnValues(2, [{id: now.id, categoryValue: '全部'}])
  203. } else {
  204. let column3 = categories.filter(i => i.parentId === now.id)
  205. column3.unshift({id: now.id, categoryValue: '全部'})
  206. picker.setColumnValues(2, column3)
  207. }
  208. }
  209. }
  210. }
  211. }
  212. }
  213. </script>
  214. <style lang="less">
  215. @import "./home.less";
  216. </style>