ace.blade.php 6.9 KB

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