su-inner-navbar.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  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-30"
  21. :class="state.isDark ? 'text-black' : 'text-black'"
  22. :style="[{ height: (sys_navBar - sys_statusBar)*2 + 'rpx' }]"
  23. >
  24. <view class="navbar_left">
  25. <view v-if="showLeftLogoutButton&&isLogin" class="logout_btn" @tap="onClickLogout"></view>
  26. <view v-if="showBackButton" class="back_btn" @tap="onClickBack"></view>
  27. <view v-if="showLeftButton" class="icon-box ss-flex">
  28. <view class="icon-button icon-button-left ss-flex ss-row-center" @tap="onClickLeft">
  29. <text class="sicon-back" v-if="hasHistory" />
  30. <text class="sicon-home" v-else />
  31. </view>
  32. <view class="line"></view>
  33. <view class="icon-button icon-button-right ss-flex ss-row-center" @tap="onClickRight">
  34. <text class="sicon-more" />
  35. </view>
  36. </view>
  37. </view>
  38. <slot name="center">
  39. <view class="center navbar-title">{{ title }}</view>
  40. </slot>
  41. <view class="navbar_right">
  42. <view v-if="showRecordTextButton" class="record_text_btn" @tap="onClickRecord"></view>
  43. <view v-if="showRecordButton" class="record_btn" @tap="onClickRecord"></view>
  44. <view v-if="showLogoutButton&&state.token" class="logout_btn" @tap="onClickLogout"></view>
  45. <view v-if="showImportButton" class="import_btn" @tap="onClickImport"></view>
  46. <view v-if="showExportButton" class="export_btn" @tap="onClickExport">导出</view>
  47. </view>
  48. <!-- #ifdef MP -->
  49. <view :style="[state.capsuleStyle]"></view>
  50. <!-- #endif -->
  51. </view>
  52. </view>
  53. </su-fixed>
  54. </template>
  55. <script setup>
  56. /**
  57. * 标题栏 - 基础组件navbar
  58. *
  59. * @param {Number} zIndex = 100 - 层级
  60. * @param {Boolean} back = true - 是否返回上一页
  61. * @param {String} backtext = '' - 返回文本
  62. * @param {String} bg = 'bg-white' - 公共Class
  63. * @param {String} status = '' - 状态栏颜色
  64. * @param {Boolean} alway = true - 是否常驻
  65. * @param {Boolean} opacity = false - 是否开启透明渐变
  66. * @param {Boolean} noFixed = false - 是否浮动
  67. * @param {String} ui = '' - 公共Class
  68. * @param {Boolean} capsule = false - 是否开启胶囊返回
  69. * @param {Boolean} stopBack = false - 是否禁用返回
  70. * @param {Boolean} placeholder = true - 是否开启占位
  71. * @param {Object} bgStyles = {} - 背景样式
  72. *
  73. */
  74. import { computed, reactive, onBeforeMount, ref } from 'vue'
  75. import sheep from '@/common'
  76. import { onPageScroll } from '@dcloudio/uni-app'
  77. import { showMenuTools, closeMenuTools } from '@/common/hooks/useModal'
  78. // 本地数据
  79. const state = reactive({
  80. statusCur: '',
  81. capsuleStyle: {},
  82. capsuleBack: {},
  83. isDark: false
  84. })
  85. const isLogin = computed(() => sheep.$store('user').isLogin)
  86. const sys_statusBar = sheep.$platform.device.statusBarHeight
  87. const sys_navBar = sheep.$platform.navbar
  88. const props = defineProps({
  89. zIndex: {
  90. type: Number,
  91. default: 100,
  92. },
  93. title: {
  94. //返回文本
  95. type: String,
  96. default: '',
  97. },
  98. bg: {
  99. type: String,
  100. default: 'bg-white',
  101. },
  102. // 常驻
  103. alway: {
  104. type: Boolean,
  105. default: true,
  106. },
  107. opacity: {
  108. //是否开启滑动渐变
  109. type: Boolean,
  110. default: true,
  111. },
  112. noFixed: {
  113. //是否浮动
  114. type: Boolean,
  115. default: true,
  116. },
  117. ui: {
  118. type: String,
  119. default: '',
  120. },
  121. capsule: {
  122. //是否开启胶囊返回
  123. type: Boolean,
  124. default: false,
  125. },
  126. stopBack: {
  127. type: Boolean,
  128. default: false,
  129. },
  130. placeholder: {
  131. type: [Boolean],
  132. default: false,
  133. },
  134. bgStyles: {
  135. type: Object,
  136. default() {},
  137. },
  138. showLeftButton: {
  139. type: Boolean,
  140. default: false,
  141. },
  142. showBackButton: {
  143. type: Boolean,
  144. default: false,
  145. },
  146. showRecordButton: {
  147. type: Boolean,
  148. default: false,
  149. },
  150. showLogoutButton: {
  151. type: Boolean,
  152. default: false,
  153. },
  154. showLeftLogoutButton: {
  155. type: Boolean,
  156. default: false,
  157. },
  158. showRecordTextButton: {
  159. type: Boolean,
  160. default: false,
  161. },
  162. showImportButton: {
  163. type: Boolean,
  164. default: false,
  165. },
  166. showExportButton: {
  167. type: Boolean,
  168. default: false,
  169. },
  170. });
  171. const emits = defineEmits(['navback', 'clickLeft', 'logout', 'import', 'export']);
  172. const hasHistory = sheep.$router.hasHistory();
  173. onBeforeMount(() => {
  174. init();
  175. });
  176. onPageScroll((e) => {
  177. let top = e.scrollTop;
  178. state.isDark = top < sheep.$platform.navbar;
  179. });
  180. function onClickBack(){
  181. if (hasHistory) {
  182. sheep.$router.back();
  183. } else {
  184. sheep.$router.go('/pages/index/index');
  185. }
  186. }
  187. function onClickLeft() {
  188. if (hasHistory) {
  189. sheep.$router.back();
  190. } else {
  191. sheep.$router.go('/pages/index/index');
  192. }
  193. emits('clickLeft');
  194. }
  195. function onClickRight() {
  196. showMenuTools();
  197. }
  198. function onClickRecord(){
  199. sheep.$router.go('/pages/task/record')
  200. }
  201. function onClickLogout(){
  202. emits('logout')
  203. }
  204. function onClickImport(){
  205. emits('import')
  206. }
  207. function onClickExport(){
  208. emits('export')
  209. }
  210. // 初始化
  211. const init = () => {
  212. // #ifdef MP-ALIPAY
  213. my.hideAllFavoriteMenu();
  214. // #endif
  215. state.capsuleStyle = {
  216. width: sheep.$platform.capsule.width + 'px',
  217. height: sheep.$platform.capsule.height + 'px',
  218. };
  219. state.capsuleBack = state.capsuleStyle;
  220. };
  221. </script>
  222. <style lang="scss" scoped>
  223. .navbar_right,
  224. .navbar_left{
  225. display: flex;
  226. align-items: center;
  227. }
  228. .back_btn{
  229. width: 48rpx;
  230. height: 48rpx;
  231. background: url('/static/back_icon.png') no-repeat center/48rpx 48rpx;
  232. }
  233. .record_text_btn{
  234. margin-top: 60rpx;
  235. width: 168rpx;
  236. height: 80rpx;
  237. background: url('/static/record_text_icon.png') no-repeat center/168rpx 80rpx;
  238. }
  239. .record_btn{
  240. margin-top: 8rpx;
  241. width: 80rpx;
  242. height: 80rpx;
  243. background: url('/static/record_icon.png') no-repeat center/80rpx 80rpx;
  244. }
  245. .logout_btn{
  246. margin-top: 60rpx;
  247. width: 80rpx;
  248. height: 80rpx;
  249. background: url('/static/logout_icon.png') no-repeat center/80rpx 80rpx;
  250. }
  251. .import_btn{
  252. width: 48rpx;
  253. height: 48rpx;
  254. background: url('/static/import_icon.png') no-repeat center/48rpx 48rpx;
  255. }
  256. .export_btn{
  257. height: 48rpx;
  258. font-weight: 400;
  259. font-size: 28rpx;
  260. color: #222222;
  261. line-height: 48rpx;
  262. padding-left: 40rpx;
  263. background: url('/static/export_icon.png') no-repeat left center/40rpx 40rpx;
  264. }
  265. .icon-box {
  266. box-shadow: 0px 0px 4rpx rgba(51, 51, 51, 0.08), 0px 4rpx 6rpx 2rpx rgba(102, 102, 102, 0.12);
  267. border-radius: 30rpx;
  268. width: 134rpx;
  269. height: 56rpx;
  270. margin-left: 8rpx;
  271. border: 1px solid rgba(#fff, 0.4);
  272. .line {
  273. width: 2rpx;
  274. height: 24rpx;
  275. background: #e5e5e7;
  276. }
  277. .sicon-back {
  278. font-size: 32rpx;
  279. }
  280. .sicon-home {
  281. font-size: 32rpx;
  282. }
  283. .sicon-more {
  284. font-size: 32rpx;
  285. }
  286. .icon-button {
  287. width: 67rpx;
  288. height: 56rpx;
  289. &-left:hover {
  290. background: rgba(0, 0, 0, 0.16);
  291. border-radius: 30rpx 0px 0px 30rpx;
  292. }
  293. &-right:hover {
  294. background: rgba(0, 0, 0, 0.16);
  295. border-radius: 0px 30rpx 30rpx 0px;
  296. }
  297. }
  298. }
  299. .navbar-title {
  300. font-size: 32rpx;
  301. }
  302. .tools-icon {
  303. font-size: 40rpx;
  304. }
  305. .ui-navbar-box {
  306. background-color: transparent;
  307. width: 750rpx;
  308. margin: 0 auto;
  309. .ui-bar {
  310. position: relative;
  311. z-index: 2;
  312. white-space: nowrap;
  313. display: flex;
  314. position: relative;
  315. align-items: center;
  316. justify-content: space-between;
  317. .left {
  318. @include flex-bar;
  319. .back {
  320. @include flex-bar;
  321. .back-icon {
  322. @include flex-center;
  323. width: 56rpx;
  324. height: 56rpx;
  325. margin: 0 10rpx;
  326. font-size: 46rpx !important;
  327. &.opacityIcon {
  328. position: relative;
  329. border-radius: 50%;
  330. background-color: rgba(127, 127, 127, 0.5);
  331. &::after {
  332. content: '';
  333. display: block;
  334. position: absolute;
  335. height: 200%;
  336. width: 200%;
  337. left: 0;
  338. top: 0;
  339. border-radius: inherit;
  340. transform: scale(0.5);
  341. transform-origin: 0 0;
  342. opacity: 0.1;
  343. border: 1px solid currentColor;
  344. pointer-events: none;
  345. }
  346. &::before {
  347. transform: scale(0.9);
  348. }
  349. }
  350. }
  351. /* #ifdef MP-ALIPAY */
  352. ._icon-back {
  353. opacity: 0;
  354. }
  355. /* #endif */
  356. }
  357. .capsule {
  358. @include flex-bar;
  359. border-radius: 100px;
  360. position: relative;
  361. &.dark {
  362. background-color: rgba(255, 255, 255, 0.5);
  363. }
  364. &.light {
  365. background-color: rgba(0, 0, 0, 0.15);
  366. }
  367. &::after {
  368. content: '';
  369. display: block;
  370. position: absolute;
  371. height: 60%;
  372. width: 1px;
  373. left: 50%;
  374. top: 20%;
  375. background-color: currentColor;
  376. opacity: 0.1;
  377. pointer-events: none;
  378. }
  379. &::before {
  380. content: '';
  381. display: block;
  382. position: absolute;
  383. height: 200%;
  384. width: 200%;
  385. left: 0;
  386. top: 0;
  387. border-radius: inherit;
  388. transform: scale(0.5);
  389. transform-origin: 0 0;
  390. opacity: 0.1;
  391. border: 1px solid currentColor;
  392. pointer-events: none;
  393. }
  394. .capsule-back,
  395. .capsule-home {
  396. @include flex-center;
  397. flex: 1;
  398. }
  399. &.isFristPage {
  400. .capsule-back,
  401. &::after {
  402. display: none;
  403. }
  404. }
  405. }
  406. }
  407. .right {
  408. @include flex-bar;
  409. .right-content {
  410. @include flex;
  411. flex-direction: row-reverse;
  412. }
  413. }
  414. .center {
  415. @include flex-center;
  416. text-overflow: ellipsis;
  417. // text-align: center;
  418. position: absolute;
  419. left: 50%;
  420. transform: translateX(-50%);
  421. .image {
  422. display: block;
  423. height: 36px;
  424. max-width: calc(100vw - 200px);
  425. }
  426. }
  427. }
  428. .ui-bar-bg {
  429. position: absolute;
  430. width: 100%;
  431. height: 100%;
  432. top: 0;
  433. z-index: 1;
  434. pointer-events: none;
  435. }
  436. }
  437. </style>