kui-vue 3.2.10 → 3.2.11
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/components/_tool/number.js +177 -0
- package/components/_tool/utils.js +9 -3
- package/components/base/input.jsx +82 -54
- package/components/base/pop.jsx +22 -8
- package/components/button/button.jsx +1 -1
- package/components/button/styles/index.less +6 -2
- package/components/checkbox/checkbox.jsx +6 -11
- package/components/checkbox/demo/check-all.md +6 -6
- package/components/checkbox/group.jsx +0 -1
- package/components/checkbox/styles/index.less +17 -11
- package/components/divider/styles/index.less +1 -1
- package/components/dropdown/demo/rightmenu.md +2 -2
- package/components/dropdown/styles/index.less +23 -34
- package/components/form/demo/base.md +7 -1
- package/components/form/demo/valid.md +13 -4
- package/components/form/styles/index.less +1 -5
- package/components/icon/demo/base.md +2 -2
- package/components/icon/demo/search.vue +31 -14
- package/components/icon/icon.jsx +3 -1
- package/components/icon/styles/index.less +1 -1
- package/components/index.js +2 -0
- package/components/input/demo/icon.md +2 -2
- package/components/input/demo/size.md +3 -3
- package/components/input/demo/suffix.md +13 -6
- package/components/input/demo/theme.md +11 -6
- package/components/input/index.md +2 -1
- package/components/input/input.jsx +5 -0
- package/components/input/styles/index.less +52 -63
- package/components/inputNumber/demo/base.md +34 -0
- package/components/inputNumber/demo/ffix.md +27 -0
- package/components/inputNumber/demo/format.md +80 -0
- package/components/inputNumber/demo/index.vue +23 -0
- package/components/inputNumber/demo/info.md +7 -0
- package/components/inputNumber/demo/size.md +18 -0
- package/components/inputNumber/index.js +2 -0
- package/components/inputNumber/index.md +16 -0
- package/components/inputNumber/inputNumber.jsx +169 -0
- package/components/inputNumber/styles/index.less +172 -0
- package/components/menu/demo/collapsed.md +1 -1
- package/components/menu/styles/dropmenu.less +2 -2
- package/components/menu/styles/index.less +31 -14
- package/components/message/demo/icon.md +33 -0
- package/components/message/demo/index.vue +2 -0
- package/components/message/index.md +9 -7
- package/components/message/inner.jsx +5 -3
- package/components/modal/modal.jsx +31 -31
- package/components/notice/demo/icon.md +27 -11
- package/components/notice/demo/index.vue +2 -0
- package/components/notice/demo/types.md +28 -0
- package/components/notice/index.js +3 -0
- package/components/notice/index.md +8 -6
- package/components/popconfirm/styles/index.less +64 -83
- package/components/poptip/demo/base.md +7 -0
- package/components/poptip/demo/placement.md +12 -13
- package/components/poptip/styles/index.less +60 -79
- package/components/progress/demo/circle.md +2 -2
- package/components/radio/button.jsx +4 -2
- package/components/radio/demo/button.md +32 -28
- package/components/radio/group.jsx +4 -2
- package/components/radio/radio.jsx +7 -7
- package/components/radio/styles/index.less +61 -29
- package/components/rate/demo/base.md +7 -1
- package/components/rate/rate.jsx +8 -3
- package/components/rate/star.jsx +4 -3
- package/components/rate/styles/index.less +5 -3
- package/components/select/select.jsx +2 -0
- package/components/skeleton/demo/custom.md +62 -0
- package/components/skeleton/demo/index.vue +2 -0
- package/components/skeleton/demo/items.md +6 -2
- package/components/skeleton/index.md +32 -12
- package/components/skeleton/skeleton.jsx +1 -3
- package/components/skeleton/skeletonAvatar.jsx +33 -7
- package/components/skeleton/skeletonButton.jsx +29 -4
- package/components/skeleton/skeletonImage.jsx +43 -6
- package/components/skeleton/skeletonText.jsx +29 -4
- package/components/slider/demo/base.md +7 -15
- package/components/slider/demo/formatter.md +19 -0
- package/components/slider/demo/index.vue +10 -1
- package/components/slider/demo/marks.md +42 -0
- package/components/slider/demo/reverse.md +26 -0
- package/components/slider/demo/vertical.md +26 -3
- package/components/slider/demo/withNumber.md +43 -0
- package/components/slider/index.md +15 -6
- package/components/slider/slider.jsx +173 -41
- package/components/slider/styles/index.less +109 -44
- package/components/slider/thumb.jsx +165 -0
- package/components/space/demo/align.md +22 -21
- package/components/space/demo/base.md +0 -1
- package/components/space/demo/index.vue +2 -0
- package/components/space/demo/size.md +34 -22
- package/components/space/demo/vertical.md +1 -1
- package/components/space/demo/wrap.md +12 -0
- package/components/space/index.md +6 -5
- package/components/space/space.jsx +40 -35
- package/components/space/styles/index.less +15 -0
- package/components/spin/demo/mode.md +6 -4
- package/components/spin/spin.jsx +1 -1
- package/components/styles/index.less +1 -0
- package/components/switch/demo/loading.md +1 -1
- package/components/switch/demo/text.md +3 -1
- package/components/switch/styles/index.less +31 -20
- package/components/table/styles/index.less +9 -10
- package/components/tooltip/styles/index.less +103 -76
- package/components/tooltip/tooltip.jsx +3 -0
- package/components/upload/styles/index.less +7 -0
- package/components/upload/upload.jsx +22 -12
- package/dist/k-ui.css +2 -2
- package/dist/k-ui.js +2 -2
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
@import '../../styles/var.less';
|
|
2
|
-
.k-input
|
|
2
|
+
.k-input[mult] {
|
|
3
3
|
position: relative;
|
|
4
4
|
display: inline-flex;
|
|
5
5
|
width: 100%;
|
|
@@ -10,47 +10,49 @@
|
|
|
10
10
|
border-radius: var(--kui-border-radius);
|
|
11
11
|
transition: all .3s ease-in-out;
|
|
12
12
|
box-sizing: border-box;
|
|
13
|
+
font-size: 14px;
|
|
14
|
+
padding: 0 8px;
|
|
15
|
+
gap: 8px;
|
|
13
16
|
&:hover {
|
|
14
17
|
border-color: var(--kui-color-main);
|
|
15
18
|
}
|
|
16
19
|
.k-input-icon {
|
|
17
|
-
// position: absolute;
|
|
18
|
-
// top: 0;
|
|
19
|
-
// left: 7px;
|
|
20
|
-
// top: 50%;
|
|
21
|
-
// transform: translateY(-50%);
|
|
22
|
-
margin: 0 7px;
|
|
23
20
|
font-size: 16px;
|
|
24
21
|
color: var(--kui-color-icon);
|
|
25
|
-
z-index: 1;
|
|
26
|
-
// &+.k-input {
|
|
27
|
-
// padding-left: 32px;
|
|
28
|
-
// }
|
|
29
22
|
}
|
|
30
|
-
.k-input {
|
|
31
|
-
|
|
23
|
+
.k-input-icon-search {
|
|
24
|
+
cursor: pointer;
|
|
32
25
|
}
|
|
33
|
-
.k-input
|
|
26
|
+
.k-input-text {
|
|
27
|
+
padding-left: 0;
|
|
34
28
|
border: none;
|
|
35
|
-
|
|
29
|
+
height: 32px;
|
|
30
|
+
line-height: 1.5;
|
|
31
|
+
padding: 4px 0;
|
|
32
|
+
font-size: 14px;
|
|
33
|
+
color: var(--kui-color-font);
|
|
34
|
+
background-color: transparent;
|
|
35
|
+
background-image: none;
|
|
36
|
+
box-sizing: border-box;
|
|
37
|
+
flex: 1;
|
|
38
|
+
min-width: 10px;
|
|
39
|
+
&:focus {
|
|
40
|
+
border-color: var(--kui-color-main);
|
|
41
|
+
outline: none;
|
|
42
|
+
}
|
|
36
43
|
}
|
|
37
44
|
&.k-input-focus {
|
|
38
45
|
border-color: var(--kui-color-main);
|
|
39
46
|
box-shadow: 0 0 5px var(--kui-color-main-30);
|
|
40
47
|
}
|
|
41
|
-
.k-input-suffix {
|
|
42
|
-
// position: absolute;
|
|
43
|
-
// right: 12px;
|
|
44
|
-
// top: 50%;
|
|
48
|
+
.k-input-suffix, .k-input-prefix {
|
|
45
49
|
font-size: 12px;
|
|
46
|
-
// transform: translateY(-50%);
|
|
47
50
|
white-space: nowrap;
|
|
48
51
|
line-height: 1;
|
|
49
52
|
cursor: pointer;
|
|
50
53
|
user-select: none;
|
|
51
|
-
// background: #fff;
|
|
52
54
|
transition: all .2s ease-in-out;
|
|
53
|
-
|
|
55
|
+
display: flex;
|
|
54
56
|
&:hover {
|
|
55
57
|
color: var(--kui-color-font);
|
|
56
58
|
}
|
|
@@ -60,12 +62,12 @@
|
|
|
60
62
|
color: var(--kui-color-icon);
|
|
61
63
|
}
|
|
62
64
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
+
&.k-input-circle {
|
|
66
|
+
border-radius: 20px;
|
|
65
67
|
}
|
|
66
68
|
}
|
|
67
69
|
|
|
68
|
-
.k-input, .k-textarea {
|
|
70
|
+
.k-input[single], .k-textarea {
|
|
69
71
|
box-sizing: border-box;
|
|
70
72
|
display: inline-block;
|
|
71
73
|
width: 100%;
|
|
@@ -120,51 +122,34 @@
|
|
|
120
122
|
outline: none;
|
|
121
123
|
}
|
|
122
124
|
|
|
123
|
-
// .k-input-has-suffix, .k-input-has-clear {
|
|
124
|
-
// .k-input {
|
|
125
|
-
// padding-right: 32px;
|
|
126
|
-
// }
|
|
127
|
-
// }
|
|
128
125
|
.k-input-clearable {
|
|
129
|
-
// position: absolute;
|
|
130
|
-
// right: 8px;
|
|
131
126
|
cursor: pointer;
|
|
132
|
-
// z-index: 10;
|
|
133
|
-
// top: 50%;
|
|
134
127
|
font-size: 15px;
|
|
135
|
-
// transform: translateY(-50%);
|
|
136
|
-
margin-right: 8px;
|
|
137
128
|
color: var(--kui-color-gray);
|
|
138
129
|
&:hover {
|
|
139
130
|
color: var(--kui-color-font);
|
|
140
131
|
}
|
|
141
132
|
}
|
|
142
133
|
|
|
143
|
-
|
|
134
|
+
.k-input-sm[single] {
|
|
144
135
|
padding: 2px 7px;
|
|
145
136
|
height: 24px;
|
|
146
137
|
line-height: 22px;
|
|
147
138
|
}
|
|
148
139
|
|
|
149
|
-
.k-input-sm {
|
|
150
|
-
|
|
151
|
-
|
|
140
|
+
.k-input-sm[mult] {
|
|
141
|
+
padding: 0 6px;
|
|
142
|
+
gap: 6px;
|
|
143
|
+
.k-input-text {
|
|
144
|
+
padding: 2px 0;
|
|
152
145
|
height: 24px;
|
|
153
146
|
line-height: 22px;
|
|
154
147
|
}
|
|
155
148
|
.k-input-clearable {
|
|
156
|
-
// right: 9px;
|
|
157
149
|
font-size: 14px;
|
|
158
150
|
}
|
|
159
151
|
.k-input-icon {
|
|
160
|
-
// left: 5px;
|
|
161
152
|
font-size: 16px;
|
|
162
|
-
// &+.k-input {
|
|
163
|
-
// padding-left: 24px;
|
|
164
|
-
// }
|
|
165
|
-
}
|
|
166
|
-
&.k-input-has-clear .k-input {
|
|
167
|
-
// padding-right: 25px;
|
|
168
153
|
}
|
|
169
154
|
.k-input-suffix {
|
|
170
155
|
.k-icon {
|
|
@@ -173,33 +158,25 @@ input.k-input-sm {
|
|
|
173
158
|
}
|
|
174
159
|
}
|
|
175
160
|
|
|
176
|
-
|
|
161
|
+
.k-input-lg[single] {
|
|
177
162
|
padding: 2px 10px;
|
|
178
163
|
height: 40px;
|
|
179
164
|
line-height: 38px;
|
|
180
165
|
font-size: 14px;
|
|
181
166
|
}
|
|
182
167
|
|
|
183
|
-
.k-input-lg {
|
|
184
|
-
.k-input {
|
|
185
|
-
padding: 2px
|
|
168
|
+
.k-input-lg[mult] {
|
|
169
|
+
.k-input-text {
|
|
170
|
+
padding: 2px 0;
|
|
186
171
|
height: 40px;
|
|
187
172
|
line-height: 38px;
|
|
188
173
|
font-size: 14px;
|
|
189
174
|
}
|
|
190
175
|
.k-input-clearable {
|
|
191
|
-
// right: 10px;
|
|
192
176
|
font-size: 18px;
|
|
193
177
|
}
|
|
194
178
|
.k-input-icon {
|
|
195
179
|
font-size: 25px;
|
|
196
|
-
// left: 8px;
|
|
197
|
-
// &+.k-input {
|
|
198
|
-
// padding-left: 40px;
|
|
199
|
-
// }
|
|
200
|
-
}
|
|
201
|
-
&.k-input-has-clear .k-input {
|
|
202
|
-
// padding-right: 40px;
|
|
203
180
|
}
|
|
204
181
|
.k-input-suffix {
|
|
205
182
|
.k-icon {
|
|
@@ -216,7 +193,7 @@ input.k-input-lg {
|
|
|
216
193
|
display: none;
|
|
217
194
|
}
|
|
218
195
|
|
|
219
|
-
.k-input-light {
|
|
196
|
+
.k-input-light[mult], .k-input-light[single], .k-textarea-light {
|
|
220
197
|
border: none;
|
|
221
198
|
background-color: var(--kui-color-gray-80);
|
|
222
199
|
&:focus, &.k-input-focus {
|
|
@@ -224,7 +201,19 @@ input.k-input-lg {
|
|
|
224
201
|
}
|
|
225
202
|
}
|
|
226
203
|
|
|
227
|
-
.k-input-circle {
|
|
204
|
+
.k-input-circle[single] {
|
|
228
205
|
border-radius: 20px;
|
|
229
|
-
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
.k-input-disabled[mult] {
|
|
209
|
+
cursor: not-allowed;
|
|
210
|
+
color: var(--kui-color-disable-color);
|
|
211
|
+
background: var(--kui-color-disable-back);
|
|
212
|
+
border-color: var(--kui-color-disable-border);
|
|
213
|
+
&:hover {
|
|
214
|
+
border-color: var(--kui-color-disable-border);
|
|
215
|
+
}
|
|
216
|
+
& * {
|
|
217
|
+
cursor: not-allowed;
|
|
218
|
+
}
|
|
230
219
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
<cn>
|
|
2
|
+
#### 基本用法
|
|
3
|
+
基本用法
|
|
4
|
+
</cn>
|
|
5
|
+
|
|
6
|
+
```vue
|
|
7
|
+
<template>
|
|
8
|
+
<div style="width:200px;font-size:12px;">
|
|
9
|
+
简单数字输入框<br/>
|
|
10
|
+
<InputNumber v-model="value"/>
|
|
11
|
+
<br/>
|
|
12
|
+
<br/>
|
|
13
|
+
步长为2<br/>
|
|
14
|
+
<InputNumber :step="2" :value="2"/>
|
|
15
|
+
<br/>
|
|
16
|
+
<br/>
|
|
17
|
+
设置了上下界 min=1,max=10<br/>
|
|
18
|
+
<InputNumber :min="1" :max="10"/>
|
|
19
|
+
<br/>
|
|
20
|
+
<br/>
|
|
21
|
+
禁用<br/>
|
|
22
|
+
<InputNumber disabled />
|
|
23
|
+
</div>
|
|
24
|
+
</template>
|
|
25
|
+
<script>
|
|
26
|
+
export default{
|
|
27
|
+
data() {
|
|
28
|
+
return {
|
|
29
|
+
value: ''
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
</script>
|
|
34
|
+
```
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
<cn>
|
|
2
|
+
#### 扩展, 前缀和后缀
|
|
3
|
+
suffix,prefix 扩展
|
|
4
|
+
</cn>
|
|
5
|
+
|
|
6
|
+
```vue
|
|
7
|
+
<template>
|
|
8
|
+
<div style="width:256px;">
|
|
9
|
+
<InputNumber placeholder="请填写您的薪资" icon="cafe" >
|
|
10
|
+
<template slot="suffix">
|
|
11
|
+
<Tooltip title="此处如果不知道怎么填,请咨询管理员">
|
|
12
|
+
<Icon type="heart" color="red"/>
|
|
13
|
+
</Tooltip>
|
|
14
|
+
</template>
|
|
15
|
+
</InputNumber>
|
|
16
|
+
<br/>
|
|
17
|
+
<br/>
|
|
18
|
+
<InputNumber placeholder="请输入金额" suffix="元" prefix="$"/>
|
|
19
|
+
<br/>
|
|
20
|
+
<br/>
|
|
21
|
+
<InputNumber placeholder="请输入充值金额" :step="50" suffix="元" prefix="充值"/>
|
|
22
|
+
<br/>
|
|
23
|
+
<br/>
|
|
24
|
+
<InputNumber placeholder="请输入金额" suffix=".00"/>
|
|
25
|
+
</div>
|
|
26
|
+
</template>
|
|
27
|
+
```
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
<cn>
|
|
2
|
+
#### 高精度小数/格式化展示
|
|
3
|
+
通过 formatter 格式化数字,以展示具有具体含义的数据,往往需要配合 parser 一起使用。
|
|
4
|
+
</cn>
|
|
5
|
+
|
|
6
|
+
```vue
|
|
7
|
+
<template>
|
|
8
|
+
<div style="width:520px;">
|
|
9
|
+
0.1+0.2 = 0.3 (yes) ,输出:{{n}}
|
|
10
|
+
<InputNumber :step="0.2" v-model="n"/>
|
|
11
|
+
<br/>
|
|
12
|
+
<br/>
|
|
13
|
+
步长为 0.00000000000001 ,输出:{{n1}}
|
|
14
|
+
<InputNumber
|
|
15
|
+
v-model="n1"
|
|
16
|
+
:min="0"
|
|
17
|
+
:max="10"
|
|
18
|
+
:step="0.00000000000001"/>
|
|
19
|
+
<br/>
|
|
20
|
+
<br/>
|
|
21
|
+
保留2位小数, 输出:{{n3}}<br/>
|
|
22
|
+
<InputNumber :precision="2" v-model="n3" />
|
|
23
|
+
<br/>
|
|
24
|
+
<br/>
|
|
25
|
+
货币,千分位,输出: {{n4}}<br/>
|
|
26
|
+
<InputNumber
|
|
27
|
+
@change="log"
|
|
28
|
+
v-model="n4"
|
|
29
|
+
:min="0"
|
|
30
|
+
:formatter="value => `¥ ${value}`.replace(/\B(?=(\d{3})+(?!\d))/g, ',')"
|
|
31
|
+
:parser="value => value.replace(/\¥\s?|(,*)/g, '')"
|
|
32
|
+
/>
|
|
33
|
+
<br/>
|
|
34
|
+
<br/>
|
|
35
|
+
百分比% ,输出: {{n5}}<br/>
|
|
36
|
+
<InputNumber
|
|
37
|
+
v-model="n5"
|
|
38
|
+
:min="0"
|
|
39
|
+
:max="100"
|
|
40
|
+
:formatter="value => `${value}%`"
|
|
41
|
+
:parser="value => value.replace('%', '')"
|
|
42
|
+
/>
|
|
43
|
+
<br/>
|
|
44
|
+
<br/>
|
|
45
|
+
只能输入数字,输出: {{n6}}<br/>
|
|
46
|
+
<InputNumber
|
|
47
|
+
v-model="n6"
|
|
48
|
+
:formatter="value => value.replace(/\D/g, '')"
|
|
49
|
+
/>
|
|
50
|
+
<br/>
|
|
51
|
+
<br/>
|
|
52
|
+
自定义 ,输出:{{n7}}<br/>
|
|
53
|
+
<InputNumber
|
|
54
|
+
v-model="n7"
|
|
55
|
+
:formatter="value => String(value).split('').join('-')"
|
|
56
|
+
:parser="value => value.replace(/\-/g, '')"
|
|
57
|
+
/>
|
|
58
|
+
</div>
|
|
59
|
+
</template>
|
|
60
|
+
<script>
|
|
61
|
+
export default{
|
|
62
|
+
data(){
|
|
63
|
+
return {
|
|
64
|
+
n:0.1,
|
|
65
|
+
n1: 1,
|
|
66
|
+
n3: 3.14159,
|
|
67
|
+
n4: 1000,
|
|
68
|
+
n5: 100,
|
|
69
|
+
n6: '',
|
|
70
|
+
n7: 111111
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
methods:{
|
|
74
|
+
log(value){
|
|
75
|
+
console.log(value)
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
</script>
|
|
80
|
+
```
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import Info from "./info";
|
|
3
|
+
import Base from "./base";
|
|
4
|
+
import Format from "./format";
|
|
5
|
+
import Ffix from "./ffix";
|
|
6
|
+
import Size from "./size";
|
|
7
|
+
|
|
8
|
+
import CN from "../index.md";
|
|
9
|
+
export default {
|
|
10
|
+
render() {
|
|
11
|
+
return (
|
|
12
|
+
<div class="switch-demo">
|
|
13
|
+
<Info class="typo" />
|
|
14
|
+
<Base />
|
|
15
|
+
<Format />
|
|
16
|
+
<Ffix />
|
|
17
|
+
<Size />
|
|
18
|
+
<CN class="typo" />
|
|
19
|
+
</div>
|
|
20
|
+
);
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
</script>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<cn>
|
|
2
|
+
#### 尺寸
|
|
3
|
+
`large` 为大尺寸, `small` 为小尺寸
|
|
4
|
+
</cn>
|
|
5
|
+
|
|
6
|
+
```vue
|
|
7
|
+
<template>
|
|
8
|
+
<div style="width:512px;">
|
|
9
|
+
<InputNumber placeholder="Large Input" size="large" icon="logo-kui" clearable />
|
|
10
|
+
<br/>
|
|
11
|
+
<br/>
|
|
12
|
+
<InputNumber placeholder="Base Input" icon="logo-kui" clearable />
|
|
13
|
+
<br/>
|
|
14
|
+
<br/>
|
|
15
|
+
<InputNumber size="small" placeholder="Small Input" icon="logo-kui" clearable />
|
|
16
|
+
</div>
|
|
17
|
+
</template>
|
|
18
|
+
```
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
### InputNumber API
|
|
2
|
+
| 属性 | 说明 | 类型 | 默认值 |
|
|
3
|
+
| -------------- | -------------------------------------------------------------------- | ------------- | ------ |
|
|
4
|
+
| min | 最小值 | number | 0 |
|
|
5
|
+
| max | 最大值 | number | 100 |
|
|
6
|
+
| step | 每次改变步数,可以为小数 | Number,String | 1 |
|
|
7
|
+
| value(v-model) | 当前值 | Number | - |
|
|
8
|
+
| formatter | 指定输入框展示值的格式 | Function | - |
|
|
9
|
+
| parser | 指定从 formatter 里转换回数字的方式,和 formatter 搭配使用 | Function | - |
|
|
10
|
+
| change | 变化回调 | Function | - |
|
|
11
|
+
| size | 输入框大小 | String | - |
|
|
12
|
+
| disabled | 禁用 | Boolean | - |
|
|
13
|
+
| precision | 数值精度 | Number | - |
|
|
14
|
+
| suffix | 自定义后缀 | String,slot | - |
|
|
15
|
+
| prefix | 前缀内容 | String,slot | - |
|
|
16
|
+
| controls | 是否显示增减按钮 | Boolean | true |
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import BaseInput from '../base/input'
|
|
2
|
+
import Icon from '../icon'
|
|
3
|
+
import { plus, minus, round, toNumber } from '../_tool/number'
|
|
4
|
+
export default {
|
|
5
|
+
props: {
|
|
6
|
+
value: [Array, Number, String],
|
|
7
|
+
min: { type: Number },
|
|
8
|
+
max: { type: Number },
|
|
9
|
+
disabled: Boolean,
|
|
10
|
+
formatter: Function,
|
|
11
|
+
parser: Function,
|
|
12
|
+
size: String,
|
|
13
|
+
precision: Number,
|
|
14
|
+
suffix: String,
|
|
15
|
+
prefix: String,
|
|
16
|
+
controls: { type: Boolean, default: true },
|
|
17
|
+
step: {
|
|
18
|
+
type: Number,
|
|
19
|
+
default: 1,
|
|
20
|
+
},
|
|
21
|
+
theme: String,
|
|
22
|
+
},
|
|
23
|
+
watch: {
|
|
24
|
+
value(v) {
|
|
25
|
+
if (this.formatter) {
|
|
26
|
+
v = this.formatter(v + '')
|
|
27
|
+
}
|
|
28
|
+
this.defaultValue = v //this.getVal(v)
|
|
29
|
+
// console.log('watch', this.defaultValue)
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
data() {
|
|
33
|
+
return {
|
|
34
|
+
defaultValue: this.getVal(this.value),
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
methods: {
|
|
38
|
+
getVal(v) {
|
|
39
|
+
let { min, max, precision, formatter, parser } = this
|
|
40
|
+
if (parser) {
|
|
41
|
+
v = parser(v + '')
|
|
42
|
+
}
|
|
43
|
+
if (v !== undefined && v !== '' && v !== null) {
|
|
44
|
+
if (isNaN(Number(v))) {
|
|
45
|
+
v = (v + '').replace(/^([^-]+)(?=-\S*)/, '') // 移除第一个负号之前的所有字符
|
|
46
|
+
.replace(/(?<!^)-/g, '') // 移除第一个负号之外的所有负号
|
|
47
|
+
.replace(/[^0-9.-]/g, '') // 移除数字 小数点 负号之外的所有字符
|
|
48
|
+
.replace(/(?<!^[\d-]+)\./g, '') // 移除第一个小数点之外的所有句点
|
|
49
|
+
// .replace(/^0*(-?\d+)(\.(\d{1,2}))?\S*?$/, '$1$2') // 保留两位小数
|
|
50
|
+
// console.log(v)
|
|
51
|
+
}
|
|
52
|
+
if (v === '') return ''
|
|
53
|
+
v = toNumber(v + '')
|
|
54
|
+
} else {
|
|
55
|
+
return ''
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
if (max !== undefined && v >= max) v = max
|
|
60
|
+
else if (min !== undefined && v <= min) v = min
|
|
61
|
+
|
|
62
|
+
if (precision > 0) {
|
|
63
|
+
v = round(v, precision)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (formatter) {
|
|
67
|
+
v = formatter(v + '')
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return v
|
|
71
|
+
},
|
|
72
|
+
setVal(up) {
|
|
73
|
+
if (this.disabled) return;
|
|
74
|
+
let { step = 1, defaultValue, parser, formatter } = this
|
|
75
|
+
|
|
76
|
+
let v = this.getVal(defaultValue) || 0
|
|
77
|
+
|
|
78
|
+
if (parser) {
|
|
79
|
+
v = parser(v + '')
|
|
80
|
+
}
|
|
81
|
+
v = up == 1 ? plus(v, step) : minus(v, step)
|
|
82
|
+
|
|
83
|
+
let a = this.getVal(v)
|
|
84
|
+
|
|
85
|
+
// console.log('a', a)
|
|
86
|
+
|
|
87
|
+
this.defaultValue = a + ''
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
if (parser) {
|
|
91
|
+
a = parser(a)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
this.$emit('input', a)
|
|
96
|
+
this.$emit('change', a)
|
|
97
|
+
},
|
|
98
|
+
change(x) {
|
|
99
|
+
let { formatter, parser } = this
|
|
100
|
+
let input = x + '', output = x;
|
|
101
|
+
|
|
102
|
+
if (formatter) {
|
|
103
|
+
input = formatter(x + '')
|
|
104
|
+
}
|
|
105
|
+
// if (formatter) {
|
|
106
|
+
// x = formatter(x + '')
|
|
107
|
+
// }
|
|
108
|
+
this.defaultValue = input
|
|
109
|
+
|
|
110
|
+
// output = toNumber(output + '')
|
|
111
|
+
|
|
112
|
+
this.$emit('input', output)
|
|
113
|
+
this.$emit('change', output)
|
|
114
|
+
},
|
|
115
|
+
blurHandle(e) {
|
|
116
|
+
let v = this.getVal(e.target.value)
|
|
117
|
+
// console.log(v)
|
|
118
|
+
this.defaultValue = v + ''
|
|
119
|
+
// console.log('blur1', v)
|
|
120
|
+
|
|
121
|
+
let output = v
|
|
122
|
+
if (this.parser) {
|
|
123
|
+
output = this.parser(output + '')
|
|
124
|
+
}
|
|
125
|
+
// console.log('blur2', output)
|
|
126
|
+
if (output !== '') {
|
|
127
|
+
output = toNumber(output + '')
|
|
128
|
+
}
|
|
129
|
+
// console.log('blur3', output)
|
|
130
|
+
|
|
131
|
+
this.$emit('input', output)
|
|
132
|
+
this.$emit('blur', e)
|
|
133
|
+
this.$emit('change', output);
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
provide() {
|
|
137
|
+
return {
|
|
138
|
+
Input: this
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
render() {
|
|
142
|
+
let { defaultValue, controls } = this
|
|
143
|
+
const props = {
|
|
144
|
+
props: {
|
|
145
|
+
...this.$props,
|
|
146
|
+
inputType: 'input-number',
|
|
147
|
+
value: defaultValue + ''
|
|
148
|
+
},
|
|
149
|
+
attrs: { ...this.$attrs },
|
|
150
|
+
on: {
|
|
151
|
+
...this.$listeners,
|
|
152
|
+
'input': (e) => this.change(e),
|
|
153
|
+
'blur': (e) => this.blurHandle(e),
|
|
154
|
+
// 'change': (e) => this.change(e),
|
|
155
|
+
},
|
|
156
|
+
}
|
|
157
|
+
const { suffix } = this
|
|
158
|
+
const suffixNode = this.$slots.suffix || (suffix ? <div class="k-input-number-suffix">{suffix}</div> : null)
|
|
159
|
+
return <BaseInput {...props}>
|
|
160
|
+
<template slot="suffix">
|
|
161
|
+
{suffixNode}
|
|
162
|
+
{controls ? <div class="k-input-number-controls">
|
|
163
|
+
<span class="k-input-number-control" onClick={() => this.setVal(1)}><Icon type="chevron-up" /></span>
|
|
164
|
+
<span class="k-input-number-control" onClick={this.setVal}><Icon type="chevron-down" /></span>
|
|
165
|
+
</div> : null}
|
|
166
|
+
</template>
|
|
167
|
+
</BaseInput>
|
|
168
|
+
}
|
|
169
|
+
}
|