segmented-control.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <template>
  2. <view>
  3. <uni-card is-full>
  4. <text class="uni-h6">标签组件多用于商品分类、重点内容显示等场景。</text>
  5. </uni-card>
  6. <uni-section title="实心标签" type="line">
  7. <view class="uni-padding-wrap uni-common-mt">
  8. <uni-segmented-control :current="current" :values="items" :style-type="styleType"
  9. :active-color="activeColor" @clickItem="onClickItem" />
  10. </view>
  11. <view class="content">
  12. <view v-if="current === 0"><text class="content-text">选项卡1的内容</text></view>
  13. <view v-if="current === 1"><text class="content-text">选项卡2的内容</text></view>
  14. <view v-if="current === 2"><text class="content-text">选项卡3的内容</text></view>
  15. </view>
  16. </uni-section>
  17. <uni-section title="Style" type="line"></uni-section>
  18. <view class="example-body">
  19. <radio-group class="uni-list" @change="styleChange">
  20. <view v-for="(item, index) in styles" :key="index" class="uni-list-item">
  21. <view class="uni-list-item__container">
  22. <view class="uni-list-item__content">
  23. <text class="uni-list-item__content-title">{{ item.text }}</text>
  24. </view>
  25. <view class="uni-list-item__extra">
  26. <radio :value="item.value" :checked="item.checked" />
  27. </view>
  28. </view>
  29. </view>
  30. </radio-group>
  31. </view>
  32. <uni-section title="Color" type="line"></uni-section>
  33. <view class="example-body">
  34. <radio-group class="uni-list" @change="colorChange">
  35. <view v-for="(item, index) in colors" :key="index" class="uni-list-item">
  36. <view class="uni-list-item__container">
  37. <view class="uni-list-item__content">
  38. <view :style="{ backgroundColor: item }" class="color-tag" />
  39. </view>
  40. <view class="uni-list-item__extra">
  41. <radio :value="item" :checked="index === colorIndex" />
  42. </view>
  43. </view>
  44. </view>
  45. </radio-group>
  46. </view>
  47. </view>
  48. </template>
  49. <script>
  50. export default {
  51. components: {},
  52. data() {
  53. return {
  54. items: ['选项卡1', '选项卡2', '选项卡3'],
  55. styles: [{
  56. value: 'button',
  57. text: '按钮',
  58. checked: true
  59. },
  60. {
  61. value: 'text',
  62. text: '文字'
  63. }
  64. ],
  65. colors: ['#007aff', '#4cd964', '#dd524d'],
  66. current: 0,
  67. colorIndex: 0,
  68. activeColor: '#007aff',
  69. styleType: 'button'
  70. }
  71. },
  72. methods: {
  73. onClickItem(e) {
  74. if (this.current !== e.currentIndex) {
  75. this.current = e.currentIndex
  76. }
  77. },
  78. styleChange(e) {
  79. if (this.styleType !== e.detail.value) {
  80. this.styleType = e.detail.value
  81. }
  82. },
  83. colorChange(e) {
  84. if (this.styleType !== e.detail.value) {
  85. console.log(e.detail.value);
  86. this.activeColor = e.detail.value
  87. }
  88. }
  89. }
  90. }
  91. </script>
  92. <style lang="scss">
  93. .example-body {
  94. /* #ifndef APP-NVUE */
  95. display: flex;
  96. /* #endif */
  97. flex-direction: row;
  98. padding: 0;
  99. }
  100. .uni-common-mt {
  101. margin-top: 30px;
  102. }
  103. .uni-padding-wrap {
  104. // width: 750rpx;
  105. padding: 0px 30px;
  106. }
  107. .content {
  108. /* #ifndef APP-NVUE */
  109. display: flex;
  110. /* #endif */
  111. justify-content: center;
  112. align-items: center;
  113. height: 150px;
  114. text-align: center;
  115. }
  116. .content-text {
  117. font-size: 14px;
  118. color: $uni-text-color;
  119. }
  120. .color-tag {
  121. width: 25px;
  122. height: 25px;
  123. }
  124. .uni-list {
  125. flex: 1;
  126. }
  127. .uni-list-item {
  128. /* #ifndef APP-NVUE */
  129. display: flex;
  130. /* #endif */
  131. flex: 1;
  132. flex-direction: row;
  133. background-color: #FFFFFF;
  134. }
  135. .uni-list-item__container {
  136. padding: 12px 15px;
  137. width: 100%;
  138. flex: 1;
  139. position: relative;
  140. /* #ifndef APP-NVUE */
  141. display: flex;
  142. box-sizing: border-box;
  143. /* #endif */
  144. flex-direction: row;
  145. justify-content: space-between;
  146. align-items: center;
  147. border-bottom-style: solid;
  148. border-bottom-width: 1px;
  149. border-bottom-color: #eee;
  150. }
  151. .uni-list-item__content-title {
  152. font-size: 14px;
  153. }
  154. </style>