attachment.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. return '<a href="' + Config.upload.cdnurl + value + '" target="_blank"><img src="' + Config.upload.cdnurl + value + '!/fwfh/50x50" alt=""></a>';
  55. } else {
  56. return '无';
  57. }
  58. },
  59. url: function (value, row, index) {
  60. return '<a href="' + Config.upload.cdnurl + value + '" target="_blank" class="label bg-green">' + value + '</a>';
  61. },
  62. }
  63. }
  64. };
  65. return Controller;
  66. });