xray_outbound_modal.html 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. {{define "modals/outModal"}}
  2. <a-modal id="out-modal" v-model="outModal.visible" :title="outModal.title" @ok="outModal.ok"
  3. :confirm-loading="outModal.confirmLoading" :closable="true" :mask-closable="false"
  4. :ok-button-props="{ props: { disabled: !outModal.isValid } }" :style="{ overflow: 'hidden' }"
  5. :ok-text="outModal.okText" cancel-text='{{ i18n "close" }}' :class="themeSwitcher.currentTheme">
  6. {{template "form/outbound"}}
  7. </a-modal>
  8. <script>
  9. const outModal = {
  10. title: '',
  11. visible: false,
  12. confirmLoading: false,
  13. okText: '{{ i18n "sure" }}',
  14. isEdit: false,
  15. confirm: null,
  16. outbound: new Outbound(),
  17. jsonMode: false,
  18. link: '',
  19. cm: null,
  20. duplicateTag: false,
  21. isValid: true,
  22. activeKey: '1',
  23. tags: [],
  24. ok() {
  25. ObjectUtil.execute(outModal.confirm, outModal.outbound.toJson());
  26. },
  27. show({
  28. title = '',
  29. okText = '{{ i18n "sure" }}',
  30. outbound,
  31. confirm = (outbound) => {},
  32. isEdit = false,
  33. tags = []
  34. }) {
  35. this.title = title;
  36. this.okText = okText;
  37. this.confirm = confirm;
  38. this.jsonMode = false;
  39. this.link = '';
  40. this.activeKey = '1';
  41. this.visible = true;
  42. this.outbound = isEdit ? Outbound.fromJson(outbound) : new Outbound();
  43. this.isEdit = isEdit;
  44. this.tags = tags;
  45. this.check()
  46. },
  47. close() {
  48. outModal.visible = false;
  49. outModal.loading(false);
  50. },
  51. loading(loading = true) {
  52. outModal.confirmLoading = loading;
  53. },
  54. check() {
  55. if (outModal.outbound.tag == '' || outModal.tags.includes(outModal.outbound.tag)) {
  56. this.duplicateTag = true;
  57. this.isValid = false;
  58. } else {
  59. this.duplicateTag = false;
  60. this.isValid = true;
  61. }
  62. },
  63. toggleJson(jsonTab) {
  64. textAreaObj = document.getElementById('outboundJson');
  65. if (jsonTab) {
  66. if (this.cm != null) {
  67. this.cm.toTextArea();
  68. this.cm = null;
  69. }
  70. textAreaObj.value = JSON.stringify(this.outbound.toJson(), null, 2);
  71. this.cm = CodeMirror.fromTextArea(textAreaObj, app.cmOptions);
  72. this.cm.on('change', editor => {
  73. value = editor.getValue();
  74. if (this.isJsonString(value)) {
  75. this.outbound = Outbound.fromJson(JSON.parse(value));
  76. this.check();
  77. }
  78. });
  79. this.activeKey = '2';
  80. } else {
  81. if (this.cm != null) {
  82. this.cm.toTextArea();
  83. this.cm = null;
  84. }
  85. this.activeKey = '1';
  86. }
  87. },
  88. isJsonString(str) {
  89. try {
  90. JSON.parse(str);
  91. } catch (e) {
  92. return false;
  93. }
  94. return true;
  95. },
  96. };
  97. new Vue({
  98. delimiters: ['[[', ']]'],
  99. el: '#out-modal',
  100. data: {
  101. outModal: outModal,
  102. get outbound() {
  103. return outModal.outbound;
  104. },
  105. },
  106. methods: {
  107. streamNetworkChange() {
  108. if (this.outModal.outbound.protocol == Protocols.VLESS && !outModal.outbound
  109. .canEnableTlsFlow()) {
  110. delete this.outModal.outbound.settings.flow;
  111. }
  112. },
  113. canEnableTls() {
  114. return this.outModal.outbound.canEnableTls();
  115. },
  116. convertLink() {
  117. newOutbound = Outbound.fromLink(outModal.link);
  118. if (newOutbound) {
  119. this.outModal.outbound = newOutbound;
  120. this.outModal.toggleJson(true);
  121. this.outModal.check();
  122. this.$message.success('Link imported successfully...');
  123. outModal.link = '';
  124. } else {
  125. this.$message.error('Wrong Link!');
  126. outModal.link = '';
  127. }
  128. },
  129. },
  130. });
  131. </script>
  132. {{end}}