ace.blade.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  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. .modal-body {
  113. background-color: #ffffff;
  114. }
  115. .selected-row {
  116. background-color: rgba(221, 251, 239, 0.56);
  117. }
  118. </style>
  119. </style>
  120. <div class="container-fluid" style="padding: 0px;">
  121. <div class="row">
  122. <div class="col-2 left-panel"> <!-- 左侧20% -->
  123. {!!$leftForm!!}
  124. <!-- 代码树 start-->
  125. <div class="main-card-body"></div>
  126. <!-- 代码树 end-->
  127. </div>
  128. <div class="col-10 main-panel" style="padding-right: 0px;"> <!-- 右侧80% -->
  129. <div class="main-panel-header">
  130. <button type="button" class="btn btn-info btn-sm" id="save-btn" disabled>Save</button>
  131. <button type="button" class="btn btn-warning btn-sm" data-toggle="modal" id="variable-btn" data-target="#iframeModal" disabled>Variable</button>
  132. <button type="button" class="btn btn-success btn-sm" id="publish-btn" disabled>Publish</button>
  133. <button type="button" class="btn btn-info btn-sm float-right" id="history-btn" disabled>History</button>
  134. </div>
  135. <div class="main-panel-content" id="editor" style="width: 100%; height: 100%;"></div>
  136. <input type="hidden" name="template_id" id="template_id" />
  137. </div>
  138. </div>
  139. </div>
  140. <!-- 变量管理弹窗 -->
  141. <div class="modal fade" id="iframeModal" tabindex="-1" aria-labelledby="iframeModalLabel" aria-hidden="true">
  142. <div class="modal-dialog modal-dialog-centered modal-xxl">
  143. <div class="modal-content">
  144. <div class="modal-header">
  145. <h5 class="modal-title" id="iframeModalLabel">Variable Management</h5>
  146. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  147. <span aria-hidden="true">&times;</span>
  148. </button>
  149. </div>
  150. <div class="modal-body">
  151. <iframe src="/prime-control/dist-template-var" width="100%" height="750px" frameborder="0" style="max-width: 100%;overflow: hidden"></iframe>
  152. </div>
  153. <div class="modal-footer">
  154. <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
  155. </div>
  156. </div>
  157. </div>
  158. </div>
  159. <!-- Modal -->
  160. <!-- Modal -->
  161. <div class="modal fade" id="addFileModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  162. <div class="modal-dialog modal-sm" role="document">
  163. <div class="modal-content">
  164. <div class="modal-header">
  165. <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
  166. </div>
  167. <div class="modal-body">
  168. <div class="row">
  169. <div class="col-xs-2 text-right">
  170. File Name:
  171. </div>
  172. <div class="col-xs-8">
  173. <input type="hidden" class="form-control" id="file_path_name" name="file_path_name">
  174. <input type="text" class="form-control" id="file_name_input" name="file_name_input">
  175. </div>
  176. <div class="col-xs-2">
  177. <button type="button" class="btn btn-success" id="addFileButton">OK</button>
  178. </div>
  179. </div>
  180. </div>
  181. </div>
  182. </div>
  183. </div>
  184. <!-- Bootstrap Modal -->
  185. <div class="modal fade" id="templateLogModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  186. <div class="modal-dialog modal-xl" role="document" >
  187. <div class="modal-content">
  188. <div class="modal-header">
  189. <h5 class="modal-title" id="exampleModalLabel">Template Logs</h5>
  190. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  191. <span aria-hidden="true">&times;</span>
  192. </button>
  193. </div>
  194. <div class="modal-body" style="height: 600px;">
  195. <div class="row" style="height: 100%;">
  196. <!-- 左侧显示 Previous Content -->
  197. <div class="col-md-8">
  198. <h5>Content</h5>
  199. <textarea id="contentDetails" style="height: 550px; overflow-y: auto; border: 1px solid #ededed; padding: 10px;width: 100%;"></textarea>
  200. </div>
  201. <!-- 右侧显示 Version 和 Created At 列表 -->
  202. <div class="col-md-4">
  203. <h5>Version</h5>
  204. <table class="table table-condensed table-hover">
  205. <tbody id="templateLogTableBody">
  206. <!-- 动态生成的列表 -->
  207. </tbody>
  208. </table>
  209. </div>
  210. </div>
  211. </div>
  212. <div class="modal-footer">
  213. <input type="hidden" id="templateLogId" name="templateLogId"/>
  214. <input type="hidden" id="templateVersion" name="templateVersion"/>
  215. <button type="button" class="btn btn-success" id="restoreTemplateLog">Restore Version</button>
  216. <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
  217. </div>
  218. </div>
  219. </div>
  220. </div>
  221. <script src="/vendor/ace/ace.js" type="text/javascript"></script>
  222. <script>
  223. //https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.12/ace.js
  224. // 创建 Ace 编辑器实例
  225. var editor = ace.edit("editor");
  226. // 设置语言
  227. editor.getSession().setMode("ace/mode/html");
  228. // 设置主题
  229. editor.setTheme("ace/theme/monokai");
  230. editor.setAutoScrollEditorIntoView(true);
  231. // 其他配置
  232. editor.setOptions({
  233. showPrintMargin: true // 不显示打印边距
  234. });
  235. $(document).ready(function() {
  236. var loadingIndex = '';
  237. var fileId = '';
  238. var changeButtonDisabled = function (status) {
  239. $('#save-btn').prop('disabled', status);
  240. $('#variable-btn').prop('disabled', status);
  241. $('#publish-btn').prop('disabled', status);
  242. $('#history-btn').prop('disabled', status);
  243. }
  244. var changeIframeUrl = function() {
  245. appearance_id = $('select[name="appearance_id"]').val();
  246. dist_id = $('input[name="dist_id"]').val();
  247. var iframeUrl = '/prime-control/dist-template-var?templateCode=' + fileId + '&appearanceId=' + appearance_id+'&distId=' + dist_id;
  248. $('#iframeModal iframe').attr('src', iframeUrl);
  249. }
  250. //点击代码树后中间的Ace编辑器,内容展示
  251. var actionclick = function() {
  252. $('.file-action').click(function() {
  253. //去掉上一个文件的加粗
  254. $('.active').removeClass('active');
  255. //加粗
  256. var $li = $(this).closest('li');
  257. $li.addClass('active');
  258. //去掉保存与变量管理按钮的disabled
  259. changeButtonDisabled(false);
  260. //加载编辑代码
  261. loadingIndex = layer.load(1, {
  262. shade: [0.5, '#000'] // 设置遮罩层
  263. });
  264. var appearance_id = $('select[name="appearance_id"]').val();
  265. var dist_id = $('input[name="dist_id"]').val();
  266. fileId = $(this).attr('file_id');
  267. //得到文件名
  268. fileName = $(this).html();
  269. if (fileName.endsWith('.css')) {
  270. editor.getSession().setMode("ace/mode/css");
  271. } else if (fileName.endsWith('.js')) {
  272. editor.getSession().setMode("ace/mode/javascript");
  273. }else {
  274. editor.getSession().setMode("ace/mode/html");
  275. }
  276. //改变iframe的url
  277. changeIframeUrl();
  278. //编辑代码
  279. $.ajax({
  280. url: '/prime-control/dist-template/ace',
  281. type: 'POST',
  282. data: {
  283. act:'content',
  284. appearance_id: appearance_id,
  285. dist_id: dist_id,
  286. id: fileId
  287. },
  288. success: function(response) {
  289. $("#template_id").val(fileId);
  290. editor.setValue(response);
  291. layer.close(loadingIndex);
  292. }
  293. });
  294. });
  295. }
  296. // 加载代码树
  297. var postData = function () {
  298. var appearance_id = $('select[name="appearance_id"]').val();
  299. var dist_id = $('input[name="dist_id"]').val();
  300. //改变iframe的url
  301. changeIframeUrl();
  302. $.ajax({
  303. url: '/prime-control/dist-template/ace',
  304. type: 'POST',
  305. data: {
  306. act:'tree',
  307. appearance_id: appearance_id,
  308. dist_id: dist_id
  309. },
  310. success: function(response) {
  311. layer.close(loadingIndex);
  312. $('.main-card-body').html(response);
  313. actionclick();
  314. delFileButtonClick();
  315. }
  316. });
  317. }
  318. //左边外观选择与分销商选择联动
  319. $('select[name="appearance_id"]').change(function() {
  320. //console.log('-------2-----')
  321. if ($(this).val() == '') {
  322. changeButtonDisabled(true);
  323. }
  324. loadingIndex = layer.load(1, {
  325. shade: [0.5, '#000'] // 设置遮罩层
  326. });
  327. //请空编辑器内容
  328. editor.setValue('');
  329. //请空代码树
  330. $('.main-card-body').html('');
  331. //显示代码树
  332. postData();
  333. });
  334. //分销商选择
  335. $('input[name="dist_id"]').change(function() {
  336. //console.log('-------0-----')
  337. loadingIndex = layer.load(1, {
  338. shade: [0.5, '#000'] // 设置遮罩层
  339. });
  340. //请空编辑器内容
  341. editor.setValue('');
  342. //请空代码树
  343. $('.main-card-body').html('');
  344. dist_id = $(this).val();
  345. //在分销商名字前加上分销商id
  346. setTimeout(function() {
  347. $("div[name='dist_id'] .option").prepend(dist_id+" - ");
  348. }, 100); // 延迟2000毫秒(即2秒)
  349. //改变appearance_id
  350. $.ajax({
  351. url: '/prime-control/dist-template/ace',
  352. type: 'POST',
  353. data: {
  354. act:'get_appearance_id',
  355. dist_id: dist_id,
  356. },
  357. success: function(response) {
  358. //console.log('-------1-----')
  359. // 更改选中的值
  360. var $select = $('select[name="appearance_id"]');
  361. $select.select2('val', response);
  362. //显示代码树
  363. // postData();
  364. }
  365. });
  366. });
  367. // 模版编辑保存
  368. $("#save-btn").click(function() {
  369. var appearance_id = $('select[name="appearance_id"]').val();
  370. var dist_id = $('input[name="dist_id"]').val();
  371. var template_id = $("#template_id").val();
  372. var content = editor.getValue();
  373. if (template_id == '') {
  374. Dcat.error('操作失败:请先选择模板');
  375. return false;
  376. }
  377. if (appearance_id == '') {
  378. Dcat.error('操作失败:请先选择主题');
  379. return false;
  380. }
  381. loadingIndex = layer.load(1, {
  382. shade: [0.5, '#000'] // 设置遮罩层
  383. });
  384. $.ajax({
  385. url: '/prime-control/dist-template/ace',
  386. type: 'POST',
  387. data: {
  388. act:'content_save',
  389. template_code: template_id,
  390. appearance_id: appearance_id,
  391. dist_id: dist_id,
  392. content: content
  393. },
  394. success: function(response) {
  395. layer.close(loadingIndex);
  396. if (response == '1') {
  397. Dcat.success('保存成功');
  398. }else{
  399. Dcat.error('保存失败');
  400. }
  401. }
  402. });
  403. })
  404. // 模版发布
  405. $("#publish-btn").click(function() {
  406. var appearance_id = $('select[name="appearance_id"]').val();
  407. var dist_id = $('input[name="dist_id"]').val();
  408. if (appearance_id == '') {
  409. Dcat.error('操作失败:请先选择主题');
  410. return false;
  411. }
  412. loadingIndex = layer.load(1, {
  413. shade: [0.5, '#000'] // 设置遮罩层
  414. });
  415. $.ajax({
  416. url: '/prime-control/dist-template/ace',
  417. type: 'POST',
  418. data: {
  419. act:'publish',
  420. appearance_id: appearance_id,
  421. dist_id: dist_id
  422. },
  423. success: function(response) {
  424. layer.close(loadingIndex);
  425. Dcat.success('保存成功');
  426. }
  427. });
  428. })
  429. //文件新增
  430. $('#addFileModal').on('show.bs.modal', function (event) {
  431. // 获取触发模态框的元素
  432. var button = $(event.relatedTarget);
  433. // 获取 file_path_name 的值
  434. var filePathName = button.attr('file_path_name');
  435. $('#file_path_name').val(filePathName);
  436. });
  437. var ajaxAddDelFile = function (appearance_id,dist_id,fileId,filePathName,fileInputName,type) {
  438. $.ajax({
  439. url: '/prime-control/dist-template/ace',
  440. type: 'POST',
  441. data: {
  442. act:'add_del_tree',
  443. type: type,
  444. appearance_id: appearance_id,
  445. dist_id: dist_id,
  446. file_path_name: filePathName,
  447. file_name_input: fileInputName,
  448. file_id: fileId
  449. },
  450. success: function(response) {
  451. layer.close(loadingIndex);
  452. $("#file_name_input").val('')
  453. if (response.status == '1') {
  454. Dcat.success('保存成功');
  455. //刷新代码树
  456. postData();
  457. }else{
  458. Dcat.error(response.msg);
  459. }
  460. }
  461. });
  462. }
  463. //代码树新增
  464. $("#addFileButton").click(function () {
  465. var filePathName = $('#file_path_name').val();
  466. var fileInputName = $('#file_name_input').val();
  467. var appearanceId = $('select[name="appearance_id"]').val();
  468. var distId = $('input[name="dist_id"]').val();
  469. if (fileInputName == '') {
  470. Dcat.error('文件名不能为空');
  471. return false;
  472. }
  473. loadingIndex = layer.load(1, {
  474. shade: [0.5, '#000'] // 设置遮罩层
  475. });
  476. $('#addFileModal').modal('hide');
  477. ajaxAddDelFile(appearanceId,distId,0,filePathName,fileInputName,'add');
  478. });
  479. //代码树删除
  480. function delFileButtonClick() {
  481. $(".delFileButton").click(function () {
  482. var filePathName = "";
  483. var fileInputName = "";
  484. var appearanceId = $('select[name="appearance_id"]').val();
  485. var distId = $('input[name="dist_id"]').val();
  486. var fileId = $(this).attr('file_id');
  487. var fileName = $(this).attr('file_name');
  488. msg = '确定要删除'+fileName+'吗?';
  489. Dcat.confirm('确认删除',msg , function () {
  490. loadingIndex = layer.load(1, {
  491. shade: [0.5, '#000'] // 设置遮罩层
  492. });
  493. ajaxAddDelFile(appearanceId,distId,fileId,filePathName,fileInputName,'del');
  494. });
  495. });
  496. }
  497. //历史记录弹窗
  498. $("#history-btn").click(function () {
  499. loadingIndex = layer.load(1, {
  500. shade: [0.5, '#000'] // 设置遮罩层
  501. });
  502. var appearanceId = $('select[name="appearance_id"]').val();
  503. var distId = $('input[name="dist_id"]').val();
  504. if (fileId == '') {
  505. Dcat.error('操作失败:请先选择模板');
  506. return false;
  507. }
  508. $.ajax({
  509. url: '/prime-control/dist-template/ace',
  510. method: 'POST',
  511. data: {
  512. act: 'fetch_template_logs',
  513. file_id: fileId,
  514. dist_id: distId,
  515. appearance_id: appearanceId,
  516. },
  517. success: function(data) {
  518. const tableBody = $('#templateLogTableBody');
  519. tableBody.empty();
  520. data.forEach(log => {
  521. const row = `<tr log_id="${log.id}">
  522. <td>版本:${log.version} <br /> ${log.created_at}</td>
  523. </tr>`;
  524. tableBody.append(row);
  525. });
  526. layer.close(loadingIndex);
  527. // Show modal
  528. $('#templateLogModal').modal('show');
  529. },
  530. error: function(error) {
  531. layer.close(loadingIndex);
  532. alert('Error fetching data!');
  533. }
  534. });
  535. });
  536. //显示历史记录内容
  537. $(document).on('click', '#templateLogTableBody tr', function() {
  538. loadingIndex = layer.load(1, {
  539. shade: [0.5, '#000'] // 设置遮罩层
  540. });
  541. // 移除其他行的选中样式
  542. $('#templateLogTableBody tr').removeClass('selected-row');
  543. // 当前点击行添加选中样式
  544. $(this).addClass('selected-row');
  545. //
  546. var logId = $(this).attr('log_id');
  547. var appearanceId = $('select[name="appearance_id"]').val();
  548. var distId = $('input[name="dist_id"]').val();
  549. $.ajax({
  550. url: '/prime-control/dist-template/ace',
  551. method: 'POST',
  552. data: {
  553. act: 'fetch_template_log_content',
  554. log_id: logId,
  555. dist_id: distId,
  556. appearance_id: appearanceId,
  557. },
  558. success: function(data) {
  559. layer.close(loadingIndex);
  560. $('#contentDetails').html(data.previous_content);
  561. $("#templateLogId").val(data.id);
  562. },
  563. error: function(error) {
  564. layer.close(loadingIndex);
  565. alert('Error fetching data!');
  566. }
  567. });
  568. });
  569. $("#restoreTemplateLog").click(function () {
  570. var logId = $("#templateLogId").val();
  571. var templateVersion = $("#templateVersion").val();
  572. //确认框
  573. msg = '确定恢复'+templateVersion+'版本吗?';
  574. Dcat.confirm('确定恢复',msg , function () {
  575. loadingIndex = layer.load(1, {
  576. shade: [0.5, '#000'] // 设置遮罩层
  577. });
  578. //ajax
  579. $.ajax({
  580. url: '/prime-control/dist-template/ace',
  581. method: 'POST',
  582. data: {
  583. act:'restore_template_log',
  584. log_id: logId,
  585. },
  586. success: function(data) {
  587. layer.close(loadingIndex);
  588. if (data.status == '1') {
  589. Dcat.success('恢复成功');
  590. //关闭弹窗
  591. $('#templateLogModal').modal('hide');
  592. //请空编辑器内容
  593. editor.setValue('');
  594. //刷新代码树
  595. postData();
  596. }else{
  597. Dcat.error(data.msg);
  598. }
  599. },
  600. error: function(error) {
  601. layer.close(loadingIndex);
  602. alert('Error fetching data!');
  603. }
  604. });
  605. });
  606. });
  607. });
  608. </script>