1
0

xray_balancer_modal.html 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. </table>
  36. </a-form>
  37. </a-modal>
  38. <script>
  39. const balancerModal = {
  40. title: '',
  41. visible: false,
  42. confirmLoading: false,
  43. okText: '{{ i18n "sure" }}',
  44. isEdit: false,
  45. confirm: null,
  46. duplicateTag: false,
  47. emptySelector: false,
  48. balancer: {
  49. tag: '',
  50. strategy: 'random',
  51. selector: []
  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({ title = '', okText = '{{ i18n "sure" }}', balancerTags = [], balancer, confirm = (balancer) => { }, isEdit = false }) {
  64. this.title = title;
  65. this.okText = okText;
  66. this.confirm = confirm;
  67. this.visible = true;
  68. if (isEdit) {
  69. balancerModal.balancer = balancer;
  70. } else {
  71. balancerModal.balancer = {
  72. tag: '',
  73. strategy: 'random',
  74. selector: []
  75. };
  76. }
  77. this.balancerTags = balancerTags.filter((tag) => tag != balancer.tag);
  78. this.outboundTags = app.templateSettings.outbounds.filter((o) => !ObjectUtil.isEmpty(o.tag)).map(obj => obj.tag);
  79. this.isEdit = isEdit;
  80. this.check();
  81. this.checkSelector();
  82. },
  83. close() {
  84. this.visible = false;
  85. this.loading(false);
  86. },
  87. loading(loading=true) {
  88. this.confirmLoading = loading;
  89. },
  90. check() {
  91. if (this.balancer.tag == '' || this.balancerTags.includes(this.balancer.tag)) {
  92. this.duplicateTag = true;
  93. this.isValid = false;
  94. } else {
  95. this.duplicateTag = false;
  96. this.isValid = true;
  97. }
  98. },
  99. checkSelector() {
  100. this.emptySelector = this.balancer.selector.length == 0;
  101. }
  102. };
  103. new Vue({
  104. delimiters: ['[[', ']]'],
  105. el: '#balancer-modal',
  106. data: {
  107. balancerModal: balancerModal
  108. },
  109. methods: {
  110. }
  111. });
  112. </script>
  113. {{end}}