cms.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. define(['jquery', 'table', 'form'], function($, Table, Form) {
  2. Yzn.config.openArea = ['90%', '90%'];
  3. var Controller = {
  4. index: function() {
  5. var B_tab_height = parent.layui.$("#content>.pear-frame").length > 0 ? 93 : 135;
  6. var B_frame_height = parent.layui.$("#content").height() - B_tab_height;
  7. $(window).on('resize', function() {
  8. setTimeout(function() {
  9. B_frame_height = parent.layui.$("#content").height() - B_tab_height;
  10. frameheight();
  11. }, 100);
  12. });
  13. $('.collapse').on("click", function() {
  14. var t = $(this).find('.layui-icon');
  15. $('#left-sider').toggleClass("layui-hide");
  16. if ($('#left-sider').hasClass("layui-hide")) {
  17. t.attr("class", "layui-icon layui-icon-shrink-right");
  18. $("#right-box").attr("class", 'layui-col-md12 layui-col-sm12');
  19. } else {
  20. t.attr("class", "layui-icon layui-icon-spread-left");
  21. $("#right-box").attr("class", 'layui-col-md10 layui-col-sm12');
  22. }
  23. });
  24. function frameheight() {
  25. $("#categorys").height(B_frame_height);
  26. $("#iframe_content").height(B_frame_height + 36);
  27. }
  28. frameheight();
  29. require(['jstree'], function() {
  30. let isExpanded = false;
  31. $('.openAll').click(function() {
  32. $("#category-tree").jstree(isExpanded === true ? "open_all" : "close_all");
  33. $(this).html(isExpanded ? '<i class="iconfont icon-add-line"></i> 全部展开' : '<i class="iconfont icon-subtract-line"></i> 全部折叠');
  34. isExpanded = !isExpanded;
  35. });
  36. $('#category-tree').on('activate_node.jstree', function(e, data) {
  37. var node = data.node;
  38. if (node.original.url) {
  39. $('#iframe_content').attr('src', node.original.url);
  40. }
  41. });
  42. $('#category-tree').jstree({
  43. themes: { stripes: true },
  44. core: { multiple: false, data: Config.categoryList }
  45. });
  46. });
  47. },
  48. panl: function() {
  49. require(['echarts', 'echarts-theme'], function(Echarts) {
  50. var echartsRecords = Echarts.init(document.getElementById('echarts-records'), 'walden');
  51. var optionRecords = {
  52. tooltip: { trigger: 'axis' },
  53. legend: {},
  54. grid: { left: '3%', right: '4%', bottom: '3%', containLabel: true },
  55. toolbox: { feature: { saveAsImage: {} } },
  56. xAxis: { type: 'category', boundaryGap: false, data: Config.xAxisData },
  57. yAxis: { type: 'value' },
  58. series: Config.seriesData
  59. };
  60. echartsRecords.setOption(optionRecords);
  61. window.onresize = function() { echartsRecords.resize(); };
  62. $(document).on('click', '.btn-time', function() {
  63. var start_time = $(this).data('start');
  64. var end_time = $(this).data('end');
  65. $('.datetime').val(start_time + ' - ' + end_time);
  66. refreshEchart(start_time + ' - ' + end_time);
  67. });
  68. layui.lay('.datetime').each(function() {
  69. layui.laydate.render({
  70. elem: this,
  71. trigger: 'click',
  72. range: true,
  73. type: 'datetime',
  74. done: function(value) { refreshEchart(value); }
  75. });
  76. });
  77. $(document).on('click', '.btn-refresh', function() {
  78. if ($(this).data('type')) {
  79. refreshEchart($(this).data('type'), '');
  80. } else {
  81. var input = $(this).closest('.layui-btn-group').find('.datetime');
  82. refreshEchart($(input).val());
  83. }
  84. });
  85. var refreshEchart = function(date) {
  86. Yzn.api.ajax({ url: 'cms.cms/panl', data: { date: date } }, function(res) {
  87. optionRecords.xAxis.data = res.xAxisData;
  88. optionRecords.series = res.seriesData;
  89. echartsRecords.clear();
  90. echartsRecords.setOption(optionRecords, true);
  91. return false;
  92. });
  93. };
  94. });
  95. },
  96. classlist: function() {
  97. Table.init = {
  98. table_elem: '#currentTable',
  99. table_render_id: 'currentTable',
  100. add_url: 'cms.cms/add?catid=' + Config.catid,
  101. edit_url: 'cms.cms/edit?catid=' + Config.catid,
  102. delete_url: 'cms.cms/del?catid=' + Config.catid,
  103. multi_url: 'cms.cms/multi?catid=' + Config.catid,
  104. recyclebin_url: 'cms.cms/recyclebin?catid=' + Config.catid
  105. };
  106. Table.render({
  107. init: Table.init,
  108. toolbar: ['refresh', 'add', 'delete', {
  109. text: '批量移动',
  110. auth: 'remove',
  111. icon: 'iconfont icon-drag-move-2-fill',
  112. class: 'layui-btn layui-btn-sm layui-btn-normal btn-move btn-disabled layui-btn-disabled',
  113. extend: ''
  114. }, 'recyclebin'],
  115. url: 'cms.cms/classlist?catid=' + Config.catid,
  116. lineStyle: 'height: 45px;',
  117. cols: [[
  118. { type: 'checkbox', fixed: 'left' },
  119. { field: 'listorder', width: 70, title: '排序', edit: 'text', search: false },
  120. { field: 'id', width: 80, title: 'ID' },
  121. { field: 'title', align: 'left', title: '标题', templet: '#title', searchOp: 'like' },
  122. { field: 'lang_status', minWidth: 180, title: '翻译状态', templet: function(d) {
  123. var map = d.lang_status || {};
  124. var langs = Config.enabledLangs || [];
  125. var html = [];
  126. $.each(langs, function(_, item) {
  127. var ok = parseInt(map[item.mark] || 0) === 1;
  128. var label = item.name || item.code || item.mark;
  129. html.push('<span style="display:inline-block;margin:2px 6px 2px 0;padding:2px 6px;border-radius:10px;font-size:12px;' + (ok ? 'background:#e8f8f5;color:#16b777;' : 'background:#fff2f0;color:#ff5722;') + '">' + label + ' ' + (ok ? '✓' : '✗') + '</span>');
  130. });
  131. return html.join('');
  132. } },
  133. { field: 'flag', width: 100, title: '属性', hide: true, selectList: {1:'置顶',2:'头条',3:'特荐',4:'推荐',5:'热点',6:'幻灯'}, searchOp: 'FIND_IN_SET' },
  134. { field: 'thumb', width: 70, align: 'center', title: '图片', search: false, templet: Table.formatter.image },
  135. { field: 'hits', width: 80, title: '点击量', search: 'between', searchTip: '点击量' },
  136. { field: 'update_time', width: 160, title: '更新时间', search: 'range' },
  137. { field: 'url', width: 60, align: 'center', title: 'URL', templet: Table.formatter.url, search: false },
  138. { field: 'status', width: 100, align: 'center', title: '状态', unresize: true, templet: Table.formatter.switch, tips: '待审核|通过', selectList: {0:'待审核',1:'通过'} },
  139. { fixed: 'right', width: 90, title: '操作', templet: Table.formatter.tool, operat: ['edit', 'delete'] }
  140. ]],
  141. page: {}
  142. });
  143. $('body').on('click', '.btn-move', function() {
  144. var checkStatus = layui.table.checkStatus('currentTable');
  145. var ids = [], data = checkStatus.data;
  146. if (data.length > 0) {
  147. $.each(data, function(i, v) { ids.push(v.id); });
  148. Layer.open({
  149. title: '批量移动',
  150. type: 1,
  151. content: $('#remove'),
  152. area: ['300px', '250px'],
  153. btn: ['移动'],
  154. yes: function(index) {
  155. var tocatid = $("select[name='remove']").val();
  156. if (tocatid == 0) {
  157. Layer.msg('请选择移动的栏目', { icon: 2 });
  158. return;
  159. }
  160. Yzn.api.ajax({ url: 'cms.cms/remove?catid=' + Config.catid, data: { ids: ids, tocatid: tocatid } }, function() {
  161. layui.table.reload('currentTable');
  162. Layer.close(index);
  163. });
  164. },
  165. end: function() { $('#remove').hide(); }
  166. });
  167. } else {
  168. Layer.msg('请选择需要移动的数据', { icon: 2 });
  169. }
  170. });
  171. Table.toolbarEvents['btn-add'] = function(obj, options) {
  172. parent.Yzn.api.open(options.init.add_url, $(this).data('original-title') || $(this).attr('title') || '添加', $(this).data() || {});
  173. };
  174. Table.toolEvents['btn-editone'] = function(obj, options) {
  175. var data = obj.data;
  176. var ids = data[options.pk];
  177. var row = $.extend({}, data ? data : {}, { id: ids });
  178. var url = options.init.edit_url;
  179. parent.Yzn.api.open(Table.api.toolSpliceUrl(url, row), $(this).data('original-title') || $(this).attr('title') || '编辑', $(this).data() || {});
  180. };
  181. Table.api.bindevent();
  182. },
  183. recyclebin: function() {
  184. Table.init = {
  185. table_elem: '#currentTable',
  186. table_render_id: 'currentTable',
  187. restore_url: 'cms.cms/restore?catid=' + Config.catid,
  188. destroy_url: 'cms.cms/destroy?catid=' + Config.catid
  189. };
  190. Table.render({
  191. init: Table.init,
  192. url: 'cms.cms/recyclebin?catid=' + Config.catid,
  193. toolbar: ['refresh', 'restore', 'destroy'],
  194. cols: [[
  195. { type: 'checkbox', fixed: 'left' },
  196. { field: 'id', width: 70, title: 'ID' },
  197. { field: 'title', align: 'left', title: '标题', templet: '#title' },
  198. { field: 'update_time', width: 180, title: '更新时间' },
  199. { fixed: 'right', width: 140, title: '操作', templet: Table.formatter.tool, operat: ['restore', 'destroy'] }
  200. ]]
  201. });
  202. Table.api.bindevent();
  203. },
  204. add: function() {
  205. $('.lang-switch').on('click', function() {
  206. $('.lang-switch').removeClass('active');
  207. $(this).addClass('active');
  208. $('#current-lang').val($(this).data('lang'));
  209. });
  210. Controller.api.bindevent(true);
  211. },
  212. edit: function() {
  213. Controller.api.bindevent(false);
  214. },
  215. api: {
  216. bindevent: function(isAdd) {
  217. var insertHtml = function(html) {
  218. if (typeof UE !== 'undefined' && typeof UE.list['editor-content'] !== 'undefined') {
  219. UE.list['editor-content'].setContent(html, false);
  220. } else if (typeof tinymce !== 'undefined' && tinymce.get('editor-content')) {
  221. tinymce.get('editor-content').setContent(html);
  222. } else {
  223. Layer.open({ content: '当前编辑器不支持插入html,请至插件市场安装编辑器插件', title: '温馨提示' });
  224. }
  225. };
  226. var input = $("input[name='modelField[title]']");
  227. if (input.length && $('.btn-repeat').length === 0) {
  228. input.after("<button type='button' class='layui-btn layui-btn-sm btn-repeat'>重复检测</button>");
  229. }
  230. $(document).on('click', '.btn-repeat', function() {
  231. Yzn.api.ajax({ url: 'cms.cms/check_title', data: { id: Config.id, catid: Config.catid, data: input.val() } });
  232. });
  233. $(document).on('click', '.btn-grabimg', function() {
  234. Yzn.api.ajax({ url: 'general.attachments/getUrlFile', data: { content: $('#editor-content').val(), type: 'images' } }, function(data) {
  235. insertHtml(data);
  236. return false;
  237. });
  238. });
  239. $(document).on('click', '.btn-filterword', function() {
  240. Yzn.api.ajax({ url: 'ajax/filterWord', data: { content: $('#editor-content').val() } }, function() {}, function(data, ret) {
  241. if ($.isArray(data)) {
  242. if (data.length > 1) {
  243. Layer.alert('违禁词:' + data.join(','), { icon: 2 });
  244. } else {
  245. Layer.alert(ret.msg);
  246. }
  247. return false;
  248. }
  249. });
  250. });
  251. $(document).on('click', '.btn-getwords', function() {
  252. require(['tagsinput'], function() {
  253. Yzn.api.ajax({ url: 'getwords/index', data: { content: $('#editor-content').val() } }, function(data) {
  254. $('.tags-keywords').importTags(data);
  255. });
  256. });
  257. });
  258. $(document).on('change', '.fieldlist .tabbar-img-value', function() {
  259. $(this).prev('img').attr('src', $(this).val());
  260. });
  261. $(document).on('fa.event.appendfieldlist', '.btn-append', function(e, obj) {
  262. Form.events.plupload(obj);
  263. Form.events.faselect(obj);
  264. });
  265. Form.api.bindevent($('form.layui-form'), function(data, ret) {
  266. if (isAdd) {
  267. Layer.confirm(ret.msg, { btn: ['继续添加', '返回列表'] }, function() {
  268. $(window).scrollTop(0);
  269. location.reload();
  270. }, function() {
  271. Controller.api.closeAndRefresh();
  272. });
  273. } else {
  274. Controller.api.closeAndRefresh();
  275. }
  276. return false;
  277. });
  278. },
  279. closeAndRefresh: function() {
  280. if (parent.$('#iframe_content').length > 0) {
  281. parent.$('#iframe_content').contents().find('.btn-refresh')[0].click();
  282. } else {
  283. parent.$('.btn-refresh').trigger('click');
  284. }
  285. var index = parent.Layer.getFrameIndex(window.name);
  286. parent.Layer.close(index);
  287. }
  288. }
  289. };
  290. return Controller;
  291. });