su-inner-navbar.vue 7.8 KB

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