1
This commit is contained in:
31
uview-plus/components/u-scroll-list/nvue.js
Normal file
31
uview-plus/components/u-scroll-list/nvue.js
Normal file
@@ -0,0 +1,31 @@
|
||||
// 引入bindingx,此库类似于微信小程序wxs,目的是让js运行在视图层,减少视图层和逻辑层的通信折损
|
||||
const BindingX = uni.requireNativePlugin('bindingx')
|
||||
import { os } from '../../libs/function/index';
|
||||
export default {
|
||||
methods: {
|
||||
// 此处不写注释,请自行体会
|
||||
nvueScrollHandler(e) {
|
||||
const anchor = this.$refs['u-scroll-list__scroll-view'].ref
|
||||
let element = {}
|
||||
if (this.$refs['u-scroll-list__indicator__line__bar']) {
|
||||
element = this.$refs['u-scroll-list__indicator__line__bar'].ref
|
||||
}
|
||||
const scrollLeft = e.contentOffset.x
|
||||
const contentSize = e.contentSize.width
|
||||
const { scrollWidth } = this
|
||||
const barAllMoveWidth = this.indicatorWidth - this.indicatorBarWidth
|
||||
// 在安卓和iOS上,需要除的倍数不一样,iOS需要除以2
|
||||
const actionNum = os() === 'ios' ? 2 : 1
|
||||
const expression = `(x / ${actionNum}) / ${contentSize - scrollWidth} * ${barAllMoveWidth}`
|
||||
BindingX.bind({
|
||||
anchor,
|
||||
eventType: 'scroll',
|
||||
props: [{
|
||||
element,
|
||||
property: 'transform.translateX',
|
||||
expression
|
||||
}]
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
0
uview-plus/components/u-scroll-list/other.js
Normal file
0
uview-plus/components/u-scroll-list/other.js
Normal file
36
uview-plus/components/u-scroll-list/props.js
Normal file
36
uview-plus/components/u-scroll-list/props.js
Normal file
@@ -0,0 +1,36 @@
|
||||
import { defineMixin } from '../../libs/vue'
|
||||
import defProps from '../../libs/config/props.js'
|
||||
export const props = defineMixin({
|
||||
props: {
|
||||
// 指示器的整体宽度
|
||||
indicatorWidth: {
|
||||
type: [String, Number],
|
||||
default: () => defProps.scrollList.indicatorWidth
|
||||
},
|
||||
// 滑块的宽度
|
||||
indicatorBarWidth: {
|
||||
type: [String, Number],
|
||||
default: () => defProps.scrollList.indicatorBarWidth
|
||||
},
|
||||
// 是否显示面板指示器
|
||||
indicator: {
|
||||
type: Boolean,
|
||||
default: () => defProps.scrollList.indicator
|
||||
},
|
||||
// 指示器非激活颜色
|
||||
indicatorColor: {
|
||||
type: String,
|
||||
default: () => defProps.scrollList.indicatorColor
|
||||
},
|
||||
// 指示器的激活颜色
|
||||
indicatorActiveColor: {
|
||||
type: String,
|
||||
default: () => defProps.scrollList.indicatorActiveColor
|
||||
},
|
||||
// 指示器样式,可通过bottom,left,right进行定位
|
||||
indicatorStyle: {
|
||||
type: [String, Object],
|
||||
default: () => defProps.scrollList.indicatorStyle
|
||||
}
|
||||
}
|
||||
})
|
||||
20
uview-plus/components/u-scroll-list/scrollList.js
Normal file
20
uview-plus/components/u-scroll-list/scrollList.js
Normal file
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* @Author : LQ
|
||||
* @Description :
|
||||
* @version : 1.0
|
||||
* @Date : 2021-08-20 16:44:21
|
||||
* @LastAuthor : LQ
|
||||
* @lastTime : 2021-08-20 17:19:28
|
||||
* @FilePath : /u-view2.0/uview-ui/libs/config/props/scrollList.js
|
||||
*/
|
||||
export default {
|
||||
// scrollList
|
||||
scrollList: {
|
||||
indicatorWidth: 50,
|
||||
indicatorBarWidth: 20,
|
||||
indicator: true,
|
||||
indicatorColor: '#f2f2f2',
|
||||
indicatorActiveColor: '#3c9cff',
|
||||
indicatorStyle: ''
|
||||
}
|
||||
}
|
||||
50
uview-plus/components/u-scroll-list/scrollWxs.wxs
Normal file
50
uview-plus/components/u-scroll-list/scrollWxs.wxs
Normal file
@@ -0,0 +1,50 @@
|
||||
function scroll(event, ownerInstance) {
|
||||
// detail中含有scroll-view的信息,比如scroll-view的实际宽度,当前时间点scroll-view的移动距离等
|
||||
var detail = event.detail
|
||||
var scrollWidth = detail.scrollWidth
|
||||
var scrollLeft = detail.scrollLeft
|
||||
// 获取当前组件的dataset,说白了就是祸国殃民的腾xun搞出来的垃ji
|
||||
var dataset = event.currentTarget.dataset
|
||||
// 此为scroll-view外部包裹元素的宽度
|
||||
// 某些HX版本(3.1.18),发现view元素中大写的data-scrollWidth,在wxs中,变成了全部小写,所以这里需要特别处理
|
||||
var scrollComponentWidth = dataset.scrollWidth || dataset.scrollwidth || 0
|
||||
// 指示器和滑块的宽度
|
||||
var indicatorWidth = dataset.indicatorWidth || dataset.indicatorwidth || 0
|
||||
var barWidth = dataset.barWidth || dataset.barwidth || 0
|
||||
// 此处的计算理由为:scroll-view的滚动距离与目标滚动距离(scroll-view的实际宽度减去包裹元素的宽度)之比,等于滑块当前移动距离与总需
|
||||
// 滑动距离(指示器的总宽度减去滑块宽度)的比值
|
||||
var x = scrollLeft / (scrollWidth - scrollComponentWidth) * (indicatorWidth - barWidth)
|
||||
setBarStyle(ownerInstance, x)
|
||||
}
|
||||
|
||||
// 由于webview的无能,无法保证scroll-view在滑动过程中,一直触发scroll事件,会导致
|
||||
// 无法监听到某些滚动值,当在首尾临界值无法监听到时,这是致命的,因为错失这些值会导致滑块无法回到起点和终点
|
||||
// 所以这里需要对临界值做监听并处理
|
||||
function scrolltolower(event, ownerInstance) {
|
||||
ownerInstance.callMethod('scrollEvent', 'right')
|
||||
// 获取当前组件的dataset
|
||||
var dataset = event.currentTarget.dataset
|
||||
// 指示器和滑块的宽度
|
||||
var indicatorWidth = dataset.indicatorWidth || dataset.indicatorwidth || 0
|
||||
var barWidth = dataset.barWidth || dataset.barwidth || 0
|
||||
// scroll-view滚动到右边终点时,将滑块也设置为到右边的终点,它所需移动的距离为:指示器宽度 - 滑块宽度
|
||||
setBarStyle(ownerInstance, indicatorWidth - barWidth)
|
||||
}
|
||||
|
||||
function scrolltoupper(event, ownerInstance) {
|
||||
ownerInstance.callMethod('scrollEvent', 'left')
|
||||
// 滚动到左边时,将滑块设置为0的偏移距离,回到起点
|
||||
setBarStyle(ownerInstance, 0)
|
||||
}
|
||||
|
||||
function setBarStyle(ownerInstance, x) {
|
||||
ownerInstance.selectComponent('.u-scroll-list__indicator__line__bar') && ownerInstance.selectComponent('.u-scroll-list__indicator__line__bar').setStyle({
|
||||
transform: 'translateX(' + x + 'px)'
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
scroll: scroll,
|
||||
scrolltolower: scrolltolower,
|
||||
scrolltoupper: scrolltoupper
|
||||
}
|
||||
235
uview-plus/components/u-scroll-list/u-scroll-list.vue
Normal file
235
uview-plus/components/u-scroll-list/u-scroll-list.vue
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user