uni-tab.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <!-- components/custom-tabs.vue -->
  2. <template>
  3. <div class="">
  4. <view class="wrap">
  5. <view class="tabs dis a-end">
  6. <view v-for="(item, index) in tabList" :key="index" class="tab dis a-c j-c" :class="{
  7. active: activeTab === index,
  8. tab1: activeTab !== index,
  9. left: activeTab === 0,
  10. right: activeTab === 1
  11. }" :style="{
  12. backgroundColor: activeTab !== index?noactivebackgroundColor:''
  13. }" @click="handleTab(index)">
  14. <view class="tabtitle" :class="activeTab === 0 ? 'tabtext' : 'tabtext1'">
  15. <image v-if="activeTab==index" src="/static/image/Vector 22.png" mode=""></image>
  16. <view class="">
  17. {{ item.label }}
  18. </view>
  19. </view>
  20. </view>
  21. </view>
  22. <view class="content-container">
  23. <!-- 内容插槽 -->
  24. <view class="content-wrap contentwrap1" v-show="activeTab === 0">
  25. <slot name="content0">
  26. </slot>
  27. </view>
  28. <view class="content-wrap contentwrap2" v-show="activeTab === 1">
  29. <slot name="content1"></slot>
  30. </view>
  31. </view>
  32. </view>
  33. </div>
  34. </template>
  35. <script>
  36. export default {
  37. model: {
  38. prop: 'value',
  39. event: 'change'
  40. },
  41. props: {
  42. // 标签数据
  43. tabList: {
  44. type: Array,
  45. default: () => []
  46. },
  47. // 当前激活标签
  48. value: {
  49. type: Number,
  50. default: 0
  51. },
  52. //未选中标签背景色
  53. noactivebackgroundColor: {
  54. type: String,
  55. default: '#fff'
  56. }
  57. },
  58. data() {
  59. return {
  60. activeTab: this.value
  61. }
  62. },
  63. watch: {
  64. value(newVal) {
  65. this.activeTab = newVal
  66. }
  67. },
  68. methods: {
  69. handleTab(index) {
  70. this.activeTab = index
  71. this.$emit('change', index)
  72. this.$emit('tab-change', index)
  73. }
  74. }
  75. }
  76. </script>
  77. <!-- 保持原有样式不变 -->
  78. <style lang="scss" scoped>
  79. .page {
  80. background-color: #F8F8F8;
  81. height: 100vh;
  82. }
  83. .wrap {
  84. position: relative;
  85. width: 100%;
  86. margin: 0 auto;
  87. box-sizing: border-box;
  88. border-radius: 0px 10px 10px 10px;
  89. }
  90. .tabs {
  91. display: flex;
  92. position: relative;
  93. overflow: hidden;
  94. border-radius: 10px 10px 0 0;
  95. }
  96. .tab {
  97. flex: 1;
  98. height: 86rpx;
  99. color: #333;
  100. font-size: 30rpx;
  101. position: relative;
  102. // background-color: rgba(254, 249, 239, 55%);
  103. border-top-right-radius: 10px;
  104. border-top-left-radius: 10px;
  105. box-shadow: inset 0px 0px 3px 0px #FFFFFF, 0px 4px 10px 0px rgba(255, 255, 255, 0.25);
  106. &.active {
  107. background: #FFFCE5;
  108. color: #1F1F1F;
  109. height: 106rpx;
  110. font-size: 36rpx;
  111. font-weight: bold;
  112. border-top-right-radius: 10px;
  113. border-top-left-radius: 10px;
  114. }
  115. &.left.active {
  116. border-top-right-radius: 0;
  117. &::after {
  118. content: "";
  119. position: absolute;
  120. top: 0;
  121. right: -50px;
  122. height: 100%;
  123. width: 50px;
  124. z-index: 2;
  125. background-color: #FFFCE5;
  126. clip-path: path("M0 0 C25 0 25 50 50 50 L0 50 Z");
  127. }
  128. }
  129. // 右侧标签的曲线
  130. &.right.active {
  131. border-top-left-radius: 0;
  132. &::before {
  133. content: "";
  134. position: absolute;
  135. top: 0;
  136. left: -49px;
  137. height: 100%;
  138. width: 50px;
  139. z-index: 2;
  140. background-color: #FFFCE5;
  141. clip-path: path("M50 0 C25 0 25 50 0 50 L50 50 Z");
  142. }
  143. }
  144. }
  145. .tab1 {
  146. flex: 1;
  147. height: 86rpx;
  148. color: #333;
  149. font-size: 30rpx;
  150. position: relative;
  151. // background-color: rgba(254, 249, 239, 55%);
  152. border-top-right-radius: 10px;
  153. border-top-left-radius: 10px;
  154. margin-top: 10rpx;
  155. box-shadow: inset 0px 0px 3px 0px #FFFFFF, 0px 4px 10px 0px rgba(255, 255, 255, 0.25);
  156. }
  157. .tabtext {
  158. margin-left: 50rpx;
  159. }
  160. .tabtext1 {
  161. margin-right: 50rpx;
  162. }
  163. .content-container {
  164. position: relative;
  165. height: auto;
  166. background: #fff;
  167. ;
  168. border-radius: 10px 10px 10px 10px;
  169. margin-top: -6rpx;
  170. }
  171. .content-wrap {
  172. height: 100%;
  173. box-sizing: border-box;
  174. border: 4rpx solid #FFFFFF;
  175. border-top: none;
  176. background: linear-gradient(180deg, #FFFCE1 0%, #FFFFFF 15%);
  177. }
  178. .contentwrap1 {
  179. border-radius: 0px 10px 10px 10px;
  180. }
  181. .contentwrap2 {
  182. border-radius: 10px 0 10px 10px;
  183. }
  184. .tabtitle {
  185. position: relative;
  186. z-index: 1; // 父级降低层级
  187. // 文字部分
  188. &__text {
  189. position: relative; // 必须定位元素才能生效z-index
  190. z-index: 3; // 高于装饰图片
  191. display: inline-block;
  192. }
  193. // 装饰图片
  194. image {
  195. position: absolute;
  196. bottom: -14rpx; // 根据实际图片高度调整
  197. left: 50%;
  198. transform: translateX(-50%);
  199. z-index: 2; // 介于父级和文字之间
  200. width: 100%;
  201. height: 20rpx;
  202. }
  203. }
  204. </style>