@netang/quasar 0.0.35 → 0.0.36
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/data/index.vue +23 -0
- package/components/field-table/index.vue +6 -3
- package/components/input-format/index.vue +153 -9
- package/package.json +1 -1
- package/utils/price.js +13 -13
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
<q-field
|
|
4
4
|
class="n-field-table"
|
|
5
5
|
:model-value="showValue"
|
|
6
|
+
:disable="disable"
|
|
6
7
|
:readonly="readonly"
|
|
7
8
|
:clearable="clearable && (! multiple || collapseTags)"
|
|
8
9
|
@focus="onFieldFocus"
|
|
@@ -37,7 +38,7 @@
|
|
|
37
38
|
:key="`options-${index}`"
|
|
38
39
|
:label="currentFormatLabel(item)"
|
|
39
40
|
dense
|
|
40
|
-
removable
|
|
41
|
+
:removable="! readonly && ! disable"
|
|
41
42
|
@remove="onRemoveSelected(index)"
|
|
42
43
|
/>
|
|
43
44
|
</template>
|
|
@@ -58,13 +59,13 @@
|
|
|
58
59
|
ref="inputRef"
|
|
59
60
|
class="q-field__input q-placeholder col q-field__input--padding"
|
|
60
61
|
v-model="inputValue"
|
|
61
|
-
v-if="filter"
|
|
62
|
+
v-if="filter && ! readonly && ! disable"
|
|
62
63
|
/>
|
|
63
64
|
|
|
64
65
|
</template>
|
|
65
66
|
|
|
66
67
|
<!-- 弹出对话框图标 -->
|
|
67
|
-
<template v-slot:append v-if="! noDialog">
|
|
68
|
+
<template v-slot:append v-if="! noDialog && ! readonly && ! disable">
|
|
68
69
|
<q-icon
|
|
69
70
|
class="cursor-pointer"
|
|
70
71
|
name="search"
|
|
@@ -222,6 +223,8 @@ export default {
|
|
|
222
223
|
placeholder: String,
|
|
223
224
|
// 是否可清除
|
|
224
225
|
clearable: Boolean,
|
|
226
|
+
// 是否禁用
|
|
227
|
+
disable: Boolean,
|
|
225
228
|
// 是否只读
|
|
226
229
|
readonly: Boolean,
|
|
227
230
|
// 输入防抖(毫秒)
|
|
@@ -32,8 +32,12 @@ export default {
|
|
|
32
32
|
modelValue: {
|
|
33
33
|
required: false,
|
|
34
34
|
},
|
|
35
|
-
//
|
|
36
|
-
|
|
35
|
+
// 值是否为数组
|
|
36
|
+
valueArray: Boolean,
|
|
37
|
+
// 修改前值
|
|
38
|
+
formatBefore: [Function, Object, Boolean],
|
|
39
|
+
// 修改后值
|
|
40
|
+
formatAfter: [Function, Object, Boolean],
|
|
37
41
|
},
|
|
38
42
|
|
|
39
43
|
/**
|
|
@@ -61,7 +65,7 @@ export default {
|
|
|
61
65
|
// ==========【数据】============================================================================================
|
|
62
66
|
|
|
63
67
|
// 当前值
|
|
64
|
-
const currentValue = ref(props.modelValue)
|
|
68
|
+
const currentValue = ref(formatModelValue(props.modelValue))
|
|
65
69
|
|
|
66
70
|
// ==========【监听数据】=========================================================================================
|
|
67
71
|
|
|
@@ -69,11 +73,143 @@ export default {
|
|
|
69
73
|
* 监听声明值
|
|
70
74
|
*/
|
|
71
75
|
watch(()=>props.modelValue, function (val) {
|
|
72
|
-
currentValue.value = val
|
|
76
|
+
currentValue.value = formatModelValue(val)
|
|
73
77
|
})
|
|
74
78
|
|
|
75
79
|
// ==========【方法】=============================================================================================
|
|
76
80
|
|
|
81
|
+
/**
|
|
82
|
+
* 格式化声明值
|
|
83
|
+
*/
|
|
84
|
+
function formatModelValue(val) {
|
|
85
|
+
|
|
86
|
+
if (props.formatBefore) {
|
|
87
|
+
|
|
88
|
+
// 如果是方法
|
|
89
|
+
if (_.isFunction(props.formatBefore)) {
|
|
90
|
+
return props.formatBefore(val)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// 如果是参数
|
|
94
|
+
if (props.formatBefore === true || utils.isValidObject(props.formatBefore)) {
|
|
95
|
+
|
|
96
|
+
// 如果值是数组
|
|
97
|
+
if (Array.isArray(val)) {
|
|
98
|
+
|
|
99
|
+
// 格式化数组值
|
|
100
|
+
return formatArrayValue(val, props.formatBefore === true ? {} : props.formatBefore)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// 如果是有效值
|
|
104
|
+
if (utils.isValidValue(val)) {
|
|
105
|
+
|
|
106
|
+
// 格式化字符串值
|
|
107
|
+
return formatStringValue(val, props.formatBefore === true ? {} : props.formatBefore, false)
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return ''
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return val
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* 格式化数组值
|
|
119
|
+
*/
|
|
120
|
+
function formatArrayValue(val, params) {
|
|
121
|
+
|
|
122
|
+
// 如果数组有值
|
|
123
|
+
if (val.length) {
|
|
124
|
+
|
|
125
|
+
const o = Object.assign({
|
|
126
|
+
// 是否去重
|
|
127
|
+
unique: true,
|
|
128
|
+
// 分隔符
|
|
129
|
+
separator: ',',
|
|
130
|
+
// 是否给每个值去除首位空格
|
|
131
|
+
trim: true,
|
|
132
|
+
// 验证每个值是否为有效字符串/数字
|
|
133
|
+
isValidValue: true,
|
|
134
|
+
}, params)
|
|
135
|
+
|
|
136
|
+
// 是否给每个值去除首位空格
|
|
137
|
+
if (o.trim) {
|
|
138
|
+
val = val.map(e => utils.trimString(e))
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// 是否验证每个值是否为有效字符串/数字
|
|
142
|
+
if (o.isValidValue) {
|
|
143
|
+
val = val.filter(val => utils.isValidValue(val))
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// 去重
|
|
147
|
+
if (o.unique) {
|
|
148
|
+
val = _.uniq(val)
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// 合并为字符串
|
|
152
|
+
return val.join(o.separator)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return ''
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* 格式化字符串值
|
|
160
|
+
*/
|
|
161
|
+
function formatStringValue(val, params, valueArray) {
|
|
162
|
+
|
|
163
|
+
console.log(val, params, valueArray)
|
|
164
|
+
|
|
165
|
+
const o = Object.assign({
|
|
166
|
+
// 替换内容
|
|
167
|
+
replace: /\n|\,|\s+/g,
|
|
168
|
+
// 是否去重
|
|
169
|
+
unique: true,
|
|
170
|
+
// 分隔符
|
|
171
|
+
separator: ',',
|
|
172
|
+
// 验证每个值是否为有效字符串/数字
|
|
173
|
+
isValidValue: true,
|
|
174
|
+
}, params)
|
|
175
|
+
|
|
176
|
+
// 去除首位空格
|
|
177
|
+
val = utils.trimString(val)
|
|
178
|
+
|
|
179
|
+
// 如果有分割符
|
|
180
|
+
if (utils.isValidValue(o.separator, true)) {
|
|
181
|
+
|
|
182
|
+
o.separator = String(o.separator)
|
|
183
|
+
|
|
184
|
+
// 是否替换
|
|
185
|
+
if (o.replace) {
|
|
186
|
+
val = val.replace(o.replace, o.separator)
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// 分隔成数组
|
|
190
|
+
val = utils.split(val, o.separator)
|
|
191
|
+
|
|
192
|
+
// 去重
|
|
193
|
+
if (o.unique) {
|
|
194
|
+
val = _.uniq(val)
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// 如果验证每个值是否为有效字符串/数字
|
|
198
|
+
if (o.isValidValue) {
|
|
199
|
+
val = val.filter(val => utils.isValidValue(val))
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// 如果值不是数组
|
|
203
|
+
if (! valueArray) {
|
|
204
|
+
val = val.join(o.separator)
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return val
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return valueArray ? [ val ] : ''
|
|
211
|
+
}
|
|
212
|
+
|
|
77
213
|
/**
|
|
78
214
|
* 失去焦点触发
|
|
79
215
|
*/
|
|
@@ -81,11 +217,19 @@ export default {
|
|
|
81
217
|
|
|
82
218
|
let val = currentValue.value
|
|
83
219
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
220
|
+
// 如果修改值
|
|
221
|
+
if (props.formatAfter) {
|
|
222
|
+
|
|
223
|
+
// 如果是方法
|
|
224
|
+
if (_.isFunction(props.formatAfter)) {
|
|
225
|
+
val = props.formatAfter(val)
|
|
226
|
+
|
|
227
|
+
// 如果是参数
|
|
228
|
+
} else if (props.formatAfter === true || utils.isValidObject(props.formatAfter)) {
|
|
229
|
+
|
|
230
|
+
// 格式化字符串值
|
|
231
|
+
val = formatStringValue(val, props.formatAfter === true ? {} : props.formatAfter, props.valueArray)
|
|
232
|
+
}
|
|
89
233
|
}
|
|
90
234
|
|
|
91
235
|
// 更新值
|
package/package.json
CHANGED
package/utils/price.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 换算金额
|
|
3
|
-
*/
|
|
4
|
-
utils.price = function(value, params) {
|
|
5
|
-
return utils.decimal(value, Object.assign({
|
|
6
|
-
// 最小值
|
|
7
|
-
min: 0,
|
|
8
|
-
// 小数点位数
|
|
9
|
-
decimalLength: 2,
|
|
10
|
-
// 是否开启人民币分转元(如值 189 -> 1.89)
|
|
11
|
-
centToYuan: utils.config('priceCent') === true,
|
|
12
|
-
}, params))
|
|
13
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* 换算金额
|
|
3
|
+
*/
|
|
4
|
+
utils.price = function(value, params) {
|
|
5
|
+
return utils.decimal(value, Object.assign({
|
|
6
|
+
// 最小值
|
|
7
|
+
min: 0,
|
|
8
|
+
// 小数点位数
|
|
9
|
+
decimalLength: 2,
|
|
10
|
+
// 是否开启人民币分转元(如值 189 -> 1.89)
|
|
11
|
+
centToYuan: utils.config('priceCent') === true,
|
|
12
|
+
}, params))
|
|
13
|
+
}
|