ace.blade.php 12 KB

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