segmented-control.nvue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <template>
  2. <view>
  3. <view class="uni-padding-wrap uni-common-mt">
  4. <uni-segmented-control :current="current" :values="items" :style-type="styleType" :active-color="activeColor" @clickItem="onClickItem" />
  5. </view>
  6. <view class="content">
  7. <view v-if="current === 0"><text class="content-text">选项卡1的内容</text></view>
  8. <view v-if="current === 1"><text class="content-text">选项卡2的内容</text></view>
  9. <view v-if="current === 2"><text class="content-text">选项卡3的内容</text></view>
  10. </view>
  11. <uni-section title="Style" type="line"></uni-section>
  12. <view class="example-body">
  13. <radio-group class="uni-list " @change="styleChange">
  14. <view v-for="(item, index) in styles" :key="index" class="uni-list-item">
  15. <view class="uni-list-item__container">
  16. <view class="uni-list-item__content">
  17. <text class="uni-list-item__content-title">{{ item.text }}</text>
  18. </view>
  19. <view class="uni-list-item__extra">
  20. <radio :value="item.value" :checked="item.checked" />
  21. </view>
  22. </view>
  23. </view>
  24. </radio-group>
  25. </view>
  26. <uni-section title="Color" type="line"></uni-section>
  27. <view class="example-body">
  28. <radio-group class="uni-list" @change="colorChange">
  29. <view v-for="(item, index) in colors" :key="index" class="uni-list-item">
  30. <view class="uni-list-item__container">
  31. <view class="uni-list-item__content">
  32. <view :style="{ backgroundColor: item }" class="color-tag" />
  33. </view>
  34. <view class="uni-list-item__extra">
  35. <radio :value="item" :checked="index === colorIndex" />
  36. </view>
  37. </view>
  38. </view>
  39. </radio-group>
  40. </view>
  41. </view>
  42. </template>
  43. <script>
  44. export default {
  45. components: {},
  46. data() {
  47. return {
  48. items: ['选项卡1', '选项卡2', '选项卡3'],
  49. styles: [{
  50. value: 'button',
  51. text: '按钮',
  52. checked: true
  53. },
  54. {
  55. value: 'text',
  56. text: '文字'
  57. }
  58. ],
  59. colors: ['#007aff', '#4cd964', '#dd524d'],
  60. current: 0,
  61. colorIndex: 0,
  62. activeColor: '#007aff',
  63. styleType: 'button'
  64. }
  65. },
  66. methods: {
  67. onClickItem(e) {
  68. if (this.current !== e.currentIndex) {
  69. this.current = e.currentIndex
  70. }
  71. },
  72. styleChange(e) {
  73. if (this.styleType !== e.detail.value) {
  74. this.styleType = e.detail.value
  75. }
  76. },
  77. colorChange(e) {
  78. if (this.styleType !== e.detail.value) {
  79. console.log(e.detail.value);
  80. this.activeColor = e.detail.value
  81. }
  82. }
  83. }
  84. }
  85. </script>
  86. <style>
  87. @charset "UTF-8";
  88. /* 头条小程序组件内不能引入字体 */
  89. /* #ifdef MP-TOUTIAO */
  90. @font-face {
  91. font-family: uniicons;
  92. font-weight: normal;
  93. font-style: normal;
  94. src: url("~@/static/uni.ttf") format("truetype");
  95. }
  96. /* #endif */
  97. /* #ifndef APP-NVUE */
  98. page {
  99. display: flex;
  100. flex-direction: column;
  101. box-sizing: border-box;
  102. background-color: #efeff4;
  103. min-height: 100%;
  104. height: auto;
  105. }
  106. view {
  107. font-size: 14px;
  108. line-height: inherit;
  109. }
  110. .example {
  111. padding: 0 15px 15px;
  112. }
  113. .example-info {
  114. padding: 15px;
  115. color: #3b4144;
  116. background: #ffffff;
  117. }
  118. .example-body {
  119. /* #ifndef APP-NVUE */
  120. display: flex;
  121. /* #endif */
  122. flex-direction: row;
  123. flex-wrap: wrap;
  124. justify-content: center;
  125. padding: 0;
  126. font-size: 14px;
  127. background-color: #ffffff;
  128. }
  129. /* #endif */
  130. .example {
  131. padding: 0 15px;
  132. }
  133. .example-info {
  134. /* #ifndef APP-NVUE */
  135. display: block;
  136. /* #endif */
  137. padding: 15px;
  138. color: #3b4144;
  139. background-color: #ffffff;
  140. font-size: 14px;
  141. line-height: 20px;
  142. }
  143. .example-info-text {
  144. font-size: 14px;
  145. line-height: 20px;
  146. color: #3b4144;
  147. }
  148. .example-body {
  149. flex-direction: column;
  150. padding: 15px;
  151. background-color: #ffffff;
  152. }
  153. .word-btn-white {
  154. font-size: 18px;
  155. color: #FFFFFF;
  156. }
  157. .word-btn {
  158. /* #ifndef APP-NVUE */
  159. display: flex;
  160. /* #endif */
  161. flex-direction: row;
  162. align-items: center;
  163. justify-content: center;
  164. border-radius: 6px;
  165. height: 48px;
  166. margin: 15px;
  167. background-color: #007AFF;
  168. }
  169. .word-btn--hover {
  170. background-color: #4ca2ff;
  171. }
  172. .example-body {
  173. /* #ifndef APP-NVUE */
  174. display: flex;
  175. /* #endif */
  176. flex-direction: row;
  177. padding: 0;
  178. }
  179. .uni-common-mt {
  180. margin-top: 30px;
  181. }
  182. .uni-padding-wrap {
  183. width: 750rpx;
  184. padding: 0px 30px;
  185. }
  186. .content {
  187. /* #ifndef APP-NVUE */
  188. display: flex;
  189. /* #endif */
  190. justify-content: center;
  191. align-items: center;
  192. height: 150px;
  193. text-align: center;
  194. }
  195. .content-text {
  196. font-size: 18px;
  197. color: #333;
  198. }
  199. .color-tag {
  200. width: 25px;
  201. height: 25px;
  202. }
  203. .uni-list {
  204. flex: 1;
  205. }
  206. .uni-list-item {
  207. /* #ifndef APP-NVUE */
  208. display: flex;
  209. /* #endif */
  210. flex: 1;
  211. flex-direction: row;
  212. background-color: #FFFFFF;
  213. }
  214. .uni-list-item__container {
  215. padding: 12px 15px;
  216. width: 100%;
  217. flex: 1;
  218. position: relative;
  219. /* #ifndef APP-NVUE */
  220. display: flex;
  221. box-sizing: border-box;
  222. /* #endif */
  223. flex-direction: row;
  224. justify-content: space-between;
  225. align-items: center;
  226. border-bottom-style: solid;
  227. border-bottom-width: 1px;
  228. border-bottom-color: #e5e5e5;
  229. }
  230. .uni-list-item__content-title {
  231. font-size: 16px;
  232. }
  233. </style>