first commit

This commit is contained in:
PC-202306242200\Administrator
2026-03-28 23:09:02 +08:00
commit dac42e3b0c
3512 changed files with 181637 additions and 0 deletions

View File

@@ -0,0 +1,112 @@
"use strict";
const uni_modules_uviewPlus_libs_config_props = require("../../libs/config/props.js");
const props = {
props: {
// 步进器标识符在change回调返回
name: {
type: [String, Number],
default: () => uni_modules_uviewPlus_libs_config_props.defProps.numberBox.name
},
// 用于双向绑定的值初始化时设置设为默认min值(最小值)
modelValue: {
type: [String, Number],
default: () => uni_modules_uviewPlus_libs_config_props.defProps.numberBox.value
},
// 最小值
min: {
type: [String, Number],
default: () => uni_modules_uviewPlus_libs_config_props.defProps.numberBox.min
},
// 最大值
max: {
type: [String, Number],
default: () => uni_modules_uviewPlus_libs_config_props.defProps.numberBox.max
},
// 加减的步长,可为小数
step: {
type: [String, Number],
default: () => uni_modules_uviewPlus_libs_config_props.defProps.numberBox.step
},
// 是否只允许输入整数
integer: {
type: Boolean,
default: () => uni_modules_uviewPlus_libs_config_props.defProps.numberBox.integer
},
// 是否禁用,包括输入框,加减按钮
disabled: {
type: Boolean,
default: () => uni_modules_uviewPlus_libs_config_props.defProps.numberBox.disabled
},
// 是否禁用输入框
disabledInput: {
type: Boolean,
default: () => uni_modules_uviewPlus_libs_config_props.defProps.numberBox.disabledInput
},
// 是否开启异步变更,开启后需要手动控制输入值
asyncChange: {
type: Boolean,
default: () => uni_modules_uviewPlus_libs_config_props.defProps.numberBox.asyncChange
},
// 输入框宽度单位为px
inputWidth: {
type: [String, Number],
default: () => uni_modules_uviewPlus_libs_config_props.defProps.numberBox.inputWidth
},
// 是否显示减少按钮
showMinus: {
type: Boolean,
default: () => uni_modules_uviewPlus_libs_config_props.defProps.numberBox.showMinus
},
// 是否显示增加按钮
showPlus: {
type: Boolean,
default: () => uni_modules_uviewPlus_libs_config_props.defProps.numberBox.showPlus
},
// 显示的小数位数
decimalLength: {
type: [String, Number, null],
default: () => uni_modules_uviewPlus_libs_config_props.defProps.numberBox.decimalLength
},
// 是否开启长按加减手势
longPress: {
type: Boolean,
default: () => uni_modules_uviewPlus_libs_config_props.defProps.numberBox.longPress
},
// 输入框文字和加减按钮图标的颜色
color: {
type: String,
default: () => uni_modules_uviewPlus_libs_config_props.defProps.numberBox.color
},
// 按钮大小宽高等于此值单位px输入框高度和此值保持一致
buttonSize: {
type: [String, Number],
default: () => uni_modules_uviewPlus_libs_config_props.defProps.numberBox.buttonSize
},
// 输入框和按钮的背景颜色
bgColor: {
type: String,
default: () => uni_modules_uviewPlus_libs_config_props.defProps.numberBox.bgColor
},
// 指定光标于键盘的距离避免键盘遮挡输入框单位px
cursorSpacing: {
type: [String, Number],
default: () => uni_modules_uviewPlus_libs_config_props.defProps.numberBox.cursorSpacing
},
// 是否禁用增加按钮
disablePlus: {
type: Boolean,
default: () => uni_modules_uviewPlus_libs_config_props.defProps.numberBox.disablePlus
},
// 是否禁用减少按钮
disableMinus: {
type: Boolean,
default: () => uni_modules_uviewPlus_libs_config_props.defProps.numberBox.disableMinus
},
// 加减按钮图标的样式
iconStyle: {
type: [Object, String],
default: () => uni_modules_uviewPlus_libs_config_props.defProps.numberBox.iconStyle
}
}
};
exports.props = props;

View File

