xray_balancer_modal.html 4.8 KB

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