@netang/quasar 0.0.20
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/LICENSE +21 -0
- package/README.md +17 -0
- package/components/column-title/index.vue +32 -0
- package/components/dialog/components/index.js +6 -0
- package/components/dialog/components/move-to-tree/index.vue +150 -0
- package/components/dialog/index.vue +330 -0
- package/components/dialog-table/index.vue +92 -0
- package/components/dragger/index.vue +202 -0
- package/components/drawer/index.vue +262 -0
- package/components/field-date/index.vue +844 -0
- package/components/field-date/methods.js +100 -0
- package/components/field-table/index.vue +468 -0
- package/components/field-text/index.vue +167 -0
- package/components/field-tree/index.vue +435 -0
- package/components/input-number/index.vue +324 -0
- package/components/input-number/number.js +67 -0
- package/components/input-price-cent/index.vue +213 -0
- package/components/input-price-yuan/index.vue +179 -0
- package/components/layout/index.vue +119 -0
- package/components/list-menu/index.vue +137 -0
- package/components/list-menu-item/index.vue +79 -0
- package/components/power-data/index.vue +667 -0
- package/components/search/index.vue +176 -0
- package/components/search-item/index.vue +219 -0
- package/components/select/index.vue +71 -0
- package/components/select-filter/index.vue +75 -0
- package/components/table/index.vue +347 -0
- package/components/table-column-fixed/index.vue +68 -0
- package/components/table-pagination/index.vue +83 -0
- package/components/table-summary/index.vue +91 -0
- package/components/thumbnail/index.vue +87 -0
- package/components/toolbar/container.vue +31 -0
- package/components/toolbar/index.vue +405 -0
- package/components/uploader/index.vue +157 -0
- package/components/uploader-query/index.vue +731 -0
- package/package.json +21 -0
- package/sass/common.scss +165 -0
- package/sass/index.scss +14 -0
- package/sass/line.scss +39 -0
- package/sass/quasar/btn.scss +46 -0
- package/sass/quasar/common.scss +3 -0
- package/sass/quasar/dialog.scss +7 -0
- package/sass/quasar/drawer.scss +6 -0
- package/sass/quasar/field.scss +210 -0
- package/sass/quasar/loading.scss +6 -0
- package/sass/quasar/menu.scss +8 -0
- package/sass/quasar/table.scss +112 -0
- package/sass/quasar/toolbar.scss +22 -0
- package/store/index.js +32 -0
- package/utils/$area.js +387 -0
- package/utils/$auth.js +135 -0
- package/utils/$dialog.js +43 -0
- package/utils/$role.js +807 -0
- package/utils/$rule.js +17 -0
- package/utils/$search.js +336 -0
- package/utils/$table.js +802 -0
- package/utils/$tree.js +620 -0
- package/utils/$uploader.js +1029 -0
- package/utils/alert.js +10 -0
- package/utils/bus.js +6 -0
- package/utils/config.js +22 -0
- package/utils/confrim.js +11 -0
- package/utils/dict.js +44 -0
- package/utils/getData.js +61 -0
- package/utils/getFile.js +30 -0
- package/utils/getImage.js +136 -0
- package/utils/getTime.js +94 -0
- package/utils/http.js +251 -0
- package/utils/loading.js +13 -0
- package/utils/notify.js +13 -0
- package/utils/previewImage.js +8 -0
- package/utils/symbols.js +3 -0
- package/utils/timestamp.js +18 -0
- package/utils/toast.js +13 -0
- package/utils/uploader/aliyun.js +6 -0
- package/utils/uploader/local.js +8 -0
- package/utils/uploader/qiniu.js +311 -0
- package/utils/useAuth.js +26 -0
- package/utils/useRouter.js +36 -0
- package/utils/useUploader.js +58 -0
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<q-input
|
|
3
|
+
class="n-input-number"
|
|
4
|
+
v-model="currentValue"
|
|
5
|
+
@update:model-value="onInput"
|
|
6
|
+
@blur="onBlur"
|
|
7
|
+
v-on="$listeners"
|
|
8
|
+
v-bind="$attrs"
|
|
9
|
+
>
|
|
10
|
+
<template #prepend>
|
|
11
|
+
<q-btn
|
|
12
|
+
color="default"
|
|
13
|
+
icon="remove"
|
|
14
|
+
flat
|
|
15
|
+
dense
|
|
16
|
+
:disable="minusDisabled"
|
|
17
|
+
@click="onChange('minus')"
|
|
18
|
+
@overlimit="onOverlimit('minus')"
|
|
19
|
+
/>
|
|
20
|
+
</template>
|
|
21
|
+
<template #append>
|
|
22
|
+
<q-btn
|
|
23
|
+
color="default"
|
|
24
|
+
icon="add"
|
|
25
|
+
flat
|
|
26
|
+
dense
|
|
27
|
+
:disable="plusDisabled"
|
|
28
|
+
@click="onChange('plus')"
|
|
29
|
+
@overlimit="onOverlimit('plus')"
|
|
30
|
+
/>
|
|
31
|
+
</template>
|
|
32
|
+
</q-input>
|
|
33
|
+
</template>
|
|
34
|
+
|
|
35
|
+
<script>
|
|
36
|
+
import { computed, ref, watch } from 'vue'
|
|
37
|
+
import { formatNumbers, addNumber } from './number'
|
|
38
|
+
|
|
39
|
+
export default {
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* 标识
|
|
43
|
+
*/
|
|
44
|
+
name: 'NInputNumber',
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* 声明属性
|
|
48
|
+
*/
|
|
49
|
+
props: {
|
|
50
|
+
// 值
|
|
51
|
+
modelValue: {
|
|
52
|
+
required: false
|
|
53
|
+
},
|
|
54
|
+
// 最小值
|
|
55
|
+
min: {
|
|
56
|
+
type: [Number, String],
|
|
57
|
+
default: 1,
|
|
58
|
+
},
|
|
59
|
+
// 最大值
|
|
60
|
+
max: {
|
|
61
|
+
type: [Number, String],
|
|
62
|
+
default: Infinity,
|
|
63
|
+
},
|
|
64
|
+
// 初始值,当 v-model 为空时生效
|
|
65
|
+
defaultValue: {
|
|
66
|
+
type: [Number, String],
|
|
67
|
+
default: 1,
|
|
68
|
+
},
|
|
69
|
+
// 步长,每次点击时改变的值
|
|
70
|
+
step: {
|
|
71
|
+
type: [Number, String],
|
|
72
|
+
default: 1,
|
|
73
|
+
},
|
|
74
|
+
// 固定显示的小数位数
|
|
75
|
+
decimalLength: [Number, String],
|
|
76
|
+
// 是否只允许输入整数
|
|
77
|
+
integer: {
|
|
78
|
+
type: Boolean,
|
|
79
|
+
default: true,
|
|
80
|
+
},
|
|
81
|
+
// 是否禁用步进器
|
|
82
|
+
disabled: Boolean,
|
|
83
|
+
// 是否禁用增加按钮
|
|
84
|
+
disablePlus: Boolean,
|
|
85
|
+
// 是否禁用减少按钮
|
|
86
|
+
disableMinus: Boolean,
|
|
87
|
+
// 是否禁用输入框
|
|
88
|
+
disableInput: Boolean,
|
|
89
|
+
// 是否开启异步变更,开启后需要手动控制输入值
|
|
90
|
+
asyncChange: Boolean,
|
|
91
|
+
// 是否显示增加按钮
|
|
92
|
+
showPlus: {
|
|
93
|
+
type: Boolean,
|
|
94
|
+
default: true,
|
|
95
|
+
},
|
|
96
|
+
// 是否显示减少按钮
|
|
97
|
+
showMinus: {
|
|
98
|
+
type: Boolean,
|
|
99
|
+
default: true,
|
|
100
|
+
},
|
|
101
|
+
// 是否允许输入的值为空
|
|
102
|
+
allowEmpty: Boolean,
|
|
103
|
+
// 显示文字
|
|
104
|
+
showText: {
|
|
105
|
+
type: Boolean,
|
|
106
|
+
default: true,
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* 声明事件
|
|
112
|
+
*/
|
|
113
|
+
emits: [
|
|
114
|
+
'update:modelValue',
|
|
115
|
+
'change',
|
|
116
|
+
'blur',
|
|
117
|
+
'overlimit',
|
|
118
|
+
'minus',
|
|
119
|
+
'plus',
|
|
120
|
+
],
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* 组合式
|
|
124
|
+
*/
|
|
125
|
+
setup(props, { emit }) {
|
|
126
|
+
|
|
127
|
+
// ==========【数据】============================================================================================
|
|
128
|
+
|
|
129
|
+
// 当前值
|
|
130
|
+
const defaultValue = props.modelValue ?? props.defaultValue
|
|
131
|
+
const value = format(defaultValue)
|
|
132
|
+
if (! _.isEqual(value, props.modelValue)) {
|
|
133
|
+
emit('update:modelValue', value)
|
|
134
|
+
}
|
|
135
|
+
const currentValue = ref(value)
|
|
136
|
+
|
|
137
|
+
// ==========【计算属性】=========================================================================================
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* 是否禁用减少按钮
|
|
141
|
+
*/
|
|
142
|
+
const minusDisabled = computed(function () {
|
|
143
|
+
return props.disabled || props.disableMinus || currentValue.value <= +props.min
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* 是否禁用增加按钮
|
|
148
|
+
*/
|
|
149
|
+
const plusDisabled = computed(function () {
|
|
150
|
+
return props.disabled || props.disablePlus || currentValue.value >= +props.max
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
// ==========【监听数据】=========================================================================================
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* 监听值
|
|
157
|
+
*/
|
|
158
|
+
watch(()=>props.modelValue, function (val) {
|
|
159
|
+
if (! _.isEqual(val, currentValue.value)) {
|
|
160
|
+
currentValue.value = format(val)
|
|
161
|
+
}
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* 监听当前值
|
|
166
|
+
*/
|
|
167
|
+
watch(currentValue, function (val) {
|
|
168
|
+
emit('update:modelValue', val)
|
|
169
|
+
emit('change', val)
|
|
170
|
+
})
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* 监听其他
|
|
174
|
+
*/
|
|
175
|
+
watch([()=>props.max, ()=>props.min, ()=>props.integer, ()=>props.decimalLength], function () {
|
|
176
|
+
const val = format(currentValue.value)
|
|
177
|
+
if (! _.isEqual(val, currentValue.value)) {
|
|
178
|
+
currentValue.value = val
|
|
179
|
+
}
|
|
180
|
+
})
|
|
181
|
+
|
|
182
|
+
// ==========【方法】=============================================================================================
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* 格式化数字
|
|
186
|
+
*/
|
|
187
|
+
function formatNumber(value) {
|
|
188
|
+
return formatNumbers(String(value), ! props.integer)
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* 格式化
|
|
193
|
+
*/
|
|
194
|
+
function format(value) {
|
|
195
|
+
if (props.allowEmpty && value === '') {
|
|
196
|
+
return value
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
value = formatNumber(value)
|
|
200
|
+
|
|
201
|
+
// format range
|
|
202
|
+
value = value === '' ? 0 : +value
|
|
203
|
+
value = isNaN(value) ? props.min : value
|
|
204
|
+
value = Math.max(Math.min(props.max, value), props.min)
|
|
205
|
+
|
|
206
|
+
// 格式化小数位数
|
|
207
|
+
if (! _.isNil(props.decimalLength)) {
|
|
208
|
+
value = value.toFixed(props.decimalLength)
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return value
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* 输入触发
|
|
216
|
+
*/
|
|
217
|
+
function onInput(value) {
|
|
218
|
+
|
|
219
|
+
let formatted = formatNumber(value)
|
|
220
|
+
|
|
221
|
+
// limit max decimal length
|
|
222
|
+
if (! _.isNil(props.decimalLength) && formatted.indexOf('.') !== -1) {
|
|
223
|
+
const pair = utils.split(formatted, '.')
|
|
224
|
+
formatted = `${pair[0]}.${pair[1].slice(0, props.decimalLength)}`
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// prefer number type
|
|
228
|
+
if (formatted === String(+formatted)) {
|
|
229
|
+
formatted = +formatted
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
emitChange(formatted)
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* 失去焦点触发
|
|
237
|
+
*/
|
|
238
|
+
function onBlur(value) {
|
|
239
|
+
value = format(value)
|
|
240
|
+
emitChange(value)
|
|
241
|
+
emit('blur', value)
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* 提交改变值
|
|
246
|
+
*/
|
|
247
|
+
function emitChange(value) {
|
|
248
|
+
|
|
249
|
+
// 是否开启异步变更,开启后需要手动控制输入值
|
|
250
|
+
if (props.asyncChange) {
|
|
251
|
+
emit('input', value)
|
|
252
|
+
emit('change', value)
|
|
253
|
+
return
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
currentValue.value = value
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* 改变值
|
|
261
|
+
*/
|
|
262
|
+
function onChange(type) {
|
|
263
|
+
|
|
264
|
+
if (props[`${type}Disabled`]) {
|
|
265
|
+
emit('overlimit', type)
|
|
266
|
+
return
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
const diff = type === 'minus' ? -props.step : +props.step
|
|
270
|
+
|
|
271
|
+
const value = format(addNumber(+currentValue.value, diff))
|
|
272
|
+
|
|
273
|
+
emitChange(value)
|
|
274
|
+
emit(type)
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* 点击不可用的按钮时触发
|
|
279
|
+
*/
|
|
280
|
+
function onOverlimit(type) {
|
|
281
|
+
emit('overlimit', type)
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// ==========【返回】=============================================================================================
|
|
285
|
+
|
|
286
|
+
return {
|
|
287
|
+
// 当前值
|
|
288
|
+
currentValue,
|
|
289
|
+
|
|
290
|
+
// 是否禁用减少按钮
|
|
291
|
+
minusDisabled,
|
|
292
|
+
// 是否禁用增加按钮
|
|
293
|
+
plusDisabled,
|
|
294
|
+
|
|
295
|
+
// 输入触发
|
|
296
|
+
onInput,
|
|
297
|
+
// 失去焦点触发
|
|
298
|
+
onBlur,
|
|
299
|
+
// 改变值
|
|
300
|
+
onChange,
|
|
301
|
+
// 点击不可用的按钮时触发
|
|
302
|
+
onOverlimit,
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
</script>
|
|
307
|
+
|
|
308
|
+
<style lang="scss">
|
|
309
|
+
@import "@/assets/sass/var.scss";
|
|
310
|
+
|
|
311
|
+
.n-input-number {
|
|
312
|
+
&.q-field {
|
|
313
|
+
&--outlined {
|
|
314
|
+
.q-field__control {
|
|
315
|
+
padding: 0 4px !important;
|
|
316
|
+
.q-field__native {
|
|
317
|
+
text-align: center;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
</style>
|
|
324
|
+
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 删除前后字符
|
|
3
|
+
* @param {string} value
|
|
4
|
+
* @param {string} char
|
|
5
|
+
* @param {RegExp} regExp
|
|
6
|
+
* @returns {string}
|
|
7
|
+
*/
|
|
8
|
+
function trimExtraChar(value, char, regExp) {
|
|
9
|
+
const index = value.indexOf(char)
|
|
10
|
+
let prefix = ''
|
|
11
|
+
|
|
12
|
+
if (index === -1) {
|
|
13
|
+
return value
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (char === '-' && index !== 0) {
|
|
17
|
+
return value.slice(0, index)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (char === '.' && value.match(/^(\.|-\.)/)) {
|
|
21
|
+
prefix = index ? '-0' : '0'
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
prefix + value.slice(0, index + 1) + value.slice(index).replace(regExp, '')
|
|
26
|
+
)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 格式化数字
|
|
31
|
+
* @param {string} value
|
|
32
|
+
* @param {boolean} allowDot
|
|
33
|
+
* @param {boolean} allowMinus
|
|
34
|
+
* @returns {string}
|
|
35
|
+
*/
|
|
36
|
+
export function formatNumbers(
|
|
37
|
+
value,
|
|
38
|
+
allowDot = true,
|
|
39
|
+
allowMinus = true
|
|
40
|
+
) {
|
|
41
|
+
if (allowDot) {
|
|
42
|
+
value = trimExtraChar(value, '.', /\./g)
|
|
43
|
+
} else {
|
|
44
|
+
value = value.split('.')[0]
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (allowMinus) {
|
|
48
|
+
value = trimExtraChar(value, '-', /-/g)
|
|
49
|
+
} else {
|
|
50
|
+
value = value.replace(/-/, '')
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const regExp = allowDot ? /[^-0-9.]/g : /[^-0-9]/g
|
|
54
|
+
|
|
55
|
+
return value.replace(regExp, '')
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* 增加数字
|
|
60
|
+
* @param {number} num1
|
|
61
|
+
* @param {number} num2
|
|
62
|
+
* @returns {number}
|
|
63
|
+
*/
|
|
64
|
+
export function addNumber(num1, num2) {
|
|
65
|
+
const cardinal = 10 ** 10
|
|
66
|
+
return Math.round((num1 + num2) * cardinal) / cardinal
|
|
67
|
+
}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<q-input
|
|
3
|
+
v-model="currentValue"
|
|
4
|
+
@blur="onBlur"
|
|
5
|
+
v-bind="$attrs"
|
|
6
|
+
>
|
|
7
|
+
<template
|
|
8
|
+
v-for="slotName in slotNames"
|
|
9
|
+
v-slot:[slotName]
|
|
10
|
+
>
|
|
11
|
+
<slot :name="slotName" />
|
|
12
|
+
</template>
|
|
13
|
+
</q-input>
|
|
14
|
+
</template>
|
|
15
|
+
|
|
16
|
+
<script>
|
|
17
|
+
import { computed, ref, watch } from 'vue'
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 金额(分转元)
|
|
21
|
+
*/
|
|
22
|
+
export default {
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 标识
|
|
26
|
+
*/
|
|
27
|
+
name: 'NInputPrice',
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 声明属性
|
|
31
|
+
*/
|
|
32
|
+
props: {
|
|
33
|
+
// 值
|
|
34
|
+
modelValue: [String, Number],
|
|
35
|
+
// 最小值(分)
|
|
36
|
+
min: {
|
|
37
|
+
type: Number,
|
|
38
|
+
default: 1,
|
|
39
|
+
},
|
|
40
|
+
// 最大值(分)
|
|
41
|
+
max: Number,
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* 声明事件
|
|
46
|
+
*/
|
|
47
|
+
emits: [
|
|
48
|
+
'update:modelValue',
|
|
49
|
+
],
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* 组合式
|
|
53
|
+
*/
|
|
54
|
+
setup(props, { emit, slots }) {
|
|
55
|
+
|
|
56
|
+
// ==========【数据】============================================================================================
|
|
57
|
+
|
|
58
|
+
// 当前值
|
|
59
|
+
const currentValue = ref(formatModelValue())
|
|
60
|
+
|
|
61
|
+
// ==========【计算属性】==========================================================================================
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* 插槽标识数组
|
|
65
|
+
*/
|
|
66
|
+
const slotNames = computed(function() {
|
|
67
|
+
if (utils.isValidObject(slots)) {
|
|
68
|
+
return Object.keys(slots)
|
|
69
|
+
}
|
|
70
|
+
return []
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* 最大值
|
|
75
|
+
*/
|
|
76
|
+
const maxValue = computed(function() {
|
|
77
|
+
const maxValue = new BigNumber(props.max)
|
|
78
|
+
if (maxValue.isFinite()) {
|
|
79
|
+
return maxValue
|
|
80
|
+
.dividedBy(100)
|
|
81
|
+
.toNumber()
|
|
82
|
+
}
|
|
83
|
+
return null
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* 最小值
|
|
88
|
+
*/
|
|
89
|
+
const minValue = computed(function() {
|
|
90
|
+
const maxValue = new BigNumber(props.min)
|
|
91
|
+
if (maxValue.isFinite()) {
|
|
92
|
+
return maxValue
|
|
93
|
+
.dividedBy(100)
|
|
94
|
+
.toNumber()
|
|
95
|
+
}
|
|
96
|
+
return null
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
// ==========【监听数据】=========================================================================================
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* 监听声明值
|
|
103
|
+
*/
|
|
104
|
+
watch(()=>props.modelValue, function() {
|
|
105
|
+
currentValue.value = formatModelValue()
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
// ==========【方法】=============================================================================================
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* 格式化传值
|
|
112
|
+
*/
|
|
113
|
+
function formatModelValue() {
|
|
114
|
+
// 分转元
|
|
115
|
+
return utils.price(props.modelValue, '')
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* 提交值
|
|
120
|
+
*/
|
|
121
|
+
function emitModelValue(newVal) {
|
|
122
|
+
// 更新值(元转分)
|
|
123
|
+
emit('update:modelValue', utils.priceYuanToCent(newVal, ''))
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* 失去焦点触发
|
|
128
|
+
*/
|
|
129
|
+
function onBlur() {
|
|
130
|
+
|
|
131
|
+
if (utils.isValidValue(currentValue.value)) {
|
|
132
|
+
|
|
133
|
+
let val = new BigNumber(currentValue.value)
|
|
134
|
+
|
|
135
|
+
if (val.isFinite()) {
|
|
136
|
+
|
|
137
|
+
// 值是否有更新
|
|
138
|
+
let isChange = false
|
|
139
|
+
|
|
140
|
+
if (
|
|
141
|
+
// 如果值 > 0
|
|
142
|
+
val.isGreaterThan(0)
|
|
143
|
+
// 如果值精度 > 2
|
|
144
|
+
&& val.decimalPlaces() > 2
|
|
145
|
+
) {
|
|
146
|
+
// 值有更新
|
|
147
|
+
isChange = true
|
|
148
|
+
|
|
149
|
+
// 将元向下舍入 2 位精度(如 68.345 -> 68.34)
|
|
150
|
+
val = val.decimalPlaces(2, BigNumber.ROUND_DOWN)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// 如果值 >= 最大值
|
|
154
|
+
if (maxValue.value !== null) {
|
|
155
|
+
if (val.isGreaterThanOrEqualTo(maxValue.value)) {
|
|
156
|
+
|
|
157
|
+
// 更新当前值
|
|
158
|
+
currentValue.value = maxValue.value
|
|
159
|
+
|
|
160
|
+
// 提交值
|
|
161
|
+
emitModelValue(currentValue.value)
|
|
162
|
+
return
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// 如果值 <= 最小值
|
|
167
|
+
if (minValue.value !== null) {
|
|
168
|
+
if (val.isLessThanOrEqualTo(minValue.value)) {
|
|
169
|
+
|
|
170
|
+
// 更新当前值
|
|
171
|
+
currentValue.value = minValue.value
|
|
172
|
+
|
|
173
|
+
// 提交值
|
|
174
|
+
emitModelValue(currentValue.value)
|
|
175
|
+
return
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// 获取最新值
|
|
180
|
+
val = val.toNumber()
|
|
181
|
+
|
|
182
|
+
if (isChange) {
|
|
183
|
+
// 更新当前值
|
|
184
|
+
currentValue.value = val
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// 提交值
|
|
188
|
+
emitModelValue(val)
|
|
189
|
+
return
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// 更新当前值
|
|
194
|
+
currentValue.value = ''
|
|
195
|
+
|
|
196
|
+
// 提交值
|
|
197
|
+
emitModelValue(currentValue.value)
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// ==========【返回】=============================================================================================
|
|
201
|
+
|
|
202
|
+
return {
|
|
203
|
+
// 当前值
|
|
204
|
+
currentValue,
|
|
205
|
+
// 插槽标识数组
|
|
206
|
+
slotNames,
|
|
207
|
+
|
|
208
|
+
// 失去焦点触发
|
|
209
|
+
onBlur,
|
|
210
|
+
}
|
|
211
|
+
},
|
|
212
|
+
}
|
|
213
|
+
</script>
|