me.vue 8.5 KB

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