bootstrap-table-mobile.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /**
  2. * 基于bootstrap-table-mobile修改
  3. * 修正部分iPhone手机不显示卡片视图
  4. * Copyright (c) 2019 ruoyi
  5. */
  6. !function ($) {
  7. 'use strict';
  8. var resetView = function (that) {
  9. if (that.options.height || that.options.showFooter) {
  10. setTimeout(that.resetView(), 1);
  11. }
  12. };
  13. // 判断是否 iphone
  14. var isIPhone = function () {
  15. var browserName = navigator.userAgent.toLowerCase();
  16. return /(iPhone|iPad|iPod|iOS)/i.test(browserName);
  17. };
  18. var changeView = function (that, width, height) {
  19. if (that.options.minHeight) {
  20. if (checkValuesLessEqual(width, that.options.minWidth) && checkValuesLessEqual(height, that.options.minHeight)) {
  21. conditionCardView(that);
  22. } else if (checkValuesGreater(width, that.options.minWidth) && checkValuesGreater(height, that.options.minHeight)) {
  23. conditionFullView(that);
  24. }
  25. } else {
  26. if (checkValuesLessEqual(width, that.options.minWidth) || isIPhone()) {
  27. conditionCardView(that);
  28. } else if (checkValuesGreater(width, that.options.minWidth)) {
  29. conditionFullView(that);
  30. }
  31. }
  32. resetView(that);
  33. };
  34. var checkValuesLessEqual = function (currentValue, targetValue) {
  35. return currentValue <= targetValue;
  36. };
  37. var checkValuesGreater = function (currentValue, targetValue) {
  38. return currentValue > targetValue;
  39. };
  40. var conditionCardView = function (that) {
  41. changeTableView(that, false);
  42. };
  43. var conditionFullView = function (that) {
  44. changeTableView(that, true);
  45. };
  46. var changeTableView = function (that, cardViewState) {
  47. that.options.cardView = cardViewState;
  48. that.toggleView();
  49. };
  50. $.extend($.fn.bootstrapTable.defaults, {
  51. mobileResponsive: false,
  52. minWidth: 562,
  53. minHeight: undefined,
  54. checkOnInit: true,
  55. toggled: false
  56. });
  57. var BootstrapTable = $.fn.bootstrapTable.Constructor,
  58. _init = BootstrapTable.prototype.init;
  59. BootstrapTable.prototype.init = function () {
  60. _init.apply(this, Array.prototype.slice.apply(arguments));
  61. if (!this.options.mobileResponsive) {
  62. return;
  63. }
  64. if (!this.options.minWidth) {
  65. return;
  66. }
  67. var that = this;
  68. $(window).resize(function () {
  69. changeView(that, $(this).width(), $(this).height())
  70. });
  71. if (this.options.checkOnInit) {
  72. changeView(this, $(window).width(), $(window).height());
  73. }
  74. };
  75. }(jQuery);