Logs.vue 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <template>
  2. <div class="ap-logs">
  3. <code-mirror :value="output" :options="cmOptions" view-height="1000px" :is-scroll="true" />
  4. </div>
  5. </template>
  6. <script>
  7. export default {
  8. name: 'AnsiblePlaybookSidepageLogs',
  9. props: {
  10. data: {
  11. type: Object,
  12. required: true,
  13. },
  14. },
  15. data () {
  16. return {
  17. T: undefined,
  18. cmOptions: {
  19. tabSize: 2,
  20. styleActiveLine: true,
  21. lineNumbers: true,
  22. line: true,
  23. mode: 'text/x-yaml',
  24. theme: 'material',
  25. autofocus: true,
  26. },
  27. playbookItem: {},
  28. }
  29. },
  30. computed: {
  31. output () {
  32. return this.playbookItem.output || ''
  33. },
  34. isRun () {
  35. const { status } = this.data
  36. return status === 'running'
  37. },
  38. },
  39. watch: {
  40. isRun: {
  41. handler (newIsRun) {
  42. if (newIsRun) {
  43. this.querys()
  44. } else {
  45. this.unQuerys()
  46. }
  47. },
  48. immediate: true,
  49. },
  50. },
  51. created () {
  52. this.manager = new this.$Manager('ansibleplaybooks')
  53. this.fetchQueryInfo()
  54. },
  55. beforeDestroy () {
  56. this.unQuerys()
  57. },
  58. methods: {
  59. async fetchQueryInfo (id = this.data.id) {
  60. try {
  61. const { data } = await this.manager.get({ id })
  62. this.playbookItem = data
  63. } catch (err) {
  64. throw err
  65. }
  66. },
  67. querys () {
  68. this.T = setInterval(this.fetchQueryInfo, 1000)
  69. },
  70. unQuerys () {
  71. clearInterval(this.T)
  72. },
  73. },
  74. }
  75. </script>
  76. <style>
  77. .ap-logs .CodeMirror {
  78. height: 100% !important;
  79. }
  80. </style>