Asbook.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <template>
  2. <base-dialog @cancel="cancelDialog">
  3. <div slot="header">{{params.title}}</div>
  4. <div slot="body">
  5. <a-descriptions bordered size="small">
  6. <a-descriptions-item :label="$t('network.text_21')">
  7. {{ansibleplaybookData.name}}
  8. </a-descriptions-item>
  9. <a-descriptions-item :label="$t('network.text_27')">
  10. <status :status="ansibleplaybookData.status" statusModule="ansiblePlaybook" />
  11. </a-descriptions-item>
  12. </a-descriptions>
  13. <div class="mt-3">
  14. <code-mirror :value="ansibleplaybookData.output " :options="cmOptions" />
  15. </div>
  16. </div>
  17. <div slot="footer">
  18. <a-button class="ml-2 mr-2" @click="handleRun" :disabled="this.isRunning">{{$t('network.text_28')}}</a-button>
  19. <a-popconfirm
  20. class=""
  21. placement="topRight"
  22. :title="$t('network.text_29')"
  23. :ok-text="$t('scope.text_856')"
  24. :cancel-text="$t('network.text_31')"
  25. @confirm="handleStop">
  26. <a-button class="" :disabled="!this.isRunning">{{$t('network.text_32')}}</a-button>
  27. </a-popconfirm>
  28. <a-button class="ml-2" @click="cancelDialog">{{$t('network.text_33')}}</a-button>
  29. </div>
  30. </base-dialog>
  31. </template>
  32. <script>
  33. import Ansible from '../controls/ansible'
  34. import WindowsMixin from '@/mixins/windows'
  35. import DialogMixin from '@/mixins/dialog'
  36. export default {
  37. name: 'AnsibleplaybookDialog',
  38. components: {
  39. },
  40. mixins: [WindowsMixin, DialogMixin],
  41. data () {
  42. return {
  43. T: null,
  44. isRunning: false,
  45. ansibleplaybookData: {},
  46. columns: [
  47. {
  48. field: 'name',
  49. title: this.$t('network.text_34'),
  50. },
  51. ],
  52. cmOptions: {
  53. tabSize: 2,
  54. styleActiveLine: true,
  55. lineNumbers: true,
  56. line: true,
  57. name: 'javascript',
  58. json: true,
  59. theme: 'material',
  60. },
  61. baseInfo: [
  62. {
  63. field: 'start_time',
  64. title: this.$t('network.text_35'),
  65. formatter: ({ cellValue }) => {
  66. return this.$moment(cellValue).format(this.$t('network.text_36'))
  67. },
  68. },
  69. {
  70. field: 'end_time',
  71. title: this.$t('network.text_37'),
  72. formatter: ({ cellValue }) => {
  73. return this.$moment(cellValue).format(this.$t('network.text_36'))
  74. },
  75. },
  76. ],
  77. extraInfo: [
  78. {
  79. title: this.$t('network.text_38'),
  80. items: [
  81. {
  82. field: 'output',
  83. title: this.$t('network.text_39'),
  84. slots: {
  85. default: ({ row }, h) => {
  86. return [
  87. <code-mirror value={ row.output } options={ this.cmOptions } />,
  88. ]
  89. },
  90. },
  91. },
  92. ],
  93. },
  94. ],
  95. }
  96. },
  97. watch: {
  98. isRunning (nextVal) {
  99. clearInterval(this.T)
  100. if (nextVal) {
  101. this.T = setInterval(() => {
  102. this.refresh()
  103. }, 10000)
  104. }
  105. },
  106. },
  107. created () {
  108. const { ansiblePlaybookId } = this.params
  109. this.ansibleEvents = new Ansible(ansiblePlaybookId)
  110. this.refresh()
  111. },
  112. methods: {
  113. refresh () {
  114. return this.ansibleEvents
  115. .get()
  116. .then(({ data }) => {
  117. this.ansibleplaybookData = data
  118. this.isRunning = data.status === 'running'
  119. if (!this.isRunning) {
  120. clearInterval(this.T)
  121. }
  122. this.$nextTick(() => {
  123. document.getElementsByClassName('CodeMirror-scroll')[0].scrollTop = 999999
  124. })
  125. })
  126. },
  127. async handleStop () {
  128. try {
  129. await this.ansibleEvents.stop()
  130. this.$message.success(this.$t('network.text_40'))
  131. this.refresh()
  132. } catch (err) {
  133. throw err
  134. }
  135. },
  136. async handleRun () {
  137. try {
  138. this.ansibleplaybookData.output = ' '
  139. await this.ansibleEvents.run()
  140. this.refresh()
  141. } catch (err) {
  142. throw err
  143. }
  144. },
  145. handleCancel () {
  146. this.$router.push('/lbagent')
  147. },
  148. },
  149. }
  150. </script>
  151. <style lang="less" scoped>
  152. .ansible-playbook {
  153. ::v-deep {
  154. .CodeMirror {
  155. height: 700px !important;
  156. }
  157. }
  158. }
  159. </style>