You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

178 lines
8.4 KiB

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