admin.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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: 'auth/admin/index',
  8. add_url: 'auth/admin/add',
  9. edit_url: 'auth/admin/edit',
  10. del_url: 'auth/admin/del',
  11. multi_url: 'auth/admin/multi',
  12. }
  13. });
  14. var table = $("#table");
  15. //在表格内容渲染完成后回调的事件
  16. table.on('post-body.bs.table', function (e, json) {
  17. $("tbody tr[data-index]", this).each(function () {
  18. if (parseInt($("td:eq(1)", this).text()) == Config.admin.id) {
  19. $("input[type=checkbox]", this).prop("disabled", true);
  20. }
  21. });
  22. });
  23. // 初始化表格
  24. table.bootstrapTable({
  25. url: $.fn.bootstrapTable.defaults.extend.index_url,
  26. columns: [
  27. [
  28. {field: 'state', checkbox: true, },
  29. {field: 'id', title: 'ID'},
  30. {field: 'username', title: __('Username')},
  31. {field: 'nickname', title: __('Nickname')},
  32. {field: 'groups_text', title: __('Group'), operate:false, formatter: Table.api.formatter.label},
  33. {field: 'email', title: __('Email')},
  34. {field: 'mobile', title: __('Mobile')},
  35. {field: 'status', title: __("Status"), searchList: {"normal":__('Normal'),"hidden":__('Hidden')}, formatter: Table.api.formatter.status},
  36. {field: 'logintime', title: __('Login time'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
  37. {field: 'operate', title: __('Operate'), table: table,
  38. buttons: [
  39. {
  40. name: 'detail',
  41. text: __('修改金额'),
  42. title: __('修改金额'),
  43. classname: 'btn btn-xs btn-primary btn-dialog',
  44. icon: 'fa fa-list',
  45. url: 'auth/admin/changemoney',
  46. callback: function (data) {
  47. Layer.alert("接收到回传数据:" + JSON.stringify(data), {title: "回传数据"});
  48. },
  49. visible: function (row) {
  50. //返回true时按钮显示,返回false隐藏
  51. return true;
  52. }
  53. },
  54. ],
  55. events: Table.api.events.operate, formatter: function (value, row, index) {
  56. if(row.id == Config.admin.id){
  57. return '';
  58. }
  59. return Table.api.formatter.operate.call(this, value, row, index);
  60. }}
  61. ]
  62. ]
  63. });
  64. // 为表格绑定事件
  65. Table.api.bindevent(table);
  66. },
  67. add: function () {
  68. Form.api.bindevent($("form[role=form]"));
  69. },
  70. edit: function () {
  71. Form.api.bindevent($("form[role=form]"));
  72. },
  73. changemoney: function () {
  74. Form.api.bindevent($("form[role=form]"));
  75. },
  76. };
  77. return Controller;
  78. });