attachment.js 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. // 为表格绑定事件
  38. Table.api.bindevent(table);
  39. },
  40. add: function () {
  41. Controller.api.bindevent();
  42. },
  43. edit: function () {
  44. Controller.api.bindevent();
  45. },
  46. api: {
  47. bindevent: function () {
  48. Form.api.bindevent($("form[role=form]"));
  49. },
  50. formatter: {
  51. thumb: function (value, row, index) {
  52. //console.log(row);
  53. if (row.mimetype.indexOf("image") > -1) {
  54. var reg = /ajax\/upload$/;
  55. if (reg.test(Config.upload.uploadurl)) {
  56. return '<a href="' + Config.upload.cdnurl + value + '" target="_blank"><img src="' + Config.upload.cdnurl + value + '" alt="" style="max-height:90px;max-width:120px"></a>';
  57. } else {
  58. return '<a href="' + Config.upload.cdnurl + value + '" target="_blank"><img src="' + Config.upload.cdnurl + value + '!/fwfh/50x50" alt=""></a>';
  59. }
  60. } else {
  61. return '无';
  62. }
  63. },
  64. url: function (value, row, index) {
  65. return '<a href="' + Config.upload.cdnurl + value + '" target="_blank" class="label bg-green">' + value + '</a>';
  66. },
  67. }
  68. }
  69. };
  70. return Controller;
  71. });