ace.blade.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. .main-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. .modal-body {
  25. background-color: #e9ecef;
  26. }
  27. .submenu {
  28. list-style: none;
  29. padding-left: 3px;
  30. }
  31. .submenu .list-group-item {
  32. padding: 10px 0px 10px 20px;
  33. }
  34. </style>
  35. <div class="container-fluid">
  36. <div class="row">
  37. <div class="col-2 left-panel"> <!-- 左侧20% -->
  38. {!!$leftForm!!}
  39. <!-- 代码树 start-->
  40. <div class="card-body"></div>
  41. <!-- 代码树 end-->
  42. </div>
  43. <div class="col-10 main-panel"> <!-- 右侧80% -->
  44. <div class="main-panel-header">
  45. <button type="button" class="btn btn-primary btn-sm" id="save-btn">Save</button>
  46. <button type="button" class="btn btn-success btn-sm" data-toggle="modal" data-target="#iframeModal">Variable Management</button>
  47. </div>
  48. <div class="main-panel-content" id="editor" style="width: 100%; height: 100%;"></div>
  49. <input type="hidden" name="template_id" id="template_id" />
  50. </div>
  51. </div>
  52. </div>
  53. <!-- 变量管理弹窗 -->
  54. <div class="modal fade" id="iframeModal" tabindex="-1" aria-labelledby="iframeModalLabel" aria-hidden="true">
  55. <div class="modal-dialog modal-dialog-centered modal-xl">
  56. <div class="modal-content">
  57. <div class="modal-header">
  58. <h5 class="modal-title" id="iframeModalLabel">Variable Management</h5>
  59. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  60. <span aria-hidden="true">&times;</span>
  61. </button>
  62. </div>
  63. <div class="modal-body">
  64. <iframe src="/prime-control/dist-template-var" width="100%" height="700px" frameborder="0" style="max-width: 100%;overflow: hidden"></iframe>
  65. </div>
  66. <div class="modal-footer">
  67. <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
  68. </div>
  69. </div>
  70. </div>
  71. </div>
  72. <script src="/vendor/ace/ace.js" type="text/javascript"></script>
  73. <script>
  74. // 创建 Ace 编辑器实例
  75. var editor = ace.edit("editor");
  76. // 设置语言
  77. editor.getSession().setMode("ace/mode/html");
  78. // 设置主题
  79. editor.setTheme("ace/theme/monokai");
  80. editor.setAutoScrollEditorIntoView(true);
  81. // 其他配置
  82. editor.setOptions({
  83. showPrintMargin: true // 不显示打印边距
  84. });
  85. $(document).ready(function() {
  86. var fileId = '';
  87. var changeIframeUrl = function() {
  88. appearance_id = $('select[name="appearance_id"]').val();
  89. dist_id = $('input[name="dist_id"]').val();
  90. var iframeUrl = '/prime-control/dist-template-var?templateId=' + fileId + '&appearanceId=' + appearance_id+'&distId=' + dist_id;
  91. $('#iframeModal iframe').attr('src', iframeUrl);
  92. }
  93. //中间的Ace编辑器,内容展示
  94. var actionclick = function() {
  95. $('.file-action').click(function() {
  96. var loadingIndex = layer.load(1, {
  97. shade: [0.5, '#000'] // 设置遮罩层
  98. });
  99. fileId = $(this).attr('file_id');
  100. //改变iframe的url
  101. changeIframeUrl();
  102. //编辑代码
  103. $.ajax({
  104. url: '/prime-control/dist-template/ace',
  105. type: 'POST',
  106. data: {
  107. act:'content',
  108. id: fileId
  109. },
  110. success: function(response) {
  111. $("#template_id").val(fileId);
  112. editor.setValue(response);
  113. layer.close(loadingIndex);
  114. }
  115. });
  116. });
  117. }
  118. // 加载代码树
  119. var postData = function () {
  120. var appearance_id = $('select[name="appearance_id"]').val();
  121. var dist_id = $('input[name="dist_id"]').val();
  122. //改变iframe的url
  123. changeIframeUrl();
  124. $.ajax({
  125. url: '/prime-control/dist-template/ace',
  126. type: 'POST',
  127. data: {
  128. act:'tree',
  129. appearance_id: appearance_id,
  130. dist_id: dist_id
  131. },
  132. success: function(response) {
  133. $('.card-body').html(response);
  134. actionclick();
  135. }
  136. });
  137. }
  138. //左边外观选择与分销商选择联动
  139. $('select[name="appearance_id"]').change(function() {
  140. postData();
  141. });
  142. $('input[name="dist_id"]').change(function() {
  143. postData();
  144. });
  145. // 模版编辑保存
  146. $("#save-btn").click(function() {
  147. var template_id = $("#template_id").val();
  148. var content = editor.getValue();
  149. if (template_id == '') {
  150. Dcat.error('操作失败:请先选择模板');
  151. return false;
  152. }
  153. $.ajax({
  154. url: '/prime-control/dist-template/ace',
  155. type: 'POST',
  156. data: {
  157. act:'content_save',
  158. template_id: template_id,
  159. content: content
  160. },
  161. success: function(response) {
  162. if (response == '1') {
  163. Dcat.success('保存成功');
  164. }else{
  165. Dcat.error('保存失败');
  166. }
  167. }
  168. });
  169. })
  170. });
  171. </script>