monaco.blade.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <style>
  2. .content-header {
  3. display: none;
  4. }
  5. .left-panel {
  6. background-color: #fff; /* 左侧面板的背景色 */
  7. height: 89vh; /* 高度占满 */
  8. }
  9. .right-panel {
  10. background-color: #e9ecef; /* 右侧面板的背景色 */
  11. height: 86vh; /* 高度占满 */
  12. }
  13. .right-panel-header {
  14. background-color: #fff;
  15. }
  16. .card-body {
  17. max-height: 60vh; /* 设置最大高度 */
  18. overflow-y: auto; /* 启用垂直滚动条 */
  19. border-radius: 4px; /* 圆角 */
  20. }
  21. #editor {
  22. height: 600px; /* 设置编辑器的高度 */
  23. width: 800px; /* 设置编辑器的宽度 */
  24. background-color: #fff;
  25. }
  26. .submenu {
  27. list-style: none;
  28. padding-left: 3px;
  29. }
  30. .submenu .list-group-item {
  31. padding: 10px 0px 10px 20px;
  32. }
  33. </style>
  34. <div class="container-fluid">
  35. <div class="row">
  36. <div class="col-2 left-panel"> <!-- 左侧20% -->
  37. {!!$leftForm!!}
  38. <!-- 代码树 start-->
  39. <div class="card-body"></div>
  40. <!-- 代码树 end-->
  41. </div>
  42. <div class="col-10 right-panel"> <!-- 右侧80% -->
  43. <div class="right-panel-header">
  44. <button type="button" class="btn btn-primary btn-sm" id="save-btn">保存</button>
  45. </div>
  46. <div class="right-panel-content" id="editor" style="width: 100%; height: 100%;"></div>
  47. <input type="hidden" name="template_id" id="template_id" />
  48. </div>
  49. </div>
  50. </div>
  51. <script src="/vendor/ace/ace.js" type="text/javascript"></script>
  52. <script>
  53. // 创建 Ace 编辑器实例
  54. var editor = ace.edit("editor");
  55. // 设置语言
  56. editor.getSession().setMode("ace/mode/html");
  57. // 设置主题
  58. editor.setTheme("ace/theme/tomorrow");
  59. editor.setAutoScrollEditorIntoView(true);
  60. // 其他配置
  61. editor.setOptions({
  62. showPrintMargin: true // 不显示打印边距
  63. });
  64. $(document).ready(function() {
  65. // 创建 Ace 编辑器实例
  66. var actionclick = function() {
  67. $('.file-action').click(function() {
  68. var id = $(this).attr('file_id');
  69. $.ajax({
  70. url: '/prime-control/dist-template/monaco',
  71. type: 'POST',
  72. data: {
  73. act:'content',
  74. id: id
  75. },
  76. success: function(response) {
  77. $("#template_id").val(id);
  78. editor.setValue(response);
  79. }
  80. });
  81. });
  82. }
  83. var postData = function () {
  84. var appearance_id = $('select[name="appearance_id"]').val();
  85. var dist_id = $('input[name="dist_id"]').val();
  86. $.ajax({
  87. url: '/prime-control/dist-template/monaco',
  88. type: 'POST',
  89. data: {
  90. act:'tree',
  91. appearance_id: appearance_id,
  92. dist_id: dist_id
  93. },
  94. success: function(response) {
  95. $('.card-body').html(response);
  96. actionclick();
  97. }
  98. });
  99. }
  100. $('select[name="appearance_id"]').change(function() {
  101. postData();
  102. });
  103. $('input[name="dist_id"]').change(function() {
  104. postData();
  105. });
  106. $("#save-btn").click(function() {
  107. var template_id = $("#template_id").val();
  108. var content = editor.getValue();
  109. if (template_id == '') {
  110. Dcat.error('操作失败:请先选择模板');
  111. return false;
  112. }
  113. $.ajax({
  114. url: '/prime-control/dist-template/monaco',
  115. type: 'POST',
  116. data: {
  117. act:'save',
  118. template_id: template_id,
  119. content: content
  120. },
  121. success: function(response) {
  122. if (response == '1') {
  123. Dcat.success('保存成功');
  124. }else{
  125. Dcat.error('保存失败');
  126. }
  127. }
  128. });
  129. })
  130. });
  131. </script>