remote.js 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'layui'], function ($, undefined, Backend, Table, Form, Layui) {
  2. let Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. extend: {
  7. index_url: 'special/remote/index' + location.search,
  8. add_url: 'special/remote/add',
  9. edit_url: 'special/remote/edit',
  10. del_url: 'special/remote/del',
  11. multi_url: 'special/remote/multi',
  12. table: 'special_remote',
  13. }
  14. });
  15. let table = $("#table");
  16. // 初始化表格
  17. table.bootstrapTable({
  18. url: $.fn.bootstrapTable.defaults.extend.index_url,
  19. pk: 'id',
  20. sortName: 'sort',
  21. showToggle: false,
  22. showColumns: false,
  23. showExport: false,
  24. columns: [
  25. [
  26. {field: 'sort', title: __('Sort'), searchable: false},
  27. {field: 'name', title: __('Name'), operate: 'LIKE %...%',},
  28. {field: 'color', title: __('Color'),formatter: function (value) {
  29. return '<div style="width: 20px; height: 20px; margin-left: 30px; background: '+ value +'"></div>';
  30. }, searchable: false},
  31. {field: 'describe', title: __('Describe'), searchable: false},
  32. {
  33. field: 'status',
  34. title: __('Status'),
  35. formatter: Table.api.formatter.normal,
  36. custom: {0:'danger',1:'success'},
  37. searchList: {
  38. 0: '禁用',
  39. 1: '启用',
  40. },
  41. },
  42. {
  43. field: 'check',
  44. title: __('Check'),
  45. formatter: Table.api.formatter.label,
  46. custom: {0: 'default', 1: 'success'},
  47. searchList: {
  48. 0: '否',
  49. 1: '是',
  50. },
  51. },
  52. {field: 'createdAt', title: __('Createdat'), operate:'RANGE', addclass:'datetimerange', searchable: false},
  53. {field: 'updatedAt', title: __('Updatedat'), operate:'RANGE', addclass:'datetimerange', searchable: false},
  54. {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  55. ]
  56. ]
  57. });
  58. // 为表格绑定事件
  59. Table.api.bindevent(table);
  60. },
  61. add: function () {
  62. Controller.api.bindevent();
  63. },
  64. edit: function () {
  65. Controller.api.bindevent();
  66. },
  67. api: {
  68. bindevent: function () {
  69. Layui.use('colorpicker', function(){
  70. let colorpicker = layui.colorpicker;
  71. //渲染
  72. colorpicker.render({
  73. elem : '#d-color', //绑定元素
  74. size : 'lg',
  75. color : $('#c-color').val(),
  76. change : function(color){
  77. $('#c-color').val( color );
  78. }
  79. });
  80. });
  81. Form.api.bindevent($("form[role=form]"));
  82. }
  83. }
  84. };
  85. return Controller;
  86. });