Monitor.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <template>
  2. <dashboard-cards ref="dashboardCards" useLocalPanels :extraParams="extraParams" :localPanels="localPanels" />
  3. </template>
  4. <script>
  5. import WindowsMixin from '@/mixins/windows'
  6. import DashboardCards from '@Monitor/components/MonitorCard/DashboardCards'
  7. import { WIRE_MONITOR_OPTS } from '../constants'
  8. export default {
  9. name: 'WireMonitorSidepage',
  10. components: {
  11. DashboardCards,
  12. },
  13. mixins: [WindowsMixin],
  14. props: {
  15. data: { // listItemData
  16. type: Object,
  17. required: true,
  18. },
  19. },
  20. data () {
  21. return {
  22. singleActions: [
  23. ],
  24. }
  25. },
  26. computed: {
  27. monitorConstants () {
  28. return WIRE_MONITOR_OPTS
  29. },
  30. wireId () {
  31. return this.data.id
  32. },
  33. localPanels () {
  34. return this.monitorConstants.map(item => {
  35. return {
  36. panel_name: `${item.label}${item.metric ? `(${item.metric})` : `(${item.fromItem}.${item.seleteItem})`}`,
  37. constants: item,
  38. queryData: this.genQueryData(item),
  39. }
  40. })
  41. },
  42. },
  43. created () {
  44. },
  45. methods: {
  46. genQueryData (val) {
  47. const opt = val
  48. let select = []
  49. if (val.as) {
  50. const asItems = val.as.split(',')
  51. select = val.seleteItem.split(',').map((val, i) => {
  52. return [
  53. {
  54. type: 'field',
  55. params: [val],
  56. },
  57. { // 对应 mean(val.seleteItem)
  58. type: opt.groupFunc || 'mean',
  59. params: [],
  60. },
  61. { // 确保后端返回columns有 val.label 的别名
  62. type: 'alias',
  63. params: [asItems[i]],
  64. },
  65. ]
  66. })
  67. } else {
  68. select = val.seleteItem.split(',').map((val, i) => {
  69. return [
  70. {
  71. type: 'field',
  72. params: [val],
  73. },
  74. { // 对应 mean(val.seleteItem)
  75. type: opt.groupFunc || 'mean',
  76. params: [],
  77. },
  78. { // 确保后端返回columns有 val.label 的别名
  79. type: 'alias',
  80. params: [val],
  81. },
  82. ]
  83. })
  84. }
  85. const data = {
  86. metric_query: [
  87. {
  88. model: {
  89. measurement: val.fromItem,
  90. select,
  91. group_by: [
  92. { type: 'tag', params: ['id'] },
  93. ],
  94. tags: [
  95. {
  96. key: 'id',
  97. value: this.wireId,
  98. operator: '=',
  99. },
  100. ],
  101. },
  102. },
  103. ],
  104. scope: this.$store.getters.scope,
  105. unit: true,
  106. }
  107. return data
  108. },
  109. },
  110. }
  111. </script>