NavHeader.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <template>
  2. <div
  3. class="header"
  4. style="height:44px"
  5. :style="{ paddingTop: systemInfo.statusBarHeight + 'px', color: fontColor, backgroundColor: bgColor }"
  6. >
  7. <van-icon name="arrow-left" :size="24" :color="fontColor" @click="navigateBack" />
  8. <span class="name" :style="{ color: fontColor }" v-if="this.colorType !== 'light'"><slot></slot></span>
  9. </div>
  10. </template>
  11. <script>
  12. import { mapState } from 'vuex';
  13. export default {
  14. data() {
  15. return {
  16. colorType: 'light'
  17. };
  18. },
  19. computed: {
  20. ...mapState(['systemInfo']),
  21. fontColor() {
  22. if (this.colorType == 'light') {
  23. return '#fff';
  24. } else {
  25. return '#000';
  26. }
  27. },
  28. bgColor() {
  29. if (this.colorType == 'light') {
  30. return 'rgba(255,255,255,0)';
  31. } else {
  32. return 'rgba(255,255,255,1)';
  33. }
  34. }
  35. },
  36. onPageScroll(e) {
  37. if (e.scrollTop > 50) {
  38. this.colorType = 'dark';
  39. wx.setNavigationBarColor({
  40. frontColor: '#000000',
  41. backgroundColor: '#ffffff',
  42. animation: {
  43. duration: 300
  44. }
  45. });
  46. } else {
  47. this.colorType = 'light';
  48. wx.setNavigationBarColor({
  49. frontColor: '#ffffff',
  50. backgroundColor: '#000000',
  51. animation: {
  52. duration: 300
  53. }
  54. });
  55. }
  56. }
  57. };
  58. </script>
  59. <style lang="less" scoped>
  60. .header {
  61. top: 0;
  62. left: 0;
  63. right: 0;
  64. position: fixed;
  65. z-index: 20;
  66. transition: all ease-in-out 0.3s;
  67. padding: 0 15px;
  68. .flex();
  69. .name {
  70. padding: 0 100px;
  71. position: absolute;
  72. left: 0;
  73. right: 0;
  74. height: 44px;
  75. bottom: 0;
  76. font-size: 17px;
  77. font-weight: bold;
  78. color: #000000;
  79. line-height: 44px;
  80. text-align: center;
  81. z-index: 0;
  82. }
  83. ._van-icon {
  84. position: relative;
  85. z-index: 2;
  86. }
  87. }
  88. </style>