su-inner-navbar.vue 8.3 KB

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