ace.blade.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <style>
  2. .content-header {
  3. display: none;
  4. }
  5. .left-panel {
  6. background-color: #fff; /* 左侧面板的背景色 */
  7. height: 100vh; /* 高度占满 */
  8. }
  9. .main-panel {
  10. background-color: #e9ecef; /* 右侧面板的背景色 */
  11. height: 97vh; /* 高度占满 */
  12. }
  13. .right-panel-header {
  14. background-color: #fff;
  15. }
  16. .card-body {
  17. max-height: 100vh; /* 设置最大高度 */
  18. overflow-y: auto; /* 启用垂直滚动条 */
  19. border-radius: 4px; /* 圆角 */
  20. }
  21. #editor {
  22. background-color: #1e1e1e;
  23. }
  24. .submenu {
  25. list-style: none;
  26. padding-left: 3px;
  27. }
  28. .submenu .list-group-item {
  29. padding: 10px 0px 10px 20px;
  30. }
  31. </style>
  32. <div class="container-fluid">
  33. <div class="row">
  34. <div class="col-2 left-panel"> <!-- 左侧20% -->
  35. {!!$leftForm!!}
  36. <!-- 代码树 start-->
  37. <div class="card-body"></div>
  38. <!-- 代码树 end-->
  39. </div>
  40. <div class="col-8 main-panel"> <!-- 右侧80% -->
  41. <div class="right-panel-header">
  42. <button type="button" class="btn btn-primary btn-sm" id="save-btn">保存</button>
  43. </div>
  44. <div class="right-panel-content" id="editor" style="width: 100%; height: 100%;"></div>
  45. <input type="hidden" name="template_id" id="template_id" />
  46. </div>
  47. <div class="col-2 right-panel">
  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/monokai");
  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. //编辑代码
  70. $.ajax({
  71. url: '/prime-control/dist-template/ace',
  72. type: 'POST',
  73. data: {
  74. act:'content',
  75. id: id
  76. },
  77. success: function(response) {
  78. $("#template_id").val(id);
  79. editor.setValue(response);
  80. }
  81. });
  82. //显示右边变量列表
  83. $.ajax({
  84. url: '/prime-control/dist-template/ace',
  85. type: 'POST',
  86. data: {
  87. act:'aceRight',
  88. template_id: id,
  89. dist_id: $('input[name="dist_id"]').val(),
  90. appearance_id: $('select[name="appearance_id"]').val()
  91. },
  92. success: function(response) {
  93. $("#variables-list").html(response);
  94. }
  95. });
  96. });
  97. }
  98. var postData = function () {
  99. var appearance_id = $('select[name="appearance_id"]').val();
  100. var dist_id = $('input[name="dist_id"]').val();
  101. $.ajax({
  102. url: '/prime-control/dist-template/ace',
  103. type: 'POST',
  104. data: {
  105. act:'tree',
  106. appearance_id: appearance_id,
  107. dist_id: dist_id
  108. },
  109. success: function(response) {
  110. $('.card-body').html(response);
  111. actionclick();
  112. }
  113. });
  114. }
  115. $('select[name="appearance_id"]').change(function() {
  116. postData();
  117. });
  118. $('input[name="dist_id"]').change(function() {
  119. postData();
  120. });
  121. $("#save-btn").click(function() {
  122. var template_id = $("#template_id").val();
  123. var content = editor.getValue();
  124. if (template_id == '') {
  125. Dcat.error('操作失败:请先选择模板');
  126. return false;
  127. }
  128. $.ajax({
  129. url: '/prime-control/dist-template/ace',
  130. type: 'POST',
  131. data: {
  132. act:'save',
  133. template_id: template_id,
  134. content: content
  135. },
  136. success: function(response) {
  137. if (response == '1') {
  138. Dcat.success('保存成功');
  139. }else{
  140. Dcat.error('保存失败');
  141. }
  142. }
  143. });
  144. })
  145. });
  146. </script>