privatebookpage.js 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. extend: {
  7. index_url: 'privatebookpage/index',
  8. add_url: 'privatebookpage/add',
  9. edit_url: 'privatebookpage/edit',
  10. del_url: 'privatebookpage/del',
  11. table: 'private_book_page',
  12. }
  13. });
  14. var table = $("#table");
  15. // 初始化表格
  16. table.bootstrapTable({
  17. url: $.fn.bootstrapTable.defaults.extend.index_url,
  18. pk: 'id',
  19. sortName: 'id',
  20. columns: [
  21. [
  22. {checkbox: true},
  23. {field: 'id', title: __('Id')},
  24. {field: 'title', title: __('Title'),operate:false},
  25. {field: 'url', title: __('页面地址'),operate:false, formatter: function (value, row, index) {
  26. return '/index/recharge/singlepage?page_id='+ row.id;
  27. }},
  28. {field: 'status', title: __('状态'), operate:false, formatter: function (value, row, index) {
  29. if (value == '0') {
  30. return "隐藏";
  31. }
  32. return "正常";
  33. }},
  34. {field: 'end_time', title: __('结束时间'), operate:false,formatter:Table.api.formatter.datetime},
  35. {field: 'createtime', title: __('创建时间'), operate:false,formatter:Table.api.formatter.datetime},
  36. {field: 'updatetime', title: __('更新时间'), operate:false,formatter:Table.api.formatter.datetime},
  37. {field: 'id', title: __('资源列表'),formatter: Controller.api.formatter.id},
  38. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,formatter:function (value,row) {
  39. var html = '';
  40. html += '<a href="javascript:;" data-id="'+row.id+'" class="btn btn-xs btn-default clean-cache" >清除缓存 </a> ';
  41. html += '<a href="/admin/privatebookpage/edit/ids/"'+row.id+' class="btn btn-xs btn-success btn-editone"><i class="fa fa-pencil"></i></a> ';
  42. html+='<a href="javascript:;" class="btn btn-xs btn-danger btn-delone" ><i class="fa fa-trash"></i></a>';
  43. return html;
  44. }}
  45. ]
  46. ]
  47. });
  48. // 为表格绑定事件
  49. Table.api.bindevent(table);
  50. //btn-collect
  51. $(document).on('click','.clean-cache',function () {
  52. var id = $(this).attr('data-id');
  53. $.post('Privatebookpage/cleancache/id/'+id,function(res){
  54. console.log(res);
  55. if(res.code == 1){
  56. layer.alert('操作成功');
  57. }else{
  58. layer.alert('操作失败');
  59. }
  60. });
  61. });
  62. },
  63. add: function () {
  64. Controller.api.bindevent();
  65. },
  66. edit: function () {
  67. Controller.api.bindevent();
  68. },
  69. api: {
  70. bindevent: function () {
  71. Form.api.bindevent($("form[role=form]"));
  72. },
  73. formatter: {
  74. id: function (value, row, index) {
  75. //这里手动构造URL
  76. url = "privatebookpageresource/index?page_id="+row.id;
  77. return '<a href="' + url + '" class="label label-success addtabsit" title="' + __("Search %s", value) + '">资源列表</a>';
  78. }
  79. }
  80. }
  81. };
  82. return Controller;
  83. });