detail-navbar.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <template>
  2. <su-fixed alway :bgStyles="{ background: '#fff' }" :val="0" noNav opacity :placeholder="false">
  3. <su-status-bar />
  4. <view
  5. class="ui-bar ss-flex ss-col-center ss-row-between ss-p-x-20"
  6. :style="[{ height: sys_navBar - sys_statusBar + 'px' }]"
  7. >
  8. <!-- 左 -->
  9. <view class="icon-box ss-flex">
  10. <view class="icon-button icon-button-left ss-flex ss-row-center" @tap="onClickLeft">
  11. <text class="sicon-back" v-if="hasHistory" />
  12. <text class="sicon-home" v-else />
  13. </view>
  14. <view class="line"></view>
  15. <view class="icon-button icon-button-right ss-flex ss-row-center" @tap="onClickRight">
  16. <text class="sicon-more" />
  17. </view>
  18. </view>
  19. <!-- 中 -->
  20. <view class="detail-tab-card ss-flex-1" :style="[{ opacity: state.tabOpacityVal }]">
  21. <view class="tab-box ss-flex ss-col-center ss-row-around">
  22. <view
  23. class="tab-item ss-flex-1 ss-flex ss-row-center ss-col-center"
  24. v-for="item in state.tabList"
  25. :key="item.value"
  26. @tap="onTab(item)"
  27. >
  28. <view class="tab-title" :class="state.curTab === item.value ? 'cur-tab-title' : ''">
  29. {{ item.label }}
  30. </view>
  31. <view v-show="state.curTab === item.value" class="tab-line"></view>
  32. </view>
  33. </view>
  34. </view>
  35. <!-- #ifdef MP -->
  36. <view :style="[capsuleStyle]"></view>
  37. <!-- #endif -->
  38. </view>
  39. </su-fixed>
  40. </template>
  41. <script setup>
  42. import { reactive } from 'vue';
  43. import { onPageScroll } from '@dcloudio/uni-app';
  44. import sheep from '@/sheep';
  45. import throttle from '@/sheep/helper/throttle.js';
  46. import { showMenuTools, closeMenuTools } from '@/sheep/hooks/useModal';
  47. const sys_statusBar = sheep.$platform.device.statusBarHeight;
  48. const sys_navBar = sheep.$platform.navbar;
  49. const capsuleStyle = {
  50. width: sheep.$platform.capsule.width + 'px',
  51. height: sheep.$platform.capsule.height + 'px',
  52. };
  53. const state = reactive({
  54. tabOpacityVal: 0,
  55. curTab: 'goods',
  56. tabList: [
  57. {
  58. label: '商品',
  59. value: 'goods',
  60. to: 'detail-swiper-selector',
  61. },
  62. {
  63. label: '评价',
  64. value: 'comment',
  65. to: 'detail-comment-selector',
  66. },
  67. {
  68. label: '详情',
  69. value: 'detail',
  70. to: 'detail-content-selector',
  71. },
  72. ],
  73. });
  74. const emits = defineEmits(['clickLeft']);
  75. const hasHistory = sheep.$router.hasHistory();
  76. function onClickLeft() {
  77. if (hasHistory) {
  78. sheep.$router.back();
  79. } else {
  80. sheep.$router.go('/pages/index/index');
  81. }
  82. emits('clickLeft');
  83. }
  84. function onClickRight() {
  85. showMenuTools();
  86. }
  87. let commentCard = {
  88. top: 0,
  89. bottom: 0,
  90. };
  91. function getCommentCardNode() {
  92. return new Promise((res, rej) => {
  93. uni.createSelectorQuery()
  94. .select('.detail-comment-selector')
  95. .boundingClientRect((data) => {
  96. if (data) {
  97. commentCard.top = data.top;
  98. commentCard.bottom = data.top + data.height;
  99. res(data);
  100. } else {
  101. res(null);
  102. }
  103. })
  104. .exec();
  105. });
  106. }
  107. function onTab(tab) {
  108. let scrollTop = 0;
  109. if (tab.value === 'comment') {
  110. scrollTop = commentCard.top - sys_navBar + 1;
  111. } else if (tab.value === 'detail') {
  112. scrollTop = commentCard.bottom - sys_navBar + 1;
  113. }
  114. uni.pageScrollTo({
  115. scrollTop,
  116. duration: 200,
  117. });
  118. }
  119. onPageScroll((e) => {
  120. state.tabOpacityVal = e.scrollTop > sheep.$platform.navbar ? 1 : e.scrollTop * 0.01;
  121. if (commentCard.top === 0) {
  122. throttle(() => {
  123. getCommentCardNode();
  124. }, 50);
  125. }
  126. if (e.scrollTop < commentCard.top - sys_navBar) {
  127. state.curTab = 'goods';
  128. } else if (
  129. e.scrollTop >= commentCard.top - sys_navBar &&
  130. e.scrollTop <= commentCard.bottom - sys_navBar
  131. ) {
  132. state.curTab = 'comment';
  133. } else {
  134. state.curTab = 'detail';
  135. }
  136. });
  137. </script>
  138. <style lang="scss" scoped>
  139. .icon-box {
  140. box-shadow: 0px 0px 4rpx rgba(51, 51, 51, 0.08), 0px 4rpx 6rpx 2rpx rgba(102, 102, 102, 0.12);
  141. border-radius: 30rpx;
  142. width: 134rpx;
  143. height: 56rpx;
  144. margin-left: 8rpx;
  145. border: 1px solid rgba(#fff, 0.4);
  146. .line {
  147. width: 2rpx;
  148. height: 24rpx;
  149. background: #e5e5e7;
  150. }
  151. .sicon-back {
  152. font-size: 32rpx;
  153. color: #000;
  154. }
  155. .sicon-home {
  156. font-size: 32rpx;
  157. color: #000;
  158. }
  159. .sicon-more {
  160. font-size: 32rpx;
  161. color: #000;
  162. }
  163. .icon-button {
  164. width: 67rpx;
  165. height: 56rpx;
  166. &-left:hover {
  167. background: rgba(0, 0, 0, 0.16);
  168. border-radius: 30rpx 0px 0px 30rpx;
  169. }
  170. &-right:hover {
  171. background: rgba(0, 0, 0, 0.16);
  172. border-radius: 0px 30rpx 30rpx 0px;
  173. }
  174. }
  175. }
  176. .left-box {
  177. position: relative;
  178. width: 60rpx;
  179. height: 60rpx;
  180. display: flex;
  181. justify-content: center;
  182. align-items: center;
  183. .circle {
  184. position: absolute;
  185. left: 0;
  186. top: 0;
  187. width: 60rpx;
  188. height: 60rpx;
  189. background: rgba(#fff, 0.6);
  190. border: 1rpx solid #ebebeb;
  191. border-radius: 50%;
  192. box-sizing: border-box;
  193. z-index: -1;
  194. }
  195. }
  196. .right {
  197. position: relative;
  198. width: 60rpx;
  199. height: 60rpx;
  200. display: flex;
  201. justify-content: center;
  202. align-items: center;
  203. .circle {
  204. position: absolute;
  205. left: 0;
  206. top: 0;
  207. width: 60rpx;
  208. height: 60rpx;
  209. background: rgba(#ffffff, 0.6);
  210. border: 1rpx solid #ebebeb;
  211. box-sizing: border-box;
  212. border-radius: 50%;
  213. z-index: -1;
  214. }
  215. }
  216. .detail-tab-card {
  217. width: 50%;
  218. .tab-item {
  219. height: 80rpx;
  220. position: relative;
  221. z-index: 11;
  222. .tab-title {
  223. font-size: 30rpx;
  224. }
  225. .cur-tab-title {
  226. font-weight: $font-weight-bold;
  227. }
  228. .tab-line {
  229. width: 60rpx;
  230. height: 6rpx;
  231. border-radius: 6rpx;
  232. position: absolute;
  233. left: 50%;
  234. transform: translateX(-50%);
  235. bottom: 10rpx;
  236. background-color: var(--ui-BG-Main);
  237. z-index: 12;
  238. }
  239. }
  240. }
  241. </style>