xray_outbound_modal.html 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. {{define "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. ok() {
  24. ObjectUtil.execute(outModal.confirm, outModal.outbound.toJson());
  25. },
  26. show({ title='', okText='{{ i18n "sure" }}', outbound, confirm=(outbound)=>{}, isEdit=false }) {
  27. this.title = title;
  28. this.okText = okText;
  29. this.confirm = confirm;
  30. this.jsonMode = false;
  31. this.link = '';
  32. this.activeKey = '1';
  33. this.visible = true;
  34. this.outbound = isEdit ? Outbound.fromJson(outbound) : new Outbound();
  35. this.isEdit = isEdit;
  36. this.check()
  37. },
  38. close() {
  39. outModal.visible = false;
  40. outModal.loading(false);
  41. },
  42. loading(loading) {
  43. outModal.confirmLoading = loading;
  44. },
  45. check(){
  46. if(outModal.outbound.tag == ''){
  47. this.duplicateTag = true;
  48. this.isValid = false;
  49. } else {
  50. this.duplicateTag = false;
  51. this.isValid = true;
  52. }
  53. },
  54. toggleJson(jsonTab) {
  55. textAreaObj = document.getElementById('outboundJson');
  56. if(jsonTab){
  57. if(this.cm != null) {
  58. this.cm.toTextArea();
  59. this.cm=null;
  60. }
  61. textAreaObj.value = JSON.stringify(this.outbound.toJson(), null, 2);
  62. this.cm = CodeMirror.fromTextArea(textAreaObj, app.cmOptions);
  63. this.cm.on('change',editor => {
  64. value = editor.getValue();
  65. if(this.isJsonString(value)){
  66. this.outbound = Outbound.fromJson(JSON.parse(value));
  67. this.check();
  68. }
  69. });
  70. this.activeKey = '2';
  71. } else {
  72. if(this.cm != null) {
  73. this.cm.toTextArea();
  74. this.cm=null;
  75. }
  76. this.activeKey = '1';
  77. }
  78. },
  79. isJsonString(str) {
  80. try {
  81. JSON.parse(str);
  82. } catch (e) {
  83. return false;
  84. }
  85. return true;
  86. },
  87. };
  88. new Vue({
  89. delimiters: ['[[', ']]'],
  90. el: '#out-modal',
  91. data: {
  92. outModal: outModal,
  93. get outbound() {
  94. return outModal.outbound;
  95. },
  96. },
  97. methods: {
  98. streamNetworkChange() {
  99. if (this.outModal.outbound.protocol == Protocols.VLESS && !outModal.outbound.canEnableTlsFlow()) {
  100. delete this.outModal.outbound.settings.flow;
  101. }
  102. },
  103. canEnableTls() {
  104. return this.outModal.outbound.canEnableTls();
  105. },
  106. convertLink(){
  107. newOutbound = Outbound.fromLink(outModal.link);
  108. if(newOutbound){
  109. this.outModal.outbound = newOutbound;
  110. this.outModal.toggleJson(true);
  111. this.outModal.check();
  112. this.$message.success('Link imported successfully...');
  113. outModal.link = '';
  114. } else {
  115. this.$message.error('Wrong Link!');
  116. outModal.link = '';
  117. }
  118. },
  119. },
  120. });
  121. </script>
  122. {{end}}