su-inner-navbar.vue 8.4 KB

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