app.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { computed } from 'vue'
  2. import { useStore, mapGetters } from 'vuex'
  3. import store from '@/store/index'
  4. import platform from '@/core/platform'
  5. // 字符串驼峰转中划线
  6. const formatToLine = value => {
  7. return value.replace(/([A-Z])/g, '-$1').toLowerCase()
  8. }
  9. // 主题样式 (因小程序端不支持styleObject语法,所以需要转换成字符串)
  10. const appTheme2Str = appTheme => {
  11. let str = ''
  12. for (const index in appTheme) {
  13. const name = formatToLine(index)
  14. str += `--${name}:${appTheme[index]};`
  15. }
  16. return str
  17. }
  18. export default {
  19. data() {
  20. return {
  21. platform
  22. }
  23. },
  24. computed: {
  25. appTheme: () => store.getters.appTheme,
  26. appThemeStyle: () => appTheme2Str(store.getters.appTheme)
  27. },
  28. mounted() {
  29. // #ifdef H5
  30. // 微信公众号端隐藏 navigationBar (解决双标题栏问题)
  31. if (this.platform === 'WXOFFICIAL') {
  32. this.hideNavigationBar()
  33. }
  34. // #endif
  35. },
  36. methods: {
  37. // #ifdef H5
  38. // 隐藏 navigationBar
  39. hideNavigationBar() {
  40. this.$nextTick(() => {
  41. const navTitleDom = document.getElementsByTagName('uni-page-head')
  42. if (navTitleDom.length) {
  43. navTitleDom[0].style.display = 'none'
  44. document.body.style.setProperty('--window-top', '0px');
  45. }
  46. })
  47. }
  48. // #endif
  49. }
  50. }