LogEntry.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 accessLogPath = ref<string>()
  13. const errorLogPath = ref<string>()
  14. const hasAccessLog = computed(() => {
  15. let flag = false
  16. props.ngxConfig?.servers[props.currentServerIdx].directives?.forEach((v, k) => {
  17. if (v.directive === 'access_log') {
  18. flag = true
  19. accessIdx.value = k
  20. // Extract log path from directive params
  21. if (v.params) {
  22. const params = v.params.split(' ')
  23. if (params.length > 0) {
  24. accessLogPath.value = params[0]
  25. }
  26. }
  27. }
  28. })
  29. return flag
  30. })
  31. const hasErrorLog = computed(() => {
  32. let flag = false
  33. props.ngxConfig?.servers[props.currentServerIdx].directives?.forEach((v, k) => {
  34. if (v.directive === 'error_log') {
  35. flag = true
  36. errorIdx.value = k
  37. // Extract log path from directive params
  38. if (v.params) {
  39. const params = v.params.split(' ')
  40. if (params.length > 0) {
  41. errorLogPath.value = params[0]
  42. }
  43. }
  44. }
  45. })
  46. return flag
  47. })
  48. const router = useRouter()
  49. function on_click_access_log() {
  50. router.push({
  51. path: '/nginx_log/site',
  52. query: {
  53. type: 'site',
  54. log_path: accessLogPath.value,
  55. },
  56. })
  57. }
  58. function on_click_error_log() {
  59. router.push({
  60. path: '/nginx_log/site',
  61. query: {
  62. type: 'site',
  63. log_path: errorLogPath.value,
  64. },
  65. })
  66. }
  67. </script>
  68. <template>
  69. <ASpace
  70. v-if="hasAccessLog || hasErrorLog"
  71. style="margin-left: -15px;margin-bottom: 5px"
  72. >
  73. <AButton
  74. v-if="hasAccessLog"
  75. type="link"
  76. @click="on_click_access_log"
  77. >
  78. <FileTextOutlined />
  79. {{ $gettext('Access Logs') }}
  80. </AButton>
  81. <AButton
  82. v-if="hasErrorLog"
  83. type="link"
  84. @click="on_click_error_log"
  85. >
  86. <FileExclamationOutlined />
  87. {{ $gettext('Error Logs') }}
  88. </AButton>
  89. </ASpace>
  90. </template>
  91. <style lang="less" scoped>
  92. </style>