ProxyView.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <template>
  2. <div>
  3. <el-page-header
  4. :icon="null"
  5. style="width: 100%; margin-left: 30px; margin-bottom: 20px"
  6. >
  7. <template #title>
  8. <span>{{ proxyType }}</span>
  9. </template>
  10. <template #content> </template>
  11. <template #extra>
  12. <div class="flex items-center" style="margin-right: 30px">
  13. <el-popconfirm
  14. title="Are you sure to clear all data of offline proxies?"
  15. @confirm="clearOfflineProxies"
  16. >
  17. <template #reference>
  18. <el-button>ClearOfflineProxies</el-button>
  19. </template>
  20. </el-popconfirm>
  21. <el-button @click="$emit('refresh')">Refresh</el-button>
  22. </div>
  23. </template>
  24. </el-page-header>
  25. <el-table
  26. :data="proxies"
  27. :default-sort="{ prop: 'name', order: 'ascending' }"
  28. style="width: 100%"
  29. >
  30. <el-table-column type="expand">
  31. <template #default="props">
  32. <ProxyViewExpand :row="props.row" :proxyType="proxyType" />
  33. </template>
  34. </el-table-column>
  35. <el-table-column label="Name" prop="name" sortable> </el-table-column>
  36. <el-table-column label="Port" prop="port" sortable> </el-table-column>
  37. <el-table-column label="Connections" prop="conns" sortable>
  38. </el-table-column>
  39. <el-table-column
  40. label="Traffic In"
  41. prop="trafficIn"
  42. :formatter="formatTrafficIn"
  43. sortable
  44. >
  45. </el-table-column>
  46. <el-table-column
  47. label="Traffic Out"
  48. prop="trafficOut"
  49. :formatter="formatTrafficOut"
  50. sortable
  51. >
  52. </el-table-column>
  53. <el-table-column label="ClientVersion" prop="clientVersion" sortable>
  54. </el-table-column>
  55. <el-table-column label="Status" prop="status" sortable>
  56. <template #default="scope">
  57. <el-tag v-if="scope.row.status === 'online'" type="success">{{
  58. scope.row.status
  59. }}</el-tag>
  60. <el-tag v-else type="danger">{{ scope.row.status }}</el-tag>
  61. </template>
  62. </el-table-column>
  63. <el-table-column label="Operations">
  64. <template #default="scope">
  65. <el-button
  66. type="primary"
  67. :name="scope.row.name"
  68. style="margin-bottom: 10px"
  69. @click="dialogVisibleName = scope.row.name; dialogVisible = true"
  70. >Traffic
  71. </el-button>
  72. </template>
  73. </el-table-column>
  74. </el-table>
  75. </div>
  76. <el-dialog
  77. v-model="dialogVisible"
  78. destroy-on-close="true"
  79. :title="dialogVisibleName"
  80. width="700px">
  81. <Traffic :proxyName="dialogVisibleName" />
  82. </el-dialog>
  83. </template>
  84. <script setup lang="ts">
  85. import * as Humanize from 'humanize-plus'
  86. import type { TableColumnCtx } from 'element-plus'
  87. import type { BaseProxy } from '../utils/proxy.js'
  88. import { ElMessage } from 'element-plus'
  89. import ProxyViewExpand from './ProxyViewExpand.vue'
  90. import { ref } from 'vue'
  91. defineProps<{
  92. proxies: BaseProxy[]
  93. proxyType: string
  94. }>()
  95. const emit = defineEmits(['refresh'])
  96. const dialogVisible = ref(false)
  97. const dialogVisibleName = ref("")
  98. const formatTrafficIn = (row: BaseProxy, _: TableColumnCtx<BaseProxy>) => {
  99. return Humanize.fileSize(row.trafficIn)
  100. }
  101. const formatTrafficOut = (row: BaseProxy, _: TableColumnCtx<BaseProxy>) => {
  102. return Humanize.fileSize(row.trafficOut)
  103. }
  104. const clearOfflineProxies = () => {
  105. fetch('../api/proxies?status=offline', {
  106. method: 'DELETE',
  107. credentials: 'include',
  108. })
  109. .then((res) => {
  110. if (res.ok) {
  111. ElMessage({
  112. message: 'Successfully cleared offline proxies',
  113. type: 'success',
  114. })
  115. emit('refresh')
  116. } else {
  117. ElMessage({
  118. message: 'Failed to clear offline proxies: ' + res.status + ' ' + res.statusText,
  119. type: 'warning',
  120. })
  121. }
  122. })
  123. .catch((err) => {
  124. ElMessage({
  125. message: 'Failed to clear offline proxies: ' + err.message,
  126. type: 'warning',
  127. })
  128. })
  129. }
  130. </script>
  131. <style>
  132. .el-page-header__title {
  133. font-size: 20px;
  134. }
  135. </style>