LogEntry.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <script setup lang="ts">
  2. import type { NgxConfig } from '@/api/ngx'
  3. import { FileExclamationOutlined, FileTextOutlined } from '@ant-design/icons-vue'
  4. import { useRouter } from 'vue-router'
  5. const props = defineProps<{
  6. ngxConfig: NgxConfig
  7. currentServerIdx: number
  8. name?: string
  9. }>()
  10. const accessIdx = ref<number>()
  11. const errorIdx = ref<number>()
  12. const hasAccessLog = computed(() => {
  13. let flag = false
  14. props.ngxConfig?.servers[props.currentServerIdx].directives?.forEach((v, k) => {
  15. if (v.directive === 'access_log') {
  16. flag = true
  17. accessIdx.value = k
  18. }
  19. })
  20. return flag
  21. })
  22. const hasErrorLog = computed(() => {
  23. let flag = false
  24. props.ngxConfig?.servers[props.currentServerIdx].directives?.forEach((v, k) => {
  25. if (v.directive === 'error_log') {
  26. flag = true
  27. errorIdx.value = k
  28. }
  29. })
  30. return flag
  31. })
  32. const router = useRouter()
  33. function on_click_access_log() {
  34. router.push({
  35. path: '/nginx_log/site',
  36. query: {
  37. server_idx: props.currentServerIdx,
  38. directive_idx: accessIdx.value,
  39. conf_name: props.name,
  40. },
  41. })
  42. }
  43. function on_click_error_log() {
  44. router.push({
  45. path: '/nginx_log/site',
  46. query: {
  47. server_idx: props.currentServerIdx,
  48. directive_idx: errorIdx.value,
  49. conf_name: props.name,
  50. },
  51. })
  52. }
  53. </script>
  54. <template>
  55. <ASpace
  56. v-if="hasAccessLog || hasErrorLog"
  57. style="margin-left: -15px;margin-bottom: 5px"
  58. >
  59. <AButton
  60. v-if="hasAccessLog"
  61. type="link"
  62. @click="on_click_access_log"
  63. >
  64. <FileTextOutlined />
  65. {{ $gettext('Access Logs') }}
  66. </AButton>
  67. <AButton
  68. v-if="hasErrorLog"
  69. type="link"
  70. @click="on_click_error_log"
  71. >
  72. <FileExclamationOutlined />
  73. {{ $gettext('Error Logs') }}
  74. </AButton>
  75. </ASpace>
  76. </template>
  77. <style lang="less" scoped>
  78. </style>