attachment.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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: 'admin_id', title: __('Admin_id'), visible: false, addClass: "selectpage", extend: "data-source='auth/admin/index' data-field='nickname'"},
  25. {field: 'user_id', title: __('User_id'), visible: false, addClass: "selectpage", extend: "data-source='user/user/index' data-field='nickname'"},
  26. {field: 'url', title: __('Preview'), formatter: Controller.api.formatter.thumb, operate: false},
  27. {field: 'url', title: __('Url'), formatter: Controller.api.formatter.url},
  28. {field: 'imagewidth', title: __('Imagewidth'), sortable: true},
  29. {field: 'imageheight', title: __('Imageheight'), sortable: true},
  30. {field: 'imagetype', title: __('Imagetype'), formatter: Table.api.formatter.search},
  31. {field: 'storage', title: __('Storage'), formatter: Table.api.formatter.search},
  32. {field: 'filesize', title: __('Filesize'), operate: 'BETWEEN', sortable: true},
  33. {field: 'mimetype', title: __('Mimetype'), formatter: Table.api.formatter.search},
  34. {
  35. field: 'createtime',
  36. title: __('Createtime'),
  37. formatter: Table.api.formatter.datetime,
  38. operate: 'RANGE',
  39. addclass: 'datetimerange',
  40. sortable: true
  41. },
  42. {
  43. field: 'operate',
  44. title: __('Operate'),
  45. table: table,
  46. events: Table.api.events.operate,
  47. formatter: Table.api.formatter.operate
  48. }
  49. ]
  50. ],
  51. });
  52. // 为表格绑定事件
  53. Table.api.bindevent(table);
  54. },
  55. select: function () {
  56. // 初始化表格参数配置
  57. Table.api.init({
  58. extend: {
  59. index_url: 'general/attachment/select',
  60. }
  61. });
  62. var table = $("#table");
  63. // 初始化表格
  64. table.bootstrapTable({
  65. url: $.fn.bootstrapTable.defaults.extend.index_url,
  66. sortName: 'id',
  67. showToggle: false,
  68. showExport: false,
  69. columns: [
  70. [
  71. {field: 'state', checkbox: true,},
  72. {field: 'id', title: __('Id')},
  73. {field: 'admin_id', title: __('Admin_id'), visible: false},
  74. {field: 'user_id', title: __('User_id'), visible: false},
  75. {field: 'url', title: __('Preview'), formatter: Controller.api.formatter.thumb, operate: false},
  76. {field: 'imagewidth', title: __('Imagewidth'), operate: false},
  77. {field: 'imageheight', title: __('Imageheight'), operate: false},
  78. {
  79. field: 'mimetype', title: __('Mimetype'), operate: 'LIKE %...%',
  80. process: function (value, arg) {
  81. return value.replace(/\*/g, '%');
  82. }
  83. },
  84. {field: 'createtime', title: __('Createtime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true},
  85. {
  86. field: 'operate', title: __('Operate'), events: {
  87. 'click .btn-chooseone': function (e, value, row, index) {
  88. var multiple = Backend.api.query('multiple');
  89. multiple = multiple == 'true' ? true : false;
  90. Fast.api.close({url: row.url, multiple: multiple});
  91. },
  92. }, formatter: function () {
  93. return '<a href="javascript:;" class="btn btn-danger btn-chooseone btn-xs"><i class="fa fa-check"></i> ' + __('Choose') + '</a>';
  94. }
  95. }
  96. ]
  97. ]
  98. });
  99. // 选中多个
  100. $(document).on("click", ".btn-choose-multi", function () {
  101. var urlArr = new Array();
  102. $.each(table.bootstrapTable("getAllSelections"), function (i, j) {
  103. urlArr.push(j.url);
  104. });
  105. var multiple = Backend.api.query('multiple');
  106. multiple = multiple == 'true' ? true : false;
  107. Fast.api.close({url: urlArr.join(","), multiple: multiple});
  108. });
  109. // 为表格绑定事件
  110. Table.api.bindevent(table);
  111. require(['upload'], function (Upload) {
  112. Upload.api.plupload($("#toolbar .plupload"), function () {
  113. $(".btn-refresh").trigger("click");
  114. });
  115. });
  116. },
  117. add: function () {
  118. Controller.api.bindevent();
  119. },
  120. edit: function () {
  121. Controller.api.bindevent();
  122. },
  123. api: {
  124. bindevent: function () {
  125. Form.api.bindevent($("form[role=form]"));
  126. },
  127. formatter: {
  128. thumb: function (value, row, index) {
  129. if (row.mimetype.indexOf("image") > -1) {
  130. var style = row.storage == 'upyun' ? '!/fwfh/120x90' : '';
  131. return '<a href="' + row.fullurl + '" target="_blank"><img src="' + row.fullurl + style + '" alt="" style="max-height:90px;max-width:120px"></a>';
  132. } else {
  133. return '<a href="' + row.fullurl + '" target="_blank"><img src="https://tool.fastadmin.net/icon/' + row.imagetype + '.png" alt=""></a>';
  134. }
  135. },
  136. url: function (value, row, index) {
  137. return '<a href="' + row.fullurl + '" target="_blank" class="label bg-green">' + value + '</a>';
  138. },
  139. }
  140. }
  141. };
  142. return Controller;
  143. });