ace.blade.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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" disabled>Save</button>
  55. <button type="button" class="btn btn-success btn-sm" data-toggle="modal" id="variable-btn" data-target="#iframeModal" disabled>Variable Management</button>
  56. <button type="button" class="btn btn-success btn-sm float-right" id="publish-btn" disabled>Publish</button>
  57. </div>
  58. <div class="main-panel-content" id="editor" style="width: 100%; height: 100%;"></div>
  59. <input type="hidden" name="template_id" id="template_id" />
  60. </div>
  61. </div>
  62. </div>
  63. <!-- 变量管理弹窗 -->
  64. <div class="modal fade" id="iframeModal" tabindex="-1" aria-labelledby="iframeModalLabel" aria-hidden="true">
  65. <div class="modal-dialog modal-dialog-centered modal-xl">
  66. <div class="modal-content">
  67. <div class="modal-header">
  68. <h5 class="modal-title" id="iframeModalLabel">Variable Management</h5>
  69. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  70. <span aria-hidden="true">&times;</span>
  71. </button>
  72. </div>
  73. <div class="modal-body">
  74. <iframe src="/prime-control/dist-template-var" width="100%" height="700px" frameborder="0" style="max-width: 100%;overflow: hidden"></iframe>
  75. </div>
  76. <div class="modal-footer">
  77. <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
  78. </div>
  79. </div>
  80. </div>
  81. </div>
  82. <script src="/vendor/ace/ace.js" type="text/javascript"></script>
  83. <script>
  84. //https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.12/ace.js
  85. // 创建 Ace 编辑器实例
  86. var editor = ace.edit("editor");
  87. // 设置语言
  88. editor.getSession().setMode("ace/mode/html");
  89. // 设置主题
  90. editor.setTheme("ace/theme/monokai");
  91. editor.setAutoScrollEditorIntoView(true);
  92. // 其他配置
  93. editor.setOptions({
  94. showPrintMargin: true // 不显示打印边距
  95. });
  96. $(document).ready(function() {
  97. var loadingIndex = '';
  98. var fileId = '';
  99. var changeButtonDisabled = function (status) {
  100. $('#save-btn').prop('disabled', status);
  101. $('#variable-btn').prop('disabled', status);
  102. $('#publish-btn').prop('disabled', status);
  103. }
  104. var changeIframeUrl = function() {
  105. appearance_id = $('select[name="appearance_id"]').val();
  106. dist_id = $('input[name="dist_id"]').val();
  107. var iframeUrl = '/prime-control/dist-template-var?templateCode=' + fileId + '&appearanceId=' + appearance_id+'&distId=' + dist_id;
  108. $('#iframeModal iframe').attr('src', iframeUrl);
  109. }
  110. //中间的Ace编辑器,内容展示
  111. var actionclick = function() {
  112. $('.file-action').click(function() {
  113. //去掉保存与变量管理按钮的disabled
  114. changeButtonDisabled(false);
  115. //加载编辑代码
  116. loadingIndex = layer.load(1, {
  117. shade: [0.5, '#000'] // 设置遮罩层
  118. });
  119. var appearance_id = $('select[name="appearance_id"]').val();
  120. var dist_id = $('input[name="dist_id"]').val();
  121. fileId = $(this).attr('file_id');
  122. //得到文件名
  123. fileName = $(this).html();
  124. if (fileName.endsWith('.css')) {
  125. editor.getSession().setMode("ace/mode/css");
  126. } else if (fileName.endsWith('.js')) {
  127. editor.getSession().setMode("ace/mode/javascript");
  128. }else {
  129. editor.getSession().setMode("ace/mode/html");
  130. }
  131. //改变iframe的url
  132. changeIframeUrl();
  133. //编辑代码
  134. $.ajax({
  135. url: '/prime-control/dist-template/ace',
  136. type: 'POST',
  137. data: {
  138. act:'content',
  139. appearance_id: appearance_id,
  140. dist_id: dist_id,
  141. id: fileId
  142. },
  143. success: function(response) {
  144. $("#template_id").val(fileId);
  145. editor.setValue(response);
  146. layer.close(loadingIndex);
  147. }
  148. });
  149. });
  150. }
  151. // 加载代码树
  152. var postData = function () {
  153. var appearance_id = $('select[name="appearance_id"]').val();
  154. var dist_id = $('input[name="dist_id"]').val();
  155. //改变iframe的url
  156. changeIframeUrl();
  157. $.ajax({
  158. url: '/prime-control/dist-template/ace',
  159. type: 'POST',
  160. data: {
  161. act:'tree',
  162. appearance_id: appearance_id,
  163. dist_id: dist_id
  164. },
  165. success: function(response) {
  166. layer.close(loadingIndex);
  167. $('.main-card-body').html(response);
  168. actionclick();
  169. }
  170. });
  171. }
  172. //左边外观选择与分销商选择联动
  173. $('select[name="appearance_id"]').change(function() {
  174. if ($(this).val() == '') {
  175. changeButtonDisabled(true);
  176. }
  177. loadingIndex = layer.load(1, {
  178. shade: [0.5, '#000'] // 设置遮罩层
  179. });
  180. //请空编辑器内容
  181. editor.setValue('');
  182. //显示代码树
  183. postData();
  184. });
  185. $('input[name="dist_id"]').change(function() {
  186. loadingIndex = layer.load(1, {
  187. shade: [0.5, '#000'] // 设置遮罩层
  188. });
  189. //请空编辑器内容
  190. editor.setValue('');
  191. //显示代码树
  192. postData();
  193. });
  194. // 模版编辑保存
  195. $("#save-btn").click(function() {
  196. var appearance_id = $('select[name="appearance_id"]').val();
  197. var dist_id = $('input[name="dist_id"]').val();
  198. var template_id = $("#template_id").val();
  199. var content = editor.getValue();
  200. if (template_id == '') {
  201. Dcat.error('操作失败:请先选择模板');
  202. return false;
  203. }
  204. if (appearance_id == '') {
  205. Dcat.error('操作失败:请先选择主题');
  206. return false;
  207. }
  208. loadingIndex = layer.load(1, {
  209. shade: [0.5, '#000'] // 设置遮罩层
  210. });
  211. $.ajax({
  212. url: '/prime-control/dist-template/ace',
  213. type: 'POST',
  214. data: {
  215. act:'content_save',
  216. template_code: template_id,
  217. appearance_id: appearance_id,
  218. dist_id: dist_id,
  219. content: content
  220. },
  221. success: function(response) {
  222. layer.close(loadingIndex);
  223. if (response == '1') {
  224. Dcat.success('保存成功');
  225. }else{
  226. Dcat.error('保存失败');
  227. }
  228. }
  229. });
  230. })
  231. });
  232. </script>