ace.blade.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  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. .list-group-flush .float-right {
  38. padding-right: 5px;
  39. }
  40. .list-group-flush .icon-x {
  41. color:#cdcdcd;font-size: 10px
  42. }
  43. .submenu .list-group-item {
  44. padding: 10px 0px 10px 20px;
  45. }
  46. .submenu .list-group-item:hover {
  47. background-color: rgba(221, 251, 239, 0.56);
  48. }
  49. .submenu .list-group-item.active {
  50. background-color: rgba(221, 251, 239, 0.56);
  51. border-color:#fff;
  52. color: #414750;
  53. }
  54. .custom-blue-bold {
  55. color: #1e1e1e; /* Bootstrap 的 primary 颜色 */
  56. font-weight: bold;
  57. }
  58. .modal-xxl {
  59. max-width: 75%; /* 或其他所需的宽度 */
  60. }
  61. .field_dist_id {
  62. max-height: 30px;
  63. white-space: nowrap; /* 防止文字换行 */
  64. overflow: hidden; /* 隐藏超出部分 */
  65. text-overflow: ellipsis; /* 显示省略号 */
  66. }
  67. .field_dist_id .form-control {
  68. height: 17px; /* 设置高度为 17px */
  69. overflow: hidden; /* 隐藏超出部分 */
  70. display: flex; /* 使用 flexbox 布局 */
  71. align-items: center; /* 垂直居中对齐 */
  72. }
  73. .field_dist_id .option {
  74. white-space: nowrap; /* 防止文字换行 */
  75. overflow: hidden; /* 隐藏超出部分 */
  76. text-overflow: ellipsis; /* 显示省略号 */
  77. display: flex; /* 使用 flexbox 布局 */
  78. align-items: center; /* 垂直居中对齐 */
  79. }
  80. .field_dist_id .pull-right {
  81. margin-left: auto; /* 将删除按钮推到右侧 */
  82. }
  83. #addFileModal .modal-body {
  84. display: flex;
  85. align-items: center;
  86. height: 100px; /* 可根据需要调整高度 */
  87. background-color: #ffffff;
  88. }
  89. #addFileModal .modal-body div {
  90. display: flex;
  91. align-items: center;
  92. }
  93. #addFileModal .modal-body .text-right {
  94. padding-left: 5px;
  95. padding-right: 5px;
  96. }
  97. #addFileModal .modal-sm {
  98. max-width:320px;
  99. }
  100. #addFileModal .modal-dialog {
  101. position: absolute;
  102. top: 45%;
  103. left: 50%;
  104. transform: translate(-40%, -50%);
  105. }
  106. #addFileButton {
  107. margin-right: 5px;
  108. }
  109. .btn-warning.disabled, .btn-warning:disabled {
  110. color: #ffffff;
  111. }
  112. </style>
  113. </style>
  114. <div class="container-fluid" style="padding: 0px;">
  115. <div class="row">
  116. <div class="col-2 left-panel"> <!-- 左侧20% -->
  117. {!!$leftForm!!}
  118. <!-- 代码树 start-->
  119. <div class="main-card-body"></div>
  120. <!-- 代码树 end-->
  121. </div>
  122. <div class="col-10 main-panel" style="padding-right: 0px;"> <!-- 右侧80% -->
  123. <div class="main-panel-header">
  124. <button type="button" class="btn btn-info btn-sm" id="save-btn" disabled>Save</button>
  125. <button type="button" class="btn btn-warning btn-sm" data-toggle="modal" id="variable-btn" data-target="#iframeModal" disabled>Variable</button>
  126. <button type="button" class="btn btn-success btn-sm" id="publish-btn" disabled>Publish</button>
  127. </div>
  128. <div class="main-panel-content" id="editor" style="width: 100%; height: 100%;"></div>
  129. <input type="hidden" name="template_id" id="template_id" />
  130. </div>
  131. </div>
  132. </div>
  133. <!-- 变量管理弹窗 -->
  134. <div class="modal fade" id="iframeModal" tabindex="-1" aria-labelledby="iframeModalLabel" aria-hidden="true">
  135. <div class="modal-dialog modal-dialog-centered modal-xxl">
  136. <div class="modal-content">
  137. <div class="modal-header">
  138. <h5 class="modal-title" id="iframeModalLabel">Variable Management</h5>
  139. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  140. <span aria-hidden="true">&times;</span>
  141. </button>
  142. </div>
  143. <div class="modal-body">
  144. <iframe src="/prime-control/dist-template-var" width="100%" height="750px" frameborder="0" style="max-width: 100%;overflow: hidden"></iframe>
  145. </div>
  146. <div class="modal-footer">
  147. <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
  148. </div>
  149. </div>
  150. </div>
  151. </div>
  152. <!-- Modal -->
  153. <!-- Modal -->
  154. <div class="modal fade" id="addFileModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  155. <div class="modal-dialog modal-sm" role="document">
  156. <div class="modal-content">
  157. <div class="modal-header">
  158. <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
  159. </div>
  160. <div class="modal-body">
  161. <div class="row">
  162. <div class="col-xs-2 text-right">
  163. File Name:
  164. </div>
  165. <div class="col-xs-8">
  166. <input type="hidden" class="form-control" id="file_path_name" name="file_path_name">
  167. <input type="text" class="form-control" id="file_name_input" name="file_name_input">
  168. </div>
  169. <div class="col-xs-2">
  170. <button type="button" class="btn btn-success" id="addFileButton">OK</button>
  171. </div>
  172. </div>
  173. </div>
  174. </div>
  175. </div>
  176. </div>
  177. <script src="/vendor/ace/ace.js" type="text/javascript"></script>
  178. <script>
  179. //https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.12/ace.js
  180. // 创建 Ace 编辑器实例
  181. var editor = ace.edit("editor");
  182. // 设置语言
  183. editor.getSession().setMode("ace/mode/html");
  184. // 设置主题
  185. editor.setTheme("ace/theme/monokai");
  186. editor.setAutoScrollEditorIntoView(true);
  187. // 其他配置
  188. editor.setOptions({
  189. showPrintMargin: true // 不显示打印边距
  190. });
  191. $(document).ready(function() {
  192. var loadingIndex = '';
  193. var fileId = '';
  194. var changeButtonDisabled = function (status) {
  195. $('#save-btn').prop('disabled', status);
  196. $('#variable-btn').prop('disabled', status);
  197. $('#publish-btn').prop('disabled', status);
  198. }
  199. var changeIframeUrl = function() {
  200. appearance_id = $('select[name="appearance_id"]').val();
  201. dist_id = $('input[name="dist_id"]').val();
  202. var iframeUrl = '/prime-control/dist-template-var?templateCode=' + fileId + '&appearanceId=' + appearance_id+'&distId=' + dist_id;
  203. $('#iframeModal iframe').attr('src', iframeUrl);
  204. }
  205. //点击代码树后中间的Ace编辑器,内容展示
  206. var actionclick = function() {
  207. $('.file-action').click(function() {
  208. //去掉上一个文件的加粗
  209. $('.active').removeClass('active');
  210. //加粗
  211. var $li = $(this).closest('li');
  212. $li.addClass('active');
  213. //去掉保存与变量管理按钮的disabled
  214. changeButtonDisabled(false);
  215. //加载编辑代码
  216. loadingIndex = layer.load(1, {
  217. shade: [0.5, '#000'] // 设置遮罩层
  218. });
  219. var appearance_id = $('select[name="appearance_id"]').val();
  220. var dist_id = $('input[name="dist_id"]').val();
  221. fileId = $(this).attr('file_id');
  222. //得到文件名
  223. fileName = $(this).html();
  224. if (fileName.endsWith('.css')) {
  225. editor.getSession().setMode("ace/mode/css");
  226. } else if (fileName.endsWith('.js')) {
  227. editor.getSession().setMode("ace/mode/javascript");
  228. }else {
  229. editor.getSession().setMode("ace/mode/html");
  230. }
  231. //改变iframe的url
  232. changeIframeUrl();
  233. //编辑代码
  234. $.ajax({
  235. url: '/prime-control/dist-template/ace',
  236. type: 'POST',
  237. data: {
  238. act:'content',
  239. appearance_id: appearance_id,
  240. dist_id: dist_id,
  241. id: fileId
  242. },
  243. success: function(response) {
  244. $("#template_id").val(fileId);
  245. editor.setValue(response);
  246. layer.close(loadingIndex);
  247. }
  248. });
  249. });
  250. }
  251. // 加载代码树
  252. var postData = function () {
  253. var appearance_id = $('select[name="appearance_id"]').val();
  254. var dist_id = $('input[name="dist_id"]').val();
  255. //改变iframe的url
  256. changeIframeUrl();
  257. $.ajax({
  258. url: '/prime-control/dist-template/ace',
  259. type: 'POST',
  260. data: {
  261. act:'tree',
  262. appearance_id: appearance_id,
  263. dist_id: dist_id
  264. },
  265. success: function(response) {
  266. layer.close(loadingIndex);
  267. $('.main-card-body').html(response);
  268. actionclick();
  269. delFileButtonClick();
  270. }
  271. });
  272. }
  273. //左边外观选择与分销商选择联动
  274. $('select[name="appearance_id"]').change(function() {
  275. if ($(this).val() == '') {
  276. changeButtonDisabled(true);
  277. }
  278. loadingIndex = layer.load(1, {
  279. shade: [0.5, '#000'] // 设置遮罩层
  280. });
  281. //请空编辑器内容
  282. editor.setValue('');
  283. //显示代码树
  284. postData();
  285. });
  286. $('input[name="dist_id"]').change(function() {
  287. loadingIndex = layer.load(1, {
  288. shade: [0.5, '#000'] // 设置遮罩层
  289. });
  290. //请空编辑器内容
  291. editor.setValue('');
  292. dist_id = $(this).val();
  293. //在分销商名字前加上分销商id
  294. setTimeout(function() {
  295. $("div[name='dist_id'] .option").text(dist_id+" - " + $("div[name='dist_id'] .option").text());
  296. }, 100); // 延迟2000毫秒(即2秒)
  297. //改变appearance_id
  298. $.ajax({
  299. url: '/prime-control/dist-template/ace',
  300. type: 'POST',
  301. data: {
  302. act:'get_appearance_id',
  303. dist_id: dist_id,
  304. },
  305. success: function(response) {
  306. // 更改选中的值
  307. var $select = $('select[name="appearance_id"]');
  308. $select.select2('val', response);
  309. //显示代码树
  310. // postData();
  311. }
  312. });
  313. });
  314. // 模版编辑保存
  315. $("#save-btn").click(function() {
  316. var appearance_id = $('select[name="appearance_id"]').val();
  317. var dist_id = $('input[name="dist_id"]').val();
  318. var template_id = $("#template_id").val();
  319. var content = editor.getValue();
  320. if (template_id == '') {
  321. Dcat.error('操作失败:请先选择模板');
  322. return false;
  323. }
  324. if (appearance_id == '') {
  325. Dcat.error('操作失败:请先选择主题');
  326. return false;
  327. }
  328. loadingIndex = layer.load(1, {
  329. shade: [0.5, '#000'] // 设置遮罩层
  330. });
  331. $.ajax({
  332. url: '/prime-control/dist-template/ace',
  333. type: 'POST',
  334. data: {
  335. act:'content_save',
  336. template_code: template_id,
  337. appearance_id: appearance_id,
  338. dist_id: dist_id,
  339. content: content
  340. },
  341. success: function(response) {
  342. layer.close(loadingIndex);
  343. if (response == '1') {
  344. Dcat.success('保存成功');
  345. }else{
  346. Dcat.error('保存失败');
  347. }
  348. }
  349. });
  350. })
  351. // 模版发布
  352. $("#publish-btn").click(function() {
  353. var appearance_id = $('select[name="appearance_id"]').val();
  354. var dist_id = $('input[name="dist_id"]').val();
  355. if (appearance_id == '') {
  356. Dcat.error('操作失败:请先选择主题');
  357. return false;
  358. }
  359. loadingIndex = layer.load(1, {
  360. shade: [0.5, '#000'] // 设置遮罩层
  361. });
  362. $.ajax({
  363. url: '/prime-control/dist-template/ace',
  364. type: 'POST',
  365. data: {
  366. act:'publish',
  367. appearance_id: appearance_id,
  368. dist_id: dist_id
  369. },
  370. success: function(response) {
  371. layer.close(loadingIndex);
  372. Dcat.success('保存成功');
  373. }
  374. });
  375. })
  376. //文件新增
  377. $('#addFileModal').on('show.bs.modal', function (event) {
  378. // 获取触发模态框的元素
  379. var button = $(event.relatedTarget);
  380. // 获取 file_path_name 的值
  381. var filePathName = button.attr('file_path_name');
  382. $('#file_path_name').val(filePathName);
  383. });
  384. var ajaxAddDelFile = function (appearance_id,dist_id,fileId,filePathName,fileInputName,type) {
  385. $.ajax({
  386. url: '/prime-control/dist-template/ace',
  387. type: 'POST',
  388. data: {
  389. act:'add_del_tree',
  390. type: type,
  391. appearance_id: appearance_id,
  392. dist_id: dist_id,
  393. file_path_name: filePathName,
  394. file_name_input: fileInputName,
  395. file_id: fileId
  396. },
  397. success: function(response) {
  398. layer.close(loadingIndex);
  399. $("#file_name_input").val('')
  400. if (response.status == '1') {
  401. Dcat.success('保存成功');
  402. //刷新代码树
  403. postData();
  404. }else{
  405. Dcat.error(response.msg);
  406. }
  407. }
  408. });
  409. }
  410. $("#addFileButton").click(function () {
  411. var filePathName = $('#file_path_name').val();
  412. var fileInputName = $('#file_name_input').val();
  413. var appearanceId = $('select[name="appearance_id"]').val();
  414. var distId = $('input[name="dist_id"]').val();
  415. if (fileInputName == '') {
  416. Dcat.error('文件名不能为空');
  417. return false;
  418. }
  419. loadingIndex = layer.load(1, {
  420. shade: [0.5, '#000'] // 设置遮罩层
  421. });
  422. $('#addFileModal').modal('hide');
  423. ajaxAddDelFile(appearanceId,distId,0,filePathName,fileInputName,'add');
  424. });
  425. function delFileButtonClick() {
  426. $(".delFileButton").click(function () {
  427. var filePathName = "";
  428. var fileInputName = "";
  429. var appearanceId = $('select[name="appearance_id"]').val();
  430. var distId = $('input[name="dist_id"]').val();
  431. var fileId = $(this).attr('file_id');
  432. var fileName = $(this).attr('file_name');
  433. msg = '确定要删除'+fileName+'吗?';
  434. Dcat.confirm('确认删除',msg , function () {
  435. loadingIndex = layer.load(1, {
  436. shade: [0.5, '#000'] // 设置遮罩层
  437. });
  438. ajaxAddDelFile(appearanceId,distId,fileId,filePathName,fileInputName,'del');
  439. });
  440. });
  441. }
  442. });
  443. </script>