category.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. define(['jquery', 'table', 'form'], function($, Table, Form) {
  2. Yzn.config.openArea = ['80%', '80%'];
  3. var Controller = {
  4. index: function() {
  5. Table.init = {
  6. table_elem: '#currentTable',
  7. table_render_id: 'currentTable',
  8. add_url: "cms.category/add",
  9. edit_url: "cms.category/edit",
  10. delete_url: "cms.category/del",
  11. multi_url: 'cms.category/multi',
  12. };
  13. Table.render({
  14. init: Table.init,
  15. toolbar: ['refresh', 'add', 'delete', {
  16. text: '栏目授权',
  17. url: "cms.category/cat_priv",
  18. auth: 'cat_priv',
  19. class: 'layui-btn layui-btn-sm layui-btn-normal btn-dialog',
  20. icon: 'iconfont icon-menu-line',
  21. },
  22. {
  23. text: '栏目数据校正',
  24. url: "cms.category/count_items",
  25. class: 'layui-btn layui-btn-sm btn-ajax',
  26. icon: 'iconfont icon-check-line',
  27. extend: '',
  28. },
  29. {
  30. text: "更新栏目缓存",
  31. url: "cms.category/public_cache",
  32. class: 'layui-btn layui-btn-sm btn-ajax',
  33. icon: 'iconfont icon-loop-left-line',
  34. extend: '',
  35. }
  36. ],
  37. url: 'cms.category/index',
  38. search: false,
  39. cols: [
  40. [
  41. { type: 'checkbox', fixed: 'left' },
  42. { field: 'listorder', width: 70, title: '排序', edit: 'text' },
  43. { field: 'id', width: 70, title: 'ID' },
  44. {
  45. field: 'catname',
  46. align: "left",
  47. title: '栏目名称',
  48. templet: function(d) {
  49. return '<span><a href="' + Table.init.edit_url + '?id=' + d.id + '" title="编辑信息" class="btn-dialog" data-table="currentTable">' + d.catname + '</a></span>';
  50. }
  51. },
  52. { field: 'items', width: 80, title: '数据量' },
  53. { field: 'catdir', width: 120, title: '唯一标识' },
  54. { field: 'lang_status', minWidth: 180, title: '翻译状态', templet: function(d) {
  55. var map = d.lang_status || {};
  56. var langs = Config.enabledLangs || [];
  57. var html = [];
  58. $.each(langs, function(_, item) {
  59. var ok = parseInt(map[item.mark] || 0) === 1;
  60. var label = item.name || item.code || item.mark;
  61. 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>');
  62. });
  63. return html.join('');
  64. } },
  65. { field: 'type', width: 90, title: '栏目类型', templet: Table.formatter.label, selectList: { 1: '单页', 2: '列表', 3: '外链' }, custom: { 1: "cyan", 2: "blue", 3: "green" }, search: false },
  66. { field: 'modelname', width: 120, title: '所属模型' },
  67. { field: 'url', width: 60, align: "center", title: 'URL', templet: Table.formatter.url },
  68. { field: 'status', width: 100, align: "center", title: '状态', unresize: true, templet: Table.formatter.switch },
  69. {
  70. width: 170,
  71. title: '操作',
  72. templet: Table.formatter.tool,
  73. operat: [
  74. {
  75. text: '添加子栏目',
  76. auth: 'add',
  77. class: 'layui-btn layui-btn-xs layui-btn-normal btn-dialog',
  78. extend: '',
  79. url: function(row) {
  80. return Table.init.add_url + '?parentid=' + row.id;
  81. },
  82. },
  83. 'edit', 'delete'
  84. ]
  85. }
  86. ]
  87. ],
  88. });
  89. Table.api.bindevent();
  90. },
  91. add: function() {
  92. Controller.api.bindevent();
  93. //批理添加
  94. layui.form.on('radio(filter)', function(data) {
  95. if (1 == data.value) {
  96. //批量
  97. $('#normal_add').hide();
  98. $('#catdir_tr').hide();
  99. $('#batch_add').show();
  100. $('#catname').attr('disabled', true).attr('lay-verify', '');
  101. }
  102. if (0 == data.value) {
  103. $('#normal_add').show();
  104. $('#catdir_tr').show();
  105. $('#batch_add').hide();
  106. $('#catname').attr('disabled', false).attr('lay-verify', 'required');
  107. }
  108. });
  109. //默认模型模板
  110. layui.form.on('select(filter)', function(data) {
  111. if (data.value) {
  112. Yzn.api.ajax({
  113. url: 'cms.category/public_tpl_file_list',
  114. data: { id: data.value }
  115. }, function(res) {
  116. $('.category_template').val(res.data.category_template);
  117. $('.category_template').next('.sp_hidden').val(res.data.category_template);
  118. $('.list_template').val(res.data.list_template);
  119. $('.list_template').next('.sp_hidden').val(res.data.list_template);
  120. $('.show_template').val(res.data.show_template);
  121. $('.show_template').next('.sp_hidden').val(res.data.show_template);
  122. return false
  123. });
  124. }
  125. });
  126. if (Config.parentid_modelid) {
  127. Yzn.api.ajax({
  128. url: 'cms.category/public_tpl_file_list',
  129. data: { id: Config.parentid_modelid }
  130. }, function(res) {
  131. $('.category_template').val(res.data.category_template);
  132. $('.category_template').next('.sp_hidden').val(res.data.category_template);
  133. $('.list_template').val(res.data.list_template);
  134. $('.list_template').next('.sp_hidden').val(res.data.list_template);
  135. $('.show_template').val(res.data.show_template);
  136. $('.show_template').next('.sp_hidden').val(res.data.show_template);
  137. return false
  138. });
  139. }
  140. },
  141. edit: function() {
  142. Controller.api.bindevent();
  143. },
  144. cat_priv: function() {
  145. var act = Backend.api.query('act');
  146. if (act == 'authorization') {
  147. Form.api.bindevent($("form.layui-form"));
  148. layui.form.on('checkbox', function(data) {
  149. var name = $(data.elem).data('name');
  150. if (data.elem.checked == true) {
  151. if (name == 0) {
  152. $.each($("input[type='checkbox']"), function(i, rs) {
  153. if (rs.disabled != true) {
  154. rs.checked = true;
  155. }
  156. })
  157. } else {
  158. $.each($("input[type='checkbox'][name='priv[" + name + "][]']"), function(i, rs) {
  159. if (rs.disabled != true) {
  160. rs.checked = true;
  161. }
  162. });
  163. }
  164. } else {
  165. if (name == 0) {
  166. $.each($("input[type='checkbox']"), function(i, rs) {
  167. rs.checked = false;
  168. })
  169. } else {
  170. $.each($("input[type='checkbox'][name='priv[" + name + "][]']"), function(i, rs) {
  171. rs.checked = false;
  172. });
  173. }
  174. }
  175. layui.form.render('checkbox');
  176. })
  177. } else {
  178. Table.init = {
  179. table_elem: '#currentTable',
  180. table_render_id: 'currentTable',
  181. };
  182. Table.render({
  183. init: Table.init,
  184. toolbar: ['refresh'],
  185. url: 'cms.category/cat_priv',
  186. search: false,
  187. cols: [
  188. [
  189. { field: 'title', title: '角色名称' },
  190. { field: 'num', title: '授权数量' },
  191. { fixed: 'right', title: '操作', width: 120, templet: '#barTool' }
  192. ]
  193. ]
  194. });
  195. Table.api.bindevent();
  196. }
  197. },
  198. api: {
  199. bindevent: function() {
  200. Form.api.bindevent($("form.layui-form"));
  201. layui.form.on('radio(type)', function(data) {
  202. $(".lay").addClass("layui-hide");
  203. //单页
  204. if (data.value == 1) {
  205. $('#modeTab').show();
  206. $('#authTab').hide();
  207. $('.lay-page').removeClass("layui-hide");
  208. }
  209. //列表
  210. if (data.value == 2) {
  211. $('#modeTab').show();
  212. $('#authTab').show();
  213. $('.lay-list').removeClass("layui-hide");
  214. }
  215. //外链
  216. if (data.value == 3) {
  217. $('#authTab').hide();
  218. $('#modeTab').hide();
  219. $('.lay-url').removeClass("layui-hide");
  220. }
  221. });
  222. layui.form.on('select(fasttype)', function(data) {
  223. $('#url').val($(data.elem).find("option:selected").attr("data-url"));
  224. });
  225. $("input[name='row[type]']:checked").next().trigger("click");
  226. }
  227. }
  228. };
  229. return Controller;
  230. });