ace.blade.php 10 KB

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