dns_modal.html 3.1 KB

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