file.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. $(".btn-add").data("area", ["1020px", "775px"]);
  5. // 初始化表格参数配置
  6. Table.api.init();
  7. this.table.first();
  8. this.table.second();
  9. $('#myModal').on('click','#J_new_folder', function () {
  10. var pid = $("#one #pid").val();
  11. // alert();
  12. var folder_name = $('#folder_name').val();
  13. if (folder_name){
  14. $.get('file/make_folder',{pid:pid,name:folder_name},function(res){
  15. if (res.code == 1){
  16. $('#myModal').modal('hide')
  17. $("#toolbar1 .btn-refresh").trigger("click");
  18. Toastr.success(res.msg);
  19. }else{
  20. Toastr.error(res.msg);
  21. }
  22. });
  23. }else{
  24. alert('请输入文件夹名称')
  25. }
  26. });
  27. },
  28. table: {
  29. first: function () {
  30. // 表格1
  31. var table1 = $("#table1");
  32. table1.bootstrapTable({
  33. url: 'file/index' + location.search+'&type=folder',
  34. extend: {
  35. index_url: 'file/index' + location.search+'&type=folder',
  36. add_url: 'file/add',
  37. edit_url: 'file/edit',
  38. del_url: 'file/del',
  39. multi_url: 'file/multi',
  40. import_url: '',
  41. table: 'file',
  42. },
  43. toolbar: '#toolbar1',
  44. sortName: 'id',
  45. search: false,
  46. pagination: false,
  47. columns: [
  48. [
  49. {field: 'pid', title: __('Pid'),visible:false},
  50. {
  51. field: 'operate', title: __('文件夹'), table: table1, events: Table.api.events.operate, buttons: [
  52. {
  53. name: 'log',
  54. title: '',
  55. text: function(row){return row.name},
  56. classname: 'btn text-success btn-click btn-custom',
  57. click: function (e, data) {
  58. if(data.id>0){
  59. $("#back").data('pid',data.id);
  60. $("#back").removeClass('hide');
  61. }else{
  62. $("#back").data('pid',0);
  63. $("#back").addClass('hide');
  64. }
  65. $("#myTabContent2 .form-commonsearch input[name='pid']").val(data.id);
  66. $("#myTabContent2 .form-commonsearch input[name='type']").val('file');
  67. $("#myTabContent2 .btn-refresh").trigger("click");
  68. $("#one #pid").val(data.id);
  69. $("#one .btn-refresh").trigger("click");
  70. $('#btn-upload-file').data('url','file/upload?pid='+data.id);
  71. Controller.api.reloadupload();
  72. }
  73. }
  74. ], formatter: Table.api.formatter.operate
  75. }
  76. ]
  77. ]
  78. });
  79. $('#back').click(function(){
  80. var ids = $("#one #pid").val();;
  81. if(ids>0){
  82. $.get('file/get_pid',{'ids':ids},function(res){
  83. $("#myTabContent2 .form-commonsearch input[name='pid']").val(res.data);
  84. $("#myTabContent2 .form-commonsearch input[name='type']").val('file');
  85. $("#myTabContent2 .btn-refresh").trigger("click");
  86. $("#one #pid").val(res.data);
  87. $("#one .btn-refresh").trigger("click");
  88. $('#btn-upload-file').data('url','file/upload?pid='+res.data);
  89. Controller.api.reloadupload();
  90. });
  91. }
  92. });
  93. // 为表格1绑定事件
  94. Table.api.bindevent(table1);
  95. },
  96. second: function () {
  97. // 表格2
  98. var table2 = $("#table2");
  99. table2.bootstrapTable({
  100. url: 'file/index' + location.search,
  101. extend: {
  102. index_url: 'file/index' + location.search,
  103. add_url: 'file/add',
  104. edit_url: 'file/edit',
  105. del_url: 'file/del',
  106. multi_url: 'file/multi',
  107. import_url: '',
  108. table: 'file',
  109. },
  110. toolbar: '#toolbar2',
  111. sortName: 'id',
  112. search: false,
  113. columns: [
  114. [
  115. {checkbox: true},
  116. // {field: 'id', title: __('Id')},
  117. {field: 'pid', title: __('Pid'),visible:false},
  118. {field: 'name', title: __('Name'), operate: 'LIKE',formatter: Controller.api.formatter.url,align:'left'},
  119. {field: 'url', title: __('Url'), operate: 'LIKE', formatter: Table.api.formatter.url,visible:false},
  120. {field: 'type', title: __('Type'), operate: 'LIKE',visible:false},
  121. {field: 'size', title: __('Size'), operate: 'LIKE'},
  122. {field: 'admin_name', title: __('上传人')},
  123. {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime,visible:false},
  124. {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  125. {field: 'operate', title: __('Operate'), table: table2, events: Table.api.events.operate,buttons:[
  126. {
  127. name:'下载',
  128. title:'下载',
  129. text:'下载',
  130. icon:'fa fa-download',
  131. url:function(row){
  132. return row.url;
  133. },
  134. classname:'btn btn-info btn-xs',
  135. extend:'download=""',
  136. visible:function(row){
  137. if(row.type=='file'){
  138. return true;
  139. }
  140. return false;
  141. }
  142. }
  143. ], formatter:
  144. function(value, row, index) {
  145. var that = $.extend({}, this);
  146. var table = $(that.table).clone(true);
  147. // operate-edit编辑 perate-del删除
  148. //判断什么时候显示什么时候不显示
  149. if (row.is_me != 1) {
  150. $(table).data("operate-del", null); // 列表页面隐藏 .编辑operate-edit - 删除按钮operate-del
  151. $(table).data("operate-edit", null); // 列表页面隐藏 .编辑operate-edit - 删除按钮operate-del
  152. }
  153. that.table = table2;
  154. return Table.api.formatter.operate.call(that, value, row, index);
  155. }
  156. }
  157. ]
  158. ]
  159. });
  160. var toolbar = ".toolbar";
  161. if ($('.btn-updata', toolbar).size() > 0) {
  162. require(['upload'], function (Upload) {
  163. Upload.api.upload($('.btn-updata', toolbar), function (data, ret) {
  164. table2.trigger("uncheckbox");
  165. table2.bootstrapTable('refresh');
  166. if(data == 1){
  167. Toastr.success('操作成功');
  168. }else{
  169. Toastr.error('操作失败');
  170. }
  171. });
  172. });
  173. }
  174. // 为表格2绑定事件
  175. Table.api.bindevent(table2);
  176. table2.on('post-body.bs.table', function () {
  177. $(".btn-editone").data("area", ["460px", "280px"]);
  178. })
  179. }
  180. },
  181. // index: function () {
  182. // var pid = $("#page_pid").val()||0;
  183. // // 初始化表格参数配置
  184. // Table.api.init({
  185. // extend: {
  186. // index_url: 'file/index' + location.search,
  187. // add_url: 'file/add',
  188. // edit_url: 'file/edit',
  189. // del_url: 'file/del',
  190. // multi_url: 'file/multi',
  191. // import_url: '',
  192. // table: 'file',
  193. // }
  194. // });
  195. // var table = $("#table");
  196. // // 初始化表格
  197. // table.bootstrapTable({
  198. // url: $.fn.bootstrapTable.defaults.extend.index_url,
  199. // pk: 'id',
  200. // sortName: 'type',
  201. // sortOrder: 'desc',
  202. // columns: [
  203. // [
  204. // {checkbox: true},
  205. // // {field: 'id', title: __('Id')},
  206. // {field: 'pid', title: __('Pid'),visible:false},
  207. // {field: 'name', title: __('Name'), operate: 'LIKE',formatter: Controller.api.formatter.url,align:'left'},
  208. // {field: 'url', title: __('Url'), operate: 'LIKE', formatter: Table.api.formatter.url,visible:false},
  209. // {field: 'type', title: __('Type'), operate: 'LIKE',visible:false},
  210. // {field: 'size', title: __('Size'), operate: 'LIKE'},
  211. // {field: 'admin_name', title: __('上传人')},
  212. // {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime,visible:false},
  213. // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
  214. // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,buttons:[
  215. // {
  216. // name:'下载',
  217. // title:'下载',
  218. // text:'下载',
  219. // icon:'fa fa-download',
  220. // url:function(row){
  221. // return row.url;
  222. // },
  223. // classname:'btn btn-info',
  224. // extend:'download=""',
  225. // visible:function(row){
  226. // if(row.type=='file'){
  227. // return true;
  228. // }
  229. // return false;
  230. // }
  231. // }
  232. // ], formatter:
  233. // function(value, row, index) {
  234. // var that = $.extend({}, this);
  235. // var table = $(that.table).clone(true);
  236. // // operate-edit编辑 perate-del删除
  237. // //判断什么时候显示什么时候不显示
  238. // if (row.is_me != 1) {
  239. // $(table).data("operate-del", null); // 列表页面隐藏 .编辑operate-edit - 删除按钮operate-del
  240. // $(table).data("operate-edit", null); // 列表页面隐藏 .编辑operate-edit - 删除按钮operate-del
  241. // }
  242. // that.table = table;
  243. // return Table.api.formatter.operate.call(that, value, row, index);
  244. // }
  245. // }
  246. // ]
  247. // ]
  248. // });
  249. // $('#myModal').on('click','#J_new_folder', function () {
  250. // var folder_name = $('#folder_name').val();
  251. // if (folder_name){
  252. // $.get('file/make_folder',{pid:pid,name:folder_name},function(res){
  253. // if (res.code == 1){
  254. // $('#myModal').modal('hide')
  255. // var container = $("#table").data("bootstrap.table").$container;
  256. // var options = $("#table").bootstrapTable('getOptions');
  257. // $("form.form-commonsearch", container).trigger('submit');
  258. // Toastr.success(res.msg);
  259. // }else{
  260. // Toastr.error(res.msg);
  261. // }
  262. // });
  263. // }else{
  264. // alert('请输入文件夹名称')
  265. // }
  266. // })
  267. // var toolbar = ".toolbar";
  268. // // 导入按钮事件
  269. // if ($('.btn-updata', toolbar).size() > 0) {
  270. // require(['upload'], function (Upload) {
  271. // Upload.api.upload($('.btn-updata', toolbar), function (data, ret) {
  272. // table.trigger("uncheckbox");
  273. // table.bootstrapTable('refresh');
  274. // if(data == 1){
  275. // Toastr.success('操作成功');
  276. // }else{
  277. // Toastr.error('操作失败');
  278. // }
  279. // });
  280. // });
  281. // }
  282. // // 为表格绑定事件
  283. // Table.api.bindevent(table);
  284. // table.on('post-body.bs.table',function(){
  285. // $(".btn-editone").data("area",["450px","360px"]);
  286. // })
  287. // table.on('post-common-search.bs.table',function(){
  288. // console.log('search')
  289. // });
  290. // },
  291. recyclebin: function () {
  292. // 初始化表格参数配置
  293. Table.api.init({
  294. extend: {
  295. 'dragsort_url': ''
  296. }
  297. });
  298. var table = $("#table");
  299. // 初始化表格
  300. table.bootstrapTable({
  301. url: 'file/recyclebin' + location.search,
  302. pk: 'id',
  303. sortName: 'id',
  304. columns: [
  305. [
  306. {checkbox: true},
  307. {field: 'id', title: __('Id')},
  308. {field: 'name', title: __('Name'), align: 'left'},
  309. {
  310. field: 'deletetime',
  311. title: __('Deletetime'),
  312. operate: 'RANGE',
  313. addclass: 'datetimerange',
  314. formatter: Table.api.formatter.datetime
  315. },
  316. {
  317. field: 'operate',
  318. width: '130px',
  319. title: __('Operate'),
  320. table: table,
  321. events: Table.api.events.operate,
  322. buttons: [
  323. {
  324. name: 'Restore',
  325. text: __('Restore'),
  326. classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
  327. icon: 'fa fa-rotate-left',
  328. url: 'file/restore',
  329. refresh: true
  330. },
  331. {
  332. name: 'Destroy',
  333. text: __('Destroy'),
  334. classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
  335. icon: 'fa fa-times',
  336. url: 'file/destroy',
  337. refresh: true
  338. }
  339. ],
  340. formatter: Table.api.formatter.operate
  341. }
  342. ]
  343. ]
  344. });
  345. // 为表格绑定事件
  346. Table.api.bindevent(table);
  347. },
  348. add: function () {
  349. Controller.api.bindevent();
  350. },
  351. edit: function () {
  352. Controller.api.bindevent();
  353. },
  354. api: {
  355. bindevent: function () {
  356. Form.api.bindevent($("form[role=form]"));
  357. },
  358. formatter: {//渲染的方法
  359. url: function (value, row, index) {
  360. if(row.type!='folder')return '<a href="'+ (row.url||'') +'" class="btn-ip" target="_blank" download=""><i class="fa fa-file text-danger"></i> '+value + '</a>';
  361. return '<a href="?pid='+row.id+'" class=" btn-ip" data-toggle="tooltip" title="" data-field="pid" data-value="'+row.id+'" data-original-title="'+value+'" '+index+'><i style="color: #E1BF4C" class="fa fa-folder"></i> '+value+'</a>';
  362. },
  363. operate:function (value, row, index) {
  364. return '<a href="/file/edit/ids/'+row.id+'" class="btn btn-xs btn-success btn-editone" data-toggle="tooltip" title="" data-table-id="table" data-field-index="9" data-row-index="0" data-button-index="1" data-original-title="编辑"><i class="fa fa-pencil"></i></a> <a href="javascript:;" class="btn btn-xs btn-danger btn-delone" data-toggle="tooltip" title="删除" data-table-id="table" data-field-index="9" data-row-index="0" data-button-index="2"><i class="fa fa-trash"></i></a>'
  365. },
  366. },
  367. events: {
  368. url: {
  369. //格式为:方法名+空格+DOM元素
  370. // 'click .btn-ip': function (e, value, row, index) {
  371. // e.stopPropagation();
  372. // var container = $("#table").data("bootstrap.table").$container;
  373. // var options = $("#table").bootstrapTable('getOptions');
  374. // //这里我们手动将数据填充到表单然后提交
  375. // $("form.form-commonsearch [name='pid']", container).val(row.pid);
  376. // $("form.form-commonsearch", container).trigger('submit');
  377. // }
  378. },
  379. }
  380. ,reloadupload:function(){
  381. var table2 = $('#table2');
  382. var toolbar = ".toolbar";
  383. if ($('.btn-updata', toolbar).size() > 0) {
  384. require(['upload'], function (Upload) {
  385. Upload.api.upload($('.btn-updata', toolbar), function (data, ret) {
  386. table2.trigger("uncheckbox");
  387. table2.bootstrapTable('refresh');
  388. if(data == 1){
  389. Toastr.success('操作成功');
  390. }else{
  391. Toastr.error('操作失败');
  392. }
  393. });
  394. });
  395. }
  396. }
  397. }
  398. };
  399. return Controller;
  400. });