ace.blade.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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 loadingIndex = '';
  97. var fileId = '';
  98. var changeIframeUrl = function() {
  99. appearance_id = $('select[name="appearance_id"]').val();
  100. dist_id = $('input[name="dist_id"]').val();
  101. var iframeUrl = '/prime-control/dist-template-var?templateId=' + fileId + '&appearanceId=' + appearance_id+'&distId=' + dist_id;
  102. $('#iframeModal iframe').attr('src', iframeUrl);
  103. }
  104. //中间的Ace编辑器,内容展示
  105. var actionclick = function() {
  106. $('.file-action').click(function() {
  107. loadingIndex = layer.load(1, {
  108. shade: [0.5, '#000'] // 设置遮罩层
  109. });
  110. fileId = $(this).attr('file_id');
  111. //得到文件名
  112. fileName = $(this).html();
  113. if (fileName.endsWith('.css')) {
  114. editor.getSession().setMode("ace/mode/css");
  115. } else if (fileName.endsWith('.js')) {
  116. editor.getSession().setMode("ace/mode/javascript");
  117. }else {
  118. editor.getSession().setMode("ace/mode/html");
  119. }
  120. //改变iframe的url
  121. changeIframeUrl();
  122. //编辑代码
  123. $.ajax({
  124. url: '/prime-control/dist-template/ace',
  125. type: 'POST',
  126. data: {
  127. act:'content',
  128. id: fileId
  129. },
  130. success: function(response) {
  131. $("#template_id").val(fileId);
  132. editor.setValue(response);
  133. layer.close(loadingIndex);
  134. }
  135. });
  136. });
  137. }
  138. // 加载代码树
  139. var postData = function () {
  140. var appearance_id = $('select[name="appearance_id"]').val();
  141. var dist_id = $('input[name="dist_id"]').val();
  142. //改变iframe的url
  143. changeIframeUrl();
  144. $.ajax({
  145. url: '/prime-control/dist-template/ace',
  146. type: 'POST',
  147. data: {
  148. act:'tree',
  149. appearance_id: appearance_id,
  150. dist_id: dist_id
  151. },
  152. success: function(response) {
  153. layer.close(loadingIndex);
  154. $('.main-card-body').html(response);
  155. actionclick();
  156. }
  157. });
  158. }
  159. //左边外观选择与分销商选择联动
  160. $('select[name="appearance_id"]').change(function() {
  161. loadingIndex = layer.load(1, {
  162. shade: [0.5, '#000'] // 设置遮罩层
  163. });
  164. //请空编辑器内容
  165. editor.setValue('');
  166. //显示代码树
  167. postData();
  168. });
  169. $('input[name="dist_id"]').change(function() {
  170. loadingIndex = layer.load(1, {
  171. shade: [0.5, '#000'] // 设置遮罩层
  172. });
  173. //请空编辑器内容
  174. editor.setValue('');
  175. //显示代码树
  176. postData();
  177. });
  178. // 模版编辑保存
  179. $("#save-btn").click(function() {
  180. var template_id = $("#template_id").val();
  181. var content = editor.getValue();
  182. if (template_id == '') {
  183. Dcat.error('操作失败:请先选择模板');
  184. return false;
  185. }
  186. $.ajax({
  187. url: '/prime-control/dist-template/ace',
  188. type: 'POST',
  189. data: {
  190. act:'content_save',
  191. template_id: template_id,
  192. content: content
  193. },
  194. success: function(response) {
  195. if (response == '1') {
  196. Dcat.success('保存成功');
  197. }else{
  198. Dcat.error('保存失败');
  199. }
  200. }
  201. });
  202. })
  203. });
  204. </script>