swiper-dot.nvue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. <template>
  2. <view class="content">
  3. <uni-swiper-dot :info="info" :current="current" :mode="mode" :dots-styles="dotsStyles" field="content">
  4. <swiper class="swiper-box" @change="change">
  5. <swiper-item v-for="(item, index) in info" :key="index">
  6. <view :class="item.colorClass" class="swiper-item">
  7. <image class="image" :src="item.url" mode="aspectFill" />
  8. </view>
  9. </swiper-item>
  10. </swiper>
  11. </uni-swiper-dot>
  12. <uni-section title="模式选择" type="line"></uni-section>
  13. <view class="example-body">
  14. <view :class="{ active: modeIndex === 0 }" class="example-body-item" @click="selectMode('default', 0)"><text class="example-body-item-text">default</text></view>
  15. <view :class="{ active: modeIndex === 1 }" class="example-body-item" @click="selectMode('dot', 1)"><text class="example-body-item-text">dot</text></view>
  16. <view :class="{ active: modeIndex === 2 }" class="example-body-item" @click="selectMode('round', 2)"><text class="example-body-item-text">round</text></view>
  17. <view :class="{ active: modeIndex === 3 }" class="example-body-item" @click="selectMode('nav', 3)"><text class="example-body-item-text">nav</text></view>
  18. <view :class="{ active: modeIndex === 4 }" class="example-body-item" @click="selectMode('indexes', 4)"><text class="example-body-item-text">indexes</text></view>
  19. </view>
  20. <uni-section title="颜色样式选择" type="line"></uni-section>
  21. <view class="example-body">
  22. <template v-if="mode !== 'nav'">
  23. <view v-for="(item, index) in dotStyle" :class="{ active: styleIndex === index }" :key="index" class="example-body-item" @click="selectStyle(index)">
  24. <view :style="{ 'background-color': item.selectedBackgroundColor, border: item.selectedBorder }" class="example-body-dots" />
  25. <view :style="{ 'background-color': item.backgroundColor, border: item.border }" class="example-body-dots" />
  26. <view :style="{ 'background-color': item.backgroundColor, border: item.border }" class="example-body-dots" />
  27. </view>
  28. </template>
  29. <template v-if="mode === 'nav'">
  30. <view v-for="(item, index) in dotStyle" :class="{ active: styleIndex === index }" :key="index" :style="{ 'background-color': item.selectedBackgroundColor }" class="example-body-item" @click="selectStyle(index)">
  31. <text class="example-body-item-text" :style="{ color: item.color }">内容</text>
  32. </view>
  33. </template>
  34. </view>
  35. </view>
  36. </template>
  37. <script>
  38. export default {
  39. components: {},
  40. data() {
  41. return {
  42. info: [{
  43. colorClass: 'uni-bg-red',
  44. url: 'https://img-cdn-qiniu.dcloud.net.cn/uniapp/images/shuijiao.jpg',
  45. content: '内容 A'
  46. },
  47. {
  48. colorClass: 'uni-bg-green',
  49. url: 'https://img-cdn-qiniu.dcloud.net.cn/uniapp/images/muwu.jpg',
  50. content: '内容 B'
  51. },
  52. {
  53. colorClass: 'uni-bg-blue',
  54. url: 'https://img-cdn-qiniu.dcloud.net.cn/uniapp/images/cbd.jpg',
  55. content: '内容 C'
  56. }
  57. ],
  58. dotStyle: [{
  59. backgroundColor: 'rgba(0, 0, 0, .3)',
  60. border: '1px rgba(0, 0, 0, .3) solid',
  61. color: '#fff',
  62. selectedBackgroundColor: 'rgba(0, 0, 0, .9)',
  63. selectedBorder: '1px rgba(0, 0, 0, .9) solid'
  64. },
  65. {
  66. backgroundColor: 'rgba(255, 90, 95,0.3)',
  67. border: '1px rgba(255, 90, 95,0.3) solid',
  68. color: '#fff',
  69. selectedBackgroundColor: 'rgba(255, 90, 95,0.9)',
  70. selectedBorder: '1px rgba(255, 90, 95,0.9) solid'
  71. },
  72. {
  73. backgroundColor: 'rgba(83, 200, 249,0.3)',
  74. border: '1px rgba(83, 200, 249,0.3) solid',
  75. color: '#fff',
  76. selectedBackgroundColor: 'rgba(83, 200, 249,0.9)',
  77. selectedBorder: '1px rgba(83, 200, 249,0.9) solid'
  78. }
  79. ],
  80. modeIndex: -1,
  81. styleIndex: -1,
  82. current: 0,
  83. mode: 'default',
  84. dotsStyles: {}
  85. }
  86. },
  87. onLoad() {},
  88. methods: {
  89. change(e) {
  90. this.current = e.detail.current
  91. },
  92. selectStyle(index) {
  93. this.dotsStyles = this.dotStyle[index]
  94. this.styleIndex = index
  95. },
  96. selectMode(mode, index) {
  97. this.mode = mode
  98. this.modeIndex = index
  99. this.styleIndex = -1
  100. this.dotsStyles = this.dotStyle[0]
  101. }
  102. }
  103. }
  104. </script>
  105. <style>
  106. @charset "UTF-8";
  107. /* 头条小程序组件内不能引入字体 */
  108. /* #ifdef MP-TOUTIAO */
  109. @font-face {
  110. font-family: uniicons;
  111. font-weight: normal;
  112. font-style: normal;
  113. src: url("~@/static/uni.ttf") format("truetype");
  114. }
  115. /* #endif */
  116. /* #ifndef APP-NVUE */
  117. page {
  118. display: flex;
  119. flex-direction: column;
  120. box-sizing: border-box;
  121. background-color: #efeff4;
  122. min-height: 100%;
  123. height: auto;
  124. }
  125. view {
  126. font-size: 14px;
  127. line-height: inherit;
  128. }
  129. .example {
  130. padding: 0 15px 15px;
  131. }
  132. .example-info {
  133. padding: 15px;
  134. color: #3b4144;
  135. background: #ffffff;
  136. }
  137. .example-body {
  138. /* #ifndef APP-NVUE */
  139. display: flex;
  140. /* #endif */
  141. flex-direction: row;
  142. flex-wrap: wrap;
  143. justify-content: center;
  144. padding: 0;
  145. font-size: 14px;
  146. background-color: #ffffff;
  147. }
  148. /* #endif */
  149. .example {
  150. padding: 0 15px;
  151. }
  152. .example-info {
  153. /* #ifndef APP-NVUE */
  154. display: block;
  155. /* #endif */
  156. padding: 15px;
  157. color: #3b4144;
  158. background-color: #ffffff;
  159. font-size: 14px;
  160. line-height: 20px;
  161. }
  162. .example-info-text {
  163. font-size: 14px;
  164. line-height: 20px;
  165. color: #3b4144;
  166. }
  167. .example-body {
  168. flex-direction: column;
  169. padding: 15px;
  170. background-color: #ffffff;
  171. }
  172. .word-btn-white {
  173. font-size: 18px;
  174. color: #FFFFFF;
  175. }
  176. .word-btn {
  177. /* #ifndef APP-NVUE */
  178. display: flex;
  179. /* #endif */
  180. flex-direction: row;
  181. align-items: center;
  182. justify-content: center;
  183. border-radius: 6px;
  184. height: 48px;
  185. margin: 15px;
  186. background-color: #007AFF;
  187. }
  188. .word-btn--hover {
  189. background-color: #4ca2ff;
  190. }
  191. .swiper-box {
  192. height: 200px;
  193. }
  194. .swiper-item {
  195. /* #ifndef APP-NVUE */
  196. display: flex;
  197. /* #endif */
  198. flex-direction: column;
  199. justify-content: center;
  200. align-items: center;
  201. background-color: #999;
  202. color: #fff;
  203. }
  204. .image {
  205. width: 750rpx;
  206. }
  207. .uni-bg-red {
  208. background-color: #ff5a5f;
  209. }
  210. .uni-bg-green {
  211. background-color: #09bb07;
  212. }
  213. .uni-bg-blue {
  214. background-color: #007aff;
  215. }
  216. .example-body {
  217. /* #ifndef APP-NVUE */
  218. display: flex;
  219. /* #endif */
  220. flex-direction: row;
  221. padding: 20rpx;
  222. }
  223. .example-body-item {
  224. flex-direction: row;
  225. justify-content: center;
  226. align-items: center;
  227. margin: 15rpx;
  228. padding: 15rpx;
  229. height: 60rpx;
  230. /* #ifndef APP-NVUE */
  231. display: flex;
  232. padding: 0 15rpx;
  233. /* #endif */
  234. flex: 1;
  235. border-color: #e5e5e5;
  236. border-style: solid;
  237. border-width: 1px;
  238. border-radius: 5px;
  239. }
  240. .example-body-item-text {
  241. font-size: 28rpx;
  242. color: #333;
  243. }
  244. .example-body-dots {
  245. width: 16rpx;
  246. height: 16rpx;
  247. border-radius: 50px;
  248. background-color: #333333;
  249. margin-left: 10rpx;
  250. }
  251. .active {
  252. border-style: solid;
  253. border-color: #007aff;
  254. border-width: 1px;
  255. }
  256. </style>