@infly/ui 1.0.30 → 1.0.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +799 -799
- package/package.json +2 -2
- package/src/Base/InflyForm/InflyForm.test.js +329 -329
- package/src/Base/InflyForm/InflyForm.vue +986 -986
- package/src/Base/InflyInput/InflyInput.test.js +105 -105
- package/src/Base/InflyInput/InflyInput.vue +167 -167
- package/src/Base/InflyList/InflyList.test.js +229 -229
- package/src/Base/InflyList/InflyList.vue +926 -926
- package/src/Business/BusinessSwitch/BusinessSwitch.test.js +250 -250
- package/src/Business/BusinessTag/BusinessTag.test.js +70 -70
- package/src/Business/InstitutionSelect/InstitutionSelect.test.js +281 -281
|
@@ -1,105 +1,105 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* InflyInput 组件测试
|
|
3
|
-
*
|
|
4
|
-
* 验证输入组件的 v-model、类型映射、前后置内容。
|
|
5
|
-
*/
|
|
6
|
-
const { mount } = require("../../../test/helper");
|
|
7
|
-
const InflyInput = require("./InflyInput.vue");
|
|
8
|
-
|
|
9
|
-
describe("InflyInput", () => {
|
|
10
|
-
describe("渲染", () => {
|
|
11
|
-
it("默认渲染 el-input", () => {
|
|
12
|
-
const wrapper = mount(InflyInput, {
|
|
13
|
-
propsData: { value: "" },
|
|
14
|
-
});
|
|
15
|
-
assert.ok(wrapper.find(".el-input").exists());
|
|
16
|
-
wrapper.destroy();
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it("type=el-autocomplete 时渲染 el-autocomplete", () => {
|
|
20
|
-
const wrapper = mount(InflyInput, {
|
|
21
|
-
propsData: { value: "" },
|
|
22
|
-
attrs: { type: "el-autocomplete" },
|
|
23
|
-
});
|
|
24
|
-
// el-autocomplete 有特定的 class
|
|
25
|
-
assert.ok(wrapper.find(".el-autocomplete") || wrapper.exists());
|
|
26
|
-
wrapper.destroy();
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
it("渲染容器 class", () => {
|
|
30
|
-
const wrapper = mount(InflyInput, {
|
|
31
|
-
propsData: {
|
|
32
|
-
value: "",
|
|
33
|
-
containerClass: "my-container",
|
|
34
|
-
},
|
|
35
|
-
});
|
|
36
|
-
assert.ok(wrapper.find(".my-container").exists());
|
|
37
|
-
wrapper.destroy();
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
describe("v-model / 双向绑定", () => {
|
|
42
|
-
it("接受初始 value", () => {
|
|
43
|
-
const wrapper = mount(InflyInput, {
|
|
44
|
-
propsData: { value: "初始值" },
|
|
45
|
-
});
|
|
46
|
-
assert.equal(wrapper.vm.$data.inputValue, "初始值");
|
|
47
|
-
wrapper.destroy();
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it("value 变化时同步内部状态", async () => {
|
|
51
|
-
const wrapper = mount(InflyInput, {
|
|
52
|
-
propsData: { value: "旧值" },
|
|
53
|
-
});
|
|
54
|
-
wrapper.setProps({ value: "新值" });
|
|
55
|
-
await wrapper.vm.$nextTick();
|
|
56
|
-
assert.equal(wrapper.vm.$data.inputValue, "新值");
|
|
57
|
-
wrapper.destroy();
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it("内部输入触发 input 事件(Vue 2 v-model)", () => {
|
|
61
|
-
const wrapper = mount(InflyInput, {
|
|
62
|
-
propsData: { value: "" },
|
|
63
|
-
});
|
|
64
|
-
wrapper.vm.$data.inputValue = "用户输入";
|
|
65
|
-
wrapper.vm.$emit("input", "用户输入");
|
|
66
|
-
assert.ok(wrapper.emitted().input);
|
|
67
|
-
wrapper.destroy();
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
describe("Props", () => {
|
|
72
|
-
it("支持 prepend 前置内容", () => {
|
|
73
|
-
const wrapper = mount(InflyInput, {
|
|
74
|
-
propsData: {
|
|
75
|
-
value: "",
|
|
76
|
-
prepend: "https://",
|
|
77
|
-
},
|
|
78
|
-
});
|
|
79
|
-
assert.ok(wrapper.exists());
|
|
80
|
-
wrapper.destroy();
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it("支持 append 后置内容", () => {
|
|
84
|
-
const wrapper = mount(InflyInput, {
|
|
85
|
-
propsData: {
|
|
86
|
-
value: "",
|
|
87
|
-
append: ".com",
|
|
88
|
-
},
|
|
89
|
-
});
|
|
90
|
-
assert.ok(wrapper.exists());
|
|
91
|
-
wrapper.destroy();
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it("支持 wrapClass", () => {
|
|
95
|
-
const wrapper = mount(InflyInput, {
|
|
96
|
-
propsData: {
|
|
97
|
-
value: "",
|
|
98
|
-
wrapClass: "custom-wrap",
|
|
99
|
-
},
|
|
100
|
-
});
|
|
101
|
-
assert.ok(wrapper.find(".custom-wrap").exists());
|
|
102
|
-
wrapper.destroy();
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
});
|
|
1
|
+
/**
|
|
2
|
+
* InflyInput 组件测试
|
|
3
|
+
*
|
|
4
|
+
* 验证输入组件的 v-model、类型映射、前后置内容。
|
|
5
|
+
*/
|
|
6
|
+
const { mount } = require("../../../test/helper");
|
|
7
|
+
const InflyInput = require("./InflyInput.vue");
|
|
8
|
+
|
|
9
|
+
describe("InflyInput", () => {
|
|
10
|
+
describe("渲染", () => {
|
|
11
|
+
it("默认渲染 el-input", () => {
|
|
12
|
+
const wrapper = mount(InflyInput, {
|
|
13
|
+
propsData: { value: "" },
|
|
14
|
+
});
|
|
15
|
+
assert.ok(wrapper.find(".el-input").exists());
|
|
16
|
+
wrapper.destroy();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("type=el-autocomplete 时渲染 el-autocomplete", () => {
|
|
20
|
+
const wrapper = mount(InflyInput, {
|
|
21
|
+
propsData: { value: "" },
|
|
22
|
+
attrs: { type: "el-autocomplete" },
|
|
23
|
+
});
|
|
24
|
+
// el-autocomplete 有特定的 class
|
|
25
|
+
assert.ok(wrapper.find(".el-autocomplete") || wrapper.exists());
|
|
26
|
+
wrapper.destroy();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("渲染容器 class", () => {
|
|
30
|
+
const wrapper = mount(InflyInput, {
|
|
31
|
+
propsData: {
|
|
32
|
+
value: "",
|
|
33
|
+
containerClass: "my-container",
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
assert.ok(wrapper.find(".my-container").exists());
|
|
37
|
+
wrapper.destroy();
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
describe("v-model / 双向绑定", () => {
|
|
42
|
+
it("接受初始 value", () => {
|
|
43
|
+
const wrapper = mount(InflyInput, {
|
|
44
|
+
propsData: { value: "初始值" },
|
|
45
|
+
});
|
|
46
|
+
assert.equal(wrapper.vm.$data.inputValue, "初始值");
|
|
47
|
+
wrapper.destroy();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("value 变化时同步内部状态", async () => {
|
|
51
|
+
const wrapper = mount(InflyInput, {
|
|
52
|
+
propsData: { value: "旧值" },
|
|
53
|
+
});
|
|
54
|
+
wrapper.setProps({ value: "新值" });
|
|
55
|
+
await wrapper.vm.$nextTick();
|
|
56
|
+
assert.equal(wrapper.vm.$data.inputValue, "新值");
|
|
57
|
+
wrapper.destroy();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("内部输入触发 input 事件(Vue 2 v-model)", () => {
|
|
61
|
+
const wrapper = mount(InflyInput, {
|
|
62
|
+
propsData: { value: "" },
|
|
63
|
+
});
|
|
64
|
+
wrapper.vm.$data.inputValue = "用户输入";
|
|
65
|
+
wrapper.vm.$emit("input", "用户输入");
|
|
66
|
+
assert.ok(wrapper.emitted().input);
|
|
67
|
+
wrapper.destroy();
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
describe("Props", () => {
|
|
72
|
+
it("支持 prepend 前置内容", () => {
|
|
73
|
+
const wrapper = mount(InflyInput, {
|
|
74
|
+
propsData: {
|
|
75
|
+
value: "",
|
|
76
|
+
prepend: "https://",
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
assert.ok(wrapper.exists());
|
|
80
|
+
wrapper.destroy();
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("支持 append 后置内容", () => {
|
|
84
|
+
const wrapper = mount(InflyInput, {
|
|
85
|
+
propsData: {
|
|
86
|
+
value: "",
|
|
87
|
+
append: ".com",
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
assert.ok(wrapper.exists());
|
|
91
|
+
wrapper.destroy();
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it("支持 wrapClass", () => {
|
|
95
|
+
const wrapper = mount(InflyInput, {
|
|
96
|
+
propsData: {
|
|
97
|
+
value: "",
|
|
98
|
+
wrapClass: "custom-wrap",
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
assert.ok(wrapper.find(".custom-wrap").exists());
|
|
102
|
+
wrapper.destroy();
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
});
|
|
@@ -1,167 +1,167 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div class="comp-InflyInput" :class="containerClass">
|
|
3
|
-
<component
|
|
4
|
-
v-model="inputValue"
|
|
5
|
-
:is="typeMap"
|
|
6
|
-
:class="['infly-input__wrap', wrapClass]"
|
|
7
|
-
:size="$attrs.size || 'mini'"
|
|
8
|
-
:placeholder="$attrs.placeholder || `请输入${$attrs.label}`"
|
|
9
|
-
v-bind="$attrs"
|
|
10
|
-
@select="handleSelect"
|
|
11
|
-
>
|
|
12
|
-
<template v-if="prepend" slot="prepend">
|
|
13
|
-
<el-select
|
|
14
|
-
v-if="prepend.options"
|
|
15
|
-
v-model="prependSelectValue"
|
|
16
|
-
v-bind="prepend"
|
|
17
|
-
@change="prepend.change || (() => {})"
|
|
18
|
-
>
|
|
19
|
-
<el-option
|
|
20
|
-
v-for="option in prepend.options"
|
|
21
|
-
:key="option.value"
|
|
22
|
-
:label="option.label"
|
|
23
|
-
:value="option.value"
|
|
24
|
-
></el-option>
|
|
25
|
-
</el-select>
|
|
26
|
-
<div v-else>{{ prepend }}</div>
|
|
27
|
-
</template>
|
|
28
|
-
<append-renderer v-if="append && append.inside" slot="append" :append="append" />
|
|
29
|
-
</component>
|
|
30
|
-
<append-renderer v-if="append && !append.inside" :append="append" />
|
|
31
|
-
</div>
|
|
32
|
-
</template>
|
|
33
|
-
|
|
34
|
-
<script>
|
|
35
|
-
import Uts from "../../utils/Uts.js";
|
|
36
|
-
|
|
37
|
-
export default {
|
|
38
|
-
name: "InflyInput",
|
|
39
|
-
inheritAttrs: false,
|
|
40
|
-
components: {
|
|
41
|
-
RenderFunction: {
|
|
42
|
-
functional: true,
|
|
43
|
-
props: {
|
|
44
|
-
renderFn: {
|
|
45
|
-
type: Function,
|
|
46
|
-
required: true
|
|
47
|
-
}
|
|
48
|
-
},
|
|
49
|
-
render(h, ctx) {
|
|
50
|
-
return ctx.props.renderFn();
|
|
51
|
-
}
|
|
52
|
-
},
|
|
53
|
-
AppendRenderer: {
|
|
54
|
-
functional: true,
|
|
55
|
-
props: {
|
|
56
|
-
append: {
|
|
57
|
-
type: [String, Object, Function],
|
|
58
|
-
required: true
|
|
59
|
-
}
|
|
60
|
-
},
|
|
61
|
-
render(h, ctx) {
|
|
62
|
-
const { append } = ctx.props;
|
|
63
|
-
|
|
64
|
-
if (Uts.isFunction(append)) {
|
|
65
|
-
return append();
|
|
66
|
-
}
|
|
67
|
-
if (Uts.isFunction(append?.render)) {
|
|
68
|
-
return append.render();
|
|
69
|
-
}
|
|
70
|
-
return h('span', append);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
},
|
|
74
|
-
props: {
|
|
75
|
-
// 必需 Props
|
|
76
|
-
value: {
|
|
77
|
-
type: [String, Number],
|
|
78
|
-
default: ""
|
|
79
|
-
},
|
|
80
|
-
// Vue3 默认 v-model -> modelValue
|
|
81
|
-
modelValue: {
|
|
82
|
-
type: [String, Number],
|
|
83
|
-
default: ""
|
|
84
|
-
},
|
|
85
|
-
wrapClass: {
|
|
86
|
-
type: String,
|
|
87
|
-
default: ""
|
|
88
|
-
},
|
|
89
|
-
containerClass: {
|
|
90
|
-
type: String,
|
|
91
|
-
default: ""
|
|
92
|
-
},
|
|
93
|
-
prepend: {
|
|
94
|
-
type: [String, Object],
|
|
95
|
-
default: ""
|
|
96
|
-
},
|
|
97
|
-
append: {
|
|
98
|
-
type: [String, Object, Function],
|
|
99
|
-
default: ""
|
|
100
|
-
}
|
|
101
|
-
},
|
|
102
|
-
computed: {
|
|
103
|
-
typeMap() {
|
|
104
|
-
let compType = "el-input";
|
|
105
|
-
if (this.$attrs.type === "el-autocomplete") {
|
|
106
|
-
compType = "el-autocomplete";
|
|
107
|
-
}
|
|
108
|
-
if (this.$attrs.type === "infly-input-number") {
|
|
109
|
-
compType = "el-input-number";
|
|
110
|
-
}
|
|
111
|
-
return compType;
|
|
112
|
-
}
|
|
113
|
-
},
|
|
114
|
-
watch: {
|
|
115
|
-
// 外部 value 改变时,同步到内部 inputValue
|
|
116
|
-
value(newVal) {
|
|
117
|
-
this.inputValue = newVal || "";
|
|
118
|
-
},
|
|
119
|
-
modelValue(newVal) {
|
|
120
|
-
this.inputValue = newVal || "";
|
|
121
|
-
},
|
|
122
|
-
// 内部输入改变时,往外 emit input 事件
|
|
123
|
-
inputValue(newVal) {
|
|
124
|
-
this.$emit("input", newVal); // Vue2 用法
|
|
125
|
-
this.$emit("update:modelValue", newVal); // Vue3 用法
|
|
126
|
-
}
|
|
127
|
-
},
|
|
128
|
-
data() {
|
|
129
|
-
return {
|
|
130
|
-
inputValue: this.value || this.modelValue || "",
|
|
131
|
-
prependSelectValue: (this.prepend && this.prepend.defaultValue) || ""
|
|
132
|
-
};
|
|
133
|
-
},
|
|
134
|
-
methods: {
|
|
135
|
-
handleSelect(item) {
|
|
136
|
-
const { value } = item || {};
|
|
137
|
-
this.inputValue = value;
|
|
138
|
-
},
|
|
139
|
-
handleNativeInput(e) {
|
|
140
|
-
// 如果配置了 numberOnly 属性,则限制只能输入数字和小数点
|
|
141
|
-
if (this.$attrs.numberOnly !== undefined) {
|
|
142
|
-
const input = e.target;
|
|
143
|
-
const oldValue = input.value;
|
|
144
|
-
// 只保留数字和小数点
|
|
145
|
-
let newValue = oldValue.replace(/[^\d.]/g, '');
|
|
146
|
-
// 确保只有一个小数点
|
|
147
|
-
const parts = newValue.split('.');
|
|
148
|
-
if (parts.length > 2) {
|
|
149
|
-
newValue = parts[0] + '.' + parts.slice(1).join('');
|
|
150
|
-
}
|
|
151
|
-
// 如果值被修改了,更新输入框
|
|
152
|
-
if (oldValue !== newValue) {
|
|
153
|
-
input.value = newValue;
|
|
154
|
-
this.inputValue = newValue;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
</script>
|
|
161
|
-
|
|
162
|
-
<style lang="scss" scoped>
|
|
163
|
-
.comp-InflyInput {
|
|
164
|
-
display: flex;
|
|
165
|
-
align-items: center;
|
|
166
|
-
}
|
|
167
|
-
</style>
|
|
1
|
+
<template>
|
|
2
|
+
<div class="comp-InflyInput" :class="containerClass">
|
|
3
|
+
<component
|
|
4
|
+
v-model="inputValue"
|
|
5
|
+
:is="typeMap"
|
|
6
|
+
:class="['infly-input__wrap', wrapClass]"
|
|
7
|
+
:size="$attrs.size || 'mini'"
|
|
8
|
+
:placeholder="$attrs.placeholder || `请输入${$attrs.label}`"
|
|
9
|
+
v-bind="$attrs"
|
|
10
|
+
@select="handleSelect"
|
|
11
|
+
>
|
|
12
|
+
<template v-if="prepend" slot="prepend">
|
|
13
|
+
<el-select
|
|
14
|
+
v-if="prepend.options"
|
|
15
|
+
v-model="prependSelectValue"
|
|
16
|
+
v-bind="prepend"
|
|
17
|
+
@change="prepend.change || (() => {})"
|
|
18
|
+
>
|
|
19
|
+
<el-option
|
|
20
|
+
v-for="option in prepend.options"
|
|
21
|
+
:key="option.value"
|
|
22
|
+
:label="option.label"
|
|
23
|
+
:value="option.value"
|
|
24
|
+
></el-option>
|
|
25
|
+
</el-select>
|
|
26
|
+
<div v-else>{{ prepend }}</div>
|
|
27
|
+
</template>
|
|
28
|
+
<append-renderer v-if="append && append.inside" slot="append" :append="append" />
|
|
29
|
+
</component>
|
|
30
|
+
<append-renderer v-if="append && !append.inside" :append="append" />
|
|
31
|
+
</div>
|
|
32
|
+
</template>
|
|
33
|
+
|
|
34
|
+
<script>
|
|
35
|
+
import Uts from "../../utils/Uts.js";
|
|
36
|
+
|
|
37
|
+
export default {
|
|
38
|
+
name: "InflyInput",
|
|
39
|
+
inheritAttrs: false,
|
|
40
|
+
components: {
|
|
41
|
+
RenderFunction: {
|
|
42
|
+
functional: true,
|
|
43
|
+
props: {
|
|
44
|
+
renderFn: {
|
|
45
|
+
type: Function,
|
|
46
|
+
required: true
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
render(h, ctx) {
|
|
50
|
+
return ctx.props.renderFn();
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
AppendRenderer: {
|
|
54
|
+
functional: true,
|
|
55
|
+
props: {
|
|
56
|
+
append: {
|
|
57
|
+
type: [String, Object, Function],
|
|
58
|
+
required: true
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
render(h, ctx) {
|
|
62
|
+
const { append } = ctx.props;
|
|
63
|
+
|
|
64
|
+
if (Uts.isFunction(append)) {
|
|
65
|
+
return append();
|
|
66
|
+
}
|
|
67
|
+
if (Uts.isFunction(append?.render)) {
|
|
68
|
+
return append.render();
|
|
69
|
+
}
|
|
70
|
+
return h('span', append);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
props: {
|
|
75
|
+
// 必需 Props
|
|
76
|
+
value: {
|
|
77
|
+
type: [String, Number],
|
|
78
|
+
default: ""
|
|
79
|
+
},
|
|
80
|
+
// Vue3 默认 v-model -> modelValue
|
|
81
|
+
modelValue: {
|
|
82
|
+
type: [String, Number],
|
|
83
|
+
default: ""
|
|
84
|
+
},
|
|
85
|
+
wrapClass: {
|
|
86
|
+
type: String,
|
|
87
|
+
default: ""
|
|
88
|
+
},
|
|
89
|
+
containerClass: {
|
|
90
|
+
type: String,
|
|
91
|
+
default: ""
|
|
92
|
+
},
|
|
93
|
+
prepend: {
|
|
94
|
+
type: [String, Object],
|
|
95
|
+
default: ""
|
|
96
|
+
},
|
|
97
|
+
append: {
|
|
98
|
+
type: [String, Object, Function],
|
|
99
|
+
default: ""
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
computed: {
|
|
103
|
+
typeMap() {
|
|
104
|
+
let compType = "el-input";
|
|
105
|
+
if (this.$attrs.type === "el-autocomplete") {
|
|
106
|
+
compType = "el-autocomplete";
|
|
107
|
+
}
|
|
108
|
+
if (this.$attrs.type === "infly-input-number") {
|
|
109
|
+
compType = "el-input-number";
|
|
110
|
+
}
|
|
111
|
+
return compType;
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
watch: {
|
|
115
|
+
// 外部 value 改变时,同步到内部 inputValue
|
|
116
|
+
value(newVal) {
|
|
117
|
+
this.inputValue = newVal || "";
|
|
118
|
+
},
|
|
119
|
+
modelValue(newVal) {
|
|
120
|
+
this.inputValue = newVal || "";
|
|
121
|
+
},
|
|
122
|
+
// 内部输入改变时,往外 emit input 事件
|
|
123
|
+
inputValue(newVal) {
|
|
124
|
+
this.$emit("input", newVal); // Vue2 用法
|
|
125
|
+
this.$emit("update:modelValue", newVal); // Vue3 用法
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
data() {
|
|
129
|
+
return {
|
|
130
|
+
inputValue: this.value || this.modelValue || "",
|
|
131
|
+
prependSelectValue: (this.prepend && this.prepend.defaultValue) || ""
|
|
132
|
+
};
|
|
133
|
+
},
|
|
134
|
+
methods: {
|
|
135
|
+
handleSelect(item) {
|
|
136
|
+
const { value } = item || {};
|
|
137
|
+
this.inputValue = value;
|
|
138
|
+
},
|
|
139
|
+
handleNativeInput(e) {
|
|
140
|
+
// 如果配置了 numberOnly 属性,则限制只能输入数字和小数点
|
|
141
|
+
if (this.$attrs.numberOnly !== undefined) {
|
|
142
|
+
const input = e.target;
|
|
143
|
+
const oldValue = input.value;
|
|
144
|
+
// 只保留数字和小数点
|
|
145
|
+
let newValue = oldValue.replace(/[^\d.]/g, '');
|
|
146
|
+
// 确保只有一个小数点
|
|
147
|
+
const parts = newValue.split('.');
|
|
148
|
+
if (parts.length > 2) {
|
|
149
|
+
newValue = parts[0] + '.' + parts.slice(1).join('');
|
|
150
|
+
}
|
|
151
|
+
// 如果值被修改了,更新输入框
|
|
152
|
+
if (oldValue !== newValue) {
|
|
153
|
+
input.value = newValue;
|
|
154
|
+
this.inputValue = newValue;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
</script>
|
|
161
|
+
|
|
162
|
+
<style lang="scss" scoped>
|
|
163
|
+
.comp-InflyInput {
|
|
164
|
+
display: flex;
|
|
165
|
+
align-items: center;
|
|
166
|
+
}
|
|
167
|
+
</style>
|