index.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <template>
  2. <base-side-page
  3. @cancel="cancelSidePage"
  4. :title="title"
  5. icon="res-commonalerts"
  6. :res-name="detailData.name"
  7. :current-tab="params.windowData.currentTab"
  8. :tabs="detailTabs"
  9. :loaded="loaded"
  10. @tab-change="handleTabChange">
  11. <template v-slot:actions>
  12. <actions
  13. :options="singleActions"
  14. :row="detailData"
  15. button-type="link"
  16. button-size="small" />
  17. </template>
  18. <component
  19. needFetchResource
  20. :is="params.windowData.currentTab"
  21. :listId="listId"
  22. :id="listId"
  23. :resId="data.id"
  24. :data="componentData"
  25. :resource="resource"
  26. :resType="resType"
  27. :on-manager="onManager"
  28. :getParams="listParams"
  29. :isPageDestroyed="isPageDestroyed"
  30. :serverColumns="columns"
  31. hideAlertRecordResourceCount />
  32. </base-side-page>
  33. </template>
  34. <script>
  35. import CommonalertList from '@Monitor/views/commonalert/components/List'
  36. import SidePageMixin from '@/mixins/sidePage'
  37. import WindowsMixin from '@/mixins/windows'
  38. import Actions from '@/components/PageList/Actions'
  39. import AlertrecortList from '@Monitor/views/alertrecord/components/List'
  40. // import VmInstanceMonitorSidepage from './Monitor'
  41. import VmInstanceMonitorSidepage from '@Compute/views/vminstance/sidepage/Monitor'
  42. import HostMonitorSidepage from '@Compute/views/host/sidepage/Monitor'
  43. import ColumnsMixin from '../mixins/columns'
  44. import SingleActionsMixin from '../mixins/singleActions'
  45. export default {
  46. name: 'MonitorResourceSidePage',
  47. components: {
  48. CommonalertList,
  49. VmInstanceMonitorSidepage,
  50. HostMonitorSidepage,
  51. Actions,
  52. AlertrecortList,
  53. },
  54. mixins: [SidePageMixin, WindowsMixin, ColumnsMixin, SingleActionsMixin],
  55. data () {
  56. return {
  57. agent_status: '',
  58. agent_fail_reason: '',
  59. agent_fail_code: '',
  60. isPageDestroyed: false,
  61. }
  62. },
  63. computed: {
  64. listId () {
  65. switch (this.params.windowData.currentTab) {
  66. case 'CommonalertList':
  67. return 'CommonalertListSidePage'
  68. case 'vm-instance-monitor-sidepage':
  69. return 'VmInstanceMonitorSidepage'
  70. case 'host-monitor-sidepage':
  71. return 'HostMonitorSidepage'
  72. case 'AlertrecortList':
  73. return 'AlertrecortListSidePage'
  74. default:
  75. return ''
  76. }
  77. },
  78. detailTabs () {
  79. const tabs = [
  80. { label: this.$t('monitor.text_10'), key: 'AlertrecortList' },
  81. { label: this.$t('monitor.text_122'), key: this.resType === 'guest' ? 'vm-instance-monitor-sidepage' : 'host-monitor-sidepage' },
  82. { label: this.$t('dictionary.commonalert'), key: 'CommonalertList' },
  83. ]
  84. return tabs
  85. },
  86. title () {
  87. const t = this.params.res_type || ''
  88. return t === 'guest' ? this.$t('common.server') : this.$t('dictionary.host')
  89. },
  90. resType () {
  91. return this.params.res_type
  92. },
  93. componentData () {
  94. const data = Object.assign({}, this.detailData, { agent_status: this.agent_status, agent_fail_reason: this.agent_fail_reason, agent_fail_code: this.agent_fail_code })
  95. if (this.params.windowData.currentTab === 'vm-instance-monitor-sidepage' || this.params.windowData.currentTab === 'host-monitor-sidepage') {
  96. data.id = data.res_id || data.id
  97. }
  98. return data
  99. },
  100. },
  101. created () {
  102. this.$bus.$on('agentStatusQuery', (val) => {
  103. if (this.agent_status === 'failed') {
  104. this.agent_status = 'applying'
  105. }
  106. this.handleInstallTask({
  107. script_apply_id: val,
  108. })
  109. })
  110. },
  111. beforeDestroy () {
  112. this.isPageDestroyed = true
  113. },
  114. methods: {
  115. async fetchDataCallback () {
  116. if (this.params.res_type !== 'guest') return
  117. try {
  118. if (!this.data.data) return
  119. const { data: { data = [] } } = await new this.$Manager('scriptapplyrecords').list({ params: { server_id: this.data.data.res_id, details: false, limit: 1 } })
  120. if (data[0]) {
  121. this.agent_status = data[0].status
  122. if (data[0].status === 'applying') {
  123. this.handleInstallTask({
  124. server_id: this.componentData.res_id,
  125. details: false,
  126. limit: 1,
  127. })
  128. } else if (data[0].status === 'failed') {
  129. this.agent_fail_reason = data[0].reason
  130. this.agent_fail_code = data[0].fail_code || ''
  131. }
  132. }
  133. } catch (e) { }
  134. },
  135. listParams () {
  136. let params = {}
  137. if (typeof this.getParams === 'function') {
  138. params = this.getParams()
  139. } else {
  140. params = this.getParams || {}
  141. }
  142. if (this.params.windowData.currentTab === 'AlertrecortList') {
  143. return {
  144. res_id: this.detailData.res_id,
  145. }
  146. }
  147. if (this.params.windowData.currentTab === 'CommonalertList') {
  148. params.monitor_resource_id = this.detailData.res_id
  149. }
  150. return {
  151. ...params,
  152. }
  153. },
  154. handleOpenSidepage (row, tab) {
  155. this.params.windowData.currentTab = tab
  156. },
  157. async handleInstallTask (params) {
  158. try {
  159. let maxTry = 60
  160. while (maxTry > 0) {
  161. if (this.isPageDestroyed) {
  162. break
  163. }
  164. const { data: { data = [] } } = await new this.$Manager('scriptapplyrecords').list({ params })
  165. if (data[0]) {
  166. if (data[0].status === 'succeed' || data[0].status === 'failed') {
  167. this.agent_status = data[0].status
  168. this.agent_fail_reason = data[0].reason
  169. this.agent_fail_code = data[0].fail_code || ''
  170. break
  171. }
  172. }
  173. maxTry -= 1
  174. await new Promise(resolve => setTimeout(resolve, 6000))
  175. }
  176. } catch (e) { }
  177. },
  178. },
  179. }
  180. </script>
  181. <style scoped>
  182. </style>