ace.blade.php 6.1 KB

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