collect.js 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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: 'shop/collect/index' + location.search,
  8. add_url: 'shop/collect/add',
  9. edit_url: 'shop/collect/edit',
  10. del_url: 'shop/collect/del',
  11. multi_url: 'shop/collect/multi',
  12. import_url: 'shop/collect/import',
  13. table: 'shop_collect',
  14. }
  15. });
  16. var table = $("#table");
  17. // 初始化表格
  18. table.bootstrapTable({
  19. url: $.fn.bootstrapTable.defaults.extend.index_url,
  20. pk: 'id',
  21. sortName: 'id',
  22. columns: [
  23. [
  24. {checkbox: true},
  25. {field: 'id', title: __('Id')},
  26. // {field: 'user_id', title: __('User_id'), formatter: Table.api.formatter.search},
  27. {
  28. field: 'user.username',
  29. title: __('User'),
  30. operate: 'LIKE',
  31. formatter: function (value, row, index) {
  32. // 显示用户头像和用户名
  33. var avatar = row.user && row.user.avatar ? row.user.avatar : '/assets/img/avatar.png';
  34. var username = row.user && row.user.username ? row.user.username : '游客';
  35. var userId = row.user_id || '';
  36. // 处理头像URL
  37. var avatarUrl = avatar;
  38. if (avatar && !avatar.startsWith('http') && !avatar.startsWith('//')) {
  39. avatarUrl = Fast.api.cdnurl ? Fast.api.cdnurl(avatar) : avatar;
  40. }
  41. return '<div style="display:flex;align-items:center;">' +
  42. '<img src="' + avatarUrl + '" style="width:40px;height:40px;border-radius:50%;margin-right:10px;" />' +
  43. '<div>' +
  44. '<div style="color:#337ab7;font-weight:bold;">' + username + '</div>' +
  45. '<div style="color:#999;font-size:12px;">ID: ' + userId + '</div>' +
  46. '</div>' +
  47. '</div>';
  48. }
  49. },
  50. {field: 'goods.title', title: __('Goods')},
  51. {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1')}, formatter: Table.api.formatter.status},
  52. {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  53. {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  54. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  55. ]
  56. ]
  57. });
  58. // 为表格绑定事件
  59. Table.api.bindevent(table);
  60. },
  61. add: function () {
  62. Controller.api.bindevent();
  63. },
  64. edit: function () {
  65. Controller.api.bindevent();
  66. },
  67. api: {
  68. bindevent: function () {
  69. Form.api.bindevent($("form[role=form]"));
  70. }
  71. }
  72. };
  73. return Controller;
  74. });