Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 59 additions & 14 deletions packages/webpack-plugin/lib/runtime/components/web/mpx-swiper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,26 @@
import throttle from 'lodash/throttle'
import { processSize } from '../../utils'

function getSwiperIndicatorStyle (alignment, offset, margin, vertical) {
const [x, y] = alignment === 'auto' ? (vertical ? [1, 0] : [0, 1]) : alignment
const [offsetX, offsetY] = offset
const xRatio = (x + 1) / 2
const yRatio = (y + 1) / 2

return {
left: `${xRatio * 100}%`,
top: `${yRatio * 100}%`,
transform: `translate(${-xRatio * 100}%, ${-yRatio * 100}%) translate(${offsetX - x * margin}px, ${offsetY - y * margin}px)`
}
}

function getSwiperIndicatorSpacingStyle (index, spacing, vertical) {
if (!index) return
return {
[vertical ? 'marginTop' : 'marginLeft']: `${spacing}px`
}
}

BScroll.use(Slide)
BScroll.use(ObserveDOM)

Expand All @@ -21,6 +41,34 @@
type: String,
default: '#000000'
},
indicatorMargin: {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里新增了 indicator-marginindicator-spacingindicator-radiusindicator-widthindicator-heightindicator-alignmentindicator-offset 七个用户可见属性,但 PR 最后的提交撤销了对应文档,最终变更中没有说明 Web 端支持范围、默认值及数组语义。按照仓库对公开 API/跨端行为的文档同步约束,请恢复 docs-vitepress/guide/advance/platform.md 中的 swiper 文档更新。

type: Number,
default: 10
},
indicatorSpacing: {
type: Number,
default: 4
},
indicatorRadius: {
type: Number,
default: 4
},
indicatorWidth: {
type: Number,
default: 8
},
indicatorHeight: {
type: Number,
default: 8
},
indicatorAlignment: {
type: [Array, String],
default: 'auto'
},
indicatorOffset: {
type: Array,
default: () => [0, 0]
},
autoplay: Boolean,
current: {
type: Number,
Expand Down Expand Up @@ -99,6 +147,9 @@
_nextMargin () {
return processSize(this.nextMargin) || 0
},
_indicatorStyle () {
return getSwiperIndicatorStyle(this.indicatorAlignment, this.indicatorOffset, this.indicatorMargin, this.vertical)
}
},
updated () {
this.setCurrentChildLength()
Expand Down Expand Up @@ -297,17 +348,21 @@
dotsItems.push(
createElement('span', {
class: 'mpx-swiper-dots-item',
style: {
backgroundColor: i === this.currentIndex ? this.indicatorActiveColor : this.indicatorColor
}
style: Object.assign({
backgroundColor: i === this.currentIndex ? this.indicatorActiveColor : this.indicatorColor,
width: `${this.indicatorWidth}px`,
height: `${this.indicatorHeight}px`,
borderRadius: `${this.indicatorRadius}px`
}, getSwiperIndicatorSpacingStyle(i, this.indicatorSpacing, this.vertical))
})
)
}
const dots = createElement('div', {
class: {
'mpx-swiper-dots': true,
vertical: this.vertical
}
},
style: this._indicatorStyle
}, dotsItems)
children.push(dots)
}
Expand Down Expand Up @@ -343,22 +398,12 @@

.mpx-swiper-dots
position absolute
right 50%
bottom 4px
transform translateX(50%)
display flex

&.vertical
right 4px
bottom 50%
transform translateY(50%)
flex-direction column

.mpx-swiper-dots-item
display block
margin 4px
width 8px
height 8px
border-radius 50%

</style>
Loading