navigation-custom.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <template>
  2. <view class="navigation-bar" :style="{height:height}">
  3. <view class="navigation-bar-fixed" :style="{height:height,background:(!config.transparent&&!config.linear)?config.bgcolor:'#fff'}">
  4. <!-- capsule or normal -->
  5. <view v-if="[1,2].indexOf(config.type)!= -1" :class="config.type==1?'navigation-bar-capsule':'navigation-bar-textbox'" :style="{top:marginTop}">
  6. <view class="button-action" hover-class="button-action-active" @click="back_">
  7. <image src="../../static/icon/back_.png" mode=""></image>
  8. </view>
  9. <view class="button-v-line"></view>
  10. <view v-if="!config.share" class="button-action" hover-class="button-action-active" @click="home_">
  11. <image src="../../static/icon/home_.png" mode=""></image>
  12. </view>
  13. <view v-if="config.share" class="button-action" hover-class="button-action-active">
  14. <button class="button_clear" open-type="share" hover-class="none">
  15. <image src="../../static/icon/share_.png" mode=""></image>
  16. </button>
  17. </view>
  18. </view>
  19. <!-- custom button -->
  20. <view v-if="[3,4].indexOf(config.type)!= -1" @click="conduct_" :class="config.type == 3?'navigation-bar-custom-capsule':'navigation-bar-custom-textbox'" :style="{top:marginTop}">
  21. <image v-if="config.menuIcon" class="custom-icon" :src="config.menuIcon"></image>
  22. <text class="custom-describe">{{config.menuText}}</text>
  23. </view>
  24. <!-- title -->
  25. <view class="navigation-bar-title" :style="'margin-top:'+marginTop+';color:'+config.fontcolor">{{config.title}}</view>
  26. <!-- linear background -->
  27. <view v-if="config.linear" class="navigation-bar-linear" :style="{height:height,background:config.bgcolor,opacity:scrollTop/scrollMaxHeight}"></view>
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. export default {
  33. data() {
  34. return {
  35. };
  36. },
  37. computed:{
  38. height(){
  39. const {platform,statusBarHeight} = uni.getSystemInfoSync()
  40. let height = statusBarHeight +4 //ios 24px
  41. if (platform.toLowerCase() == "android" ){
  42. height +=4 //android 28px
  43. }
  44. // 胶囊高度 32px 下边框6px height 状态栏高度
  45. return height+ 38 + "px"
  46. },
  47. marginTop(){
  48. const {platform,statusBarHeight} = uni.getSystemInfoSync()
  49. let height = statusBarHeight +4
  50. if (platform.toLowerCase() == "android" ){
  51. height +=4
  52. }
  53. return height + "px"
  54. }
  55. },
  56. updated() {
  57. console.log(this.config)
  58. },
  59. mounted() {
  60. console.log(this.config)
  61. },
  62. props:{
  63. config:{
  64. type:Object,
  65. default(){
  66. return {
  67. title:"",
  68. bgcolor:"",
  69. type:2,
  70. linear:false,
  71. transparent:false,
  72. fontcolor:"#000",
  73. menuIcon:"",
  74. menuText:""
  75. }
  76. }
  77. },
  78. scrollTop:{
  79. type:Number,
  80. default:0
  81. },
  82. scrollMaxHeight:{
  83. type:Number,
  84. default:288
  85. }
  86. },
  87. methods:{
  88. back_(){
  89. uni.navigateBack({
  90. delta:1
  91. });
  92. },
  93. home_(){
  94. uni.switchTab({
  95. url:"/pages/index/index"
  96. })
  97. },
  98. conduct_(){
  99. this.$emit("customConduct")
  100. }
  101. }
  102. }
  103. </script>
  104. <style lang="scss">
  105. .navigation-bar{
  106. width: 100%;
  107. box-sizing: border-box;
  108. .navigation-bar-fixed{
  109. width: 100%;
  110. position: fixed;
  111. top:0;
  112. box-sizing: border-box;
  113. z-index: 999;
  114. background: #fff;
  115. display: flex;
  116. justify-content: center;
  117. .navigation-bar-linear{
  118. width: 100%;
  119. position: absolute;
  120. box-sizing: border-box;
  121. z-index: -1;
  122. }
  123. .navigation-bar-title{
  124. width: 280upx;
  125. line-height: 32px;
  126. height: 32px;
  127. color: #fff;
  128. font-size: 36upx;
  129. white-space: nowrap;
  130. text-overflow: ellipsis;
  131. overflow: hidden;
  132. }
  133. .navigation-bar-custom-capsule{
  134. position: absolute;
  135. display: flex;
  136. align-items: center;
  137. justify-content: center;
  138. height: 32px;
  139. left: 10px;
  140. background-color: rgba(255,255,255,.5);
  141. border-radius: 16px;
  142. padding: 0 23upx;
  143. // border:0.5px solid rgba(255,255,255,.3);
  144. box-sizing: border-box;
  145. overflow: hidden;
  146. z-index: 9;
  147. .custom-icon{
  148. width: 45upx;
  149. height: 45upx;
  150. }
  151. .custom-describe{
  152. font-size: 28upx;
  153. }
  154. }
  155. .navigation-bar-custom-textbox{
  156. position: absolute;
  157. display: flex;
  158. align-items: center;
  159. justify-content: center;
  160. height: 32px;
  161. left: 0px;
  162. padding: 0 23upx;
  163. // border:0.5px solid rgba(255,255,255,.3);
  164. box-sizing: border-box;
  165. overflow: hidden;
  166. z-index: 9;
  167. .custom-icon{
  168. width: 55upx;
  169. height: 55upx;
  170. }
  171. .custom-describe{
  172. font-size: 32upx;
  173. }
  174. }
  175. .navigation-bar-textbox{
  176. position: absolute;
  177. // height: 32px;
  178. display: flex;
  179. align-items: center;
  180. justify-content: space-between;
  181. line-height: 32px;
  182. height: 32px;
  183. font-size: 30upx;
  184. width: 85px;
  185. left: 0px;
  186. // border:0.5px solid rgba(255,255,255,.3);
  187. box-sizing: border-box;
  188. overflow: hidden;
  189. z-index: 9;
  190. .button-action{
  191. flex: 1;
  192. height: 100%;
  193. display: flex;
  194. align-items: center;
  195. justify-content: center;
  196. .button_clear{
  197. line-height: 1;
  198. background-color: transparent;
  199. border: none;
  200. margin: 0;
  201. padding: 0;
  202. }
  203. .button_clear::after{
  204. border:none;
  205. }
  206. image{
  207. width: 60upx;
  208. height: 60upx;
  209. padding: 6upx;
  210. box-sizing: border-box;
  211. }
  212. }
  213. .button-v-line{
  214. width: 0.5px;
  215. height: 18px;
  216. background-color: rgba(0,0,0,.2);
  217. }
  218. }
  219. .navigation-bar-capsule{
  220. position: absolute;
  221. // height: 32px;
  222. display: flex;
  223. align-items: center;
  224. justify-content: space-between;
  225. line-height: 32px;
  226. height: 32px;
  227. font-size: 30upx;
  228. width: 89px;
  229. left: 10px;
  230. background-color: rgba(255,255,255,.5);
  231. border-radius: 16px;
  232. // border:0.5px solid rgba(255,255,255,.3);
  233. box-sizing: border-box;
  234. overflow: hidden;
  235. z-index: 9;
  236. .button-action{
  237. flex: 1;
  238. height: 100%;
  239. display: flex;
  240. align-items: center;
  241. justify-content: center;
  242. image{
  243. width: 60upx;
  244. height: 60upx;
  245. padding: 10upx;
  246. box-sizing: border-box;
  247. }
  248. .button_clear{
  249. line-height: 1;
  250. background-color: transparent;
  251. border: none;
  252. margin: 0;
  253. padding: 0;
  254. text-decoration: none;
  255. }
  256. .button_clear::after{
  257. border:none;
  258. }
  259. }
  260. .button-action-active{
  261. background-color: rgba(0,0,0,.3)
  262. }
  263. .button-v-line{
  264. width: 0.5px;
  265. height: 18px;
  266. background-color: rgba(0,0,0,.2);
  267. }
  268. }
  269. }
  270. }
  271. </style>