List.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <template>
  2. <page-list
  3. :list="list"
  4. :columns="columns"
  5. :group-actions="groupActions"
  6. :single-actions="singleActions" />
  7. </template>
  8. <script>
  9. import { metricItems, TIME_CN, LEVEL_CN, channelMap } from '@Compute/views/node-alert/constants'
  10. import WindowsMixin from '@/mixins/windows'
  11. import ListMixin from '@/mixins/list'
  12. import { HYPERVISORS_MAP } from '@/constants'
  13. import { sizestr, splitUnit } from '@/utils/utils'
  14. export default {
  15. name: 'NodeAlertList',
  16. mixins: [WindowsMixin, ListMixin],
  17. props: {
  18. getParams: {
  19. type: Object,
  20. default: () => ({}),
  21. },
  22. isSidepage: { // 是否在抽屉里面
  23. type: Boolean,
  24. default: true,
  25. },
  26. data: { // 抽屉里面当前 list row 的数据
  27. type: Object,
  28. },
  29. alertType: {
  30. type: String,
  31. required: true,
  32. validator: val => ['guest', 'host'].includes(val),
  33. },
  34. metricOpts: {
  35. type: Array,
  36. required: true,
  37. },
  38. listId: {
  39. type: String,
  40. },
  41. },
  42. data () {
  43. return {
  44. list: this.$list.createList(this, {
  45. id: this.listId,
  46. resource: 'nodealerts',
  47. apiVersion: 'v1',
  48. getParams: this.getParams,
  49. }),
  50. columns: [
  51. {
  52. field: 'metric',
  53. title: this.$t('compute.text_744'),
  54. width: '24%',
  55. formatter: ({ row }) => {
  56. if (!row.metric) return '-'
  57. if (!metricItems[row.metric]) return row.metric
  58. return metricItems[row.metric].label
  59. },
  60. },
  61. {
  62. field: 'window',
  63. title: this.$t('compute.text_733'),
  64. width: 80,
  65. formatter: ({ row }) => {
  66. if (!row.window) return '-'
  67. const window = row.window.slice(0, -1)
  68. const unit = row.window.slice(-1)
  69. const cn = TIME_CN[unit] || unit
  70. return `${window} ${cn}`
  71. },
  72. },
  73. {
  74. field: 'comparator',
  75. title: this.$t('compute.text_745'),
  76. },
  77. {
  78. field: 'threshold',
  79. title: this.$t('compute.text_736'),
  80. formatter: ({ row }) => {
  81. if (!row.metric) return '-'
  82. const { unit } = metricItems[row.metric]
  83. let threshold = row.threshold
  84. if (unit === 'bps') {
  85. threshold = sizestr(threshold, 'B', 1000)
  86. }
  87. const text = `${threshold}${unit}`
  88. if (text) return splitUnit(text).text
  89. else return '-'
  90. },
  91. },
  92. {
  93. field: 'level',
  94. title: this.$t('compute.text_746'),
  95. slots: {
  96. default: ({ row }) => {
  97. const levelItem = LEVEL_CN[row.level]
  98. if (!levelItem) return row.level || '-'
  99. return [
  100. <a-tag color={levelItem.color}>{ levelItem.label }</a-tag>,
  101. ]
  102. },
  103. },
  104. },
  105. {
  106. field: 'channel',
  107. title: this.$t('compute.text_739'),
  108. width: 80,
  109. formatter: ({ row }) => {
  110. return channelMap[row.channel] || row.channel
  111. },
  112. },
  113. ],
  114. groupActions: [
  115. {
  116. label: this.$t('compute.perform_create'),
  117. permission: 'nodealerts_create',
  118. action: () => {
  119. this.createDialog('CreateNodeAlert', {
  120. list: this.list,
  121. alertType: this.alertType,
  122. nodeId: this.data.id,
  123. metricOpts: this.metricOpts,
  124. hypervisor: this.data.hypervisor,
  125. })
  126. },
  127. meta: () => {
  128. const ret = {
  129. validate: false,
  130. tooltip: null,
  131. buttonType: 'primary',
  132. }
  133. if (this.isSidepage) {
  134. const { hypervisor } = this.data
  135. if (hypervisor === HYPERVISORS_MAP.esxi.key) { // esxi 允许新建6个报警
  136. ret.validate = this.list.total < 6
  137. }
  138. ret.validate = this.list.total < 5 // 默认允许新建5个报警
  139. }
  140. return ret
  141. },
  142. },
  143. {
  144. label: this.$t('compute.perform_delete'),
  145. permission: 'server_delete',
  146. action: () => {
  147. this.createDialog('DeleteResDialog', {
  148. vm: this,
  149. data: this.list.selectedItems,
  150. columns: this.columns,
  151. title: this.$t('compute.text_747'),
  152. name: this.$t('compute.text_748'),
  153. onManager: this.onManager,
  154. })
  155. },
  156. meta: () => {
  157. return {
  158. validate: this.list.selectedItems.length > 0,
  159. }
  160. },
  161. },
  162. ],
  163. singleActions: [
  164. {
  165. label: this.$t('compute.text_749'),
  166. permission: 'nodealerts_update',
  167. action: obj => {
  168. this.createDialog('UpdateNodeAlert', {
  169. data: [obj],
  170. columns: this.columns,
  171. list: this.list,
  172. alertType: this.alertType,
  173. metricOpts: this.metricOpts,
  174. hypervisor: this.data.hypervisor,
  175. })
  176. },
  177. },
  178. {
  179. label: this.$t('compute.perform_delete'),
  180. permission: 'nodealerts_delete',
  181. action: obj => {
  182. this.createDialog('DeleteResDialog', {
  183. vm: this,
  184. data: [obj],
  185. columns: this.columns,
  186. title: this.$t('compute.text_747'),
  187. name: this.$t('compute.text_748'),
  188. onManager: this.onManager,
  189. })
  190. },
  191. // meta: obj => this.$getDeleteResult(obj),
  192. },
  193. ],
  194. }
  195. },
  196. created () {
  197. this.list.fetchData()
  198. },
  199. }
  200. </script>