swiper-dot.nvue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <template>
  2. <view class="content">
  3. <uni-swiper-dot class="uni-swiper-dot-box" @clickItem=clickItem :info="info" :current="current" :mode="mode" :dots-styles="dotsStyles" field="content">
  4. <swiper class="swiper-box" @change="change" :current="swiperDotIndex">
  5. <swiper-item v-for="(item, index) in 3" :key="index">
  6. <view class="swiper-item" :class="'swiper-item' + index">
  7. <text style="color: #fff; font-size: 32px;">{{index+1}}</text>
  8. </view>
  9. </swiper-item>
  10. </swiper>
  11. </uni-swiper-dot>
  12. <uni-section title="模式选择" type="line">
  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>
  21. <uni-section title="颜色样式选择" type="line">
  22. <view class="example-body">
  23. <template v-if="mode !== 'nav'">
  24. <view v-for="(item, index) in dotStyle" :class="{ active: styleIndex === index }" :key="index" class="example-body-item"
  25. @click="selectStyle(index)">
  26. <view :style="{ 'background-color': item.selectedBackgroundColor, border: item.selectedBorder }" class="example-body-dots" />
  27. <view :style="{ 'background-color': item.backgroundColor, border: item.border }" class="example-body-dots" />
  28. <view :style="{ 'background-color': item.backgroundColor, border: item.border }" class="example-body-dots" />
  29. </view>
  30. </template>
  31. <template v-if="mode === 'nav'">
  32. <view v-for="(item, index) in dotStyle" :class="{ active: styleIndex === index }" :key="index" :style="{ 'background-color': item.selectedBackgroundColor }"
  33. class="example-body-item" @click="selectStyle(index)">
  34. <text class="example-body-item-text" :style="{ color: item.color }">内容</text>
  35. </view>
  36. </template>
  37. </view>
  38. </uni-section>
  39. </view>
  40. </template>
  41. <script>
  42. export default {
  43. components: {},
  44. data() {
  45. return {
  46. info: [{
  47. colorClass: 'uni-bg-red',
  48. url: 'https://vkceyugu.cdn.bspapp.com/VKCEYUGU-dc-site/094a9dc0-50c0-11eb-b680-7980c8a877b8.jpg',
  49. content: '内容 A'
  50. },
  51. {
  52. colorClass: 'uni-bg-green',
  53. url: 'https://vkceyugu.cdn.bspapp.com/VKCEYUGU-dc-site/094a9dc0-50c0-11eb-b680-7980c8a877b8.jpg',
  54. content: '内容 B'
  55. },
  56. {
  57. colorClass: 'uni-bg-blue',
  58. url: 'https://vkceyugu.cdn.bspapp.com/VKCEYUGU-dc-site/094a9dc0-50c0-11eb-b680-7980c8a877b8.jpg',
  59. content: '内容 C'
  60. }
  61. ],
  62. dotStyle: [{
  63. backgroundColor: 'rgba(0, 0, 0, .3)',
  64. border: '1px rgba(0, 0, 0, .3) solid',
  65. color: '#fff',
  66. selectedBackgroundColor: 'rgba(0, 0, 0, .9)',
  67. selectedBorder: '1px rgba(0, 0, 0, .9) solid'
  68. },
  69. {
  70. backgroundColor: 'rgba(255, 90, 95,0.3)',
  71. border: '1px rgba(255, 90, 95,0.3) solid',
  72. color: '#fff',
  73. selectedBackgroundColor: 'rgba(255, 90, 95,0.9)',
  74. selectedBorder: '1px rgba(255, 90, 95,0.9) solid'
  75. },
  76. {
  77. backgroundColor: 'rgba(83, 200, 249,0.3)',
  78. border: '1px rgba(83, 200, 249,0.3) solid',
  79. color: '#fff',
  80. selectedBackgroundColor: 'rgba(83, 200, 249,0.9)',
  81. selectedBorder: '1px rgba(83, 200, 249,0.9) solid'
  82. }
  83. ],
  84. modeIndex: -1,
  85. styleIndex: -1,
  86. current: 0,
  87. mode: 'default',
  88. dotsStyles: {},
  89. swiperDotIndex: 0
  90. }
  91. },
  92. onLoad() {},
  93. methods: {
  94. change(e) {
  95. this.current = e.detail.current
  96. },
  97. selectStyle(index) {
  98. this.dotsStyles = this.dotStyle[index]
  99. this.styleIndex = index
  100. },
  101. selectMode(mode, index) {
  102. this.mode = mode
  103. this.modeIndex = index
  104. this.styleIndex = -1
  105. this.dotsStyles = this.dotStyle[0]
  106. },
  107. clickItem(e) {
  108. this.swiperDotIndex = e
  109. },
  110. onBanner(index) {
  111. console.log(22222, index);
  112. }
  113. }
  114. }
  115. </script>
  116. <style lang="scss">
  117. .swiper-box {
  118. height: 200px;
  119. }
  120. .swiper-item {
  121. /* #ifndef APP-NVUE */
  122. display: flex;
  123. /* #endif */
  124. flex-direction: column;
  125. justify-content: center;
  126. align-items: center;
  127. height: 200px;
  128. color: #fff;
  129. }
  130. .swiper-item0 {
  131. background-color: #cee1fd;
  132. }
  133. .swiper-item1 {
  134. background-color: #b2cef7;
  135. }
  136. .swiper-item2 {
  137. background-color: #cee1fd;
  138. }
  139. .image {
  140. width: 750rpx;
  141. }
  142. /* #ifndef APP-NVUE */
  143. ::v-deep .image img {
  144. -webkit-user-drag: none;
  145. -khtml-user-drag: none;
  146. -moz-user-drag: none;
  147. -o-user-drag: none;
  148. user-drag: none;
  149. }
  150. /* #endif */
  151. @media screen and (min-width: 500px) {
  152. .uni-swiper-dot-box {
  153. width: 400px;
  154. margin: 0 auto;
  155. margin-top: 8px;
  156. }
  157. .image {
  158. width: 100%;
  159. }
  160. }
  161. .uni-bg-red {
  162. background-color: #ff5a5f;
  163. }
  164. .uni-bg-green {
  165. background-color: #09bb07;
  166. }
  167. .uni-bg-blue {
  168. background-color: #007aff;
  169. }
  170. .example-body {
  171. /* #ifndef APP-NVUE */
  172. display: flex;
  173. /* #endif */
  174. flex-direction: row;
  175. padding: 20rpx;
  176. }
  177. .example-body-item {
  178. flex-direction: row;
  179. justify-content: center;
  180. align-items: center;
  181. margin: 15rpx;
  182. padding: 15rpx;
  183. height: 60rpx;
  184. /* #ifndef APP-NVUE */
  185. display: flex;
  186. padding: 0 15rpx;
  187. /* #endif */
  188. flex: 1;
  189. border-color: #e5e5e5;
  190. border-style: solid;
  191. border-width: 1px;
  192. border-radius: 5px;
  193. }
  194. .example-body-item-text {
  195. font-size: 28rpx;
  196. color: #333;
  197. }
  198. .example-body-dots {
  199. width: 16rpx;
  200. height: 16rpx;
  201. border-radius: 50px;
  202. background-color: #333333;
  203. margin-left: 10rpx;
  204. }
  205. .active {
  206. border-style: solid;
  207. border-color: #007aff;
  208. border-width: 1px;
  209. }
  210. </style>