MenuService.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <template>
  2. <!-- 联系客服 -->
  3. <div class="menu_service" :width="iframeWidth">
  4. <iframe
  5. id="service-iframe"
  6. class="iframe"
  7. frameborder="no"
  8. scrolling="no"
  9. allowtransparency="yes"
  10. style="overflow: hidden"
  11. :src="`${CONFIG.serviceUrl}${userInfo && userInfo.passport}`"
  12. :width="iframeWidth"
  13. :height="iframeHeight"
  14. ></iframe>
  15. <i class="iconfont icon-baseline-close-px" @click="back"></i>
  16. </div>
  17. </template>
  18. <script>
  19. import { mapActions, mapState } from "vuex";
  20. export default {
  21. name: "MenuService",
  22. components: {},
  23. data() {
  24. return {
  25. iframeWidth: 0, // iframe宽
  26. iframeHeight: 0, // iframe高
  27. };
  28. },
  29. computed: {
  30. ...mapState(["CONFIG", "userInfo"]),
  31. },
  32. watch: {},
  33. created() {},
  34. mounted() {
  35. // 根据屏幕宽和高获取iframe高度
  36. this.h5ScreenOrientation();
  37. // 监听页面重载
  38. this.onResize();
  39. },
  40. methods: {
  41. ...mapActions(["showServiceInlineAction"]),
  42. // 返回
  43. back() {
  44. this.showInnerControl("");
  45. this.showServiceInlineAction(false);
  46. },
  47. // 显示哪个组件(工具函数)
  48. showInnerControl(name) {
  49. this.$emit("showInnerControl", name);
  50. },
  51. /**
  52. * 根据屏幕宽和高获取iframe高度
  53. */
  54. h5ScreenOrientation() {
  55. // 当前的宽
  56. const width = window.innerWidth || document.documentElement.clientWidth;
  57. // 当前的高
  58. const height =
  59. window.innerHeight || document.documentElement.clientHeight;
  60. this.iframeWidth = width;
  61. this.iframeHeight = height;
  62. },
  63. /**
  64. * 监听页面重载
  65. */
  66. onResize() {
  67. var clientHeight =
  68. document.documentElement.clientHeight || document.body.clientHeight;
  69. window.onresize = () => {
  70. // 页面resize
  71. clearTimeout(this.resizeTimer);
  72. this.resizeTimer = setTimeout(() => {
  73. this.h5ScreenOrientation();
  74. }, 1000);
  75. // 页面调起输入框
  76. var nowClientHeight =
  77. document.documentElement.clientHeight || document.body.clientHeight;
  78. if (clientHeight > nowClientHeight) {
  79. // 键盘打开
  80. clearTimeout(this.resizeTimer);
  81. this.h5ScreenOrientation();
  82. document.getElementById("app").classList.add("focusState");
  83. } else {
  84. //键盘收起的事件处理
  85. document.getElementById("app").classList.remove("focusState");
  86. this.h5ScreenOrientation();
  87. }
  88. };
  89. },
  90. },
  91. };
  92. </script>
  93. <style lang='less' scoped>
  94. .menu_service {
  95. display: flex;
  96. position: fixed;
  97. z-index: 10;
  98. background-color: #f5f5f5;
  99. i {
  100. float: right;
  101. font-size: 60 / @rem;
  102. position: absolute;
  103. top: 20 / @rem;
  104. right: 20 / @rem;
  105. border-radius: 50%;
  106. background-color: #f1f3f4;
  107. }
  108. .icon-baseline-close-px {
  109. z-index: 11;
  110. margin-right: 10 / @rem;
  111. font-size: 50 / @rem;
  112. }
  113. }
  114. // 正常横屏样式
  115. @media all and (orientation: landscape),
  116. /** 伪竖屏*/all and (orientation: portrait) and (min-width: 600px) and (min-height: 800px) {
  117. .menu_service {
  118. .icon-baseline-close-px {
  119. margin-top: 10 / @rem;
  120. margin-right: 5 / @rem;
  121. font-size: 25 / @rem;
  122. }
  123. }
  124. }
  125. // ipad 横屏
  126. @media /** 伪竖屏*/all and (orientation: portrait) and (min-width: 600px) and (min-height: 800px),
  127. /**ipad伪横屏 */ all and (orientation: landscape) and (min-width: 800px) and (min-height: 600px),
  128. all and (min-device-aspect-ratio: 3/4) and (max-device-aspect-ratio: 4/3),
  129. all and (device-aspect-ratio: 4/3) {
  130. }
  131. </style>