1
0

dns_modal.html 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. {{define "dnsModal"}}
  2. <a-modal id="dns-modal" v-model="dnsModal.visible" :title="dnsModal.title" @ok="dnsModal.ok" :closable="true"
  3. :mask-closable="false" :ok-text="dnsModal.okText" cancel-text='{{ i18n "close" }}'
  4. :class="themeSwitcher.currentTheme">
  5. <a-form :colon="false" :label-col="{ md: {span:8} }" :wrapper-col="{ md: {span:14} }">
  6. <a-form-item label='{{ i18n "pages.xray.outbound.address" }}'>
  7. <a-input v-model.trim="dnsModal.dnsServer.address"></a-input>
  8. </a-form-item>
  9. <a-form-item label='{{ i18n "pages.xray.dns.domains" }}'>
  10. <a-button icon="plus" size="small" type="primary" @click="dnsModal.dnsServer.domains.push('')"></a-button>
  11. <template v-for="(domain, index) in dnsModal.dnsServer.domains">
  12. <a-input v-model.trim="dnsModal.dnsServer.domains[index]">
  13. <a-button icon="minus" size="small" slot="addonAfter"
  14. @click="dnsModal.dnsServer.domains.splice(index,1)"></a-button>
  15. </a-input>
  16. </template>
  17. </a-form-item>
  18. <a-form-item label='{{ i18n "pages.xray.dns.strategy" }}' v-if="isAdvanced">
  19. <a-select v-model="dnsModal.dnsServer.queryStrategy" style="width: 100%"
  20. :dropdown-class-name="themeSwitcher.currentTheme">
  21. <a-select-option :value="l" :label="l" v-for="l in ['UseIP', 'UseIPv4', 'UseIPv6']"> [[ l ]] </a-select-option>
  22. </a-select>
  23. </a-form-item>
  24. <a-form-item label='Skip Fallback' v-if="isAdvanced">
  25. <a-switch v-model="dnsModal.dnsServer.skipFallback"></a-switch>
  26. </a-form-item>
  27. <a-form-item label='{{ i18n "pages.xray.dns.expectIPs"}}'>
  28. <a-button icon="plus" size="small" type="primary" @click="dnsModal.dnsServer.expectIPs.push('')"></a-button>
  29. <template v-for="(domain, index) in dnsModal.dnsServer.expectIPs">
  30. <a-input v-model.trim="dnsModal.dnsServer.expectIPs[index]">
  31. <a-button icon="minus" size="small" slot="addonAfter"
  32. @click="dnsModal.dnsServer.expectIPs.splice(index,1)"></a-button>
  33. </a-input>
  34. </template>
  35. </a-form-item>
  36. </a-form>
  37. </a-modal>
  38. <script>
  39. const dnsModal = {
  40. title: '',
  41. visible: false,
  42. okText: '{{ i18n "confirm" }}',
  43. isEdit: false,
  44. confirm: null,
  45. dnsServer: {
  46. address: "localhost",
  47. domains: [],
  48. expectIPs: [],
  49. queryStrategy: 'UseIP',
  50. skipFallback: true,
  51. },
  52. ok() {
  53. domains = dnsModal.dnsServer.domains.filter(d => d.length > 0);
  54. expectIPs = dnsModal.dnsServer.expectIPs.filter(ip => ip.length > 0);
  55. dnsModal.dnsServer.domains = domains;
  56. dnsModal.dnsServer.expectIPs = expectIPs;
  57. newDnsServer = (domains.length > 0 || expectIPs.length > 0) ? dnsModal.dnsServer : dnsModal.dnsServer.address;
  58. ObjectUtil.execute(dnsModal.confirm, newDnsServer);
  59. },
  60. show({
  61. title = '',
  62. okText = '{{ i18n "confirm" }}',
  63. dnsServer,
  64. confirm = (dnsServer) => { },
  65. isEdit = false
  66. }) {
  67. this.title = title;
  68. this.okText = okText;
  69. this.confirm = confirm;
  70. this.visible = true;
  71. if (isEdit) {
  72. if (typeof dnsServer == 'object') {
  73. this.dnsServer = dnsServer;
  74. } else {
  75. this.dnsServer = {
  76. address: dnsServer ?? "",
  77. domains: [],
  78. expectIPs: [],
  79. queryStrategy: 'UseIP',
  80. skipFallback: true,
  81. }
  82. }
  83. } else {
  84. this.dnsServer = {
  85. address: "localhost",
  86. domains: [],
  87. expectIPs: [],
  88. queryStrategy: 'UseIP',
  89. skipFallback: true,
  90. }
  91. }
  92. this.isEdit = isEdit;
  93. },
  94. close() {
  95. dnsModal.visible = false;
  96. },
  97. };
  98. new Vue({
  99. delimiters: ['[[', ']]'],
  100. el: '#dns-modal',
  101. data: {
  102. dnsModal: dnsModal,
  103. },
  104. computed: {
  105. isAdvanced: {
  106. get: function () {
  107. return dnsModal.dnsServer.domains.length > 0;
  108. }
  109. }
  110. }
  111. });
  112. </script>
  113. {{end}}