navbar.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. <template>
  2. <su-fixed
  3. :noFixed="props.noFixed"
  4. :alway="props.alway"
  5. :bgStyles="props.bgStyles"
  6. :val="0"
  7. :index="props.zIndex"
  8. noNav
  9. :bg="props.bg"
  10. :ui="props.ui"
  11. :opacity="props.opacity"
  12. :placeholder="props.placeholder"
  13. :sticky="props.sticky"
  14. >
  15. <su-status-bar />
  16. <!--
  17. :class="[{ 'border-bottom': !props.opacity && props.bg != 'bg-none' }]"
  18. -->
  19. <view class="ui-navbar-box">
  20. <view
  21. class="ui-bar"
  22. :class="
  23. props.status == '' ? `text-a` : props.status == 'light' ? 'text-white' : 'text-black'
  24. "
  25. :style="[{ height: sys_navBar - sys_statusBar + 'px' }]"
  26. >
  27. <slot name="item"></slot>
  28. <view class="right">
  29. <!-- #ifdef MP -->
  30. <view :style="[state.capsuleStyle]"></view>
  31. <!-- #endif -->
  32. </view>
  33. </view>
  34. </view>
  35. </su-fixed>
  36. </template>
  37. <script setup>
  38. /**
  39. * 标题栏 - 基础组件navbar
  40. *
  41. * @param {Number} zIndex = 100 - 层级
  42. * @param {Boolean} back = true - 是否返回上一页
  43. * @param {String} backtext = '' - 返回文本
  44. * @param {String} bg = 'bg-white' - 公共Class
  45. * @param {String} status = '' - 状态栏颜色
  46. * @param {Boolean} alway = true - 是否常驻
  47. * @param {Boolean} opacity = false - 是否开启透明渐变
  48. * @param {Boolean} opacityBg = false - 开启滑动渐变后,返回按钮是否添加背景
  49. * @param {Boolean} noFixed = false - 是否浮动
  50. * @param {String} ui = '' - 公共Class
  51. * @param {Boolean} capsule = false - 是否开启胶囊返回
  52. * @param {Boolean} stopBack = false - 是否禁用返回
  53. * @param {Boolean} placeholder = true - 是否开启占位
  54. * @param {Object} bgStyles = {} - 背景样式
  55. *
  56. */
  57. import { computed, reactive, onBeforeMount } from 'vue';
  58. import sheep from '@/sheep';
  59. // 本地数据
  60. const state = reactive({
  61. statusCur: '',
  62. capsuleStyle: {},
  63. capsuleBack: {},
  64. });
  65. const sys_statusBar = sheep.$platform.device.statusBarHeight;
  66. const sys_navBar = sheep.$platform.navbar;
  67. const props = defineProps({
  68. sticky: Boolean,
  69. zIndex: {
  70. type: Number,
  71. default: 100,
  72. },
  73. back: {
  74. //是否返回上一页
  75. type: Boolean,
  76. default: true,
  77. },
  78. backtext: {
  79. //返回文本
  80. type: String,
  81. default: '',
  82. },
  83. bg: {
  84. type: String,
  85. default: 'bg-white',
  86. },
  87. status: {
  88. //状态栏颜色 可以选择light dark/其他字符串视为黑色
  89. type: String,
  90. default: '',
  91. },
  92. // 常驻
  93. alway: {
  94. type: Boolean,
  95. default: true,
  96. },
  97. opacity: {
  98. //是否开启滑动渐变
  99. type: Boolean,
  100. default: false,
  101. },
  102. opacityBg: {
  103. //开启滑动渐变后 返回按钮是否添加背景
  104. type: Boolean,
  105. default: false,
  106. },
  107. noFixed: {
  108. //是否浮动
  109. type: Boolean,
  110. default: false,
  111. },
  112. ui: {
  113. type: String,
  114. default: '',
  115. },
  116. capsule: {
  117. //是否开启胶囊返回
  118. type: Boolean,
  119. default: false,
  120. },
  121. stopBack: {
  122. type: Boolean,
  123. default: false,
  124. },
  125. placeholder: {
  126. type: [Boolean],
  127. default: true,
  128. },
  129. bgStyles: {
  130. type: Object,
  131. default() {},
  132. },
  133. });
  134. const emits = defineEmits(['navback']);
  135. onBeforeMount(() => {
  136. init();
  137. });
  138. // 返回
  139. const onNavback = () => {
  140. sheep.$router.back();
  141. };
  142. // 初始化
  143. const init = () => {
  144. state.capsuleStyle = {
  145. width: sheep.$platform.capsule.width + 'px',
  146. height: sheep.$platform.capsule.height + 'px',
  147. margin: '0 ' + (sheep.$platform.device.windowWidth - sheep.$platform.capsule.right) + 'px',
  148. };
  149. state.capsuleBack = state.capsuleStyle;
  150. };
  151. </script>
  152. <style lang="scss" scoped>
  153. .ui-navbar-box {
  154. background-color: transparent;
  155. width: 100%;
  156. .ui-bar {
  157. position: relative;
  158. z-index: 2;
  159. white-space: nowrap;
  160. display: flex;
  161. position: relative;
  162. align-items: center;
  163. justify-content: space-between;
  164. .left {
  165. @include flex-bar;
  166. .back {
  167. @include flex-bar;
  168. .back-icon {
  169. @include flex-center;
  170. width: 56rpx;
  171. height: 56rpx;
  172. margin: 0 10rpx;
  173. font-size: 46rpx !important;
  174. &.opacityIcon {
  175. position: relative;
  176. border-radius: 50%;
  177. background-color: rgba(127, 127, 127, 0.5);
  178. &::after {
  179. content: '';
  180. display: block;
  181. position: absolute;
  182. height: 200%;
  183. width: 200%;
  184. left: 0;
  185. top: 0;
  186. border-radius: inherit;
  187. transform: scale(0.5);
  188. transform-origin: 0 0;
  189. opacity: 0.1;
  190. border: 1px solid currentColor;
  191. pointer-events: none;
  192. }
  193. &::before {
  194. transform: scale(0.9);
  195. }
  196. }
  197. }
  198. /* #ifdef MP-ALIPAY */
  199. ._icon-back {
  200. opacity: 0;
  201. }
  202. /* #endif */
  203. }
  204. .capsule {
  205. @include flex-bar;
  206. border-radius: 100px;
  207. position: relative;
  208. &.dark {
  209. background-color: rgba(255, 255, 255, 0.5);
  210. }
  211. &.light {
  212. background-color: rgba(0, 0, 0, 0.15);
  213. }
  214. &::after {
  215. content: '';
  216. display: block;
  217. position: absolute;
  218. height: 60%;
  219. width: 1px;
  220. left: 50%;
  221. top: 20%;
  222. background-color: currentColor;
  223. opacity: 0.1;
  224. pointer-events: none;
  225. }
  226. &::before {
  227. content: '';
  228. display: block;
  229. position: absolute;
  230. height: 200%;
  231. width: 200%;
  232. left: 0;
  233. top: 0;
  234. border-radius: inherit;
  235. transform: scale(0.5);
  236. transform-origin: 0 0;
  237. opacity: 0.1;
  238. border: 1px solid currentColor;
  239. pointer-events: none;
  240. }
  241. .capsule-back,
  242. .capsule-home {
  243. @include flex-center;
  244. flex: 1;
  245. }
  246. &.isFristPage {
  247. .capsule-back,
  248. &::after {
  249. display: none;
  250. }
  251. }
  252. }
  253. }
  254. .right {
  255. @include flex-bar;
  256. .right-content {
  257. @include flex;
  258. flex-direction: row-reverse;
  259. }
  260. }
  261. .center {
  262. @include flex-center;
  263. text-overflow: ellipsis;
  264. text-align: center;
  265. flex: 1;
  266. .image {
  267. display: block;
  268. height: 36px;
  269. max-width: calc(100vw - 200px);
  270. }
  271. }
  272. }
  273. .ui-bar-bg {
  274. position: absolute;
  275. width: 100%;
  276. height: 100%;
  277. top: 0;
  278. z-index: 1;
  279. pointer-events: none;
  280. }
  281. }
  282. </style>