columns.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. import _ from 'lodash'
  2. import { getNameDescriptionTableColumn, getTimeTableColumn } from '@/utils/common/tableColumn'
  3. import { strategyColumn, levelColumn } from '@Monitor/views/commonalert/utils'
  4. import i18n from '@/locales'
  5. export default {
  6. data () {
  7. return {
  8. extandData: {},
  9. expandConfig: {
  10. loadMethod: this.loadMethod,
  11. lazy: true,
  12. },
  13. }
  14. },
  15. created () {
  16. this.columns = [
  17. getNameDescriptionTableColumn({
  18. edit: false,
  19. onManager: this.onManager,
  20. }),
  21. {
  22. field: 'none',
  23. title: this.$t('common.status'),
  24. slots: {
  25. default: ({ row }, h) => {
  26. return [
  27. <div class='text-truncate'>
  28. <status status='alerted' statusModule='alertresource' />
  29. </div>,
  30. ]
  31. },
  32. },
  33. },
  34. {
  35. field: 'alert_table',
  36. title: i18n.t('monitor.text_98'),
  37. slots: {
  38. default: ({ row }) => {
  39. const columns = [
  40. getNameDescriptionTableColumn({
  41. onManager: this.onManager,
  42. hideField: true,
  43. title: i18n.t('monitor.text_99'),
  44. edit: false,
  45. showDesc: false,
  46. slotCallback: row => {
  47. return (
  48. <side-page-trigger onTrigger={() => this.handleOpenAlertSidepage(row)}>{ row.alert }</side-page-trigger>
  49. )
  50. },
  51. }),
  52. getTimeTableColumn({ field: 'trigger_time', title: this.$t('monitor.text_14') }),
  53. strategyColumn(),
  54. levelColumn(),
  55. {
  56. field: 'value_str',
  57. title: this.$t('monitor.text_105'),
  58. align: 'right',
  59. formatter: ({ row }) => {
  60. const val = _.get(row, 'data.value_str') || '-'
  61. if (val === 'nodata') return this.$t('monitor.text_116')
  62. return val
  63. },
  64. },
  65. {
  66. field: 'action',
  67. title: this.$t('compute.text_863'),
  68. slots: {
  69. default: ({ row }, h) => {
  70. const ret = []
  71. ret.push(
  72. <a-button type="link" onClick = {() => viewTag(row)}>{ this.$t('common.view') }</a-button>,
  73. )
  74. return ret
  75. },
  76. },
  77. },
  78. ]
  79. const viewTag = obj => {
  80. this.createDialog('ViewItemTagsDialog', {
  81. vm: this,
  82. data: [obj],
  83. columns: columns.slice(0, 3),
  84. title: this.$t('monitor.text_104'),
  85. field: 'data.tags',
  86. })
  87. }
  88. const data = row.childData || []
  89. return [<list-body-cell-popover text={this.$t('common_701', [row.count || 0])} min-width="700px">
  90. <vxe-grid size="mini" resizable border showOverflow={false} row-config={{ isHover: true }} column-config={{ resizable: false }} columns={columns} data={data} />
  91. </list-body-cell-popover>]
  92. },
  93. },
  94. },
  95. {
  96. field: 'type',
  97. title: i18n.t('monitor.text_97'),
  98. formatter: ({ row }) => {
  99. if (row.type) {
  100. if (this.$te(`dictionary.${row.type}`)) {
  101. return this.$t(`dictionary.${row.type}`)
  102. }
  103. return row.type
  104. }
  105. return '-'
  106. },
  107. },
  108. ]
  109. this.extandData = {}
  110. },
  111. methods: {
  112. async toggleRowExpand ({ row, expanded }) {
  113. if (expanded) {
  114. try {
  115. if (!this.extandData[row.id]) {
  116. this.extandData[row.id] = await this.getAlertdata(row.id)
  117. this.$refs.pagelist.$refs.table.$refs.grid.reloadExpandContent(row)
  118. }
  119. } catch (error) {
  120. throw error
  121. }
  122. }
  123. },
  124. loadMethod ({ row }) {
  125. return new Promise(resolve => {
  126. this.getAlertdata(row.id).then(data => {
  127. row.childData = data
  128. resolve()
  129. })
  130. })
  131. },
  132. async getAlertdata (id) {
  133. try {
  134. const { data: { data } } = await new this.$Manager('alertresources', 'v1').getSpecific({ id, spec: 'alerts' })
  135. return data
  136. } catch (error) {
  137. throw error
  138. }
  139. },
  140. handleOpenAlertSidepage (row) {
  141. this.sidePageTriggerHandle(this, 'CommonalertsSidePage', {
  142. id: row.alert_id,
  143. resource: 'commonalerts',
  144. apiVersion: 'v1',
  145. sourceList: this.list,
  146. })
  147. },
  148. },
  149. }