App.vue 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <script>
  2. export default {
  3. onLaunch: function() {
  4. this.fontSizeSetting()
  5. },
  6. onHide: function() {
  7. console.log('App Hide')
  8. },
  9. methods: {
  10. fontSizeSetting() {
  11. window.onload = function() {
  12. setAndroidFontsize();
  13. htmlFontSize()
  14. }
  15. window.onresize = function() {
  16. setAndroidFontsize();
  17. htmlFontSize()
  18. }
  19. // 安卓解决微信浏览器字体被调大导致页面错乱的办法
  20. function setAndroidFontsize() {
  21. if (typeof window.WeixinJSBridge == "object" && typeof window.WeixinJSBridge.invoke == "function") {
  22. handleFontSize();
  23. } else {
  24. if (document.addEventListener) {
  25. document.addEventListener("WeixinJSBridgeReady", handleFontSize, false);
  26. } else if (document.attachEvent) {
  27. document.attachEvent("WeixinJSBridgeReady", handleFontSize);
  28. document.attachEvent("onWeixinJSBridgeReady", handleFontSize);
  29. }
  30. }
  31. }
  32. function handleFontSize() {
  33. window.WeixinJSBridge.invoke('setFontSizeCallback', {
  34. 'fontSize': 0
  35. });
  36. window.WeixinJSBridge.on('menu:setfont', function() {
  37. window.WeixinJSBridge.invoke('setFontSizeCallback', {
  38. 'fontSize': 0
  39. });
  40. });
  41. }
  42. function htmlFontSize() {
  43. var h = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
  44. var w = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
  45. var width = w > h ? h : w;
  46. width = width > 720 ? 720 : width
  47. var fz = ~~(width / 15)
  48. document.getElementsByTagName("html")[0].style.cssText = 'font-size: ' + fz + "px";
  49. var realfz = ~~(+window.getComputedStyle(document.getElementsByTagName("html")[0]).fontSize.replace(
  50. 'px', '') *
  51. 10000) / 10000
  52. if (fz !== realfz) {
  53. document.getElementsByTagName("html")[0].style.cssText = 'font-size: ' + fz * (fz / realfz) + "px";
  54. }
  55. }
  56. }
  57. }
  58. }
  59. </script>
  60. <style lang="scss">
  61. @import "@/uni_modules/uview-ui/index.scss";
  62. /*每个页面公共css */
  63. page {
  64. font-size: 28rpx;
  65. color: #333;
  66. }
  67. .flex {
  68. display: flex;
  69. align-items: center;
  70. }
  71. .flexC {
  72. display: flex;
  73. flex-direction: column;
  74. align-items: center;
  75. }
  76. .flexS {
  77. display: flex;
  78. align-items: center;
  79. justify-content: space-between;
  80. }
  81. .u-checkbox__icon-wrap {
  82. margin: 0 !important;
  83. }
  84. .uni-system-preview-image {
  85. background-color: #fff !important;
  86. }
  87. </style>