ace.blade.php 11 KB

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