feat: 首次提交
This commit is contained in:
212
components/firstui/fui-slider/bindingx.js
Normal file
212
components/firstui/fui-slider/bindingx.js
Normal file
@ -0,0 +1,212 @@
|
||||
// 本文件由FirstUI授权予新疆天衡创新研究院有限公司(手机号: 18614 0 7 2549,身份证尾号:5A07X5)专用,请尊重知识产权,勿私下传播,违者追究法律责任。
|
||||
// #ifdef APP-NVUE
|
||||
//BindingX实现滑动比较流畅(已实现),缺点不好实时更新数据,暂时废弃
|
||||
// const BindingX = uni.requireNativePlugin('bindingx');
|
||||
const animation = uni.requireNativePlugin('animation');
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
isRight: false,
|
||||
isAndroid: false
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
value(val) {
|
||||
this.initData(val)
|
||||
},
|
||||
endValue(val) {
|
||||
if (this.section) {
|
||||
this.initEndData(val)
|
||||
}
|
||||
},
|
||||
isRight(val) {
|
||||
if (!val) {
|
||||
this.$nextTick(() => {
|
||||
setTimeout(() => {
|
||||
this.handleRight = this.getEl(this.$refs['handleRight'])
|
||||
}, 50)
|
||||
})
|
||||
}
|
||||
}
|
||||
},
|
||||
created() {
|
||||
const res = uni.getSystemInfoSync();
|
||||
this.isAndroid = res.platform.toLocaleLowerCase() == "android"
|
||||
this.startX = 0
|
||||
this.endX = 0
|
||||
this.lastLeft = 0
|
||||
this.onceLeft = 0
|
||||
this.lastRight = 0
|
||||
this.onceRight = 0
|
||||
},
|
||||
mounted() {
|
||||
this.$nextTick(() => {
|
||||
setTimeout(() => {
|
||||
this.handleLeft = this.getEl(this.$refs['handleLeft'])
|
||||
this.poleLeft = this.getEl(this.$refs['poleLeft']);
|
||||
this.handleRight = null;
|
||||
this.poleRight = null;
|
||||
this.initData(this.value)
|
||||
if (this.section) {
|
||||
this.handleRight = this.getEl(this.$refs['handleRight'])
|
||||
this.poleRight = this.getEl(this.$refs['poleRight']);
|
||||
this.initEndData(this.endValue)
|
||||
}
|
||||
}, 50)
|
||||
})
|
||||
},
|
||||
methods: {
|
||||
getEl(el) {
|
||||
return el.ref;
|
||||
},
|
||||
initData(value) {
|
||||
this.startX = 0;
|
||||
this.lastLeft = 0;
|
||||
this.styleChange(Number(value), true)
|
||||
},
|
||||
initEndData(value) {
|
||||
this.endX = 0;
|
||||
this.lastRight = 0;
|
||||
value = Number(this.max) - Number(value) + Number(this.min)
|
||||
this.styleSectionChange(value, true)
|
||||
},
|
||||
format(value) {
|
||||
value = Number(value)
|
||||
let step = Number(this.step)
|
||||
return Math.round(Math.max(Number(this.min), Math.min(value, Number(this.max))) / step) * step;
|
||||
},
|
||||
_animation(move, trans, isRight) {
|
||||
animation.transition(
|
||||
isRight ? this.handleRight : this.handleLeft, {
|
||||
styles: {
|
||||
transform: move
|
||||
},
|
||||
duration: 0,
|
||||
timingFunction: 'linear',
|
||||
needLayout: false,
|
||||
delay: 0
|
||||
});
|
||||
animation.transition(
|
||||
isRight ? this.poleRight : this.poleLeft, {
|
||||
styles: {
|
||||
transform: trans
|
||||
},
|
||||
duration: 0,
|
||||
timingFunction: 'linear',
|
||||
needLayout: false,
|
||||
delay: 0
|
||||
});
|
||||
},
|
||||
touchstart(e) {
|
||||
if (this.disabled) return;
|
||||
let touch = e.touches[0] || e.changedTouches[0];
|
||||
this.startX = touch.screenX
|
||||
},
|
||||
endTouchstart(e) {
|
||||
if (this.disabled) return;
|
||||
let touch = e.touches[0] || e.changedTouches[0];
|
||||
this.endX = touch.screenX
|
||||
},
|
||||
changeValue(value, isStart, isEnd) {
|
||||
var params = {
|
||||
value: value,
|
||||
isStart: isStart
|
||||
}
|
||||
if (isEnd) {
|
||||
this.change(params)
|
||||
} else {
|
||||
this.changing(params)
|
||||
}
|
||||
},
|
||||
styleChange(value, isEnd) {
|
||||
value = this.format(value);
|
||||
const min = Number(this.min)
|
||||
const max = Number(this.max)
|
||||
if (this.section) {
|
||||
value = value > this.end ? this.end : value;
|
||||
}
|
||||
this.changeValue(value, true, isEnd)
|
||||
var dvalue = max - min;
|
||||
var maxWidth = Number(this.width) - Number(this.blockWidth);
|
||||
var width = (value - min) / dvalue * maxWidth;
|
||||
this.lastLeft = width
|
||||
if (isEnd) {
|
||||
this.onceLeft = width
|
||||
}
|
||||
this._animation(`translateX(${width}px)`, `translateX(-${Number(this.width)-width}px)`, false)
|
||||
this.isRight = value === max
|
||||
},
|
||||
styleSectionChange(value, isEnd) {
|
||||
value = this.format(value);
|
||||
const min = Number(this.min)
|
||||
const max = Number(this.max)
|
||||
var total = max + min;
|
||||
var val = total - value;
|
||||
val = val < this.start ? this.start : val;
|
||||
value = total - val;
|
||||
this.changeValue(val, false, isEnd)
|
||||
var dvalue = max - min;
|
||||
var maxWidth = Number(this.width) - Number(this.blockWidth);
|
||||
var width = (value - min) / dvalue * maxWidth;
|
||||
this.lastRight = width
|
||||
if (isEnd) {
|
||||
this.onceRight = width
|
||||
}
|
||||
this._animation(`translateX(-${width}px)`, `translateX(${Number(this.width)-width}px)`, true)
|
||||
},
|
||||
touchmove(e) {
|
||||
if (this.disabled) return;
|
||||
let touch = e.changedTouches[0];
|
||||
let pageX = touch.screenX;
|
||||
this.drag = true
|
||||
let left = pageX - this.startX + (this.onceLeft || 0);
|
||||
left = left < 0 ? 0 : left;
|
||||
let maxWidth = Number(this.width) - Number(this.blockWidth);
|
||||
left = left >= maxWidth ? maxWidth : left;
|
||||
let dvalue = Number(this.max) - Number(this.min);
|
||||
let value = (left / maxWidth) * dvalue + Number(this.min);
|
||||
// this.startX = pageX
|
||||
this.lastLeft = left
|
||||
this.styleChange(value, false)
|
||||
},
|
||||
endTouchmove(e) {
|
||||
if (this.disabled) return;
|
||||
let touch = e.changedTouches[0];
|
||||
let pageX = touch.screenX;
|
||||
this.drag = true
|
||||
let left = this.endX - pageX + (this.onceRight || 0);
|
||||
left = left < 0 ? 0 : left;
|
||||
let maxWidth = Number(this.width) - Number(this.blockWidth);
|
||||
left = left >= maxWidth ? maxWidth : left;
|
||||
let dvalue = Number(this.max) - Number(this.min);
|
||||
let value = (left / maxWidth) * dvalue + Number(this.min);
|
||||
// this.endX = pageX
|
||||
this.lastRight = left
|
||||
this.styleSectionChange(value, false)
|
||||
},
|
||||
touchend(e) {
|
||||
if (this.disabled) return;
|
||||
if (this.drag) {
|
||||
let maxWidth = Number(this.width) - Number(this.blockWidth);
|
||||
let dvalue = Number(this.max) - Number(this.min);
|
||||
let value = (this.lastLeft / maxWidth) * dvalue + Number(this.min);
|
||||
this.styleChange(value, true)
|
||||
}
|
||||
},
|
||||
endTouchend(e) {
|
||||
if (this.disabled) return;
|
||||
if (this.drag) {
|
||||
let maxWidth = Number(this.width) - Number(this.blockWidth);
|
||||
let dvalue = Number(this.max) - Number(this.min);
|
||||
let value = (this.lastRight / maxWidth) * dvalue + Number(this.min);
|
||||
this.styleSectionChange(value, true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// #endif
|
||||
|
||||
// #ifndef APP-NVUE
|
||||
export default {}
|
||||
// #endif
|
398
components/firstui/fui-slider/fui-slider.vue
Normal file
398
components/firstui/fui-slider/fui-slider.vue
Normal file
@ -0,0 +1,398 @@
|
||||
<!--本文件由FirstUI授权予新疆天衡创新研究院有限公司(手机号: 1 8 61 4 07254 9,身份证尾号:5A07X5)专用,请尊重知识产权,勿私下传播,违者追究法律责任。-->
|
||||
<template>
|
||||
<view class="fui-slider__wrap-outer">
|
||||
<text class="fui-slider__value" :class="['fui-slider__vr']"
|
||||
:style="{width:valueWidth+'px',color:valueColor,fontSize:valueSize+'px'}"
|
||||
v-if="section && showValue">{{start}}</text>
|
||||
<!-- #ifdef APP-VUE || MP-WEIXIN || H5-->
|
||||
<view class="fui-slider__wrap" :style="{width:width+'px',height:(blockHeight<height?height:blockHeight)+'px'}">
|
||||
<view class="fui-slider__pole"
|
||||
:style="{width:width+'px',height:height+'px',borderRadius:radius+'px',background:background}">
|
||||
<view class="fui-slider__pole-left" :class="{'fui-slider__pole-bg':!getActiveColor}"
|
||||
:style="{background:getActiveColor}"></view>
|
||||
<view class="fui-slider__pole-right" :class="{'fui-slider__pole-bg':!getActiveColor}"
|
||||
:style="{background:getActiveColor}"></view>
|
||||
</view>
|
||||
<view class="fui-slider__handle"
|
||||
:style="{width:blockWidth+'px',height:blockHeight+'px',borderRadius:blockRadius+'px',background:blockColor}"
|
||||
:class="['fui-slider__handle-left',disabled?'fui-slider__disabled':'']"
|
||||
:change:prop="handler.slidevalue" :prop="initValue" :data-blockWidth="blockWidth" :data-width="width"
|
||||
:data-step="step" :data-min="min" :data-max="max" :data-disabled="disabled?1:0" :data-value="start"
|
||||
:data-end="end" :data-section="section?1:0" @touchstart="handler.touchstart"
|
||||
@touchmove="handler.touchmove" @touchend="handler.touchend" @mousedown="handler.mousedown"></view>
|
||||
|
||||
<view class="fui-slider__handle"
|
||||
:style="{width:blockWidth+'px',height:blockHeight+'px',borderRadius:blockRadius+'px',background:blockColor}"
|
||||
:class="['fui-slider__handle-right',disabled?'fui-slider__disabled':'']"
|
||||
:change:prop="handler.sectionSlidevalue" :prop="initEndValue" :data-blockWidth="blockWidth"
|
||||
:data-width="width" :data-step="step" :data-min="min" :data-max="max" :data-disabled="disabled?1:0"
|
||||
:data-value="start" :data-end="end" :data-section="section?1:0" @touchstart="handler.sectionTouchstart"
|
||||
@touchmove="handler.sectionTouchmove" @touchend="handler.sectionTouchend"
|
||||
@mousedown="handler.endMousedown" v-if="section">
|
||||
</view>
|
||||
</view>
|
||||
<!-- #endif -->
|
||||
|
||||
<!-- #ifdef APP-NVUE -->
|
||||
<view class="fui-slider__wrap" :style="{width:width+'px',height:(blockHeight<height?height:blockHeight)+'px'}">
|
||||
<view class="fui-slider__pole"
|
||||
:style="{width:width+'px',height:height+'px',borderRadius:radius+'px',background:background}">
|
||||
<view class="fui-slider__pole-left" :class="['fui-slider__pole-r']" ref="poleLeft"
|
||||
:style="{background:getActiveColor}"></view>
|
||||
<view class="fui-slider__pole-right" :class="['fui-slider__pole-l']" ref="poleRight"
|
||||
:style="{background:getActiveColor}"></view>
|
||||
</view>
|
||||
<view class="fui-slider__handle" :fireEventSync="true" @touchstart="touchstart" @horizontalpan="touchmove"
|
||||
@touchend="touchend" ref="handleLeft"
|
||||
:style="{width:blockWidth+'px',height:blockHeight+'px',borderRadius:24+'px',background:blockColor}"
|
||||
:class="['fui-slider__handle-left',isAndroid?'fui-slider__border':'fui-slider__shadow']"></view>
|
||||
<view class="fui-slider__handle" :fireEventSync="true" @touchstart="endTouchstart"
|
||||
@horizontalpan="endTouchmove" @touchend="endTouchend" ref="handleRight"
|
||||
:style="{width:blockWidth+'px',height:blockHeight+'px',borderRadius:24+'px',background:blockColor}"
|
||||
:class="['fui-slider__handle-right',isAndroid?'fui-slider__border':'fui-slider__shadow']"
|
||||
v-if="!isRight && section"></view>
|
||||
</view>
|
||||
<!-- #endif -->
|
||||
|
||||
<!-- #ifndef APP-PLUS|| MP-WEIXIN || H5 -->
|
||||
<view class="fui-slider__wrap" :style="{width:width+'px',height:(blockHeight<height?height:blockHeight)+'px'}">
|
||||
<view class="fui-slider__pole"
|
||||
:style="{width:width+'px',height:height+'px',borderRadius:radius+'px',background:background}">
|
||||
<view class="fui-slider__pole-left" :class="['fui-slider__pole-r',getActiveColor?'':'fui-slider__pole-bg']"
|
||||
:style="{background:getActiveColor,transform:transLeft}">
|
||||
</view>
|
||||
<view class="fui-slider__pole-right"
|
||||
:class="['fui-slider__pole-l',getActiveColor?'':'fui-slider__pole-bg']"
|
||||
:style="{background:getActiveColor,transform:transRight}">
|
||||
</view>
|
||||
</view>
|
||||
<view class="fui-slider__handle"
|
||||
:style="{width:blockWidth+'px',height:blockHeight+'px',borderRadius:blockRadius+'px',background:blockColor,transform:moveLeft}"
|
||||
:class="['fui-slider__handle-left',isRight?'fui-slider__handle-zi':'']" @touchstart="touchstart"
|
||||
@touchmove.stop.prevent="touchmove" @touchend="touchend"></view>
|
||||
<view class="fui-slider__handle"
|
||||
:style="{width:blockWidth+'px',height:blockHeight+'px',borderRadius:blockRadius+'px',background:blockColor,transform:moveRight}"
|
||||
:class="['fui-slider__handle-right']" @touchstart="endTouchstart" @touchmove.stop.prevent="endTouchmove"
|
||||
@touchend="endTouchend" v-if="section"></view>
|
||||
</view>
|
||||
<!-- #endif -->
|
||||
<text class="fui-slider__value" :class="['fui-slider__vl']"
|
||||
:style="{width:valueWidth+'px',color:valueColor,fontSize:valueSize+'px'}"
|
||||
v-if="showValue">{{section?end:start}}</text>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
|
||||
<!-- #ifdef APP-VUE || MP-WEIXIN || H5-->
|
||||
<script src="./index.wxs" module="handler" lang="wxs"></script>
|
||||
<!-- #endif -->
|
||||
|
||||
<script>
|
||||
import bindingx from './bindingx.js'
|
||||
import mpjs from './mpjs.js'
|
||||
export default {
|
||||
name: "fui-slider",
|
||||
mixins: [mpjs, bindingx],
|
||||
emits: ['change', 'changing'],
|
||||
props: {
|
||||
width: {
|
||||
type: [Number, String],
|
||||
default: 240
|
||||
},
|
||||
height: {
|
||||
type: [Number, String],
|
||||
default: 2
|
||||
},
|
||||
radius: {
|
||||
type: [Number, String],
|
||||
default: 2
|
||||
},
|
||||
min: {
|
||||
type: [Number, String],
|
||||
default: 0
|
||||
},
|
||||
max: {
|
||||
type: [Number, String],
|
||||
default: 100
|
||||
},
|
||||
step: {
|
||||
type: [Number, String],
|
||||
default: 1
|
||||
},
|
||||
value: {
|
||||
type: [Number, String],
|
||||
default: 0
|
||||
},
|
||||
section: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
endValue: {
|
||||
type: [Number, String],
|
||||
default: 100
|
||||
},
|
||||
background: {
|
||||
type: String,
|
||||
default: '#e1e1e1'
|
||||
},
|
||||
activeColor: {
|
||||
type: String,
|
||||
default: ''
|
||||
},
|
||||
blockWidth: {
|
||||
type: [Number, String],
|
||||
default: 24
|
||||
},
|
||||
blockHeight: {
|
||||
type: [Number, String],
|
||||
default: 24
|
||||
},
|
||||
blockColor: {
|
||||
type: String,
|
||||
default: '#fff'
|
||||
},
|
||||
blockRadius: {
|
||||
type: [Number, String],
|
||||
default: 12
|
||||
},
|
||||
disabled: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
showValue: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
valueWidth: {
|
||||
type: [Number, String],
|
||||
default: 32
|
||||
},
|
||||
valueSize: {
|
||||
type: [Number, String],
|
||||
default: 14
|
||||
},
|
||||
//value字体颜色
|
||||
valueColor: {
|
||||
type: String,
|
||||
default: '#333'
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
value(val) {
|
||||
let start = this.getStartVal(val)
|
||||
this.initValue = start
|
||||
this.start = start
|
||||
},
|
||||
endValue(val) {
|
||||
let end = this.getEndVal(val)
|
||||
this.initEndValue = end
|
||||
this.end = end
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
getActiveColor() {
|
||||
let color = this.activeColor;
|
||||
// #ifdef APP-NVUE
|
||||
if (!color || color === true) {
|
||||
const app = uni && uni.$fui && uni.$fui.color;
|
||||
color = (app && app.primary) || '#465CFF';
|
||||
}
|
||||
// #endif
|
||||
return color;
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
start: 0,
|
||||
end: 0,
|
||||
initValue: 0,
|
||||
initEndValue: 0
|
||||
};
|
||||
},
|
||||
mounted() {
|
||||
setTimeout(() => {
|
||||
this.start = this.getStartVal(this.value);
|
||||
this.end = this.getEndVal(this.endValue)
|
||||
this.initValue = this.start;
|
||||
this.initEndValue = this.end;
|
||||
}, 20)
|
||||
},
|
||||
methods: {
|
||||
getStartVal(val) {
|
||||
val = Number(val)
|
||||
let min = Number(this.min)
|
||||
val = val < min ? min : val
|
||||
return val
|
||||
},
|
||||
getEndVal(val) {
|
||||
val = Number(val)
|
||||
let min = Number(this.min)
|
||||
let max = Number(this.max)
|
||||
val = val < min ? min : val
|
||||
val = val > max ? max : val
|
||||
return val
|
||||
},
|
||||
getParams(e) {
|
||||
let val = e.value || 0;
|
||||
if (this.section && !e.isStart) {
|
||||
this.end = val
|
||||
} else {
|
||||
this.start = val
|
||||
}
|
||||
let params = {
|
||||
value: this.start
|
||||
}
|
||||
if (this.section) {
|
||||
params.endValue = this.end
|
||||
}
|
||||
return params
|
||||
},
|
||||
change(e) {
|
||||
let params = this.getParams(e)
|
||||
this.$emit('change', params);
|
||||
},
|
||||
changing(e) {
|
||||
let params = this.getParams(e)
|
||||
this.$emit('changing', params);
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.fui-slider__wrap-outer {
|
||||
/* #ifndef APP-NVUE */
|
||||
display: flex;
|
||||
/* #endif */
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.fui-slider__wrap {
|
||||
/* #ifndef APP-NVUE */
|
||||
display: flex;
|
||||
flex-shrink: 0;
|
||||
/* #endif */
|
||||
align-items: center;
|
||||
flex-direction: row;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.fui-slider__pole {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.fui-slider__pole-left {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
|
||||
.fui-slider__pole-r {
|
||||
right: 0;
|
||||
/* #ifndef APP-NVUE */
|
||||
transform: translate3d(-100%, 0, 0);
|
||||
/* #endif */
|
||||
/* #ifdef APP-NVUE */
|
||||
transform: translateX(-100%);
|
||||
/* #endif */
|
||||
}
|
||||
|
||||
.fui-slider__pole-l {
|
||||
left: 0;
|
||||
/* #ifndef APP-NVUE */
|
||||
transform: translate3d(100%, 0, 0);
|
||||
/* #endif */
|
||||
/* #ifdef APP-NVUE */
|
||||
transform: translateX(100%);
|
||||
/* #endif */
|
||||
}
|
||||
|
||||
|
||||
.fui-slider__pole-right {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
right: 0;
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
.fui-slider__handle {
|
||||
/* #ifndef APP-NVUE */
|
||||
box-shadow: 0 0 4px #CCCCCC;
|
||||
/* #endif */
|
||||
/* #ifdef H5 */
|
||||
cursor: grab;
|
||||
/* #endif */
|
||||
position: absolute;
|
||||
top: 0;
|
||||
}
|
||||
|
||||
/* #ifdef APP-NVUE */
|
||||
.fui-slider__shadow {
|
||||
box-shadow: 0 0 4px #CCCCCC;
|
||||
}
|
||||
|
||||
.fui-slider__border {
|
||||
border: 0.5px solid #eee;
|
||||
}
|
||||
|
||||
/* #endif */
|
||||
|
||||
|
||||
.fui-slider__handle-left {
|
||||
left: 0;
|
||||
z-index: 3;
|
||||
}
|
||||
|
||||
.fui-slider__handle-right {
|
||||
right: 0;
|
||||
z-index: 4;
|
||||
}
|
||||
|
||||
.fui-slider__handle-zi {
|
||||
z-index: 5 !important;
|
||||
}
|
||||
|
||||
.fui-slider__value {
|
||||
/* #ifndef APP-NVUE */
|
||||
display: flex;
|
||||
white-space: nowrap;
|
||||
/* #endif */
|
||||
flex-direction: row;
|
||||
font-weight: normal;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.fui-slider__vl {
|
||||
text-align: left;
|
||||
justify-content: flex-start;
|
||||
padding-left: 8px;
|
||||
|
||||
}
|
||||
|
||||
.fui-slider__vr {
|
||||
text-align: right;
|
||||
justify-content: flex-end;
|
||||
padding-right: 8px;
|
||||
}
|
||||
|
||||
/* #ifndef APP-NVUE */
|
||||
.fui-slider__pole-bg {
|
||||
background: var(--fui-color-primary, #465CFF) !important;
|
||||
}
|
||||
|
||||
/* #endif */
|
||||
|
||||
/* #ifdef H5 */
|
||||
.fui-slider__disabled {
|
||||
cursor: not-allowed !important;
|
||||
}
|
||||
|
||||
/* #endif */
|
||||
</style>
|
290
components/firstui/fui-slider/index.wxs
Normal file
290
components/firstui/fui-slider/index.wxs
Normal file
@ -0,0 +1,290 @@
|
||||
// 本文件由FirstUI授权予新疆天衡创新研究院有限公司(手机号: 1 8 6 140 72 549,身份证尾号:5A07X5)专用,请尊重知识产权,勿私下传播,违者追究法律责任。
|
||||
var slider = {
|
||||
width: 240,
|
||||
blockWidth: 24,
|
||||
step: 1,
|
||||
min: 0,
|
||||
max: 100,
|
||||
disabled: false,
|
||||
section: false,
|
||||
start: 0,
|
||||
end: 0,
|
||||
drag: false
|
||||
}
|
||||
|
||||
function isPC() {
|
||||
if (typeof navigator !== 'object') return false;
|
||||
var userAgentInfo = navigator.userAgent;
|
||||
var Agents = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"];
|
||||
var flag = true;
|
||||
for (var v = 0; v < Agents.length - 1; v++) {
|
||||
if (userAgentInfo.indexOf(Agents[v]) > 0) {
|
||||
flag = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
var isH5 = false
|
||||
if (typeof window === 'object') isH5 = true
|
||||
|
||||
function bool(str) {
|
||||
return str === 'true' || str == true ? true : false
|
||||
}
|
||||
|
||||
function format(value) {
|
||||
return Math.round(Math.max(slider.min, Math.min(value, slider.max)) / slider.step) * slider.step;
|
||||
}
|
||||
|
||||
function setInitValue(dataset, isChange) {
|
||||
slider.drag = false
|
||||
slider.width = +dataset.width
|
||||
slider.blockWidth = +dataset.blockwidth
|
||||
slider.step = +dataset.step
|
||||
slider.min = +dataset.min
|
||||
slider.max = +dataset.max
|
||||
//H5获取bool值为undefined
|
||||
slider.disabled = (+dataset.disabled) == 1 ? true : false
|
||||
slider.section = (+dataset.section) == 1 ? true : false
|
||||
slider.start = format(+dataset.value)
|
||||
slider.end = format(+dataset.end)
|
||||
}
|
||||
|
||||
function touchstart(e, ins) {
|
||||
var state = e.instance.getState()
|
||||
var touch = e.touches[0] || e.changedTouches[0];
|
||||
if (isH5 && isPC()) {
|
||||
touch = e;
|
||||
}
|
||||
var dataset = e.instance.getDataset()
|
||||
state.startX = touch.clientX
|
||||
setInitValue(dataset)
|
||||
}
|
||||
|
||||
function sectionTouchstart(e, ins) {
|
||||
var state = e.instance.getState()
|
||||
var touch = e.touches[0] || e.changedTouches[0];
|
||||
if (isH5 && isPC()) {
|
||||
touch = e;
|
||||
}
|
||||
var dataset = e.instance.getDataset()
|
||||
state.sectionStartX = touch.clientX
|
||||
setInitValue(dataset)
|
||||
}
|
||||
|
||||
function changeValue(value, isStart, isEnd, ins) {
|
||||
var params = {
|
||||
value: value,
|
||||
isStart: isStart
|
||||
}
|
||||
if (isEnd) {
|
||||
ins.callMethod('change', params)
|
||||
} else {
|
||||
ins.callMethod('changing', params)
|
||||
}
|
||||
}
|
||||
|
||||
function styleChange(value, ins, isEnd, state) {
|
||||
if (!ins) return;
|
||||
value = format(value);
|
||||
if (slider.section) {
|
||||
value = value > slider.end ? slider.end : value;
|
||||
}
|
||||
changeValue(value, true, isEnd, ins)
|
||||
var dvalue = slider.max - slider.min;
|
||||
var maxWidth = slider.width - slider.blockWidth;
|
||||
var width = (value - slider.min) / dvalue * maxWidth;
|
||||
var block = ins.selectComponent('.fui-slider__handle-left');
|
||||
var glided = ins.selectComponent('.fui-slider__pole-left');
|
||||
if (!block || !glided) return;
|
||||
if (state) {
|
||||
state.lastLeft = width
|
||||
}
|
||||
block.setStyle({
|
||||
transform: 'translate3d(' + width + 'px,0,0)',
|
||||
'z-index': value === slider.max ? 5 : 3
|
||||
})
|
||||
glided.setStyle({
|
||||
width: width + 'px'
|
||||
})
|
||||
}
|
||||
|
||||
function styleSectionChange(value, ins, isEnd, state) {
|
||||
if (!ins) return;
|
||||
value = format(value);
|
||||
var total = slider.max + slider.min;
|
||||
var val = total - value;
|
||||
val = val < slider.start ? slider.start : val;
|
||||
value = total - val;
|
||||
changeValue(val, false, isEnd, ins)
|
||||
var dvalue = slider.max - slider.min;
|
||||
var maxWidth = slider.width - slider.blockWidth;
|
||||
var width = (value - slider.min) / dvalue * maxWidth;
|
||||
var block = ins.selectComponent('.fui-slider__handle-right');
|
||||
var glided = ins.selectComponent('.fui-slider__pole-right');
|
||||
if (!block || !glided) return;
|
||||
if (state) {
|
||||
state.lastSectionLeft = width
|
||||
}
|
||||
block.setStyle({
|
||||
transform: 'translate3d(-' + width + 'px,0,0)'
|
||||
})
|
||||
glided.setStyle({
|
||||
width: width + 'px'
|
||||
})
|
||||
}
|
||||
|
||||
function touchmove(e, ins, event) {
|
||||
if (slider.disabled) return;
|
||||
if (e.preventDefault) {
|
||||
// 阻止页面滚动
|
||||
e.preventDefault()
|
||||
}
|
||||
var state = {}
|
||||
var touch = {}
|
||||
if (isH5 && isPC()) {
|
||||
touch = e;
|
||||
state = event.instance.getState()
|
||||
} else {
|
||||
touch = e.touches[0] || e.changedTouches[0]
|
||||
state = e.instance.getState()
|
||||
}
|
||||
var pageX = touch.clientX;
|
||||
slider.drag = true
|
||||
var left = pageX - state.startX + (state.lastLeft || 0);
|
||||
left = left < 0 ? 0 : left;
|
||||
var maxWidth = slider.width - slider.blockWidth;
|
||||
left = left >= maxWidth ? maxWidth : left;
|
||||
var dvalue = slider.max - slider.min;
|
||||
var value = (left / maxWidth) * dvalue + slider.min;
|
||||
state.startX = pageX
|
||||
state.lastLeft = left
|
||||
styleChange(value, ins, false)
|
||||
}
|
||||
|
||||
function sectionTouchmove(e, ins, event) {
|
||||
if (slider.disabled) return;
|
||||
if (e.preventDefault) {
|
||||
// 阻止页面滚动
|
||||
e.preventDefault()
|
||||
}
|
||||
var state = {}
|
||||
var touch = {}
|
||||
if (isH5 && isPC()) {
|
||||
touch = e;
|
||||
state = event.instance.getState()
|
||||
} else {
|
||||
touch = e.touches[0] || e.changedTouches[0]
|
||||
state = e.instance.getState()
|
||||
}
|
||||
var pageX = touch.clientX;
|
||||
slider.drag = true
|
||||
var left = state.sectionStartX - pageX + (state.lastSectionLeft || 0);
|
||||
left = left < 0 ? 0 : left;
|
||||
var maxWidth = slider.width - slider.blockWidth;
|
||||
left = left >= maxWidth ? maxWidth : left;
|
||||
var dvalue = slider.max - slider.min;
|
||||
var value = (left / maxWidth) * dvalue + slider.min;
|
||||
state.sectionStartX = pageX
|
||||
state.lastSectionLeft = left
|
||||
styleSectionChange(value, ins, false)
|
||||
}
|
||||
|
||||
function touchend(e, ins, event) {
|
||||
if (slider.disabled) return;
|
||||
if (slider.drag) {
|
||||
var state = {}
|
||||
if (isH5 && isPC()) {
|
||||
state = event.instance.getState()
|
||||
} else {
|
||||
state = e.instance.getState()
|
||||
}
|
||||
var maxWidth = slider.width - slider.blockWidth;
|
||||
var dvalue = slider.max - slider.min;
|
||||
var value = (state.lastLeft / maxWidth) * dvalue + slider.min;
|
||||
styleChange(value, ins, true, state)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
function sectionTouchend(e, ins, event) {
|
||||
if (slider.disabled) return;
|
||||
if (slider.drag) {
|
||||
var state = {}
|
||||
if (isH5 && isPC()) {
|
||||
state = event.instance.getState()
|
||||
} else {
|
||||
state = e.instance.getState()
|
||||
}
|
||||
var maxWidth = slider.width - slider.blockWidth;
|
||||
var dvalue = slider.max - slider.min;
|
||||
var value = (state.lastSectionLeft / maxWidth) * dvalue + slider.min;
|
||||
styleSectionChange(value, ins, true, state)
|
||||
}
|
||||
}
|
||||
|
||||
function slidevalue(value, oldValue, owner, ins) {
|
||||
var state = ins.getState()
|
||||
state.startX = 0;
|
||||
state.lastLeft = 0;
|
||||
var dataset = ins.getDataset()
|
||||
setInitValue(dataset)
|
||||
styleChange(value, owner, true, state)
|
||||
}
|
||||
|
||||
function sectionSlidevalue(value, oldValue, owner, ins) {
|
||||
var state = ins.getState()
|
||||
state.sectionStartX = 0;
|
||||
state.lastSectionLeft = 0;
|
||||
var dataset = ins.getDataset()
|
||||
setInitValue(dataset)
|
||||
value = slider.max - value + slider.min
|
||||
styleSectionChange(value, owner, true, state)
|
||||
}
|
||||
var movable = false;
|
||||
|
||||
function mousedown(e, ins) {
|
||||
if (!isH5 || !isPC()) return
|
||||
touchstart(e, ins)
|
||||
movable = true
|
||||
window.onmousemove = function(event) {
|
||||
if (!isH5 || !isPC() || !movable) return
|
||||
touchmove(event, ins, e)
|
||||
}
|
||||
window.onmouseup = function(event) {
|
||||
if (!isH5 || !isPC() || !movable) return
|
||||
touchend(event, ins, e)
|
||||
movable = false
|
||||
}
|
||||
}
|
||||
|
||||
var endMovable = false;
|
||||
|
||||
function endMousedown(e, ins) {
|
||||
if (!isH5 || !isPC()) return
|
||||
sectionTouchstart(e, ins)
|
||||
endMovable = true
|
||||
window.onmousemove = function(event) {
|
||||
if (!isH5 || !isPC() || !endMovable) return
|
||||
sectionTouchmove(event, ins, e)
|
||||
}
|
||||
window.onmouseup = function(event) {
|
||||
if (!isH5 || !isPC()) return
|
||||
sectionTouchend(event, ins, e)
|
||||
endMovable = false
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
touchstart: touchstart,
|
||||
touchmove: touchmove,
|
||||
touchend: touchend,
|
||||
mousedown: mousedown,
|
||||
slidevalue: slidevalue,
|
||||
sectionTouchstart: sectionTouchstart,
|
||||
sectionTouchmove: sectionTouchmove,
|
||||
sectionTouchend: sectionTouchend,
|
||||
endMousedown: endMousedown,
|
||||
sectionSlidevalue: sectionSlidevalue
|
||||
}
|
170
components/firstui/fui-slider/mpjs.js
Normal file
170
components/firstui/fui-slider/mpjs.js
Normal file
@ -0,0 +1,170 @@
|
||||
// 本文件由FirstUI授权予新疆天衡创新研究院有限公司(手机号:18 61 4 0 72 5 49,身份证尾号:5A07X5)专用,请尊重知识产权,勿私下传播,违者追究法律责任。
|
||||
// #ifndef APP-PLUS || MP-WEIXIN || H5
|
||||
|
||||
export default {
|
||||
watch: {
|
||||
value(val) {
|
||||
this.initData(val)
|
||||
},
|
||||
endValue(val) {
|
||||
if (this.section) {
|
||||
this.initEndData(val)
|
||||
}
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
drag: false,
|
||||
startX: 0,
|
||||
endX: 0,
|
||||
lastLeft: 0,
|
||||
onceLeft: 0,
|
||||
lastRight: 0,
|
||||
onceRight: 0,
|
||||
moveLeft: 'translate3d(0,0,0)',
|
||||
transLeft: 'translate3d(-100%, 0, 0)',
|
||||
moveRight: 'translate3d(0,0,0)',
|
||||
transRight: 'translate3d(100%, 0, 0)',
|
||||
isRight: false
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.$nextTick(()=>{
|
||||
this.initData(this.value)
|
||||
if (this.section) {
|
||||
this.initEndData(this.endValue)
|
||||
}
|
||||
})
|
||||
},
|
||||
methods: {
|
||||
initData(value) {
|
||||
this.startX = 0;
|
||||
this.lastLeft = 0;
|
||||
this.styleChange(Number(value), true)
|
||||
},
|
||||
initEndData(value) {
|
||||
this.endX = 0;
|
||||
this.lastRight = 0;
|
||||
value = Number(this.max) - Number(value) + Number(this.min)
|
||||
this.styleSectionChange(value, true)
|
||||
},
|
||||
format(value) {
|
||||
value = Number(value)
|
||||
let step = Number(this.step)
|
||||
return Math.round(Math.max(Number(this.min), Math.min(value, Number(this.max))) / step) * step;
|
||||
},
|
||||
touchstart(e) {
|
||||
let touch = e.touches[0] || e.changedTouches[0];
|
||||
this.startX = touch.clientX
|
||||
},
|
||||
endTouchstart(e) {
|
||||
let touch = e.touches[0] || e.changedTouches[0];
|
||||
this.endX = touch.clientX
|
||||
},
|
||||
changeValue(value, isStart, isEnd) {
|
||||
var params = {
|
||||
value: value,
|
||||
isStart: isStart
|
||||
}
|
||||
if (isEnd) {
|
||||
this.change(params)
|
||||
} else {
|
||||
this.changing(params)
|
||||
}
|
||||
},
|
||||
styleChange(value, isEnd) {
|
||||
value = this.format(value);
|
||||
if (this.section) {
|
||||
value = value > this.end ? this.end : value;
|
||||
}
|
||||
this.changeValue(value, true, isEnd)
|
||||
const min = Number(this.min)
|
||||
const max = Number(this.max)
|
||||
var dvalue = max - min;
|
||||
var maxWidth = Number(this.width) - Number(this.blockWidth);
|
||||
var width = (value - min) / dvalue * maxWidth;
|
||||
this.lastLeft = width
|
||||
if (isEnd) {
|
||||
this.onceLeft = width
|
||||
}
|
||||
this.transLeft = `translate3d(-${Number(this.width)-width}px,0,0)`
|
||||
this.moveLeft = `translate3d(${width}px,0,0)`
|
||||
this.isRight = value === max
|
||||
},
|
||||
styleSectionChange(value, isEnd) {
|
||||
value = this.format(value);
|
||||
const min = Number(this.min)
|
||||
const max = Number(this.max)
|
||||
var total = max + min;
|
||||
var val = total - value;
|
||||
val = val < this.start ? this.start : val;
|
||||
value = total - val;
|
||||
this.changeValue(val, false, isEnd)
|
||||
var dvalue = max - min;
|
||||
var maxWidth = Number(this.width) - Number(this.blockWidth);
|
||||
var width = (value - min) / dvalue * maxWidth;
|
||||
this.lastRight = width
|
||||
if (isEnd) {
|
||||
this.onceRight = width
|
||||
}
|
||||
this.transRight = `translate3d(${Number(this.width)-width}px,0,0)`
|
||||
this.moveRight = `translate3d(-${width}px,0,0)`
|
||||
},
|
||||
touchmove(e) {
|
||||
if (this.disabled) return;
|
||||
let touch = e.touches[0] || e.changedTouches[0];
|
||||
let pageX = touch.clientX;
|
||||
this.drag = true
|
||||
let left = pageX - this.startX + (this.onceLeft || 0);
|
||||
left = left < 0 ? 0 : left;
|
||||
let maxWidth = Number(this.width) - Number(this.blockWidth);
|
||||
left = left >= maxWidth ? maxWidth : left;
|
||||
let dvalue = Number(this.max) - Number(this.min);
|
||||
let value = (left / maxWidth) * dvalue + Number(this.min);
|
||||
// this.startX = pageX
|
||||
this.lastLeft = left
|
||||
this.styleChange(value, false)
|
||||
},
|
||||
endTouchmove(e) {
|
||||
if (this.disabled) return;
|
||||
let touch = e.touches[0] || e.changedTouches[0];
|
||||
let pageX = touch.clientX;
|
||||
this.drag = true
|
||||
let left = this.endX - pageX + (this.onceRight || 0);
|
||||
left = left < 0 ? 0 : left;
|
||||
let maxWidth = Number(this.width) - Number(this.blockWidth);
|
||||
left = left >= maxWidth ? maxWidth : left;
|
||||
let dvalue = Number(this.max) - Number(this.min);
|
||||
let value = (left / maxWidth) * dvalue + Number(this.min);
|
||||
// this.endX = pageX
|
||||
this.lastRight = left
|
||||
this.styleSectionChange(value, false)
|
||||
},
|
||||
touchend(e) {
|
||||
if (this.disabled) return;
|
||||
if (this.drag) {
|
||||
let maxWidth = Number(this.width) - Number(this.blockWidth);
|
||||
let dvalue = Number(this.max) - Number(this.min);
|
||||
let value = (this.lastLeft / maxWidth) * dvalue + Number(this.min);
|
||||
this.styleChange(value, true)
|
||||
this.drag = false
|
||||
}
|
||||
},
|
||||
endTouchend(e) {
|
||||
if (this.disabled) return;
|
||||
if (this.drag) {
|
||||
let maxWidth = Number(this.width) - Number(this.blockWidth);
|
||||
let dvalue = Number(this.max) - Number(this.min);
|
||||
let value = (this.lastRight / maxWidth) * dvalue + Number(this.min);
|
||||
this.styleSectionChange(value, true)
|
||||
this.drag = false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// #endif
|
||||
|
||||
// #ifdef APP-PLUS|| MP-WEIXIN || H5
|
||||
export default {}
|
||||
// #endif
|
Reference in New Issue
Block a user