jobResult.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <template>
  2. <div>
  3. <el-dialog
  4. :title="title"
  5. :close-on-click-modal="false"
  6. v-if="visible"
  7. :visible.sync="visible"
  8. width="75%">
  9. <el-table
  10. :data="useDataList"
  11. border
  12. v-loading="dataListLoading"
  13. height="530"
  14. style="width: 100%;margin-top: -30px;">
  15. <el-table-column v-if="showID" prop="Id" header-align="center" align="center" width="80" label="id"
  16. type="index" :index='(index)=>{return (index+1) + (this.pageIndex-1)*this.pageSize}'>
  17. </el-table-column>
  18. <el-table-column v-if="showID" header-align="center" align="center" label="time">
  19. <template slot-scope="scope">
  20. {{scope.row.time | timeFormater}}
  21. </template>
  22. </el-table-column>
  23. <el-table-column v-for="col in tableClo" :key="col"
  24. :prop="col"
  25. header-align="center"
  26. align="center"
  27. :label="col">
  28. </el-table-column>
  29. </el-table>
  30. <el-pagination
  31. @size-change="sizeChangeHandle"
  32. @current-change="currentChangeHandle"
  33. :current-page="pageIndex"
  34. :page-sizes="[10, 20, 50, 100]"
  35. :page-size="pageSize"
  36. :total="totalPage"
  37. layout=" sizes, prev, pager, next">
  38. </el-pagination>
  39. </el-dialog>
  40. </div>
  41. </template>
  42. <script>
  43. export default {
  44. name: 'jobResult',
  45. data () {
  46. return {
  47. dataList: [],
  48. useDataList: [],
  49. tableClo: [],
  50. visible: true,
  51. info: null,
  52. showID: true,
  53. title: '',
  54. pageIndex: 1,
  55. pageSize: 10,
  56. totalPage: 0,
  57. dataListLoading: false
  58. }
  59. },
  60. filters: {
  61. timeFormater (value) {
  62. // console.log('@', value)
  63. var date = new Date(value)
  64. let years = date.getFullYear()
  65. let month = (date.getMonth() + 1) > 10 ? date.getMonth() + 1 : '0' + (date.getMonth() + 1)
  66. let day = (date.getDate() >= 10) ? date.getDate() : '0' + date.getDate()
  67. let hours = (date.getHours() >= 10) ? date.getHours() : '0' + date.getHours()
  68. let minutes = (date.getMinutes() >= 10) ? date.getMinutes() : '0' + date.getMinutes()
  69. let seconds = (date.getSeconds() >= 10) ? date.getSeconds() : '0' + date.getSeconds()
  70. if (value) {
  71. return years + '-' + month + '-' + day +
  72. ' ' + hours + ':' + minutes + ':' + seconds
  73. } else {
  74. return 'N/A'
  75. }
  76. }
  77. },
  78. methods: {
  79. init (info) {
  80. this.visible = true
  81. this.info = info
  82. this.title = '结果 : ' + info.jobName
  83. this.dataList = []
  84. this.useDataList = []
  85. this.getJobRes()
  86. this.pageIndex = 1
  87. this.pageSize = 10
  88. this.totalPage = 0
  89. // console.log(info)
  90. },
  91. getJobRes () {
  92. this.dataListLoading = true
  93. this.useDataList = []
  94. this.$http({
  95. url: this.$http.adornUrl('/v1/metrics/values'),
  96. methods: 'get',
  97. params: this.$http.adornParams({
  98. 'offset': (this.pageIndex - 1) * this.pageSize,
  99. 'size': this.pageSize + 1,
  100. 'metricName': this.info.jobName
  101. })
  102. }).then((data) => {
  103. if (data.data.length && data.status === 200) {
  104. this.showID = true
  105. this.dataList = data.data
  106. for (const item of this.dataList) {
  107. item.value['time'] = item.tmst
  108. for (let key in item.value) {
  109. if (typeof (item.value[key]) !== 'object') {
  110. item.value[key].toString()
  111. } else {
  112. const keysplit = key.split('-')
  113. let records = ''
  114. let record
  115. for (const i in item.value[key]) {
  116. let name, count
  117. for (const category in item.value[key][i]) {
  118. if (category !== 'count') {
  119. name = item.value[key][i][category]
  120. count = item.value[key][i].count
  121. }
  122. }
  123. record = ' (' + name + ',' + count + ') '
  124. records += record
  125. }
  126. delete item.value[key]
  127. key = key + ' (' + keysplit[0].split('_')[0] + ', count)'
  128. item.value[key] = records
  129. }
  130. }
  131. this.useDataList.push(item.value)
  132. }
  133. // console.log(this.dataList)
  134. // this.useDataList = this.dataList
  135. // this.dataList.forEach((x) => {
  136. // console.log(x)
  137. // this.useDataList.push(x.value)
  138. // })
  139. // // console.log(this.dataList[0].value)
  140. this.tableClo = Object.keys(this.dataList[0].value)
  141. this.tableClo.forEach((data, index) => {
  142. if (data === 'time') {
  143. this.tableClo.splice(index, 1)
  144. }
  145. })
  146. this.dataListLoading = false
  147. this.$nextTick(() => {
  148. this.haveNextPage()
  149. })
  150. // console.log(this.tableClo)
  151. } else {
  152. this.tableClo = []
  153. this.showID = false
  154. this.dataListLoading = false
  155. }
  156. })
  157. // this.dataList = [
  158. // {
  159. // 'name': 'demo3',
  160. // 'tmst': 1642670565000,
  161. // 'value': {
  162. // 'id_count': 6375000,
  163. // 'id_max': 124,
  164. // 'age_max': 2000,
  165. // 'age_min': 1
  166. // }
  167. // },
  168. // {
  169. // 'name': 'demo3',
  170. // 'tmst': 1642670550000,
  171. // 'value': {
  172. // 'id_count': 6375000,
  173. // 'id_max': 124,
  174. // 'age_max': 2000,
  175. // 'age_min': 1
  176. // }
  177. // }]
  178. },
  179. // 每页数
  180. sizeChangeHandle (val) {
  181. this.pageSize = val
  182. this.pageIndex = 1
  183. this.getJobRes()
  184. },
  185. // 当前页
  186. currentChangeHandle (val) {
  187. this.pageIndex = val
  188. this.getJobRes()
  189. },
  190. /** 判断是否还有下一页
  191. * 思路 : 每次请求 pageSize +1 判断实际收到的数组长度
  192. */
  193. haveNextPage () {
  194. if (this.useDataList.length > this.pageSize) {
  195. this.totalPage = (this.pageIndex - 1) * this.pageSize + this.useDataList.length
  196. this.useDataList.pop()
  197. }
  198. }
  199. }
  200. }
  201. </script>
  202. <style scoped>
  203. </style>