ace.blade.php 16 KB

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