space.core.base.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /**
  2. * @author SPACE
  3. * @date 2019年2月13日16:54
  4. */
  5. if(!window.space) {
  6. var space = {
  7. core: {
  8. dev: {
  9. page: {}
  10. }
  11. },
  12. plugins: {},
  13. utils: {}
  14. };
  15. }
  16. (function() {
  17. var currParent = window;
  18. var i = 1;
  19. while(currParent != top) {
  20. currParent = currParent.parent;
  21. }
  22. space.core.topWindow = currParent;
  23. })();
  24. space.core.dev.page.initPage = function() {
  25. space.core.dev.page.form = {};
  26. space.core.dev.page.form.rowCount = {}; // 总条数
  27. space.core.dev.page.form.rowCountPerPage = {}; // 单页数据条数
  28. space.core.dev.page.form.currentPageNo = {}; // 当前页码数
  29. space.core.dev.page.form.limits = [10, 15, 20, 25, 30]; // 单页数据条数下拉选择项
  30. }();
  31. space.core.dev.page.loadPage = function(row_count, row_count_per_page, current_page_no) {
  32. var devForm = $("#devForm");
  33. var devPage = $("#devForm").attr("devPage");
  34. // 开启分页
  35. if(devPage && devPage == "true") {
  36. // 保存分页对象
  37. with(space.core.dev.page.form) {
  38. rowCount.value = row_count;
  39. rowCountPerPage.value = row_count_per_page;
  40. currentPageNo.value = current_page_no;
  41. }
  42. // 初始化分页容器
  43. layui.laypage.render({
  44. elem: 'devPageDiv',
  45. theme: '#28a3ef',
  46. curr: space.core.dev.page.form.currentPageNo.value,
  47. limit: space.core.dev.page.form.rowCountPerPage.value,
  48. count: space.core.dev.page.form.rowCount.value,
  49. limits: space.core.dev.page.form.limits,
  50. // layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip'],
  51. layout: ['count', 'prev', 'page', 'next', 'skip'],
  52. jump: function(obj, first) {
  53. if(!first) {
  54. space.core.dev.page.goPage(obj.curr, obj.limit);
  55. }
  56. }
  57. });
  58. }
  59. }
  60. /**
  61. * 分页跳转
  62. * @param {Object} go_page_no 页码数
  63. * @param {Object} row_count_per_page 单页数据条数
  64. */
  65. space.core.dev.page.goPage = function(go_page_no, row_count_per_page) {
  66. space.core.dev.page.form.currentPageNo.value = go_page_no;
  67. space.core.dev.page.form.rowCountPerPage.value = row_count_per_page;
  68. space.core.dev.page.devFormSubmit();
  69. }
  70. /**
  71. * 表单提交,将分页对象放入隐藏域
  72. */
  73. space.core.dev.page.devFormSubmit = function() {
  74. var row_count_per_page_html = '<input type="hidden" name="currentPageNo" id="currentPageNo" value="' + space.core.dev.page.form.currentPageNo.value + '" /><br>';
  75. var current_page_no_html = '<input type="hidden" name="rowCountPerPage" id="rowCountPerPage" value="' + space.core.dev.page.form.rowCountPerPage.value + '" /><br>';
  76. $("#devForm").append(row_count_per_page_html);
  77. $("#devForm").append(current_page_no_html);
  78. $("#devForm").submit();
  79. }