page.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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'), operate: 'LIKE %...%', placeholder: '标题,模糊搜索,*表示任意字符', style: 'width:200px',
  26. process: function (value, arg) {
  27. return value.replace(/\*/g, '%'); //仅演示用法
  28. }
  29. },
  30. {field: 'keywords', title: __('Keywords'), operate: 'LIKE %...%', placeholder: '关键字,模糊搜索'},
  31. {field: 'flag', title: __('Flag'), formatter: Table.api.formatter.flag, operate: false},
  32. {field: 'image', title: __('Image'), formatter: Table.api.formatter.image, operate: false},
  33. {field: 'icon', title: __('Icon'), formatter: Table.api.formatter.icon, operate: false},
  34. {field: 'views', title: __('Views'), operate: false},
  35. {field: 'comments', title: __('Comments'), operate: false},
  36. {field: 'weigh', title: __('Weigh'), operate: false},
  37. {field: 'status', title: __('Status'), formatter: Table.api.formatter.status, searchList: {'normal': '正常', 'hidden': '隐藏'}, style: 'min-width:100px;'},
  38. {field: 'createtime', title: __('Create Time'), formatter: Table.api.formatter.datetime, operate: 'BETWEEN', type: 'datetime', addclass: 'datetimepicker', data: 'data-date-format="YYYY-MM-DD"'},
  39. {field: 'operate', title: __('Operate'), events: Table.api.events.operate, formatter: Table.api.formatter.operate}
  40. ]
  41. ],
  42. //普通搜索
  43. commonSearch: true,
  44. titleForm: '', //为空则不显示标题,不定义默认显示:普通搜索
  45. });
  46. // 为表格绑定事件
  47. Table.api.bindevent(table);
  48. },
  49. add: function () {
  50. Controller.api.bindevent();
  51. },
  52. edit: function () {
  53. Controller.api.bindevent();
  54. },
  55. api: {
  56. bindevent: function () {
  57. $("form[role=form]").validator({
  58. rules: {
  59. mobile: [/^1[3-9]\d{9}$/, "请填写有效的手机号"],
  60. chinese: [/^[\u0391-\uFFE5]+$/, "请填写中文字符"],
  61. // 使用函数定义规则
  62. phone: function (elem, param) {
  63. return /^1[3458]\d{9}$/.test($(elem).val()) || '请检查手机号格式';
  64. },
  65. image: function (elem, param) {
  66. return /^\/(.*)\.(jpg|jpeg|png|gif)$/.test($(elem).val()) || '请上传有并行的图片文件';
  67. }
  68. },
  69. messages: {
  70. },
  71. fields: {
  72. 'row[title]': "required;length(3~16)",
  73. 'row[image]': "required;image",
  74. 'row[views]': "required;range[0~100]",
  75. 'row[content]': "required"
  76. },
  77. });
  78. Form.api.bindevent($("form[role=form]"));
  79. }
  80. }
  81. };
  82. return Controller;
  83. });