attachment.js 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. define(['jquery', 'bootstrap', 'backend', 'form', 'table', 'config'], function ($, undefined, Backend, Form, Table, Config) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. extend: {
  7. index_url: 'general/attachment/index',
  8. add_url: 'general/attachment/add',
  9. edit_url: 'general/attachment/edit',
  10. del_url: 'general/attachment/del',
  11. multi_url: 'general/attachment/multi',
  12. table: 'attachment'
  13. }
  14. });
  15. var table = $("#table");
  16. // 初始化表格
  17. table.bootstrapTable({
  18. url: $.fn.bootstrapTable.defaults.extend.index_url,
  19. sortName: 'id',
  20. columns: [
  21. [
  22. {field: 'state', checkbox: true, },
  23. {field: 'id', title: __('Id')},
  24. {field: 'url', title: __('Preview'), formatter: Controller.api.formatter.thumb},
  25. {field: 'url', title: __('Url'), formatter: Controller.api.formatter.url},
  26. {field: 'imagewidth', title: __('Imagewidth')},
  27. {field: 'imageheight', title: __('Imageheight')},
  28. {field: 'imagetype', title: __('Imagetype')},
  29. {field: 'imageframes', title: __('Imageframes')},
  30. {field: 'filesize', title: __('Filesize')},
  31. {field: 'mimetype', title: __('Mimetype')},
  32. {field: 'createtime', title: __('Createtime'), formatter: Table.api.formatter.datetime},
  33. {field: 'operate', title: __('Operate'), events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  34. ]
  35. ],
  36. //普通搜索
  37. commonSearch: true,
  38. titleForm: '', //为空则不显示标题,不定义默认显示:普通搜索
  39. });
  40. // 为表格绑定事件
  41. Table.api.bindevent(table);
  42. },
  43. add: function () {
  44. Controller.api.bindevent();
  45. },
  46. edit: function () {
  47. Controller.api.bindevent();
  48. },
  49. api: {
  50. bindevent: function () {
  51. Form.api.bindevent($("form[role=form]"));
  52. },
  53. formatter: {
  54. thumb: function (value, row, index) {
  55. //console.log(row);
  56. if (row.mimetype.indexOf("image") > -1) {
  57. var reg = /ajax\/upload$/;
  58. if (reg.test(Config.upload.uploadurl)) {
  59. return '<a href="' + Config.upload.cdnurl + value + '" target="_blank"><img src="' + Config.upload.cdnurl + value + '" alt="" style="max-height:90px;max-width:120px"></a>';
  60. } else {
  61. return '<a href="' + Config.upload.cdnurl + value + '" target="_blank"><img src="' + Config.upload.cdnurl + value + '!/fwfh/50x50" alt=""></a>';
  62. }
  63. } else {
  64. return '无';
  65. }
  66. },
  67. url: function (value, row, index) {
  68. return '<a href="' + Config.upload.cdnurl + value + '" target="_blank" class="label bg-green">' + value + '</a>';
  69. },
  70. }
  71. }
  72. };
  73. return Controller;
  74. });