sadais-piui 1.2.4-beta2 → 1.2.4-beta5
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/CHANGELOG.md +512 -512
- package/LICENSE +20 -20
- package/README.md +166 -166
- package/components/pi-action-sheet/index.vue +247 -247
- package/components/pi-badge/index.vue +136 -136
- package/components/pi-bottom-bar/index.vue +139 -139
- package/components/pi-button/index.vue +492 -492
- package/components/pi-calendar/index.vue +178 -178
- package/components/pi-calendar-panel/index.vue +436 -432
- package/components/pi-canvas/index.vue +400 -400
- package/components/pi-card/index.vue +127 -127
- package/components/pi-checkbox/index.vue +345 -345
- package/components/pi-checkbox-group/index.vue +215 -215
- package/components/pi-circle-progress/index.vue +224 -224
- package/components/pi-code-input/index.vue +262 -262
- package/components/pi-count-down/index.vue +245 -245
- package/components/pi-count-up/index.vue +209 -209
- package/components/pi-date-picker/index.vue +366 -366
- package/components/pi-divider/index.vue +109 -109
- package/components/pi-dropdown/components/dropdown-tab.vue +62 -62
- package/components/pi-dropdown/index.vue +316 -316
- package/components/pi-dropdown-item/index.vue +233 -233
- package/components/pi-form/index.vue +237 -237
- package/components/pi-form-item/index.vue +534 -534
- package/components/pi-gap/index.vue +72 -72
- package/components/pi-grid/index.vue +92 -92
- package/components/pi-grid-item/index.vue +220 -220
- package/components/pi-icon/index.vue +147 -147
- package/components/pi-img/index.vue +267 -267
- package/components/pi-img-cropper/canvas.js +112 -112
- package/components/pi-img-cropper/index.vue +357 -357
- package/components/pi-img-cropper/touch.js +163 -163
- package/components/pi-img-cropper/vector.js +34 -34
- package/components/pi-input/index.vue +299 -299
- package/components/pi-line/index.vue +78 -78
- package/components/pi-line-progress/index.vue +198 -198
- package/components/pi-list/index.vue +115 -115
- package/components/pi-list-item/index.vue +331 -331
- package/components/pi-loading/index.vue +188 -188
- package/components/pi-marquee/index.vue +281 -281
- package/components/pi-marquee-item/index.vue +47 -47
- package/components/pi-mask/index.vue +198 -198
- package/components/pi-modal/index.vue +303 -303
- package/components/pi-navbar/index.vue +421 -421
- package/components/pi-notify/index.vue +239 -239
- package/components/pi-number-keyboard/index.vue +189 -189
- package/components/pi-opentype-button/index.vue +501 -501
- package/components/pi-pagination/index.vue +277 -277
- package/components/pi-picker/index.vue +317 -317
- package/components/pi-popup/index.vue +353 -353
- package/components/pi-popup-select/index.vue +291 -291
- package/components/pi-radio/index.vue +387 -387
- package/components/pi-radio-group/index.vue +262 -262
- package/components/pi-rate/index.vue +212 -212
- package/components/pi-regions-select/index.vue +318 -318
- package/components/pi-search/index.vue +351 -351
- package/components/pi-section/index.vue +218 -218
- package/components/pi-select/index.vue +391 -391
- package/components/pi-skeleton/index.vue +280 -280
- package/components/pi-status-bar/index.vue +56 -56
- package/components/pi-stepper/index.vue +394 -394
- package/components/pi-steps/index.vue +299 -299
- package/components/pi-swiper/index.vue +344 -344
- package/components/pi-switch/index.vue +227 -227
- package/components/pi-tabs/index.vue +398 -398
- package/components/pi-upload-img/index.vue +508 -506
- package/components/pi-waterfall/index.vue +130 -130
- package/components/pi-webview/index.vue +82 -82
- package/config/actionSheet.js +25 -25
- package/config/badge.js +9 -9
- package/config/bottomBar.js +11 -11
- package/config/button.js +29 -29
- package/config/calendar.js +19 -19
- package/config/calendarPanel.js +24 -24
- package/config/card.js +8 -8
- package/config/checkbox.js +14 -14
- package/config/checkboxGroup.js +14 -14
- package/config/circleProgress.js +13 -13
- package/config/codeInput.js +12 -12
- package/config/countDown.js +12 -12
- package/config/countUp.js +13 -13
- package/config/datePicker.js +22 -22
- package/config/divider.js +10 -10
- package/config/dropdown.js +21 -21
- package/config/dropdownItem.js +26 -26
- package/config/form.js +27 -27
- package/config/formItem.js +25 -25
- package/config/gap.js +8 -8
- package/config/grid.js +9 -9
- package/config/gridItem.js +12 -12
- package/config/icon.js +11 -11
- package/config/img.js +21 -21
- package/config/imgCropper.js +26 -26
- package/config/index.js +28 -28
- package/config/input.js +25 -25
- package/config/line.js +8 -8
- package/config/lineProgress.js +14 -14
- package/config/list.js +12 -12
- package/config/listItem.js +25 -25
- package/config/loading.js +10 -10
- package/config/marquee.js +8 -8
- package/config/mask.js +12 -12
- package/config/modal.js +36 -36
- package/config/navbar.js +32 -32
- package/config/notify.js +13 -13
- package/config/numberKeyboard.js +21 -21
- package/config/pagination.js +10 -10
- package/config/picker.js +19 -19
- package/config/popup.js +23 -23
- package/config/popupSelect.js +35 -35
- package/config/radio.js +15 -15
- package/config/radioGroup.js +16 -16
- package/config/rate.js +15 -15
- package/config/regionsData.js +58 -58
- package/config/regionsSelect.js +18 -18
- package/config/search.js +27 -27
- package/config/section.js +23 -23
- package/config/select.js +28 -28
- package/config/skeleton.js +13 -13
- package/config/statusBar.js +5 -5
- package/config/stepper.js +19 -19
- package/config/steps.js +19 -19
- package/config/swiper.js +22 -22
- package/config/switch.js +13 -13
- package/config/tabs.js +23 -23
- package/config/uploadImg.js +63 -63
- package/config/waterfall.js +6 -6
- package/index.js +41 -41
- package/mixin/component-custom.js +24 -24
- package/mixin/emitter.js +45 -45
- package/mixin/props-sync.js +65 -65
- package/mixin/value-sync.js +32 -32
- package/mixin/wx-code.js +30 -30
- package/package.json +25 -25
- package/plugins/async-validator.js +1511 -1511
- package/scss/animation.scss +260 -260
- package/scss/icon/icon.scss +594 -594
- package/scss/index.scss +5 -5
- package/scss/mixin.scss +47 -47
- package/tools/index.js +11 -11
|
@@ -1,394 +1,394 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<view
|
|
3
|
-
class="pi-stepper"
|
|
4
|
-
:style="[customStyle]"
|
|
5
|
-
:class="[customClass, theme, shape, { disabled }]"
|
|
6
|
-
>
|
|
7
|
-
<view
|
|
8
|
-
v-if="showAdd"
|
|
9
|
-
class="pi-stepper-icon pi-icon-subtract"
|
|
10
|
-
:class="[{ disabled: disableSubtract }]"
|
|
11
|
-
hover-class="pi-hover-class"
|
|
12
|
-
:hover-start-time="10"
|
|
13
|
-
:hover-stay-time="100"
|
|
14
|
-
:style="[iconStyle]"
|
|
15
|
-
@tap="handleChange(-1)"
|
|
16
|
-
/>
|
|
17
|
-
<input
|
|
18
|
-
:value="value"
|
|
19
|
-
type="digit"
|
|
20
|
-
class="step-input"
|
|
21
|
-
:disabled="disabled || disableInput"
|
|
22
|
-
:style="[inputStyle, { width: getInputWidth }]"
|
|
23
|
-
@input="handleInputChange"
|
|
24
|
-
/>
|
|
25
|
-
<view
|
|
26
|
-
v-if="showSubtract"
|
|
27
|
-
class="pi-stepper-icon pi-icon-add"
|
|
28
|
-
:class="[{ disabled: disableAdd }]"
|
|
29
|
-
hover-class="pi-hover-class"
|
|
30
|
-
:hover-start-time="10"
|
|
31
|
-
:hover-stay-time="100"
|
|
32
|
-
:style="[iconStyle]"
|
|
33
|
-
@tap="handleChange(1)"
|
|
34
|
-
/>
|
|
35
|
-
</view>
|
|
36
|
-
</template>
|
|
37
|
-
|
|
38
|
-
<script>
|
|
39
|
-
import ValueSync from '../../mixin/value-sync'
|
|
40
|
-
import { getConfig } from '../../config'
|
|
41
|
-
const { stepper } = getConfig()
|
|
42
|
-
|
|
43
|
-
const TAG = 'PiStepper'
|
|
44
|
-
|
|
45
|
-
export default {
|
|
46
|
-
name: 'PiStepper',
|
|
47
|
-
// 混入v-model
|
|
48
|
-
mixins: [ValueSync],
|
|
49
|
-
props: {
|
|
50
|
-
// 初始值
|
|
51
|
-
value: {
|
|
52
|
-
required: false
|
|
53
|
-
},
|
|
54
|
-
// 自定义样式,对象形式
|
|
55
|
-
customStyle: {
|
|
56
|
-
type: Object,
|
|
57
|
-
// {}
|
|
58
|
-
default() {
|
|
59
|
-
return stepper.customStyle
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
|
-
// 自定义输入样式,对象形式(默认值:{})
|
|
63
|
-
inputStyle: {
|
|
64
|
-
type: Object,
|
|
65
|
-
// {}
|
|
66
|
-
default() {
|
|
67
|
-
return stepper.inputStyle
|
|
68
|
-
}
|
|
69
|
-
},
|
|
70
|
-
// 自定义样式类,字符串形式
|
|
71
|
-
customClass: {
|
|
72
|
-
type: String,
|
|
73
|
-
// ''
|
|
74
|
-
default() {
|
|
75
|
-
return stepper.customClass
|
|
76
|
-
}
|
|
77
|
-
},
|
|
78
|
-
// 最小值
|
|
79
|
-
min: {
|
|
80
|
-
type: Number,
|
|
81
|
-
// 1
|
|
82
|
-
default() {
|
|
83
|
-
return stepper.min
|
|
84
|
-
}
|
|
85
|
-
},
|
|
86
|
-
// 最大值
|
|
87
|
-
max: {
|
|
88
|
-
type: Number,
|
|
89
|
-
// -
|
|
90
|
-
default() {
|
|
91
|
-
return stepper.max
|
|
92
|
-
}
|
|
93
|
-
},
|
|
94
|
-
// 步长,每次点击时改变的值
|
|
95
|
-
step: {
|
|
96
|
-
type: Number,
|
|
97
|
-
// 1
|
|
98
|
-
default() {
|
|
99
|
-
return stepper.step
|
|
100
|
-
}
|
|
101
|
-
},
|
|
102
|
-
// 输入框宽度,默认单位为rpx
|
|
103
|
-
inputWidth: {
|
|
104
|
-
type: [String, Number],
|
|
105
|
-
// 64
|
|
106
|
-
default() {
|
|
107
|
-
return stepper.inputWidth
|
|
108
|
-
}
|
|
109
|
-
},
|
|
110
|
-
// 按钮大小
|
|
111
|
-
buttonSize: {
|
|
112
|
-
type: [String, Number],
|
|
113
|
-
// 32
|
|
114
|
-
default() {
|
|
115
|
-
return stepper.buttonSize
|
|
116
|
-
}
|
|
117
|
-
},
|
|
118
|
-
// 按钮颜色
|
|
119
|
-
buttonColor: {
|
|
120
|
-
type: [String, Number],
|
|
121
|
-
// -
|
|
122
|
-
default() {
|
|
123
|
-
return stepper.buttonColor
|
|
124
|
-
}
|
|
125
|
-
},
|
|
126
|
-
// 小数位
|
|
127
|
-
decimal: {
|
|
128
|
-
type: Number,
|
|
129
|
-
// 0
|
|
130
|
-
default() {
|
|
131
|
-
return stepper.decimal
|
|
132
|
-
}
|
|
133
|
-
},
|
|
134
|
-
// 形状
|
|
135
|
-
shape: {
|
|
136
|
-
// round, square
|
|
137
|
-
type: String,
|
|
138
|
-
// round
|
|
139
|
-
default: stepper.shape,
|
|
140
|
-
validator: function(value) {
|
|
141
|
-
return ['square', 'round'].includes(value)
|
|
142
|
-
}
|
|
143
|
-
},
|
|
144
|
-
// 主题模式
|
|
145
|
-
theme: {
|
|
146
|
-
// line: 线框模式,fill: 实底模式
|
|
147
|
-
type: String,
|
|
148
|
-
// 'line'
|
|
149
|
-
default: stepper.theme,
|
|
150
|
-
validator: function(value) {
|
|
151
|
-
return ['line', 'fill'].includes(value)
|
|
152
|
-
}
|
|
153
|
-
},
|
|
154
|
-
// 是否只允许输入整数
|
|
155
|
-
integer: {
|
|
156
|
-
type: Boolean,
|
|
157
|
-
// false
|
|
158
|
-
default() {
|
|
159
|
-
return stepper.integer
|
|
160
|
-
}
|
|
161
|
-
},
|
|
162
|
-
// 是否显示增加按钮
|
|
163
|
-
showAdd: {
|
|
164
|
-
type: Boolean,
|
|
165
|
-
// true
|
|
166
|
-
default() {
|
|
167
|
-
return stepper.showAdd
|
|
168
|
-
}
|
|
169
|
-
},
|
|
170
|
-
// 是否显示减少按钮
|
|
171
|
-
showSubtract: {
|
|
172
|
-
type: Boolean,
|
|
173
|
-
// false
|
|
174
|
-
default() {
|
|
175
|
-
return stepper.showSubtract
|
|
176
|
-
}
|
|
177
|
-
},
|
|
178
|
-
// 是否禁用步进器
|
|
179
|
-
disabled: {
|
|
180
|
-
type: Boolean,
|
|
181
|
-
// false
|
|
182
|
-
default() {
|
|
183
|
-
return stepper.disabled
|
|
184
|
-
}
|
|
185
|
-
},
|
|
186
|
-
// 是否禁用输入框
|
|
187
|
-
disableInput: {
|
|
188
|
-
type: Boolean,
|
|
189
|
-
// true
|
|
190
|
-
default() {
|
|
191
|
-
return stepper.disableInput
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
},
|
|
195
|
-
data() {
|
|
196
|
-
return {}
|
|
197
|
-
},
|
|
198
|
-
computed: {
|
|
199
|
-
disableAdd() {
|
|
200
|
-
return this.max !== null && this.val >= this.max
|
|
201
|
-
},
|
|
202
|
-
disableSubtract() {
|
|
203
|
-
return this.min !== null && this.val <= this.min
|
|
204
|
-
},
|
|
205
|
-
getInputWidth() {
|
|
206
|
-
return this.$pi.common.addUnit(this.inputWidth)
|
|
207
|
-
},
|
|
208
|
-
getButtonSize() {
|
|
209
|
-
return this.$pi.common.addUnit(this.buttonSize)
|
|
210
|
-
},
|
|
211
|
-
iconStyle() {
|
|
212
|
-
const style = {
|
|
213
|
-
width: this.getButtonSize,
|
|
214
|
-
height: this.getButtonSize,
|
|
215
|
-
lineHeight: this.getButtonSize,
|
|
216
|
-
fontSize: this.getButtonSize
|
|
217
|
-
}
|
|
218
|
-
if (this.buttonColor) {
|
|
219
|
-
if (this.theme === 'line') {
|
|
220
|
-
style.color = this.buttonColor
|
|
221
|
-
style.borderColor = this.buttonColor
|
|
222
|
-
} else {
|
|
223
|
-
style.backgroundColor = this.buttonColor
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
return style
|
|
227
|
-
}
|
|
228
|
-
},
|
|
229
|
-
methods: {
|
|
230
|
-
// 点击减少按钮时触发
|
|
231
|
-
minus() {
|
|
232
|
-
this.computeVal('minus')
|
|
233
|
-
},
|
|
234
|
-
// 点击增加按钮时触发
|
|
235
|
-
plus() {
|
|
236
|
-
this.computeVal('plus')
|
|
237
|
-
},
|
|
238
|
-
// 为了保证小数相加出现精度溢出的问题
|
|
239
|
-
numAdd(num1, num2) {
|
|
240
|
-
let baseNum, baseNum1, baseNum2
|
|
241
|
-
try {
|
|
242
|
-
baseNum1 = num1.toString().split('.')[1].length
|
|
243
|
-
} catch (e) {
|
|
244
|
-
baseNum1 = 0
|
|
245
|
-
}
|
|
246
|
-
try {
|
|
247
|
-
baseNum2 = num2.toString().split('.')[1].length
|
|
248
|
-
} catch (e) {
|
|
249
|
-
baseNum2 = 0
|
|
250
|
-
}
|
|
251
|
-
baseNum = Math.pow(10, Math.max(baseNum1, baseNum2))
|
|
252
|
-
let precision = baseNum1 >= baseNum2 ? baseNum1 : baseNum2 // 精度
|
|
253
|
-
return ((num1 * baseNum + num2 * baseNum) / baseNum).toFixed(precision)
|
|
254
|
-
},
|
|
255
|
-
// 为了保证小数相减出现精度溢出的问题
|
|
256
|
-
numSub(num1, num2) {
|
|
257
|
-
let baseNum, baseNum1, baseNum2
|
|
258
|
-
try {
|
|
259
|
-
baseNum1 = num1.toString().split('.')[1].length
|
|
260
|
-
} catch (e) {
|
|
261
|
-
baseNum1 = 0
|
|
262
|
-
}
|
|
263
|
-
try {
|
|
264
|
-
baseNum2 = num2.toString().split('.')[1].length
|
|
265
|
-
} catch (e) {
|
|
266
|
-
baseNum2 = 0
|
|
267
|
-
}
|
|
268
|
-
baseNum = Math.pow(10, Math.max(baseNum1, baseNum2))
|
|
269
|
-
let precision = baseNum1 >= baseNum2 ? baseNum1 : baseNum2
|
|
270
|
-
return ((num1 * baseNum - num2 * baseNum) / baseNum).toFixed(precision)
|
|
271
|
-
},
|
|
272
|
-
computeVal(type) {
|
|
273
|
-
if (this.disabled) return
|
|
274
|
-
let value = 0
|
|
275
|
-
// 减
|
|
276
|
-
if (type === 'minus') {
|
|
277
|
-
// this.value 当前值 this.step 增加步长后的值
|
|
278
|
-
value = this.numSub(this.value, this.step)
|
|
279
|
-
} else if (type === 'plus') {
|
|
280
|
-
value = this.numAdd(this.value, this.step)
|
|
281
|
-
}
|
|
282
|
-
// 判断是否小于最小值和大于最大值
|
|
283
|
-
if (value < this.min || value > this.max) {
|
|
284
|
-
return
|
|
285
|
-
}
|
|
286
|
-
// this.inputVal = value
|
|
287
|
-
},
|
|
288
|
-
handleChange(range) {
|
|
289
|
-
if (this.disabled) return
|
|
290
|
-
// 增加/减少步长后的值
|
|
291
|
-
// let val = this.val + range * this.step
|
|
292
|
-
let val = range === 1 ? this.numAdd(this.val, this.step) : this.numSub(this.val, this.step)
|
|
293
|
-
if (this.max !== null && val > this.max) {
|
|
294
|
-
val = this.max
|
|
295
|
-
}
|
|
296
|
-
if (this.min !== null && val < this.min) {
|
|
297
|
-
val = this.min
|
|
298
|
-
}
|
|
299
|
-
this.handleInputChange({ detail: { value: `${val}` } })
|
|
300
|
-
},
|
|
301
|
-
handleInputChange(e) {
|
|
302
|
-
const val = e.detail.value
|
|
303
|
-
const reg = /^(\d+)(\.)?(?:(.+)$)?/
|
|
304
|
-
const result = val.match(reg)
|
|
305
|
-
const decimal = this.decimal
|
|
306
|
-
if (!result) {
|
|
307
|
-
// 说明开头就不是数字 直接初始化为0
|
|
308
|
-
this.val = this.min != null ? this.min : 0
|
|
309
|
-
this.handleEmitChange()
|
|
310
|
-
} else {
|
|
311
|
-
// 分离出 小数点、及其左右2边的数字
|
|
312
|
-
const left = result[1]
|
|
313
|
-
const dot = result[2]
|
|
314
|
-
const right = result[3]
|
|
315
|
-
let tmpVal = ''
|
|
316
|
-
if (!dot || !right) {
|
|
317
|
-
tmpVal = dot ? `${left}${dot}` : left
|
|
318
|
-
} else if (/^\d+/.test(right)) {
|
|
319
|
-
// 限制小数点位数
|
|
320
|
-
const digit = right.match(/^\d+/)[0]
|
|
321
|
-
const len = Math.min(digit.length, decimal)
|
|
322
|
-
tmpVal = `${left}${dot}${digit.substr(0, len)}`
|
|
323
|
-
} else {
|
|
324
|
-
// 若小数点右边不是以数字开头
|
|
325
|
-
tmpVal = `${left}${dot}`
|
|
326
|
-
}
|
|
327
|
-
// target.value = tmpVal
|
|
328
|
-
console.log(`tmpVal = ${tmpVal}`)
|
|
329
|
-
this.val = 0
|
|
330
|
-
this.handleEmitChange()
|
|
331
|
-
this.$nextTick(() => {
|
|
332
|
-
let tmp = parseFloat(tmpVal)
|
|
333
|
-
if (this.integer) {
|
|
334
|
-
tmp = parseInt(tmpVal)
|
|
335
|
-
}
|
|
336
|
-
tmp = tmp <= this.max ? tmp : this.max
|
|
337
|
-
tmp = tmp >= this.min ? tmp : this.min
|
|
338
|
-
this.val = tmp
|
|
339
|
-
this.handleEmitChange()
|
|
340
|
-
})
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
</script>
|
|
346
|
-
|
|
347
|
-
<style lang="scss" scoped>
|
|
348
|
-
.pi-stepper {
|
|
349
|
-
display: inline-flex;
|
|
350
|
-
align-items: center;
|
|
351
|
-
|
|
352
|
-
.step-input {
|
|
353
|
-
text-align: center;
|
|
354
|
-
}
|
|
355
|
-
.pi-stepper-icon {
|
|
356
|
-
color: $pi-primary-color;
|
|
357
|
-
border: 2rpx solid $pi-primary-color;
|
|
358
|
-
&::before {
|
|
359
|
-
transform: scale(0.8);
|
|
360
|
-
}
|
|
361
|
-
&::after {
|
|
362
|
-
content: '';
|
|
363
|
-
}
|
|
364
|
-
&.disabled {
|
|
365
|
-
opacity: $pi-disabled-opacity;
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
&.disabled {
|
|
369
|
-
opacity: $pi-disabled-opacity;
|
|
370
|
-
}
|
|
371
|
-
&.round {
|
|
372
|
-
.pi-stepper-icon {
|
|
373
|
-
border-radius: 5000rpx;
|
|
374
|
-
&::after {
|
|
375
|
-
border-radius: 5000rpx;
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
&.square {
|
|
380
|
-
.pi-stepper-icon {
|
|
381
|
-
border-radius: 8rpx;
|
|
382
|
-
&::after {
|
|
383
|
-
border-radius: 8rpx;
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
&.fill {
|
|
388
|
-
.pi-stepper-icon {
|
|
389
|
-
color: #ffffff;
|
|
390
|
-
background: $pi-primary-color;
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
</style>
|
|
1
|
+
<template>
|
|
2
|
+
<view
|
|
3
|
+
class="pi-stepper"
|
|
4
|
+
:style="[customStyle]"
|
|
5
|
+
:class="[customClass, theme, shape, { disabled }]"
|
|
6
|
+
>
|
|
7
|
+
<view
|
|
8
|
+
v-if="showAdd"
|
|
9
|
+
class="pi-stepper-icon pi-icon-subtract"
|
|
10
|
+
:class="[{ disabled: disableSubtract }]"
|
|
11
|
+
hover-class="pi-hover-class"
|
|
12
|
+
:hover-start-time="10"
|
|
13
|
+
:hover-stay-time="100"
|
|
14
|
+
:style="[iconStyle]"
|
|
15
|
+
@tap="handleChange(-1)"
|
|
16
|
+
/>
|
|
17
|
+
<input
|
|
18
|
+
:value="value"
|
|
19
|
+
type="digit"
|
|
20
|
+
class="step-input"
|
|
21
|
+
:disabled="disabled || disableInput"
|
|
22
|
+
:style="[inputStyle, { width: getInputWidth }]"
|
|
23
|
+
@input="handleInputChange"
|
|
24
|
+
/>
|
|
25
|
+
<view
|
|
26
|
+
v-if="showSubtract"
|
|
27
|
+
class="pi-stepper-icon pi-icon-add"
|
|
28
|
+
:class="[{ disabled: disableAdd }]"
|
|
29
|
+
hover-class="pi-hover-class"
|
|
30
|
+
:hover-start-time="10"
|
|
31
|
+
:hover-stay-time="100"
|
|
32
|
+
:style="[iconStyle]"
|
|
33
|
+
@tap="handleChange(1)"
|
|
34
|
+
/>
|
|
35
|
+
</view>
|
|
36
|
+
</template>
|
|
37
|
+
|
|
38
|
+
<script>
|
|
39
|
+
import ValueSync from '../../mixin/value-sync'
|
|
40
|
+
import { getConfig } from '../../config'
|
|
41
|
+
const { stepper } = getConfig()
|
|
42
|
+
|
|
43
|
+
const TAG = 'PiStepper'
|
|
44
|
+
|
|
45
|
+
export default {
|
|
46
|
+
name: 'PiStepper',
|
|
47
|
+
// 混入v-model
|
|
48
|
+
mixins: [ValueSync],
|
|
49
|
+
props: {
|
|
50
|
+
// 初始值
|
|
51
|
+
value: {
|
|
52
|
+
required: false
|
|
53
|
+
},
|
|
54
|
+
// 自定义样式,对象形式
|
|
55
|
+
customStyle: {
|
|
56
|
+
type: Object,
|
|
57
|
+
// {}
|
|
58
|
+
default() {
|
|
59
|
+
return stepper.customStyle
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
// 自定义输入样式,对象形式(默认值:{})
|
|
63
|
+
inputStyle: {
|
|
64
|
+
type: Object,
|
|
65
|
+
// {}
|
|
66
|
+
default() {
|
|
67
|
+
return stepper.inputStyle
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
// 自定义样式类,字符串形式
|
|
71
|
+
customClass: {
|
|
72
|
+
type: String,
|
|
73
|
+
// ''
|
|
74
|
+
default() {
|
|
75
|
+
return stepper.customClass
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
// 最小值
|
|
79
|
+
min: {
|
|
80
|
+
type: Number,
|
|
81
|
+
// 1
|
|
82
|
+
default() {
|
|
83
|
+
return stepper.min
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
// 最大值
|
|
87
|
+
max: {
|
|
88
|
+
type: Number,
|
|
89
|
+
// -
|
|
90
|
+
default() {
|
|
91
|
+
return stepper.max
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
// 步长,每次点击时改变的值
|
|
95
|
+
step: {
|
|
96
|
+
type: Number,
|
|
97
|
+
// 1
|
|
98
|
+
default() {
|
|
99
|
+
return stepper.step
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
// 输入框宽度,默认单位为rpx
|
|
103
|
+
inputWidth: {
|
|
104
|
+
type: [String, Number],
|
|
105
|
+
// 64
|
|
106
|
+
default() {
|
|
107
|
+
return stepper.inputWidth
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
// 按钮大小
|
|
111
|
+
buttonSize: {
|
|
112
|
+
type: [String, Number],
|
|
113
|
+
// 32
|
|
114
|
+
default() {
|
|
115
|
+
return stepper.buttonSize
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
// 按钮颜色
|
|
119
|
+
buttonColor: {
|
|
120
|
+
type: [String, Number],
|
|
121
|
+
// -
|
|
122
|
+
default() {
|
|
123
|
+
return stepper.buttonColor
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
// 小数位
|
|
127
|
+
decimal: {
|
|
128
|
+
type: Number,
|
|
129
|
+
// 0
|
|
130
|
+
default() {
|
|
131
|
+
return stepper.decimal
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
// 形状
|
|
135
|
+
shape: {
|
|
136
|
+
// round, square
|
|
137
|
+
type: String,
|
|
138
|
+
// round
|
|
139
|
+
default: stepper.shape,
|
|
140
|
+
validator: function(value) {
|
|
141
|
+
return ['square', 'round'].includes(value)
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
// 主题模式
|
|
145
|
+
theme: {
|
|
146
|
+
// line: 线框模式,fill: 实底模式
|
|
147
|
+
type: String,
|
|
148
|
+
// 'line'
|
|
149
|
+
default: stepper.theme,
|
|
150
|
+
validator: function(value) {
|
|
151
|
+
return ['line', 'fill'].includes(value)
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
// 是否只允许输入整数
|
|
155
|
+
integer: {
|
|
156
|
+
type: Boolean,
|
|
157
|
+
// false
|
|
158
|
+
default() {
|
|
159
|
+
return stepper.integer
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
// 是否显示增加按钮
|
|
163
|
+
showAdd: {
|
|
164
|
+
type: Boolean,
|
|
165
|
+
// true
|
|
166
|
+
default() {
|
|
167
|
+
return stepper.showAdd
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
// 是否显示减少按钮
|
|
171
|
+
showSubtract: {
|
|
172
|
+
type: Boolean,
|
|
173
|
+
// false
|
|
174
|
+
default() {
|
|
175
|
+
return stepper.showSubtract
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
// 是否禁用步进器
|
|
179
|
+
disabled: {
|
|
180
|
+
type: Boolean,
|
|
181
|
+
// false
|
|
182
|
+
default() {
|
|
183
|
+
return stepper.disabled
|
|
184
|
+
}
|
|
185
|
+
},
|
|
186
|
+
// 是否禁用输入框
|
|
187
|
+
disableInput: {
|
|
188
|
+
type: Boolean,
|
|
189
|
+
// true
|
|
190
|
+
default() {
|
|
191
|
+
return stepper.disableInput
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
data() {
|
|
196
|
+
return {}
|
|
197
|
+
},
|
|
198
|
+
computed: {
|
|
199
|
+
disableAdd() {
|
|
200
|
+
return this.max !== null && this.val >= this.max
|
|
201
|
+
},
|
|
202
|
+
disableSubtract() {
|
|
203
|
+
return this.min !== null && this.val <= this.min
|
|
204
|
+
},
|
|
205
|
+
getInputWidth() {
|
|
206
|
+
return this.$pi.common.addUnit(this.inputWidth)
|
|
207
|
+
},
|
|
208
|
+
getButtonSize() {
|
|
209
|
+
return this.$pi.common.addUnit(this.buttonSize)
|
|
210
|
+
},
|
|
211
|
+
iconStyle() {
|
|
212
|
+
const style = {
|
|
213
|
+
width: this.getButtonSize,
|
|
214
|
+
height: this.getButtonSize,
|
|
215
|
+
lineHeight: this.getButtonSize,
|
|
216
|
+
fontSize: this.getButtonSize
|
|
217
|
+
}
|
|
218
|
+
if (this.buttonColor) {
|
|
219
|
+
if (this.theme === 'line') {
|
|
220
|
+
style.color = this.buttonColor
|
|
221
|
+
style.borderColor = this.buttonColor
|
|
222
|
+
} else {
|
|
223
|
+
style.backgroundColor = this.buttonColor
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return style
|
|
227
|
+
}
|
|
228
|
+
},
|
|
229
|
+
methods: {
|
|
230
|
+
// 点击减少按钮时触发
|
|
231
|
+
minus() {
|
|
232
|
+
this.computeVal('minus')
|
|
233
|
+
},
|
|
234
|
+
// 点击增加按钮时触发
|
|
235
|
+
plus() {
|
|
236
|
+
this.computeVal('plus')
|
|
237
|
+
},
|
|
238
|
+
// 为了保证小数相加出现精度溢出的问题
|
|
239
|
+
numAdd(num1, num2) {
|
|
240
|
+
let baseNum, baseNum1, baseNum2
|
|
241
|
+
try {
|
|
242
|
+
baseNum1 = num1.toString().split('.')[1].length
|
|
243
|
+
} catch (e) {
|
|
244
|
+
baseNum1 = 0
|
|
245
|
+
}
|
|
246
|
+
try {
|
|
247
|
+
baseNum2 = num2.toString().split('.')[1].length
|
|
248
|
+
} catch (e) {
|
|
249
|
+
baseNum2 = 0
|
|
250
|
+
}
|
|
251
|
+
baseNum = Math.pow(10, Math.max(baseNum1, baseNum2))
|
|
252
|
+
let precision = baseNum1 >= baseNum2 ? baseNum1 : baseNum2 // 精度
|
|
253
|
+
return ((num1 * baseNum + num2 * baseNum) / baseNum).toFixed(precision)
|
|
254
|
+
},
|
|
255
|
+
// 为了保证小数相减出现精度溢出的问题
|
|
256
|
+
numSub(num1, num2) {
|
|
257
|
+
let baseNum, baseNum1, baseNum2
|
|
258
|
+
try {
|
|
259
|
+
baseNum1 = num1.toString().split('.')[1].length
|
|
260
|
+
} catch (e) {
|
|
261
|
+
baseNum1 = 0
|
|
262
|
+
}
|
|
263
|
+
try {
|
|
264
|
+
baseNum2 = num2.toString().split('.')[1].length
|
|
265
|
+
} catch (e) {
|
|
266
|
+
baseNum2 = 0
|
|
267
|
+
}
|
|
268
|
+
baseNum = Math.pow(10, Math.max(baseNum1, baseNum2))
|
|
269
|
+
let precision = baseNum1 >= baseNum2 ? baseNum1 : baseNum2
|
|
270
|
+
return ((num1 * baseNum - num2 * baseNum) / baseNum).toFixed(precision)
|
|
271
|
+
},
|
|
272
|
+
computeVal(type) {
|
|
273
|
+
if (this.disabled) return
|
|
274
|
+
let value = 0
|
|
275
|
+
// 减
|
|
276
|
+
if (type === 'minus') {
|
|
277
|
+
// this.value 当前值 this.step 增加步长后的值
|
|
278
|
+
value = this.numSub(this.value, this.step)
|
|
279
|
+
} else if (type === 'plus') {
|
|
280
|
+
value = this.numAdd(this.value, this.step)
|
|
281
|
+
}
|
|
282
|
+
// 判断是否小于最小值和大于最大值
|
|
283
|
+
if (value < this.min || value > this.max) {
|
|
284
|
+
return
|
|
285
|
+
}
|
|
286
|
+
// this.inputVal = value
|
|
287
|
+
},
|
|
288
|
+
handleChange(range) {
|
|
289
|
+
if (this.disabled) return
|
|
290
|
+
// 增加/减少步长后的值
|
|
291
|
+
// let val = this.val + range * this.step
|
|
292
|
+
let val = range === 1 ? this.numAdd(this.val, this.step) : this.numSub(this.val, this.step)
|
|
293
|
+
if (this.max !== null && val > this.max) {
|
|
294
|
+
val = this.max
|
|
295
|
+
}
|
|
296
|
+
if (this.min !== null && val < this.min) {
|
|
297
|
+
val = this.min
|
|
298
|
+
}
|
|
299
|
+
this.handleInputChange({ detail: { value: `${val}` } })
|
|
300
|
+
},
|
|
301
|
+
handleInputChange(e) {
|
|
302
|
+
const val = e.detail.value
|
|
303
|
+
const reg = /^(\d+)(\.)?(?:(.+)$)?/
|
|
304
|
+
const result = val.match(reg)
|
|
305
|
+
const decimal = this.decimal
|
|
306
|
+
if (!result) {
|
|
307
|
+
// 说明开头就不是数字 直接初始化为0
|
|
308
|
+
this.val = this.min != null ? this.min : 0
|
|
309
|
+
this.handleEmitChange()
|
|
310
|
+
} else {
|
|
311
|
+
// 分离出 小数点、及其左右2边的数字
|
|
312
|
+
const left = result[1]
|
|
313
|
+
const dot = result[2]
|
|
314
|
+
const right = result[3]
|
|
315
|
+
let tmpVal = ''
|
|
316
|
+
if (!dot || !right) {
|
|
317
|
+
tmpVal = dot ? `${left}${dot}` : left
|
|
318
|
+
} else if (/^\d+/.test(right)) {
|
|
319
|
+
// 限制小数点位数
|
|
320
|
+
const digit = right.match(/^\d+/)[0]
|
|
321
|
+
const len = Math.min(digit.length, decimal)
|
|
322
|
+
tmpVal = `${left}${dot}${digit.substr(0, len)}`
|
|
323
|
+
} else {
|
|
324
|
+
// 若小数点右边不是以数字开头
|
|
325
|
+
tmpVal = `${left}${dot}`
|
|
326
|
+
}
|
|
327
|
+
// target.value = tmpVal
|
|
328
|
+
console.log(`tmpVal = ${tmpVal}`)
|
|
329
|
+
this.val = 0
|
|
330
|
+
this.handleEmitChange()
|
|
331
|
+
this.$nextTick(() => {
|
|
332
|
+
let tmp = parseFloat(tmpVal)
|
|
333
|
+
if (this.integer) {
|
|
334
|
+
tmp = parseInt(tmpVal)
|
|
335
|
+
}
|
|
336
|
+
tmp = tmp <= this.max ? tmp : this.max
|
|
337
|
+
tmp = tmp >= this.min ? tmp : this.min
|
|
338
|
+
this.val = tmp
|
|
339
|
+
this.handleEmitChange()
|
|
340
|
+
})
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
</script>
|
|
346
|
+
|
|
347
|
+
<style lang="scss" scoped>
|
|
348
|
+
.pi-stepper {
|
|
349
|
+
display: inline-flex;
|
|
350
|
+
align-items: center;
|
|
351
|
+
|
|
352
|
+
.step-input {
|
|
353
|
+
text-align: center;
|
|
354
|
+
}
|
|
355
|
+
.pi-stepper-icon {
|
|
356
|
+
color: $pi-primary-color;
|
|
357
|
+
border: 2rpx solid $pi-primary-color;
|
|
358
|
+
&::before {
|
|
359
|
+
transform: scale(0.8);
|
|
360
|
+
}
|
|
361
|
+
&::after {
|
|
362
|
+
content: '';
|
|
363
|
+
}
|
|
364
|
+
&.disabled {
|
|
365
|
+
opacity: $pi-disabled-opacity;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
&.disabled {
|
|
369
|
+
opacity: $pi-disabled-opacity;
|
|
370
|
+
}
|
|
371
|
+
&.round {
|
|
372
|
+
.pi-stepper-icon {
|
|
373
|
+
border-radius: 5000rpx;
|
|
374
|
+
&::after {
|
|
375
|
+
border-radius: 5000rpx;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
&.square {
|
|
380
|
+
.pi-stepper-icon {
|
|
381
|
+
border-radius: 8rpx;
|
|
382
|
+
&::after {
|
|
383
|
+
border-radius: 8rpx;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
&.fill {
|
|
388
|
+
.pi-stepper-icon {
|
|
389
|
+
color: #ffffff;
|
|
390
|
+
background: $pi-primary-color;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
</style>
|