This commit is contained in:
houjunxiang
2025-10-09 18:19:55 +08:00
parent f2ffc65094
commit 386f1e7466
1553 changed files with 284685 additions and 32820 deletions

View 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
}]
})
}
}
}

View 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
},
// 指示器样式可通过bottomleftright进行定位
indicatorStyle: {
type: [String, Object],
default: () => defProps.scrollList.indicatorStyle
}
}
})

View 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: ''
}
}

View 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
}

File diff suppressed because it is too large Load Diff