| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- const Constants = require("@/utils/Constants");
- // components/dkbase/dk-stepper/dk-stepper.js
- Component({
- /**
- * 组件的属性列表
- */
- properties: {
- // 设置数字部分显示宽度
- inputWidth: {
- type: String,
- value: "32px"
- },
- value: {
- type: Number,
- observer: function (newVal) {
- this.setData({
- dataValue: newVal
- })
- }
- },
- min: {
- type: Number
- },
- decimalLength: {
- type: Number
- },
- step: {
- type: Number,
- value: 1
- },
- readonly: {
- type: Boolean,
- value: false
- },
- negative: {
- type: Boolean,
- value: true
- }
- },
- /**
- * 组件的初始数据
- */
- data: {
- inputTimer: null,
- dataValue: null,
- max: 0
- },
- /**
- * 组件的方法列表
- */
- methods: {
- /**
- * 步进器数值改变
- * @author 刘尧
- */
- changeStep(e) {
- let inputValue = this.data.negative ? ( Math.abs( e.detail.inputValue )* -1) : Number(e.detail.inputValue)
- if (this.data.decimalLength) {
- this.setData({
- dataValue: inputValue.toFixed(this.data.decimalLength),
- })
- } else {
- this.setData({
- dataValue: inputValue,
- })
- }
- // 触发自定义事件
- this.triggerEvent('change', this.data.dataValue);
- },
- /**
- * @desc : 减法
- * @author : 周兴
- * @date : 2024/2/2 11:46
- */
- handleMinus() {
- let dataValue = this.data.dataValue
- let min = this.data.min
- dataValue = dataValue - this.data.step
- if (dataValue < 0) {
- min = min * -1
- }
- // 当数值计算后小于最大值或大于最小值都可以触发减法
- if (dataValue >= min) {
- this.setData({
- dataValue: dataValue,
- })
- }
- // 触发自定义事件
- this.triggerEvent('change', this.data.dataValue);
- },
- /**
- * @desc : 加法
- * @author : 周兴
- * @date : 2024/2/2 11:46
- */
- handlePlus() {
- let dataValue = this.data.dataValue
- let max = this.data.max
- dataValue = dataValue + this.data.step
- if (dataValue <= max) {
- this.setData({
- dataValue: dataValue,
- })
- }
- // 触发自定义事件
- this.triggerEvent('change', this.data.dataValue);
- },
- },
- })
|