attachment.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. define(['jquery', 'bootstrap', 'backend', 'form', 'table'], function ($, undefined, Backend, Form, Table) {
  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. select: function () {
  41. // 初始化表格参数配置
  42. Table.api.init({
  43. extend: {
  44. index_url: 'general/attachment/select',
  45. }
  46. });
  47. var table = $("#table");
  48. // 初始化表格
  49. table.bootstrapTable({
  50. url: $.fn.bootstrapTable.defaults.extend.index_url,
  51. sortName: 'id',
  52. columns: [
  53. [
  54. {field: 'state', checkbox: true, },
  55. {field: 'id', title: __('Id')},
  56. {field: 'url', title: __('Preview'), formatter: Controller.api.formatter.thumb},
  57. {field: 'imagewidth', title: __('Imagewidth')},
  58. {field: 'imageheight', title: __('Imageheight')},
  59. {field: 'mimetype', title: __('Mimetype'), operate: 'LIKE %...%',
  60. process: function (value, arg) {
  61. return value.replace(/\*/g, '%');
  62. }},
  63. {field: 'createtime', title: __('Createtime'), formatter: Table.api.formatter.datetime},
  64. {field: 'operate', title: __('Operate'), events: {
  65. 'click .btn-chooseone': function (e, value, row, index) {
  66. var callback = Backend.api.query('callback');
  67. var id = Backend.api.query('element_id');
  68. var multiple = Backend.api.query('multiple');
  69. multiple = multiple == 'true' ? true : false;
  70. if (id && callback) {
  71. parent.window[callback](id, {url: row.url}, multiple);
  72. }
  73. },
  74. }, formatter: function () {
  75. return '<a href="javascript:;" class="btn btn-danger btn-chooseone btn-xs"><i class="fa fa-check"></i> ' + __('Choose') + '</a>';
  76. }}
  77. ]
  78. ]
  79. });
  80. // 选中多个
  81. $(document).on("click", ".btn-choose-multi", function () {
  82. var callback = Backend.api.query('callback');
  83. var id = Backend.api.query('element_id');
  84. var urlArr = new Array();
  85. $.each(table.bootstrapTable("getAllSelections"), function (i, j) {
  86. urlArr.push(j.url);
  87. });
  88. parent.window[callback](id, {url: urlArr.join(",")}, true);
  89. });
  90. // 为表格绑定事件
  91. Table.api.bindevent(table);
  92. },
  93. add: function () {
  94. Controller.api.bindevent();
  95. },
  96. edit: function () {
  97. Controller.api.bindevent();
  98. },
  99. api: {
  100. bindevent: function () {
  101. Form.api.bindevent($("form[role=form]"));
  102. },
  103. formatter: {
  104. thumb: function (value, row, index) {
  105. if (row.mimetype.indexOf("image") > -1) {
  106. var reg = /ajax\/upload$/;
  107. if (reg.test(Config.upload.uploadurl)) {
  108. return '<a href="' + Config.upload.cdnurl + value + '" target="_blank"><img src="' + Config.upload.cdnurl + value + '" alt="" style="max-height:90px;max-width:120px"></a>';
  109. } else {
  110. return '<a href="' + Config.upload.cdnurl + value + '" target="_blank"><img src="' + Config.upload.cdnurl + value + '!/fwfh/50x50" alt=""></a>';
  111. }
  112. } else {
  113. return '无';
  114. }
  115. },
  116. url: function (value, row, index) {
  117. return '<a href="' + Config.upload.cdnurl + value + '" target="_blank" class="label bg-green">' + value + '</a>';
  118. },
  119. }
  120. }
  121. };
  122. return Controller;
  123. });