1
0

dns_modal.html 3.1 KB

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