guest.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: async function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. extend: {
  7. index_url: 'user/guest/index',
  8. add_url: 'user/guest/add',
  9. edit_url: 'user/guest/edit',
  10. del_url: 'user/guest/del',
  11. multi_url: 'user/guest/multi',
  12. table: 'user',
  13. }
  14. });
  15. var table = $("#table");
  16. let levels = await $.getJSON('user/user/levels')
  17. // 初始化表格
  18. table.bootstrapTable({
  19. url: $.fn.bootstrapTable.defaults.extend.index_url,
  20. pk: 'id',
  21. sortName: 'user.id',
  22. searchFormVisible:true,
  23. columns: [
  24. [
  25. //{checkbox: true},
  26. {field: 'id', title: __('Id'), sortable: true},
  27. //{field: 'group.name', title: __('Group')},
  28. {field: 'username', title: __('Username'), operate: 'LIKE'},
  29. {field: 'nickname', title: __('Nickname'), operate: 'LIKE'},
  30. {field: 'mobile', title: __('手机号'), operate: 'LIKE'},
  31. {field: 'mob_brand', title: __('手机品牌'), operate: 'LIKE'},
  32. {field: 'mob_model', title: __('手机型号'), operate: 'LIKE'},
  33. {
  34. field: 'avatar',
  35. title: __('头像'),
  36. events: Table.api.events.image,
  37. formatter: Table.api.formatter.image,
  38. operate: false
  39. },
  40. {
  41. field: 'gender',
  42. title: __('性别'),
  43. searchList: {1: __('男'), 0: __('Female')},
  44. formatter: Table.api.formatter.label
  45. },
  46. {
  47. field: 'age',
  48. title: __('年龄'),
  49. },
  50. {
  51. field: 'city_name',
  52. title: __('城市'),
  53. searchList: function (column) {
  54. return Template('sourcetpl', {})
  55. }
  56. },
  57. {
  58. field: 'userinfo',
  59. title: '自定义',
  60. formatter(info){
  61. if(!info || !info.custom){
  62. return ''
  63. }
  64. let str=[]
  65. info.custom.forEach(item=>{
  66. str.push(`<div>${item.title}:${item.value}</div>`)
  67. })
  68. return str.join('')
  69. }
  70. },
  71. //{field: 'money', title: __('余额'), operate: 'BETWEEN', sortable: true},
  72. /* {
  73. field: 'successions',
  74. title: __('Successions'),
  75. visible: false,
  76. operate: 'BETWEEN',
  77. sortable: true
  78. },
  79. {
  80. field: 'maxsuccessions',
  81. title: __('Maxsuccessions'),
  82. visible: false,
  83. operate: 'BETWEEN',
  84. sortable: true
  85. },*/
  86. //{field: 'logintime', title: __('Logintime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
  87. //{field: 'loginip', title: __('Loginip'), formatter: Table.api.formatter.search},
  88. {
  89. field: 'jointime',
  90. title: __('注册时间'),
  91. formatter: Table.api.formatter.datetime,
  92. operate: 'RANGE',
  93. addclass: 'datetimerange',
  94. sortable: true
  95. },
  96. //{field: 'joinip', title: __('Joinip'), formatter: Table.api.formatter.search},
  97. {
  98. field: 'status',
  99. title: __('Status'),
  100. formatter: Table.api.formatter.status,
  101. searchList: {normal: __('Normal'), hidden: __('Hidden')}
  102. },
  103. /*{
  104. field: 'operate',
  105. title: __('Operate'),
  106. table: table,
  107. events: Table.api.events.operate,
  108. formatter: Table.api.formatter.operate
  109. }*/
  110. ]
  111. ],
  112. onLoadSuccess(){
  113. $(".btn-editone").data("area", ["800px","90%"]);
  114. }
  115. });
  116. // 为表格绑定事件
  117. Table.api.bindevent(table);
  118. },
  119. add: function () {
  120. Controller.api.bindevent();
  121. },
  122. edit: function () {
  123. Controller.api.bindevent();
  124. },
  125. api: {
  126. bindevent: function () {
  127. Form.api.bindevent($("form[role=form]"));
  128. }
  129. }
  130. };
  131. return Controller;
  132. });