detail.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <template>
  2. <view class="fix-top-window">
  3. <view class="uni-container">
  4. <uni-stat-table :data="tableData" :filedsMap="popupFieldsMap" :loading="loading" />
  5. <view class="uni-pagination-box">
  6. <uni-pagination show-icon show-page-size :page-size="options.pageSize" :current="options.pageCurrent"
  7. :total="options.total" @change="changePageCurrent" @pageSizeChange="changePageSize" />
  8. </view>
  9. </view>
  10. <!-- #ifndef H5 -->
  11. <fix-window />
  12. <!-- #endif -->
  13. </view>
  14. </template>
  15. <script>
  16. import {
  17. mapfields,
  18. stringifyQuery,
  19. getTimeOfSomeDayAgo,
  20. division,
  21. format,
  22. formatDate,
  23. parseDateTime,
  24. debounce
  25. } from '@/js_sdk/uni-stat/util.js'
  26. import {
  27. popupFieldsMap
  28. } from './fieldsMap.js'
  29. const panelOption = [{
  30. title: '错误总数',
  31. value: 0,
  32. tooltip: '指应用在某个时间段内出现错误的总数'
  33. }, {
  34. title: '错误率',
  35. value: 0,
  36. tooltip: '时间范围内的总错误数/应用启动次数,如果小于0.01%,默认显示为0'
  37. }]
  38. export default {
  39. data() {
  40. return {
  41. popupFieldsMap,
  42. options: {
  43. pageSize: 20,
  44. pageCurrent: 1, // 当前页
  45. total: 0, // 数据总量
  46. },
  47. query: {
  48. error_hash: '',
  49. create_time: []
  50. },
  51. loading: false,
  52. tableData: []
  53. }
  54. },
  55. onLoad(option) {
  56. let {
  57. error_hash,
  58. create_time
  59. } = option
  60. if (error_hash) {
  61. create_time = Number(create_time)
  62. this.query.error_hash = error_hash
  63. this.query.create_time = [create_time, create_time + 24 * 60 * 60 * 1000]
  64. this.getTableData(stringifyQuery(this.query))
  65. }
  66. },
  67. methods: {
  68. changePageCurrent(e) {
  69. this.options.pageCurrent = e.current
  70. this.getTableData(stringifyQuery(this.query))
  71. },
  72. changePageSize(pageSize) {
  73. this.options.pageSize = pageSize
  74. this.options.pageCurrent = 1 // 重置分页
  75. this.getTableData(stringifyQuery(this.query))
  76. },
  77. getTableData(query) {
  78. const {
  79. pageCurrent
  80. } = this.options
  81. this.loading = true
  82. const db = uniCloud.database()
  83. db.collection('uni-stat-error-logs')
  84. .where(query)
  85. .orderBy('create_time', 'desc')
  86. .skip((pageCurrent - 1) * this.options.pageSize)
  87. .limit(this.options.pageSize)
  88. .get({
  89. getCount: true
  90. })
  91. .then(res => {
  92. const {
  93. count,
  94. data
  95. } = res.result
  96. this.options.total = count
  97. for (const item of data) {
  98. item.create_time = parseDateTime(item.create_time, 'dateTime')
  99. }
  100. this.tableData = data
  101. })
  102. .finally(() => {
  103. this.loading = false
  104. })
  105. }
  106. }
  107. }
  108. </script>
  109. <style>
  110. .uni-stat-panel {
  111. box-shadow: unset;
  112. border-bottom: 1px solid #eee;
  113. padding: 0;
  114. margin: 0 15px;
  115. }
  116. </style>