@@ -0,0 +1,62 @@
.u-empty.data-v-eb6f6237,
.u-empty__wrap.data-v-eb6f6237,
.u-tabs.data-v-eb6f6237,
.u-tabs__wrapper.data-v-eb6f6237,
.u-tabs__wrapper__scroll-view-wrapper.data-v-eb6f6237,
.u-tabs__wrapper__scroll-view.data-v-eb6f6237,
.u-tabs__wrapper__nav.data-v-eb6f6237,
.u-tabs__wrapper__nav__line.data-v-eb6f6237 {
display: flex;
flex-direction: column;
flex-shrink: 0;
flex-grow: 0;
flex-basis: auto;
align-items: stretch;
align-content: flex-start;
}
.u-number-box.data-v-eb6f6237 {
display: flex;
flex-direction: row;
align-items: center;
}
.u-number-box__slot.data-v-eb6f6237 {
touch-action: none;
}
.u-number-box__plus.data-v-eb6f6237, .u-number-box__minus.data-v-eb6f6237 {
width: 35px;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
touch-action: none;
}
.u-number-box__plus--hover.data-v-eb6f6237, .u-number-box__minus--hover.data-v-eb6f6237 {
background-color: #E6E6E6 !important;
}
.u-number-box__plus--disabled.data-v-eb6f6237, .u-number-box__minus--disabled.data-v-eb6f6237 {
color: #c8c9cc;
background-color: #f7f8fa;
}
.u-number-box__plus.data-v-eb6f6237 {
border-top-right-radius: 4px;
border-bottom-right-radius: 4px;
}
.u-number-box__minus.data-v-eb6f6237 {
border-top-left-radius: 4px;
border-bottom-left-radius: 4px;
}
.u-number-box__input.data-v-eb6f6237 {
position: relative;
text-align: center;
font-size: 15px;
padding: 0;
margin: 0 2px;
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
}
.u-number-box__input--disabled.data-v-eb6f6237 {
color: #c8c9cc;
background-color: #f2f3f5;
}

View File

@@ -0,0 +1 @@
<view class="u-number-box data-v-eb6f6237"><view a:if="{{a}}" class="u-number-box__slot cursor-pointer data-v-eb6f6237" catchTap="{{b}}" onTouchStart="{{c}}" catchTouchEnd="{{d}}"><slot name="minus"/></view><view a:elif="{{e}}" catchTap="{{g}}" onTouchStart="{{h}}" catchTouchEnd="{{i}}" hover-class="u-number-box__minus--hover" hover-stay-time="150" class="{{('u-number-box__minus') + ' ' + 'cursor-pointer' + ' ' + 'data-v-eb6f6237' + ' ' + (j && 'u-number-box__minus--disabled')}}" style="{{k}}"><u-icon class="data-v-eb6f6237" u-i="eb6f6237-0" onVI="__l" u-p="{{f}}"></u-icon></view><slot name="input"><input disabled="{{l}}" cursor-spacing="{{m}}" class="{{(n && 'u-number-box__input--disabled') + ' ' + 'u-number-box__input' + ' ' + 'data-v-eb6f6237'}}" onBlur="{{o}}" onFocus="{{p}}" onInput="{{q}}" type="number" style="{{r}}" value="{{s}}"/></slot><view a:if="{{t}}" class="u-number-box__slot cursor-pointer data-v-eb6f6237" catchTap="{{v}}" onTouchStart="{{w}}" catchTouchEnd="{{x}}"><slot name="plus"/></view><view a:elif="{{y}}" catchTap="{{A}}" onTouchStart="{{B}}" catchTouchEnd="{{C}}" hover-class="u-number-box__plus--hover" hover-stay-time="150" class="{{('u-number-box__plus') + ' ' + 'cursor-pointer' + ' ' + 'data-v-eb6f6237' + ' ' + (D && 'u-number-box__minus--disabled')}}" style="{{E}}"><u-icon class="data-v-eb6f6237" u-i="eb6f6237-1" onVI="__l" u-p="{{z}}"></u-icon></view></view>

View File

