dns_modal.html 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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>
  21. </a-modal>
  22. <script>
  23. const dnsModal = {
  24. title: '',
  25. visible: false,
  26. okText: '{{ i18n "confirm" }}',
  27. isEdit: false,
  28. confirm: null,
  29. dnsServer: {
  30. address: "localhost",
  31. domains: [],
  32. queryStrategy: 'UseIP',
  33. },
  34. ok() {
  35. domains = dnsModal.dnsServer.domains.filter(d => d.length > 0);
  36. dnsModal.dnsServer.domains = domains;
  37. newDnsServer = domains.length > 0 ? dnsModal.dnsServer : dnsModal.dnsServer.address;
  38. ObjectUtil.execute(dnsModal.confirm, newDnsServer);
  39. },
  40. show({
  41. title = '',
  42. okText = '{{ i18n "confirm" }}',
  43. dnsServer,
  44. confirm = (dnsServer) => {},
  45. isEdit = false
  46. }) {
  47. this.title = title;
  48. this.okText = okText;
  49. this.confirm = confirm;
  50. this.visible = true;
  51. if (isEdit) {
  52. if (typeof dnsServer == 'object') {
  53. this.dnsServer = dnsServer;
  54. } else {
  55. this.dnsServer = {
  56. address: dnsServer ?? "",
  57. domains: [],
  58. queryStrategy: 'UseIP',
  59. }
  60. }
  61. } else {
  62. this.dnsServer = {
  63. address: "localhost",
  64. domains: [],
  65. queryStrategy: 'UseIP',
  66. }
  67. }
  68. this.isEdit = isEdit;
  69. },
  70. close() {
  71. dnsModal.visible = false;
  72. },
  73. };
  74. new Vue({
  75. delimiters: ['[[', ']]'],
  76. el: '#dns-modal',
  77. data: {
  78. dnsModal: dnsModal,
  79. },
  80. computed: {
  81. isAdvanced: {
  82. get: function() {
  83. return dnsModal.dnsServer.domains.length > 0
  84. }
  85. }
  86. }
  87. });
  88. </script>
  89. {{end}}