xray_balancer_modal.html 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. {{define "balancerModal"}}
  2. <a-modal
  3. id="balancer-modal"
  4. v-model="balancerModal.visible"
  5. :title="balancerModal.title"
  6. @ok="balancerModal.ok"
  7. :confirm-loading="balancerModal.confirmLoading"
  8. :ok-button-props="{ props: { disabled: !balancerModal.isValid } }"
  9. :closable="true"
  10. :mask-closable="false"
  11. :ok-text="balancerModal.okText"
  12. cancel-text='{{ i18n "close" }}'
  13. :class="themeSwitcher.currentTheme">
  14. <a-form :colon="false" :label-col="{ md: {span:8} }" :wrapper-col="{ md: {span:14} }">
  15. <a-form-item label='{{ i18n "pages.xray.balancer.tag" }}' has-feedback
  16. :validate-status="balancerModal.duplicateTag? 'warning' : 'success'">
  17. <a-input v-model.trim="balancerModal.balancer.tag" @change="balancerModal.check()"
  18. placeholder='{{ i18n "pages.xray.balancer.tagDesc" }}'></a-input>
  19. </a-form-item>
  20. <a-form-item label='{{ i18n "pages.xray.balancer.balancerStrategy" }}'>
  21. <a-select v-model="balancerModal.balancer.strategy" :dropdown-class-name="themeSwitcher.currentTheme">
  22. <a-select-option value="random">Random</a-select-option>
  23. <a-select-option value="roundRobin">Round Robin</a-select-option>
  24. </a-select>
  25. </a-form-item>
  26. <a-form-item label='{{ i18n "pages.xray.balancer.balancerSelectors" }}' has-feedback
  27. :validate-status="balancerModal.emptySelector? 'warning' : 'success'">
  28. <a-select v-model="balancerModal.balancer.selector" mode="tags" @change="balancerModal.checkSelector()"
  29. :dropdown-class-name="themeSwitcher.currentTheme">
  30. <a-select-option v-for="tag in balancerModal.outboundTags" :value="tag">[[ tag ]]</a-select-option>
  31. </a-select>
  32. </a-form-item>
  33. </table>
  34. </a-form>
  35. </a-modal>
  36. <script>
  37. const balancerModal = {
  38. title: '',
  39. visible: false,
  40. confirmLoading: false,
  41. okText: '{{ i18n "sure" }}',
  42. isEdit: false,
  43. confirm: null,
  44. duplicateTag: false,
  45. emptySelector: false,
  46. balancer: {
  47. tag: '',
  48. strategy: 'random',
  49. selector: []
  50. },
  51. outboundTags: [],
  52. balancerTags:[],
  53. ok() {
  54. if (balancerModal.balancer.selector.length == 0) {
  55. balancerModal.emptySelector = true;
  56. return;
  57. }
  58. balancerModal.emptySelector = false;
  59. ObjectUtil.execute(balancerModal.confirm, balancerModal.balancer);
  60. },
  61. show({ title = '', okText = '{{ i18n "sure" }}', balancerTags = [], balancer, confirm = (balancer) => { }, isEdit = false }) {
  62. this.title = title;
  63. this.okText = okText;
  64. this.confirm = confirm;
  65. this.visible = true;
  66. if (isEdit) {
  67. balancerModal.balancer = balancer;
  68. } else {
  69. balancerModal.balancer = {
  70. tag: '',
  71. strategy: 'random',
  72. selector: []
  73. };
  74. }
  75. this.balancerTags = balancerTags.filter((tag) => tag != balancer.tag);
  76. this.outboundTags = app.templateSettings.outbounds.filter((o) => !ObjectUtil.isEmpty(o.tag)).map(obj => obj.tag);
  77. this.isEdit = isEdit;
  78. this.check();
  79. this.checkSelector();
  80. },
  81. close() {
  82. this.visible = false;
  83. this.loading(false);
  84. },
  85. loading(loading=true) {
  86. this.confirmLoading = loading;
  87. },
  88. check() {
  89. if (this.balancer.tag == '' || this.balancerTags.includes(this.balancer.tag)) {
  90. this.duplicateTag = true;
  91. this.isValid = false;
  92. } else {
  93. this.duplicateTag = false;
  94. this.isValid = true;
  95. }
  96. },
  97. checkSelector() {
  98. this.emptySelector = this.balancer.selector.length == 0;
  99. }
  100. };
  101. new Vue({
  102. delimiters: ['[[', ']]'],
  103. el: '#balancer-modal',
  104. data: {
  105. balancerModal: balancerModal
  106. },
  107. methods: {
  108. }
  109. });
  110. </script>
  111. {{end}}