@@ -0,0 +1,284 @@
"use strict";
const uni_modules_uviewPlus_components_uNumberBox_props = require("./props.js");
const uni_modules_uviewPlus_libs_mixin_mpMixin = require("../../libs/mixin/mpMixin.js");
const uni_modules_uviewPlus_libs_mixin_mixin = require("../../libs/mixin/mixin.js");
const uni_modules_uviewPlus_libs_function_index = require("../../libs/function/index.js");
const common_vendor = require("../../../../common/vendor.js");
const _sfc_main = {
name: "u-number-box",
mixins: [uni_modules_uviewPlus_libs_mixin_mpMixin.mpMixin, uni_modules_uviewPlus_libs_mixin_mixin.mixin, uni_modules_uviewPlus_components_uNumberBox_props.props],
data() {
return {
// 输入框实际操作的值
currentValue: "",
// 定时器
longPressTimer: null
};
},
watch: {
// 多个值之间只要一个值发生变化都要重新检查check()函数
watchChange(n) {
this.check();
},
// 监听v-mode的变化重新初始化内部的值
modelValue: {
handler: function(newV, oldV) {
if (newV !== this.currentValue) {
this.currentValue = this.format(this.modelValue);
}
},
immediate: true
}
},
computed: {
getCursorSpacing() {
return uni_modules_uviewPlus_libs_function_index.getPx(this.cursorSpacing);
},
// 按钮的样式
buttonStyle() {
return (type) => {
const style = {
backgroundColor: this.bgColor,
height: uni_modules_uviewPlus_libs_function_index.addUnit(this.buttonSize),
color: this.color
};
if (this.isDisabled(type)) {
style.backgroundColor = "#f7f8fa";
}
return style;
};
},
// 输入框的样式
inputStyle() {
this.disabled || this.disabledInput;
const style = {
color: this.color,
backgroundColor: this.bgColor,
height: uni_modules_uviewPlus_libs_function_index.addUnit(this.buttonSize),
width: uni_modules_uviewPlus_libs_function_index.addUnit(this.inputWidth)
};
return style;
},
// 用于监听多个值发生变化
watchChange() {
return [this.integer, this.decimalLength, this.min, this.max];
},
isDisabled() {
return (type) => {
if (type === "plus") {
return this.disabled || this.disablePlus || this.currentValue >= this.max;
}
return this.disabled || this.disableMinus || this.currentValue <= this.min;
};
}
},
mounted() {
this.init();
},
emits: ["update:modelValue", "focus", "blur", "overlimit", "change", "plus", "minus"],
methods: {
init() {
this.currentValue = this.format(this.modelValue);
},
// 格式化整理数据,限制范围
format(value) {
value = this.filter(value);
value = value === "" ? 0 : +value;
value = Math.max(Math.min(this.max, value), this.min);
if (this.decimalLength !== null) {
value = value.toFixed(this.decimalLength);
}
return value;
},
// 过滤非法的字符
filter(value) {
value = String(value).replace(/[^0-9.-]/g, "");
if (this.integer && value.indexOf(".") !== -1) {
value = value.split(".")[0];
}
return value;
},
check() {
const val = this.format(this.currentValue);
if (val !== this.currentValue) {
this.currentValue = val;
}
},
// 判断是否出于禁止操作状态
// isDisabled(type) {
// if (type === 'plus') {
// // 在点击增加按钮情况下判断整体的disabled是否单独禁用增加按钮以及当前值是否大于最大的允许值
// return (
// this.disabled ||
// this.disablePlus ||
// this.currentValue >= this.max
// )
// }
// // 点击减少按钮同理
// return (
// this.disabled ||
// this.disableMinus ||
// this.currentValue <= this.min
// )
// },
// 输入框活动焦点
onFocus(event) {
this.$emit("focus", {
...event.detail,
name: this.name
});
},
// 输入框失去焦点
onBlur(event) {
this.format(event.detail.value);
this.$emit(
"blur",
{
...event.detail,
name: this.name
}
);
},
// 输入框值发生变化
onInput(e) {
const {
value = ""
} = e.detail || {};
if (value === "")
return;
let formatted = this.filter(value);
if (this.decimalLength !== null && formatted.indexOf(".") !== -1) {
const pair = formatted.split(".");
formatted = `${pair[0]}.${pair[1].slice(0, this.decimalLength)}`;
}
formatted = this.format(formatted);
this.emitChange(formatted);
},
// 发出change事件
emitChange(value) {
if (!this.asyncChange) {
this.$nextTick(() => {
this.$emit("update:modelValue", value);
this.currentValue = value;
this.$forceUpdate();
});
}
this.$emit("change", {
value,
name: this.name
});
},
onChange() {
const {
type
} = this;
if (this.isDisabled(type)) {
return this.$emit("overlimit", type);
}
const diff = type === "minus" ? -this.step : +this.step;
const value = this.format(this.add(+this.currentValue, diff));
this.emitChange(value);
this.$emit(type);
},
// 对值扩大后进行四舍五入,再除以扩大因子,避免出现浮点数操作的精度问题
add(num1, num2) {
const cardinal = Math.pow(10, 10);
return Math.round((num1 + num2) * cardinal) / cardinal;
},
// 点击加减按钮
clickHandler(type) {
this.type = type;
this.onChange();
},
longPressStep() {
this.clearTimeout();
this.longPressTimer = setTimeout(() => {
this.onChange();
this.longPressStep();
}, 250);
},
onTouchStart(type) {
if (!this.longPress)
return;
this.clearTimeout();
this.type = type;
this.longPressTimer = setTimeout(() => {
this.onChange();
this.longPressStep();
}, 600);
},
// 触摸结束,清除定时器,停止长按加减
onTouchEnd() {
if (!this.longPress)
return;
this.clearTimeout();
},
// 清除定时器
clearTimeout() {
clearTimeout(this.longPressTimer);
this.longPressTimer = null;
}
}
};
if (!Array) {
const _easycom_u_icon2 = common_vendor.resolveComponent("u-icon");
_easycom_u_icon2();
}
const _easycom_u_icon = () => "../u-icon/u-icon.js";
if (!Math) {
_easycom_u_icon();
}
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
return common_vendor.e({
a: _ctx.showMinus && _ctx.$slots.minus
}, _ctx.showMinus && _ctx.$slots.minus ? {
b: common_vendor.o(($event) => $options.clickHandler("minus")),
c: common_vendor.o(($event) => $options.onTouchStart("minus")),
d: common_vendor.o((...args) => $options.clearTimeout && $options.clearTimeout(...args))
} : _ctx.showMinus ? {
f: common_vendor.p({
name: "minus",
color: $options.isDisabled("minus") ? "#c8c9cc" : "#323233",
size: "15",
bold: true,
customStyle: _ctx.iconStyle
}),
g: common_vendor.o(($event) => $options.clickHandler("minus")),
h: common_vendor.o(($event) => $options.onTouchStart("minus")),
i: common_vendor.o((...args) => $options.clearTimeout && $options.clearTimeout(...args)),
j: $options.isDisabled("minus") ? 1 : "",
k: common_vendor.s($options.buttonStyle("minus"))
} : {}, {
e: _ctx.showMinus,
l: _ctx.disabledInput || _ctx.disabled,
m: $options.getCursorSpacing,
n: _ctx.disabled || _ctx.disabledInput ? 1 : "",
o: common_vendor.o((...args) => $options.onBlur && $options.onBlur(...args)),
p: common_vendor.o((...args) => $options.onFocus && $options.onFocus(...args)),
q: common_vendor.o([($event) => $data.currentValue = $event.detail.value, (...args) => $options.onInput && $options.onInput(...args)]),
r: common_vendor.s($options.inputStyle),
s: $data.currentValue,
t: _ctx.showPlus && _ctx.$slots.plus
}, _ctx.showPlus && _ctx.$slots.plus ? {
v: common_vendor.o(($event) => $options.clickHandler("plus")),
w: common_vendor.o(($event) => $options.onTouchStart("plus")),
x: common_vendor.o((...args) => $options.clearTimeout && $options.clearTimeout(...args))
} : _ctx.showPlus ? {
z: common_vendor.p({
name: "plus",
color: $options.isDisabled("plus") ? "#c8c9cc" : "#323233",
size: "15",
bold: true,
customStyle: _ctx.iconStyle
}),
A: common_vendor.o(($event) => $options.clickHandler("plus")),
B: common_vendor.o(($event) => $options.onTouchStart("plus")),
C: common_vendor.o((...args) => $options.clearTimeout && $options.clearTimeout(...args)),
D: $options.isDisabled("plus") ? 1 : "",
E: common_vendor.s($options.buttonStyle("plus"))
} : {}, {
y: _ctx.showPlus
});
}
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__scopeId", "data-v-eb6f6237"]]);
my.createComponent(Component);

View File

@@ -0,0 +1,7 @@
{
"component": true,
"styleIsolation": "apply-shared",
"usingComponents": {
"u-icon": "../u-icon/u-icon"
}
}