App.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <script>
  2. // 业绩统计打包路径 /h5 库存信息 /CKselect
  3. export default {
  4. onLaunch: function() {
  5. this.fontSizeSetting()
  6. uni.toast = (...args) => uni.showToast({
  7. duration: 5678,
  8. title: args[0],
  9. icon: 'none'
  10. });
  11. },
  12. onHide: function() {
  13. console.log('App Hide')
  14. },
  15. methods: {
  16. fontSizeSetting() {
  17. window.onload = function() {
  18. setAndroidFontsize();
  19. htmlFontSize()
  20. }
  21. window.onresize = function() {
  22. setAndroidFontsize();
  23. htmlFontSize()
  24. }
  25. // 安卓解决微信浏览器字体被调大导致页面错乱的办法
  26. function setAndroidFontsize() {
  27. if (typeof window.WeixinJSBridge == "object" && typeof window.WeixinJSBridge.invoke == "function") {
  28. handleFontSize();
  29. } else {
  30. if (document.addEventListener) {
  31. document.addEventListener("WeixinJSBridgeReady", handleFontSize, false);
  32. } else if (document.attachEvent) {
  33. document.attachEvent("WeixinJSBridgeReady", handleFontSize);
  34. document.attachEvent("onWeixinJSBridgeReady", handleFontSize);
  35. }
  36. }
  37. }
  38. function handleFontSize() {
  39. window.WeixinJSBridge.invoke('setFontSizeCallback', {
  40. 'fontSize': 0
  41. });
  42. window.WeixinJSBridge.on('menu:setfont', function() {
  43. window.WeixinJSBridge.invoke('setFontSizeCallback', {
  44. 'fontSize': 0
  45. });
  46. });
  47. }
  48. function htmlFontSize() {
  49. var h = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
  50. var w = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
  51. var width = w > h ? h : w;
  52. width = width > 720 ? 720 : width
  53. var fz = ~~(width / 15)
  54. document.getElementsByTagName("html")[0].style.cssText = 'font-size: ' + fz + "px";
  55. var realfz = ~~(+window.getComputedStyle(document.getElementsByTagName("html")[0]).fontSize.replace(
  56. 'px', '') *
  57. 10000) / 10000
  58. if (fz !== realfz) {
  59. document.getElementsByTagName("html")[0].style.cssText = 'font-size: ' + fz * (fz / realfz) + "px";
  60. }
  61. }
  62. }
  63. }
  64. }
  65. </script>
  66. <style lang="scss">
  67. @import './static/css/iconfont.css';
  68. @import 'common/style/icon.scss'; //引入 ColorUI 组件库图标样式
  69. /*每个页面公共css */
  70. page {
  71. background-color: #F5F5F5;
  72. font-size: 28rpx;
  73. }
  74. .flexV {
  75. display: flex;
  76. align-items: center;
  77. }
  78. .flexC {
  79. display: flex;
  80. align-items: center;
  81. justify-content: center;
  82. }
  83. .flexS {
  84. display: flex;
  85. align-items: center;
  86. justify-content: flex-start;
  87. }
  88. .flexB {
  89. display: flex;
  90. justify-content: space-between;
  91. align-items: center;
  92. }
  93. .flexT {
  94. display: flex;
  95. justify-content: space-between;
  96. align-items: flex-start;
  97. }
  98. </style>