page.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. extend: {
  7. index_url: 'page/index',
  8. add_url: 'page/add',
  9. edit_url: 'page/edit',
  10. del_url: 'page/del',
  11. multi_url: 'page/multi',
  12. table: 'page',
  13. }
  14. });
  15. var table = $("#table");
  16. // 初始化表格
  17. table.bootstrapTable({
  18. url: $.fn.bootstrapTable.defaults.extend.index_url,
  19. sortName: 'weigh',
  20. columns: [
  21. [
  22. {field: 'state', checkbox: true},
  23. {field: 'id', title: __('Id'), operate: false},
  24. {field: 'category_id', title: __('Category_id'), operate: '='},
  25. {field: 'title', title: __('Title'),
  26. operate: 'LIKE %...%',
  27. placeholder: '标题,模糊搜索,*表示任意字符',
  28. style: 'width:200px',
  29. process: function (value, arg) {
  30. return value.replace(/\*/g, '%'); //仅演示用法
  31. }
  32. },
  33. {field: 'keywords', title: __('Keywords'), operate: 'LIKE %...%', placeholder: '关键字,模糊搜索'},
  34. {field: 'flag', title: __('Flag'), formatter: Table.api.formatter.flag, operate: false},
  35. {field: 'image', title: __('Image'), formatter: Table.api.formatter.image, operate: false},
  36. {field: 'icon', title: __('Icon'), formatter: Table.api.formatter.icon, operate: false},
  37. {field: 'views', title: __('Views'), operate: false},
  38. {field: 'comments', title: __('Comments'), operate: false},
  39. {field: 'weigh', title: __('Weigh'), operate: false},
  40. {field: 'status', title: __('Status'), formatter: Table.api.formatter.status, searchList: {'normal': __('Normal'), 'hidden': __('Hidden')}, style: 'min-width:100px;'},
  41. {field: 'createtime', title: __('Create Time'), formatter: Table.api.formatter.datetime, operate: 'BETWEEN', type: 'datetime', addclass: 'datetimepicker', data: 'data-date-format="YYYY-MM-DD"'},
  42. {field: 'operate', title: __('Operate'), events: Controller.api.events.operate, formatter: Controller.api.formatter.operate}
  43. ]
  44. ],
  45. //普通搜索
  46. commonSearch: true,
  47. titleForm: '', //为空则不显示标题,不定义默认显示:普通搜索
  48. });
  49. // 为表格绑定事件
  50. Table.api.bindevent(table);
  51. },
  52. add: function () {
  53. Controller.api.bindevent();
  54. },
  55. edit: function () {
  56. Controller.api.bindevent();
  57. },
  58. api: {
  59. bindevent: function () {
  60. $("form[role=form]").validator({
  61. rules: {
  62. mobile: [/^1[3-9]\d{9}$/, "请填写有效的手机号"],
  63. chinese: [/^[\u0391-\uFFE5]+$/, "请填写中文字符"],
  64. // 使用函数定义规则
  65. phone: function (elem, param) {
  66. return /^1[3458]\d{9}$/.test($(elem).val()) || '请检查手机号格式';
  67. },
  68. image: function (elem, param) {
  69. return /^\/(.*)\.(jpg|jpeg|png|gif)$/.test($(elem).val()) || '请上传有并行的图片文件';
  70. }
  71. },
  72. messages: {
  73. },
  74. fields: {
  75. 'row[title]': "required;length(3~16)",
  76. 'row[image]': "required;image",
  77. 'row[views]': "required;range[0~100]",
  78. 'row[content]': "required"
  79. },
  80. });
  81. Form.api.bindevent($("form[role=form]"));
  82. },
  83. formatter: {
  84. operate: function (value, row, index) {
  85. return '<a class="btn btn-info btn-xs btn-detail">' + __('Detail') + '</a> ' + Table.api.formatter.operate(value, row, index);
  86. },
  87. },
  88. events: {
  89. operate: $.extend({
  90. 'click .btn-detail': function (e, value, row, index) {
  91. Backend.api.open("page/detail/" + value, __('Detail'));
  92. }
  93. }, Table.api.events.operate)
  94. }
  95. }
  96. };
  97. return Controller;
  98. });