page.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'clipboard'], function ($, undefined, Backend, Table, Form, Clipboard) {
  2. var clipboard = new Clipboard('.btn-operate-copy', {
  3. target: function (trigger) {
  4. var stxt = $(trigger).parent().parent().find('.url_text i').data('clipboard-text');
  5. trigger = document.querySelector('#many_copy_dom');
  6. $('#many_copy_dom').html(stxt);
  7. return trigger;
  8. }
  9. });
  10. clipboard.on('success',function (data) {
  11. Toastr.success('复制成功');
  12. }).on('error',function (data) {
  13. Toastr.error('复制失败');
  14. });
  15. var Controller = {
  16. index: function () {
  17. // 初始化表格参数配置
  18. Table.api.init({
  19. extend: {
  20. index_url: 'special/page/index',
  21. add_url: 'special/page/add',
  22. edit_url: 'special/page/edit',
  23. del_url: 'special/page/del',
  24. multi_url: 'special/page/multi',
  25. table: 'special_page',
  26. }
  27. });
  28. var table = $("#table");
  29. if (Config.group == 3 || Config.group == 4) {
  30. // 初始化表格
  31. table.bootstrapTable({
  32. url: $.fn.bootstrapTable.defaults.extend.index_url,
  33. pk: 'id',
  34. sortName: 'id',
  35. columns: [
  36. [
  37. {checkbox: true},
  38. {field: 'id', title: __('Id')},
  39. {field: 'url', title: __('Url'), formatter: Controller.api.source_url, operate: false},
  40. {field: 'title', title: __('Title'), operate:'LIKE %...%'},
  41. {field: 'status', title: __('Status'), visible:false, searchList: {"normal":__('status normal'),"hidden":__('status hidden')}},
  42. {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
  43. {field: 'status_text', title: __('Status'), operate:false},
  44. {
  45. field: 'copy',
  46. title: __('Operate'),
  47. operate: false,
  48. formatter: function (value, row) {
  49. if (row['status'] == 'normal') {
  50. return '<a href="javascript:;" class="btn btn-click btn-operate-copy" title="复制" data-table-id="table" data-field-index="8" data-row-index="0" data-button-index="0">复制&nbsp;&nbsp;<i class="fa fa-copy copy"></i></a>';
  51. } else {
  52. return '-';
  53. }
  54. }
  55. }
  56. ]
  57. ]
  58. });
  59. } else {
  60. // 初始化表格
  61. table.bootstrapTable({
  62. url: $.fn.bootstrapTable.defaults.extend.index_url,
  63. pk: 'id',
  64. sortName: 'id',
  65. columns: [
  66. [
  67. {checkbox: true},
  68. {field: 'id', title: __('Id')},
  69. {field: 'title', title: __('Title'), operate:'LIKE %...%'},
  70. {field: 'preview', title: __('预览'), operate:false, formatter: function(value){
  71. if (value.indexOf('http') != '-1') {
  72. return '<a href="'+value+'" target="_blank">'+value+'</a>'
  73. }
  74. return value;
  75. }},
  76. {field: 'image', title: __('Image'), formatter: Table.api.formatter.image, operate:false, visible:false},
  77. {field: 'type', title: __('Type'), visible:false, searchList: {"type 1":__('Type 1'),"type 2":__('Type 2'),"type 3":__('Type 3'),"type 4":__('Type 4')}, operate:false},
  78. {field: 'type_text', title: __('Type'), operate:false, visible:false},
  79. {field: 'book_id', title: __('Book_id'), visible:false, operate:false},
  80. {field: 'color', title: __('Color'), operate:false, visible:false},
  81. {field: 'status', title: __('Status'), visible:false, searchList: {"normal":__('status normal'),"hidden":__('status hidden')}},
  82. {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
  83. {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime, visible:false},
  84. {field: 'resourcelist', title: __('专题资源配置'),formatter: Controller.api.formatter.resourcelist, operate:false},
  85. {field: 'changestatus', title: __('显示状态'),addClass:'btn-start',formatter: Controller.api.formatter.changestatus, operate:false},
  86. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,buttons:Controller.api.formatter.showBtn()}
  87. ]
  88. ],
  89. 'onPostBody': function () {
  90. $(".btn-delone").hide();
  91. }
  92. });
  93. }
  94. // 为表格绑定事件
  95. Table.api.bindevent(table);
  96. //启动和暂停按钮
  97. $(document).on("click", ".btn-start", function () {
  98. //在table外不可以使用添加.btn-change的方法
  99. //只能自己调用Table.api.multi实现
  100. var id = $(this).data('id');
  101. var thisvalue = $(this).val();
  102. var status = "normal";
  103. if(thisvalue=='点击打开'){
  104. status = "normal";
  105. }else{
  106. status = "hidden";
  107. }
  108. var textval = thisvalue.substring(2,4);
  109. var reloadfrom = $(this).data('reload');
  110. layer.confirm('确定要'+textval+'吗?', {
  111. btn: ['确定','取消'] //按钮
  112. }, function(){
  113. $.post('/admin/special/page/multi',{ids:id,params:"status="+status},function(data){
  114. if(data.code == 1){
  115. layer.msg('操作成功');
  116. if (reloadfrom == 1) {
  117. window.location.reload();
  118. } else {
  119. table.bootstrapTable('refresh');
  120. }
  121. }else{
  122. layer.msg('操作失败');
  123. }
  124. });
  125. }, function(){
  126. layer.close();
  127. });
  128. });
  129. },
  130. add: function () {
  131. Controller.api.bindevent();
  132. },
  133. edit: function () {
  134. $(function () {
  135. if ($('#c-type').val() != 3) {
  136. $(".bg-color").removeClass("hide");
  137. }
  138. });
  139. Controller.api.bindevent();
  140. },
  141. api: {
  142. bindevent: function () {
  143. Form.api.bindevent($("form[role=form]"));
  144. $(document).on('click', "#select-resources", function () {
  145. var block_id = Config.block_id;
  146. parent.Backend.api.open($(this).attr("href") + "?action=blockresoure&block_id=" + block_id, __('Select'), {callback: refreshkey});
  147. return false;
  148. });
  149. var refreshkey = function (data) {
  150. Layer.closeAll();
  151. $('#c-book_id_text').val(data[0].id);
  152. $('#c-book_id').val(data[0].id);
  153. };
  154. $(document).on("change", "#c-type", function () {
  155. if ($("#c-type").val() == 3) {
  156. $(".bg-color").addClass("hide");
  157. //清空数据
  158. $("#c-color").val("");
  159. } else {
  160. $(".bg-color").removeClass("hide");
  161. }
  162. });
  163. },
  164. source_url: function (value, row, index) {
  165. var html = [];
  166. value = row.url;
  167. if (row.status == "normal") {
  168. html.push('<div class="link_txt"></div><div class="url_text">' + value + '&nbsp;<i class="fa fa-copy copy" data-clipboard-text="' + value + '"></i>');
  169. } else {
  170. html.push('<div class="link_txt">该专题页已关闭不可使用</div>');
  171. }
  172. return html.join('<br>');
  173. },
  174. formatter: {
  175. showBtn: function(){
  176. return [
  177. {name: 'clear_cache', text: '清除缓存', title: '清除缓存', classname: 'btn btn-xs btn-danger btn-ajax', url: '/admin/special/page/rmcache', callback:function(data){}}
  178. ];
  179. },
  180. changestatus:function(value,row,index){
  181. var showName = '';
  182. if (row.status == 'hidden'){
  183. return '<b>隐藏</b>&nbsp;&nbsp;<input type="button" class="btn-start btn btn-success" data-id="'+row.id+'" value="点击打开" />';
  184. }else{
  185. return '<b>正常</b>&nbsp;&nbsp;<input type="button" class="btn-start btn btn-warning" data-id="'+row.id+'" value="点击隐藏" />';
  186. }
  187. },
  188. resourcelist: function (value, row, index) {
  189. //这里手动构造URL
  190. url = "special/block/index?page_id="+row.id;
  191. return '<a href="' + url + '" class="label label-success addtabsit" title="资源列表">资源列表</a>';
  192. }
  193. },
  194. }
  195. };
  196. return Controller;
  197. });