xray_balancer_modal.html 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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-option value="leastLoad">Least Load</a-select-option>
  25. <a-select-option value="leastPing">Least Ping</a-select-option>
  26. </a-select>
  27. </a-form-item>
  28. <a-form-item label='{{ i18n "pages.xray.balancer.balancerSelectors" }}' has-feedback
  29. :validate-status="balancerModal.emptySelector? 'warning' : 'success'">
  30. <a-select v-model="balancerModal.balancer.selector" mode="tags" @change="balancerModal.checkSelector()"
  31. :dropdown-class-name="themeSwitcher.currentTheme">
  32. <a-select-option v-for="tag in balancerModal.outboundTags" :value="tag">[[ tag ]]</a-select-option>
  33. </a-select>
  34. </a-form-item>
  35. <a-form-item label="Fallback">
  36. <a-select v-model="balancerModal.balancer.fallbackTag" clearable
  37. :dropdown-class-name="themeSwitcher.currentTheme">
  38. <a-select-option v-for="tag in [ '', ...balancerModal.outboundTags]" :value="tag">[[ tag ]]</a-select-option>
  39. </a-select>
  40. </a-form-item>
  41. </table>
  42. </a-form>
  43. </a-modal>
  44. <script>
  45. const balancerModal = {
  46. title: '',
  47. visible: false,
  48. confirmLoading: false,
  49. okText: '{{ i18n "sure" }}',
  50. isEdit: false,
  51. confirm: null,
  52. duplicateTag: false,
  53. emptySelector: false,
  54. balancer: {
  55. tag: '',
  56. strategy: 'random',
  57. selector: [],
  58. fallbackTag: ''
  59. },
  60. outboundTags: [],
  61. balancerTags:[],
  62. ok() {
  63. if (balancerModal.balancer.selector.length == 0) {
  64. balancerModal.emptySelector = true;
  65. return;
  66. }
  67. balancerModal.emptySelector = false;
  68. ObjectUtil.execute(balancerModal.confirm, balancerModal.balancer);
  69. },
  70. show({ title = '', okText = '{{ i18n "sure" }}', balancerTags = [], balancer, confirm = (balancer) => { }, isEdit = false }) {
  71. this.title = title;
  72. this.okText = okText;
  73. this.confirm = confirm;
  74. this.visible = true;
  75. if (isEdit) {
  76. balancerModal.balancer = balancer;
  77. } else {
  78. balancerModal.balancer = {
  79. tag: '',
  80. strategy: 'random',
  81. selector: [],
  82. fallbackTag: ''
  83. };
  84. }
  85. this.balancerTags = balancerTags.filter((tag) => tag != balancer.tag);
  86. this.outboundTags = app.templateSettings.outbounds.filter((o) => !ObjectUtil.isEmpty(o.tag)).map(obj => obj.tag);
  87. this.isEdit = isEdit;
  88. this.check();
  89. this.checkSelector();
  90. },
  91. close() {
  92. this.visible = false;
  93. this.loading(false);
  94. },
  95. loading(loading=true) {
  96. this.confirmLoading = loading;
  97. },
  98. check() {
  99. if (this.balancer.tag == '' || this.balancerTags.includes(this.balancer.tag)) {
  100. this.duplicateTag = true;
  101. this.isValid = false;
  102. } else {
  103. this.duplicateTag = false;
  104. this.isValid = true;
  105. }
  106. },
  107. checkSelector() {
  108. this.emptySelector = this.balancer.selector.length == 0;
  109. }
  110. };
  111. new Vue({
  112. delimiters: ['[[', ']]'],
  113. el: '#balancer-modal',
  114. data: {
  115. balancerModal: balancerModal
  116. },
  117. methods: {
  118. }
  119. });
  120. </script>
  121. {{end}}