me.vue 8.7 KB

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