Log.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <template>
  2. <div>
  3. <a-form-model :model="form" layout="inline">
  4. <a-form-model-item :label="$t('k8s.text_1')">
  5. <a-select style="min-width: 200px;" v-model="form.activeContainer">
  6. <a-select-option v-for="item in containers" :value="item.id" :key="item.id">{{ item.name }}</a-select-option>
  7. </a-select>
  8. </a-form-model-item>
  9. <a-form-model-item :label="$t('k8s.text_320')">
  10. <a-row>
  11. <a-col :span="12">
  12. <a-form-model-item>
  13. <a-select style="min-width: 240px;" v-model="form.time">
  14. <a-select-option v-for="item in timeOptions" :value="item.value" :key="item.name">{{ item.name }}</a-select-option>
  15. </a-select>
  16. </a-form-model-item>
  17. </a-col>
  18. <a-col :span="12" v-show="isCustomTime">
  19. <a-form-model-item>
  20. <duration-second-input v-model="form.customTime" :durationOptions="durationOptions" />
  21. </a-form-model-item>
  22. </a-col>
  23. </a-row>
  24. </a-form-model-item>
  25. <a-form-model-item>
  26. <a-button type="primary" style="margin-left: -20px;" @click="fetchUrl">{{$t('common.ok')}}</a-button>
  27. </a-form-model-item>
  28. </a-form-model>
  29. <xterm :connectParams="connectParams" />
  30. </div>
  31. </template>
  32. <script>
  33. export default {
  34. name: 'Log',
  35. props: {
  36. data: {
  37. type: Object,
  38. required: true,
  39. },
  40. },
  41. data () {
  42. return {
  43. containers: [],
  44. form: {
  45. activeContainer: '',
  46. time: 3600,
  47. customTime: 3600,
  48. },
  49. connectParams: '',
  50. durationOptions: [
  51. { label: this.$t('k8s.text_321'), key: 'hours' },
  52. { label: this.$t('k8s.text_322'), key: 'minutes' },
  53. { label: this.$t('k8s.text_323'), key: 'days' },
  54. ],
  55. timeOptions: [
  56. { name: this.$t('common_95'), value: 'all' },
  57. { name: this.$t('common_nearly_num_minutes', [5]), value: 5 * 60 },
  58. { name: this.$t('common_nearly_num_minutes', [30]), value: 30 * 60 },
  59. { name: this.$t('common_nearly_num_hours', [1]), value: 60 * 60 },
  60. { name: this.$t('common_nearly_num_hours', [6]), value: 6 * 60 * 60 },
  61. { name: this.$t('common_nearly_num_hours', [12]), value: 12 * 60 * 60 },
  62. { name: this.$t('common_nearly_num_days', [1]), value: 24 * 60 * 60 },
  63. { name: this.$t('common.date_time.custom'), value: 'custom' },
  64. ],
  65. }
  66. },
  67. computed: {
  68. isAllTime () {
  69. return this.form.time === 'all'
  70. },
  71. isCustomTime () {
  72. return this.form.time === 'custom'
  73. },
  74. },
  75. created () {
  76. this.manager = new this.$Manager('containers')
  77. this.fetchData()
  78. },
  79. methods: {
  80. async fetchData () {
  81. const { data } = await this.manager.list({
  82. params: {
  83. guest_id: this.data.guest_id,
  84. scope: this.$store.getters.scope,
  85. },
  86. })
  87. this.containers = data.data
  88. const firstContainer = data.data?.[0]
  89. this.form.activeContainer = firstContainer.id
  90. this.fetchUrl()
  91. },
  92. async fetchUrl () {
  93. const params = {
  94. container_id: this.form.activeContainer,
  95. follow: true,
  96. }
  97. if (!this.isAllTime) {
  98. if (this.isCustomTime) {
  99. params.since = `${this.form.customTime}s`
  100. } else {
  101. params.since = `${this.form.time}s`
  102. }
  103. }
  104. const { data } = await new this.$Manager('webconsole', 'v1').objectRpc({
  105. methodname: 'DoContainerLog',
  106. params,
  107. })
  108. this.connectParams = data.connect_params
  109. },
  110. },
  111. }
  112. </script>