优化页面
This commit is contained in:
155
unpackage/dist/dev/mp-weixin/uni_modules/uni-number-box/components/uni-number-box/uni-number-box.js
vendored
Normal file
155
unpackage/dist/dev/mp-weixin/uni_modules/uni-number-box/components/uni-number-box/uni-number-box.js
vendored
Normal file
@@ -0,0 +1,155 @@
|
||||
"use strict";
|
||||
const common_vendor = require("../../../../common/vendor.js");
|
||||
const _sfc_main = {
|
||||
name: "UniNumberBox",
|
||||
emits: ["change", "input", "update:modelValue", "blur", "focus"],
|
||||
props: {
|
||||
value: {
|
||||
type: [Number, String],
|
||||
default: 1
|
||||
},
|
||||
modelValue: {
|
||||
type: [Number, String],
|
||||
default: 1
|
||||
},
|
||||
min: {
|
||||
type: Number,
|
||||
default: 0
|
||||
},
|
||||
max: {
|
||||
type: Number,
|
||||
default: 100
|
||||
},
|
||||
step: {
|
||||
type: Number,
|
||||
default: 1
|
||||
},
|
||||
background: {
|
||||
type: String,
|
||||
default: "#f5f5f5"
|
||||
},
|
||||
color: {
|
||||
type: String,
|
||||
default: "#333"
|
||||
},
|
||||
disabled: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
width: {
|
||||
type: Number,
|
||||
default: 40
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
inputValue: 0
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
value(val) {
|
||||
this.inputValue = +val;
|
||||
},
|
||||
modelValue(val) {
|
||||
this.inputValue = +val;
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
widthWithPx() {
|
||||
return this.width + "px";
|
||||
}
|
||||
},
|
||||
created() {
|
||||
if (this.value === 1) {
|
||||
this.inputValue = +this.modelValue;
|
||||
}
|
||||
if (this.modelValue === 1) {
|
||||
this.inputValue = +this.value;
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
_calcValue(type) {
|
||||
if (this.disabled) {
|
||||
return;
|
||||
}
|
||||
const scale = this._getDecimalScale();
|
||||
let value = this.inputValue * scale;
|
||||
let step = this.step * scale;
|
||||
if (type === "minus") {
|
||||
value -= step;
|
||||
if (value < this.min * scale) {
|
||||
return;
|
||||
}
|
||||
if (value > this.max * scale) {
|
||||
value = this.max * scale;
|
||||
}
|
||||
}
|
||||
if (type === "plus") {
|
||||
value += step;
|
||||
if (value > this.max * scale) {
|
||||
return;
|
||||
}
|
||||
if (value < this.min * scale) {
|
||||
value = this.min * scale;
|
||||
}
|
||||
}
|
||||
this.inputValue = (value / scale).toFixed(String(scale).length - 1);
|
||||
this.$emit("input", +this.inputValue);
|
||||
this.$emit("update:modelValue", +this.inputValue);
|
||||
this.$emit("change", +this.inputValue);
|
||||
},
|
||||
_getDecimalScale() {
|
||||
let scale = 1;
|
||||
if (~~this.step !== this.step) {
|
||||
scale = Math.pow(10, String(this.step).split(".")[1].length);
|
||||
}
|
||||
return scale;
|
||||
},
|
||||
_onBlur(event) {
|
||||
this.$emit("blur", event);
|
||||
let value = event.detail.value;
|
||||
if (isNaN(value)) {
|
||||
this.inputValue = this.value;
|
||||
return;
|
||||
}
|
||||
value = +value;
|
||||
if (value > this.max) {
|
||||
value = this.max;
|
||||
} else if (value < this.min) {
|
||||
value = this.min;
|
||||
}
|
||||
const scale = this._getDecimalScale();
|
||||
this.inputValue = value.toFixed(String(scale).length - 1);
|
||||
this.$emit("input", +this.inputValue);
|
||||
this.$emit("update:modelValue", +this.inputValue);
|
||||
this.$emit("change", +this.inputValue);
|
||||
},
|
||||
_onFocus(event) {
|
||||
this.$emit("focus", event);
|
||||
}
|
||||
}
|
||||
};
|
||||
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
||||
return {
|
||||
a: $data.inputValue <= $props.min || $props.disabled ? 1 : "",
|
||||
b: $props.color,
|
||||
c: common_vendor.o$1(($event) => $options._calcValue("minus")),
|
||||
d: $props.background,
|
||||
e: $props.disabled,
|
||||
f: common_vendor.o$1((...args) => $options._onFocus && $options._onFocus(...args)),
|
||||
g: common_vendor.o$1((...args) => $options._onBlur && $options._onBlur(...args)),
|
||||
h: $props.step < 1 ? "digit" : "number",
|
||||
i: $props.background,
|
||||
j: $props.color,
|
||||
k: $options.widthWithPx,
|
||||
l: $data.inputValue,
|
||||
m: common_vendor.o$1(($event) => $data.inputValue = $event.detail.value),
|
||||
n: $data.inputValue >= $props.max || $props.disabled ? 1 : "",
|
||||
o: $props.color,
|
||||
p: common_vendor.o$1(($event) => $options._calcValue("plus")),
|
||||
q: $props.background
|
||||
};
|
||||
}
|
||||
const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render]]);
|
||||
wx.createComponent(Component);
|
||||
//# sourceMappingURL=../../../../../.sourcemap/mp-weixin/uni_modules/uni-number-box/components/uni-number-box/uni-number-box.js.map
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"component": true,
|
||||
"usingComponents": {}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<view class="uni-numbox"><view bindtap="{{c}}" class="uni-numbox__minus uni-numbox-btns" style="{{'background:' + d}}"><text class="{{['uni-numbox--text', a && 'uni-numbox--disabled']}}" style="{{'color:' + b}}">-</text></view><block wx:if="{{r0}}"><input disabled="{{e}}" bindfocus="{{f}}" bindblur="{{g}}" class="uni-numbox__value" type="{{h}}" style="{{'background:' + i + ';' + ('color:' + j) + ';' + ('width:' + k)}}" value="{{l}}" bindinput="{{m}}"/></block><view bindtap="{{p}}" class="uni-numbox__plus uni-numbox-btns" style="{{'background:' + q}}"><text class="{{['uni-numbox--text', n && 'uni-numbox--disabled']}}" style="{{'color:' + o}}">+</text></view></view>
|
||||
@@ -0,0 +1,65 @@
|
||||
/**
|
||||
* 这里是uni-app内置的常用样式变量
|
||||
*
|
||||
* uni-app 官方扩展插件及插件市场(https://ext.dcloud.net.cn)上很多三方插件均使用了这些样式变量
|
||||
* 如果你是插件开发者,建议你使用scss预处理,并在插件代码中直接使用这些变量(无需 import 这个文件),方便用户通过搭积木的方式开发整体风格一致的App
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* 如果你是App开发者(插件使用者),你可以通过修改这些变量来定制自己的插件主题,实现自定义主题功能
|
||||
*
|
||||
* 如果你的项目同样使用了scss预处理,你也可以直接在你的 scss 代码中使用如下变量,同时无需 import 这个文件
|
||||
*/
|
||||
/* 颜色变量 */
|
||||
/* 行为相关颜色 */
|
||||
/* 文字基本颜色 */
|
||||
/* 背景颜色 */
|
||||
/* 边框颜色 */
|
||||
/* 尺寸变量 */
|
||||
/* 文字尺寸 */
|
||||
/* 图片尺寸 */
|
||||
/* Border Radius */
|
||||
/* 水平间距 */
|
||||
/* 垂直间距 */
|
||||
/* 透明度 */
|
||||
/* 文章场景相关 */
|
||||
.uni-numbox {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
}
|
||||
.uni-numbox-btns {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 0 8px;
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
.uni-numbox__value {
|
||||
margin: 0 2px;
|
||||
background-color: #f5f5f5;
|
||||
width: 40px;
|
||||
height: 26px;
|
||||
text-align: center;
|
||||
font-size: 14px;
|
||||
border-width: 0;
|
||||
color: #333;
|
||||
}
|
||||
.uni-numbox__minus {
|
||||
border-top-left-radius: 2px;
|
||||
border-bottom-left-radius: 2px;
|
||||
}
|
||||
.uni-numbox__plus {
|
||||
border-top-right-radius: 2px;
|
||||
border-bottom-right-radius: 2px;
|
||||
}
|
||||
.uni-numbox--text {
|
||||
line-height: 20px;
|
||||
margin-bottom: 2px;
|
||||
font-size: 20px;
|
||||
font-weight: 300;
|
||||
color: #333;
|
||||
}
|
||||
.uni-numbox .uni-numbox--disabled {
|
||||
color: #c0c0c0 !important;
|
||||
}
|
||||
Reference in New Issue
Block a user