blacklist.vue 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <template>
  2. <el-card class="simple-card" shadow="hover" v-loading="form.loading">
  3. <template #header>
  4. <div class="card-header">
  5. <span>BLACK_LIST</span>
  6. </div>
  7. </template>
  8. <el-form :disabled="!canSend">
  9. <el-form-item>
  10. <el-input type="textarea" :model-value="form.list.join('|')" :rows="5"></el-input>
  11. </el-form-item>
  12. <el-form-item>
  13. <el-button @click="getList">{{ T('Refresh') }}</el-button>
  14. <el-button @click="showForm('add')" type="primary">{{ T('Add') }}</el-button>
  15. <el-button @click="showForm('delete')" type="danger">{{ T('Delete') }}</el-button>
  16. </el-form-item>
  17. </el-form>
  18. <el-dialog v-model="form.form_visible" :title="form.form_type">
  19. <el-form label-width="100px">
  20. <el-form-item label="IP">
  21. <el-input v-model="form.form_input"></el-input>
  22. <div>多个IP以 | 分割</div>
  23. <div v-if="form.form_type==='delete'">, 全部填 <strong>all</strong></div>
  24. </el-form-item>
  25. <el-form-item>
  26. <el-button @click="form.form_visible=false">{{ T('Cancel') }}</el-button>
  27. <el-button @click="form.form_type === 'add' ? add() : remove()" type="primary">{{ T('Submit') }}</el-button>
  28. </el-form-item>
  29. </el-form>
  30. </el-dialog>
  31. </el-card>
  32. </template>
  33. <script setup>
  34. import { T } from '@/utils/i18n'
  35. import { reactive, watch } from 'vue'
  36. import { sendCmd } from '@/api/rustdesk'
  37. import { ElMessage } from 'element-plus'
  38. import { RELAY_TARGET } from '@/views/rustdesk/options'
  39. const props = defineProps({
  40. canSend: Boolean,
  41. })
  42. const form = reactive({
  43. get_cmd: 'blacklist',
  44. add_cmd: 'blacklist-add',
  45. remove_cmd: 'blacklist-remove',
  46. list: [],
  47. target: RELAY_TARGET,
  48. loading: false,
  49. form_visible: false,
  50. form_input: '',
  51. form_type: '',
  52. })
  53. const getList = async () => {
  54. form.loading = true
  55. const res = await sendCmd({ cmd: form.get_cmd, target: RELAY_TARGET }).catch(_ => false)
  56. form.loading = false
  57. if (res) {
  58. form.list = res.data.split('\n').filter(i => i)
  59. }
  60. }
  61. const showForm = (type) => {
  62. form.form_visible = true
  63. form.form_input = ''
  64. form.form_type = type
  65. }
  66. const add = async () => {
  67. const res = await sendCmd({ cmd: form.add_cmd, option: form.form_input, target: RELAY_TARGET }).catch(_ => false)
  68. if (res) {
  69. ElMessage.success(T('OperationSuccess'))
  70. getList()
  71. }
  72. }
  73. const remove = async () => {
  74. const res = await sendCmd({ cmd: form.remove_cmd, option: form.form_input, target: RELAY_TARGET }).catch(_ => false)
  75. if (res) {
  76. ElMessage.success(T('OperationSuccess'))
  77. getList()
  78. }
  79. }
  80. watch(() => props.canSend, (v) => {
  81. if (v) {
  82. getList()
  83. }
  84. })
  85. </script>
  86. <style scoped lang="scss">
  87. </style>