uni-navbar-lite.uvue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <template>
  2. <view class="uni-navbar">
  3. <!-- #ifdef APP || WEB -->
  4. <view v-if="statusBar" class="status-bar"></view>
  5. <!-- #endif -->
  6. <!-- #ifdef MP -->
  7. <view v-if="statusBar" class="status-bar" :style="{ height: statusBarHeight + 'px' }"></view>
  8. <!-- #endif -->
  9. <view class="uni-navbar-inner">
  10. <view class="left-content" @click="back">
  11. <!-- #ifdef MP-WEIXIN -->
  12. <text :style="{ color: textColor }" class="uni-icons back-icon"></text>
  13. <!-- #endif -->
  14. <!-- #ifndef MP-WEIXIN -->
  15. <text :style="{ color: textColor }" class="uni-icons">{{
  16. unicode
  17. }}</text>
  18. <!-- #endif -->
  19. </view>
  20. <view class="uni-navbar-content" :class="{ 'is-left': isLeft }">
  21. <text :style="{ color: textColor }">
  22. <slot>{{ title }}</slot>
  23. </text>
  24. </view>
  25. <view class="right-content">
  26. <slot name="right"></slot>
  27. </view>
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. // #ifndef MP-WEIXIN
  33. import iconpath from "./uniicons.ttf";
  34. // #endif
  35. export default {
  36. name: "uni-navbar",
  37. props: {
  38. title: {
  39. type: String,
  40. default: "",
  41. },
  42. isLeft: {
  43. type: Boolean,
  44. default: false,
  45. },
  46. textColor: {
  47. type: String,
  48. default: "#000",
  49. },
  50. statusBar: {
  51. type: Boolean,
  52. default: false,
  53. },
  54. stat: {
  55. type: Boolean,
  56. default: false,
  57. },
  58. },
  59. data() {
  60. return {
  61. statusBarHeight: 0,
  62. };
  63. },
  64. computed: {
  65. unicode() : string {
  66. return "\ue600";
  67. },
  68. },
  69. created() {
  70. // #ifndef MP-WEIXIN
  71. uni.loadFontFace({
  72. global: false,
  73. family: "UniIconsFontFamily",
  74. source: `url("${iconpath}")`,
  75. success() { },
  76. fail(err) {
  77. console.log(err);
  78. },
  79. });
  80. // #endif
  81. if (this.stat && this.title != '') {
  82. uni.report({
  83. name:'title',
  84. options: this.title
  85. })
  86. }
  87. },
  88. mounted() {
  89. uni.setNavigationBarColor({
  90. frontColor: "#000000",
  91. backgroundColor: "#ffffff",
  92. });
  93. // #ifdef MP-WEIXIN
  94. // TODO 部分小程序平台不支持getWindowInfo
  95. this.statusBarHeight = uni.getWindowInfo().statusBarHeight
  96. // #endif
  97. },
  98. methods: {
  99. back() {
  100. uni.navigateBack({});
  101. },
  102. },
  103. };
  104. </script>
  105. <style>
  106. /* #ifdef MP-WEIXIN */
  107. @font-face {
  108. font-family: UniIconsFontFamily;
  109. src: url('./uniicons.ttf');
  110. }
  111. .back-icon:before {
  112. content: "\e600";
  113. }
  114. /* #endif */
  115. .uni-icons {
  116. font-family: "UniIconsFontFamily" !important;
  117. font-size: 26px;
  118. font-style: normal;
  119. color: #333;
  120. }
  121. .status-bar {
  122. height: var(--status-bar-height);
  123. }
  124. .uni-navbar {
  125. background-color: #007aff;
  126. }
  127. .uni-navbar-inner {
  128. position: relative;
  129. flex-direction: row;
  130. justify-content: space-between;
  131. height: 45px;
  132. }
  133. .left-content,
  134. .right-content {
  135. justify-content: center;
  136. align-items: center;
  137. width: 40px;
  138. height: 100%;
  139. }
  140. .uni-navbar-content {
  141. position: absolute;
  142. height: 100%;
  143. top: 0;
  144. bottom: 0;
  145. left: 45px;
  146. right: 45px;
  147. flex-direction: row;
  148. justify-content: center;
  149. align-items: center;
  150. }
  151. .is-left {
  152. justify-content: flex-start;
  153. }
  154. </style>