attachment.js 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. if (Config.upload.bucket.replace(/^\s+|\s+$/gm,'').length === 0){
  55. return '<a href="' + Config.upload.cdnurl + value + '" target="_blank"><img src="' + Config.upload.cdnurl + value + '" alt="" style="max-height:90px;max-width:120px"></a>';
  56. } else {
  57. return '<a href="' + Config.upload.cdnurl + value + '" target="_blank"><img src="' + Config.upload.cdnurl + value + '!/fwfh/50x50" alt=""></a>';
  58. }
  59. } else {
  60. return '无';
  61. }
  62. },
  63. url: function (value, row, index) {
  64. return '<a href="' + Config.upload.cdnurl + value + '" target="_blank" class="label bg-green">' + value + '</a>';
  65. },
  66. }
  67. }
  68. };
  69. return Controller;
  70. });