uni-swiper-dot.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <template>
  2. <view class="uni-swiper__warp">
  3. <slot />
  4. <view v-if="mode === 'default'" :style="{'bottom':dots.bottom + 'px'}" class="uni-swiper__dots-box" key='default'>
  5. <view v-for="(item,index) in info" :style="{
  6. 'width': (index === current? dots.width*2:dots.width ) + 'px','height':dots.width/3 +'px' ,'background-color':index !== current?dots.backgroundColor:dots.selectedBackgroundColor,'border-radius':'0px'}"
  7. :key="index" class="uni-swiper__dots-item uni-swiper__dots-bar" />
  8. </view>
  9. <view v-if="mode === 'dot'" :style="{'bottom':dots.bottom + 'px'}" class="uni-swiper__dots-box" key='dot'>
  10. <view v-for="(item,index) in info" :style="{
  11. 'width': dots.width + 'px','height':dots.height +'px' ,'background-color':index !== current?dots.backgroundColor:dots.selectedBackgroundColor,'border':index !==current ? dots.border:dots.selectedBorder}"
  12. :key="index" class="uni-swiper__dots-item" />
  13. </view>
  14. <view v-if="mode === 'round'" :style="{'bottom':dots.bottom + 'px'}" class="uni-swiper__dots-box" key='round'>
  15. <view v-for="(item,index) in info" :class="[index === current&&'uni-swiper__dots-long']" :style="{
  16. 'width':(index === current? dots.width*3:dots.width ) + 'px','height':dots.height +'px' ,'background-color':index !== current?dots.backgroundColor:dots.selectedBackgroundColor,'border':index !==current ? dots.border:dots.selectedBorder}"
  17. :key="index" class="uni-swiper__dots-item " />
  18. </view>
  19. <view v-if="mode === 'nav'" key='nav' :style="{'background-color':dotsStyles.backgroundColor,'bottom':'0'}" class="uni-swiper__dots-box uni-swiper__dots-nav">
  20. <text :style="{'color':dotsStyles.color}" class="uni-swiper__dots-nav-item">{{ (current+1)+"/"+info.length +' ' +info[current][field] }}</text>
  21. </view>
  22. <view v-if="mode === 'indexes'" key='indexes' :style="{'bottom':dots.bottom + 'px'}" class="uni-swiper__dots-box">
  23. <view v-for="(item,index) in info" :style="{
  24. 'width':dots.width + 'px','height':dots.height +'px' ,'color':index === current?dots.selectedColor:dots.color,'background-color':index !== current?dots.backgroundColor:dots.selectedBackgroundColor,'border':index !==current ? dots.border:dots.selectedBorder}"
  25. :key="index" class="uni-swiper__dots-item uni-swiper__dots-indexes"><text class="uni-swiper__dots-indexes-text">{{ index+1 }}</text></view>
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. export default {
  31. name: 'UniSwiperDot',
  32. props: {
  33. info: {
  34. type: Array,
  35. default () {
  36. return []
  37. }
  38. },
  39. current: {
  40. type: Number,
  41. default: 0
  42. },
  43. dotsStyles: {
  44. type: Object,
  45. default () {
  46. return {}
  47. }
  48. },
  49. // 类型 :default(默认) indexes long nav
  50. mode: {
  51. type: String,
  52. default: 'default'
  53. },
  54. // 只在 nav 模式下生效,变量名称
  55. field: {
  56. type: String,
  57. default: ''
  58. }
  59. },
  60. data() {
  61. return {
  62. dots: {
  63. width: 8,
  64. height: 8,
  65. bottom: 10,
  66. color: '#fff',
  67. backgroundColor: 'rgba(0, 0, 0, .3)',
  68. border: '1px rgba(0, 0, 0, .3) solid',
  69. selectedBackgroundColor: '#333',
  70. selectedBorder: '1px rgba(0, 0, 0, .9) solid'
  71. }
  72. }
  73. },
  74. watch: {
  75. dotsStyles(newVal) {
  76. this.dots = Object.assign(this.dots, this.dotsStyles)
  77. },
  78. mode(newVal) {
  79. if (newVal === 'indexes') {
  80. this.dots.width = 20
  81. this.dots.height = 20
  82. } else {
  83. this.dots.width = 8
  84. this.dots.height = 8
  85. }
  86. }
  87. },
  88. created() {
  89. if (this.mode === 'indexes') {
  90. this.dots.width = 20
  91. this.dots.height = 20
  92. }
  93. this.dots = Object.assign(this.dots, this.dotsStyles)
  94. }
  95. }
  96. </script>
  97. <style lang="scss" scoped>
  98. .uni-swiper__warp {
  99. /* #ifndef APP-NVUE */
  100. display: flex;
  101. /* #endif */
  102. flex: 1;
  103. flex-direction: column;
  104. position: relative;
  105. overflow: hidden;
  106. }
  107. .uni-swiper__dots-box {
  108. position: absolute;
  109. bottom: 10px;
  110. left: 0;
  111. right: 0;
  112. /* #ifndef APP-NVUE */
  113. display: flex;
  114. /* #endif */
  115. flex: 1;
  116. flex-direction: row;
  117. justify-content: center;
  118. align-items: center;
  119. }
  120. .uni-swiper__dots-item {
  121. width: 8px;
  122. border-radius: 100px;
  123. margin-left: 6px;
  124. background-color: $uni-bg-color-mask;
  125. // transition: width 0.2s linear; 不要取消注释,不然会不能变色
  126. }
  127. .uni-swiper__dots-item:first-child {
  128. margin: 0;
  129. }
  130. .uni-swiper__dots-default {
  131. border-radius: 100px;
  132. }
  133. .uni-swiper__dots-long {
  134. border-radius: 50px;
  135. }
  136. .uni-swiper__dots-bar {
  137. border-radius: 50px;
  138. }
  139. .uni-swiper__dots-nav {
  140. bottom: 0px;
  141. height: 40px;
  142. /* #ifndef APP-NVUE */
  143. display: flex;
  144. /* #endif */
  145. flex: 1;
  146. flex-direction: row;
  147. justify-content: flex-start;
  148. align-items: center;
  149. background-color: rgba(0, 0, 0, 0.2);
  150. }
  151. .uni-swiper__dots-nav-item {
  152. /* overflow: hidden;
  153. text-overflow: ellipsis;
  154. white-space: nowrap; */
  155. font-size: $uni-font-size-base;
  156. color: #fff;
  157. margin: 0 15px;
  158. }
  159. .uni-swiper__dots-indexes {
  160. /* #ifndef APP-NVUE */
  161. display: flex;
  162. /* #endif */
  163. // flex: 1;
  164. justify-content: center;
  165. align-items: center;
  166. }
  167. .uni-swiper__dots-indexes-text {
  168. color: #fff;
  169. font-size: $uni-font-size-sm;
  170. }
  171. </style>