ace.blade.php 11 KB

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