ace.blade.php 5.1 KB

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