App.vue 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <script>
  2. // 业绩统计打包路径 /h5 库存信息 /CKselect
  3. export default {
  4. onLaunch: function() {
  5. this.fontSizeSetting()
  6. },
  7. onHide: function() {
  8. console.log('App Hide')
  9. },
  10. methods: {
  11. fontSizeSetting() {
  12. window.onload = function() {
  13. setAndroidFontsize();
  14. htmlFontSize()
  15. }
  16. window.onresize = function() {
  17. setAndroidFontsize();
  18. htmlFontSize()
  19. }
  20. // 安卓解决微信浏览器字体被调大导致页面错乱的办法
  21. function setAndroidFontsize() {
  22. if (typeof window.WeixinJSBridge == "object" && typeof window.WeixinJSBridge.invoke == "function") {
  23. handleFontSize();
  24. } else {
  25. if (document.addEventListener) {
  26. document.addEventListener("WeixinJSBridgeReady", handleFontSize, false);
  27. } else if (document.attachEvent) {
  28. document.attachEvent("WeixinJSBridgeReady", handleFontSize);
  29. document.attachEvent("onWeixinJSBridgeReady", handleFontSize);
  30. }
  31. }
  32. }
  33. function handleFontSize() {
  34. window.WeixinJSBridge.invoke('setFontSizeCallback', {
  35. 'fontSize': 0
  36. });
  37. window.WeixinJSBridge.on('menu:setfont', function() {
  38. window.WeixinJSBridge.invoke('setFontSizeCallback', {
  39. 'fontSize': 0
  40. });
  41. });
  42. }
  43. function htmlFontSize() {
  44. var h = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
  45. var w = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
  46. var width = w > h ? h : w;
  47. width = width > 720 ? 720 : width
  48. var fz = ~~(width / 15)
  49. document.getElementsByTagName("html")[0].style.cssText = 'font-size: ' + fz + "px";
  50. var realfz = ~~(+window.getComputedStyle(document.getElementsByTagName("html")[0]).fontSize.replace(
  51. 'px', '') *
  52. 10000) / 10000
  53. if (fz !== realfz) {
  54. document.getElementsByTagName("html")[0].style.cssText = 'font-size: ' + fz * (fz / realfz) + "px";
  55. }
  56. }
  57. }
  58. }
  59. }
  60. </script>
  61. <style>
  62. /*每个页面公共css */
  63. </style>