n20-common-lib 2.5.5-beta.8 → 2.5.5-beta.9
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/package.json
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
|
|
20
20
|
.el-form-item,
|
|
21
21
|
.el-form-item--small.el-form-item {
|
|
22
|
-
margin-bottom:
|
|
22
|
+
margin-bottom: 16px;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
.el-form-item__content {
|
|
@@ -53,9 +53,6 @@
|
|
|
53
53
|
margin-right: 4px;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
.n20-date-editor.el-input--prefix {
|
|
57
|
-
max-width: 166px;
|
|
58
|
-
}
|
|
59
56
|
|
|
60
57
|
.el-range-editor.el-input__inner {
|
|
61
58
|
min-width: 168px;
|
|
@@ -66,6 +63,11 @@
|
|
|
66
63
|
}
|
|
67
64
|
}
|
|
68
65
|
|
|
66
|
+
.n20-date-editor.el-date-editor--datetimerange.el-range-editor--small.has-value {
|
|
67
|
+
min-width: 168px;
|
|
68
|
+
max-width: 380px;
|
|
69
|
+
}
|
|
70
|
+
|
|
69
71
|
.el-input,
|
|
70
72
|
.el-input__inner {
|
|
71
73
|
border: none;
|
|
@@ -73,6 +75,8 @@
|
|
|
73
75
|
background-color: transparent;
|
|
74
76
|
}
|
|
75
77
|
|
|
78
|
+
|
|
79
|
+
|
|
76
80
|
.el-input__inner:active,
|
|
77
81
|
.el-input__inner:focus {
|
|
78
82
|
box-shadow: none;
|
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
<el-input
|
|
3
3
|
v-if="item.type === 'text' || item.type === undefined"
|
|
4
4
|
v-model="form[item.value]"
|
|
5
|
-
|
|
5
|
+
v-rule-key
|
|
6
|
+
:ruleErrorHide="item.ruleErrorHide"
|
|
7
|
+
:rules="item.rules"
|
|
8
|
+
rule-form="ruleValidate"
|
|
9
|
+
:clearable="(item.props && item.props.clearable) ?? true"
|
|
6
10
|
:style="{
|
|
7
11
|
width:
|
|
8
12
|
form[item.value] && form[item.value].length > 0
|
|
@@ -11,7 +15,7 @@
|
|
|
11
15
|
: context.measureText(form[item.value]).width * 1.4 + 45 > 396
|
|
12
16
|
? 396
|
|
13
17
|
: context.measureText(form[item.value]).width * 1.4 + 45) + 'px'
|
|
14
|
-
: item.width ||
|
|
18
|
+
: item.width || '100px'
|
|
15
19
|
}"
|
|
16
20
|
:value-data="context.measureText(form[item.value]).width * 1.4 + 45 + 'px'"
|
|
17
21
|
v-bind="item.props"
|
|
@@ -19,14 +23,17 @@
|
|
|
19
23
|
@blur="handleBlur"
|
|
20
24
|
/>
|
|
21
25
|
<el-input
|
|
26
|
+
v-rule-key
|
|
27
|
+
:rules="item.rules"
|
|
28
|
+
rule-form="ruleValidate"
|
|
22
29
|
v-else-if="item.type === 'search'"
|
|
23
30
|
v-model="form[item.value]"
|
|
24
|
-
:clearable="(item.props && item.props.clearable)
|
|
31
|
+
:clearable="(item.props && item.props.clearable) ?? true"
|
|
25
32
|
:style="{
|
|
26
33
|
width:
|
|
27
34
|
form[item.value] && form[item.value].length > 0
|
|
28
|
-
? context.measureText(form[item.value]).width * 1.4 +
|
|
29
|
-
: item.width ||
|
|
35
|
+
? context.measureText(form[item.value]).width * 1.4 + 40 + 'px'
|
|
36
|
+
: item.width || '100px'
|
|
30
37
|
}"
|
|
31
38
|
readonly
|
|
32
39
|
v-bind="item.props"
|
|
@@ -43,9 +50,12 @@
|
|
|
43
50
|
></i>
|
|
44
51
|
</el-input>
|
|
45
52
|
<el-select
|
|
53
|
+
v-rule-key
|
|
54
|
+
:rules="item.rules"
|
|
55
|
+
rule-form="ruleValidate"
|
|
46
56
|
v-else-if="item.type === 'select'"
|
|
47
57
|
v-model="form[item.value]"
|
|
48
|
-
:clearable="(item.props && item.props.clearable)
|
|
58
|
+
:clearable="(item.props && item.props.clearable) ?? true"
|
|
49
59
|
:multiple="item.multiple"
|
|
50
60
|
collapse-tags
|
|
51
61
|
:style="{
|
|
@@ -59,9 +69,9 @@
|
|
|
59
69
|
)
|
|
60
70
|
).width *
|
|
61
71
|
1.4 +
|
|
62
|
-
|
|
72
|
+
68 +
|
|
63
73
|
'px'
|
|
64
|
-
: item.width ||
|
|
74
|
+
: item.width || '100px'
|
|
65
75
|
}"
|
|
66
76
|
v-bind="item.props"
|
|
67
77
|
@change="handleChange"
|
|
@@ -86,6 +96,9 @@
|
|
|
86
96
|
</template>
|
|
87
97
|
</el-select>
|
|
88
98
|
<inputNumber
|
|
99
|
+
v-rule-key
|
|
100
|
+
:rules="item.rules"
|
|
101
|
+
rule-form="ruleValidate"
|
|
89
102
|
v-else-if="item.type === 'number'"
|
|
90
103
|
v-model="form[item.value]"
|
|
91
104
|
:style="{
|
|
@@ -96,12 +109,15 @@
|
|
|
96
109
|
: context.measureText(form[item.value]).width * 1.6 + 60 > 396
|
|
97
110
|
? 396
|
|
98
111
|
: context.measureText(form[item.value]).width * 1.6 + 60) + 'px'
|
|
99
|
-
: item.width ||
|
|
112
|
+
: item.width || '100px'
|
|
100
113
|
}"
|
|
101
114
|
v-bind="item.props"
|
|
102
115
|
@blur="handleChange"
|
|
103
116
|
/>
|
|
104
117
|
<inputNumberRange
|
|
118
|
+
v-rule-key
|
|
119
|
+
:rules="item.rules"
|
|
120
|
+
rule-form="ruleValidate"
|
|
105
121
|
v-else-if="item.type === 'numberrange'"
|
|
106
122
|
:start-value.sync="form[item.startValue]"
|
|
107
123
|
:end-value.sync="form[item.endValue]"
|
|
@@ -114,25 +130,34 @@
|
|
|
114
130
|
@blur="handleChange"
|
|
115
131
|
/>
|
|
116
132
|
<datePickerPor
|
|
133
|
+
v-rule-key
|
|
134
|
+
:rules="item.rules"
|
|
135
|
+
rule-form="ruleValidate"
|
|
117
136
|
v-else-if="['date', 'datetime', 'year', 'month', 'week'].includes(item.type)"
|
|
118
137
|
v-model="form[item.value]"
|
|
119
138
|
:type="item.type"
|
|
120
|
-
:clearable="(item.props && item.props.clearable)
|
|
121
|
-
:style="{ width: item.width ||
|
|
139
|
+
:clearable="(item.props && item.props.clearable) ?? true"
|
|
140
|
+
:style="{ width: item.width || 175 + 'px' }"
|
|
122
141
|
v-bind="item.props"
|
|
123
142
|
@change="handleChange"
|
|
124
143
|
/>
|
|
125
144
|
<datePickerPor
|
|
145
|
+
v-rule-key
|
|
146
|
+
:rules="item.rules"
|
|
147
|
+
rule-form="ruleValidate"
|
|
126
148
|
v-else-if="['daterange', 'datetimerange', ' monthrange'].includes(item.type)"
|
|
127
149
|
:type="item.type"
|
|
128
150
|
:start-date.sync="form[item.startDate]"
|
|
129
151
|
:end-date.sync="form[item.endDate]"
|
|
130
|
-
:clearable="(item.props && item.props.clearable)
|
|
131
|
-
:style="{ width: item.width
|
|
152
|
+
:clearable="(item.props && item.props.clearable) ?? true"
|
|
153
|
+
:style="{ width: item.width }"
|
|
132
154
|
v-bind="item.props"
|
|
133
155
|
@change="handleChange"
|
|
134
156
|
/>
|
|
135
157
|
<el-checkbox-group
|
|
158
|
+
v-rule-key
|
|
159
|
+
:rules="item.rules"
|
|
160
|
+
rule-form="ruleValidate"
|
|
136
161
|
v-else-if="item.type === 'checkbox'"
|
|
137
162
|
v-model="form[item.value]"
|
|
138
163
|
v-bind="item.props"
|
|
@@ -142,7 +167,15 @@
|
|
|
142
167
|
c.label
|
|
143
168
|
}}</el-checkbox>
|
|
144
169
|
</el-checkbox-group>
|
|
145
|
-
<el-radio-group
|
|
170
|
+
<el-radio-group
|
|
171
|
+
v-rule-key
|
|
172
|
+
rule-form="ruleValidate"
|
|
173
|
+
:rules="item.rules"
|
|
174
|
+
v-else-if="item.type === 'radio'"
|
|
175
|
+
v-model="form[item.value]"
|
|
176
|
+
v-bind="item.props"
|
|
177
|
+
v-on="item.on"
|
|
178
|
+
>
|
|
146
179
|
<el-radio v-for="c in item.options" :key="c.value" :label="c.value" :disabled="c.disabled">{{ c.label }}</el-radio>
|
|
147
180
|
</el-radio-group>
|
|
148
181
|
</template>
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
ref="input"
|
|
5
5
|
v-model="valueStr"
|
|
6
6
|
class="n20-stc"
|
|
7
|
+
v-bind="$attrs"
|
|
7
8
|
:disabled="disabled"
|
|
8
9
|
:placeholder="phd"
|
|
9
10
|
:clearable="isClearable"
|
|
@@ -14,6 +15,12 @@
|
|
|
14
15
|
@change="changeFn"
|
|
15
16
|
@keydown.native="stepFn"
|
|
16
17
|
>
|
|
18
|
+
<template slot="suffix">
|
|
19
|
+
<slot name="suffix"></slot>
|
|
20
|
+
</template>
|
|
21
|
+
<template slot="prefix">
|
|
22
|
+
<slot name="prefix"></slot>
|
|
23
|
+
</template>
|
|
17
24
|
<template v-if="type === 'rate'">
|
|
18
25
|
<span v-if="suffixV" slot="suffix" class="el-input__icon">{{ suffix }}</span>
|
|
19
26
|
</template>
|
|
@@ -1,94 +1,64 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
if (evType === 'submit') {
|
|
12
|
-
return _rules
|
|
13
|
-
} else {
|
|
14
|
-
return _rules.filter((r) => r.trigger.includes(evType))
|
|
15
|
-
}
|
|
16
|
-
} else {
|
|
1
|
+
const VALIDATE = '_v-rule-key_validate_'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param {object|| array} rules
|
|
6
|
+
* @param {string} type
|
|
7
|
+
* @returns array
|
|
8
|
+
*/
|
|
9
|
+
function getRules(rules, type) {
|
|
10
|
+
if (!rules) {
|
|
17
11
|
return []
|
|
18
12
|
}
|
|
13
|
+
let _rules = []
|
|
14
|
+
if (Array.isArray(rules)) {
|
|
15
|
+
_rules = rules
|
|
16
|
+
} else if (typeof rules === 'object') {
|
|
17
|
+
_rules.push(rules)
|
|
18
|
+
}
|
|
19
|
+
return type === 'submit' ? _rules : _rules.filter((r) => r.trigger.includes(type))
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
if (rule.min !== undefined || rule.max !== undefined) {
|
|
60
|
-
if (value === undefined || value === null) {
|
|
61
|
-
reject(rule.message)
|
|
62
|
-
return
|
|
63
|
-
} else {
|
|
64
|
-
let _v = value.toString()
|
|
65
|
-
if (_v.length < rule.min || _v.length > rule.max) {
|
|
66
|
-
reject(rule.message)
|
|
67
|
-
return
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
if (rule.regexp) {
|
|
72
|
-
if (new RegExp(rule.regexp).test(value)) {
|
|
73
|
-
reject(rule.message)
|
|
74
|
-
return
|
|
22
|
+
// 函数用于验证规则
|
|
23
|
+
async function validateRule(rule, value) {
|
|
24
|
+
// 判断是否必填
|
|
25
|
+
if (
|
|
26
|
+
rule.required &&
|
|
27
|
+
(value === undefined || value === null || value === '' || (Array.isArray(value) && value.length === 0))
|
|
28
|
+
) {
|
|
29
|
+
throw new Error(rule.message)
|
|
30
|
+
}
|
|
31
|
+
// 判断值类型
|
|
32
|
+
const typeValidations = {
|
|
33
|
+
string: typeof value === 'string',
|
|
34
|
+
number: typeof value === 'number',
|
|
35
|
+
boolean: typeof value === 'boolean',
|
|
36
|
+
array: Array.isArray(value) && value.length > 0,
|
|
37
|
+
date: new Date(value).toString() !== 'Invalid Date'
|
|
38
|
+
}
|
|
39
|
+
if (rule.type && !typeValidations[rule.type]) {
|
|
40
|
+
throw new Error(rule.message)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// 判断值范围
|
|
44
|
+
const length = value && value.toString().length
|
|
45
|
+
if ((rule.min !== undefined && length < rule.min) || (rule.max !== undefined && length > rule.max)) {
|
|
46
|
+
throw new Error(rule.message)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// 判断正则表达式
|
|
50
|
+
if (rule.regexp && new RegExp(rule.regexp).test(value)) {
|
|
51
|
+
throw new Error(rule.message)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// 判断自定义验证函数
|
|
55
|
+
if (rule.validator) {
|
|
56
|
+
await rule.validator(rule, value, (err) => {
|
|
57
|
+
if (err) {
|
|
58
|
+
throw new Error(err === true ? rule.message : err)
|
|
75
59
|
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
resolve()
|
|
79
|
-
return
|
|
80
|
-
}
|
|
81
|
-
if (rule.validator) {
|
|
82
|
-
rule.validator(rule, value, (err) => {
|
|
83
|
-
if (err === undefined || err === false) {
|
|
84
|
-
resolve()
|
|
85
|
-
return
|
|
86
|
-
} else {
|
|
87
|
-
reject(err === true ? rule.message : err)
|
|
88
|
-
}
|
|
89
|
-
})
|
|
90
|
-
}
|
|
91
|
-
})
|
|
60
|
+
})
|
|
61
|
+
}
|
|
92
62
|
}
|
|
93
63
|
|
|
94
64
|
function showErr(el, err = '', rErr) {
|
|
@@ -99,10 +69,10 @@ function showErr(el, err = '', rErr) {
|
|
|
99
69
|
if (!msgEl) {
|
|
100
70
|
let msgEl = document.createElement('div')
|
|
101
71
|
msgEl.classList.add('rule-key__error_msg')
|
|
102
|
-
msgEl.innerText = err.toString()
|
|
72
|
+
msgEl.innerText = err.message.toString()
|
|
103
73
|
el.appendChild(msgEl)
|
|
104
74
|
} else if (msgEl) {
|
|
105
|
-
msgEl.innerText = err.toString()
|
|
75
|
+
msgEl.innerText = err.message.toString()
|
|
106
76
|
}
|
|
107
77
|
}
|
|
108
78
|
}
|
|
@@ -118,78 +88,81 @@ function hideErr(el, rErr) {
|
|
|
118
88
|
}
|
|
119
89
|
|
|
120
90
|
const directive = {}
|
|
91
|
+
// 定义指令
|
|
121
92
|
directive.install = (Vue) => {
|
|
93
|
+
// 注册指令
|
|
122
94
|
Vue.directive('rule-key', {
|
|
95
|
+
// 绑定指令
|
|
123
96
|
bind(el, binding, node) {
|
|
97
|
+
// 获取当前节点
|
|
124
98
|
let _this = node.child
|
|
125
|
-
|
|
126
99
|
// 获取表单验证规则
|
|
127
100
|
let ruleForm = _this.$attrs['rule-form'] || _this.$attrs['ruleForm']
|
|
128
101
|
ruleForm && el.classList.add(ruleForm)
|
|
129
102
|
|
|
130
103
|
// 获取表单验证错误隐藏
|
|
131
|
-
let
|
|
132
|
-
|
|
104
|
+
let errorHide = _this.$attrs['rule-error-hide'] || _this.$attrs['ruleErrorHide']
|
|
105
|
+
errorHide = errorHide !== 'true' && errorHide !== true
|
|
133
106
|
|
|
134
107
|
// 表单验证
|
|
135
|
-
el[
|
|
136
|
-
let
|
|
108
|
+
el[VALIDATE] = async (type) => {
|
|
109
|
+
let _value = _this[binding.value || 'value']
|
|
110
|
+
|
|
137
111
|
let _rules = getRules(_this.$attrs['rules'], type)
|
|
112
|
+
|
|
138
113
|
if (_rules.length > 0) {
|
|
139
114
|
// 验证表单
|
|
140
|
-
|
|
141
|
-
.
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
showErr(el, err, rErr)
|
|
149
|
-
return Promise.resolve(false)
|
|
150
|
-
})
|
|
115
|
+
try {
|
|
116
|
+
let res = await Promise.all(_rules.map((rule) => validateRule(rule, _value)))
|
|
117
|
+
hideErr(el, errorHide)
|
|
118
|
+
return true
|
|
119
|
+
} catch (error) {
|
|
120
|
+
showErr(el, error, errorHide) // 验证失败,显示错误
|
|
121
|
+
return false
|
|
122
|
+
}
|
|
151
123
|
} else {
|
|
152
|
-
return
|
|
124
|
+
return true
|
|
153
125
|
}
|
|
154
126
|
}
|
|
155
127
|
|
|
128
|
+
// 监听change事件
|
|
156
129
|
_this.$on('change', () => {
|
|
157
|
-
setTimeout(() => el[
|
|
130
|
+
setTimeout(() => el[VALIDATE]('change'))
|
|
158
131
|
})
|
|
159
|
-
// el.addEventListener('change', () => {
|
|
160
|
-
// el[VD](undefined, 'change')
|
|
161
|
-
// })
|
|
162
132
|
|
|
133
|
+
// 监听blur事件
|
|
163
134
|
_this.$on('blur', () => {
|
|
164
|
-
setTimeout(() => el[
|
|
135
|
+
setTimeout(() => el[VALIDATE]('blur'))
|
|
165
136
|
})
|
|
166
|
-
// el.addEventListener('blur', () => {
|
|
167
|
-
// el[VD](undefined, 'blur')
|
|
168
|
-
// })
|
|
169
137
|
}
|
|
170
138
|
})
|
|
139
|
+
// 添加规则验证表单方法
|
|
171
140
|
Vue.prototype.$rulesValidateForm = rulesValidateForm
|
|
141
|
+
// 添加规则验证表单清除方法
|
|
172
142
|
Vue.prototype.$rulesValidateFormClear = rulesValidateFormClear
|
|
173
143
|
}
|
|
174
144
|
|
|
175
|
-
function rulesValidateForm(query, fn) {
|
|
145
|
+
async function rulesValidateForm(query, fn) {
|
|
176
146
|
let nodeList = document.querySelectorAll('.' + query)
|
|
177
|
-
|
|
147
|
+
let length = nodeList.length
|
|
148
|
+
if (length > 0) {
|
|
178
149
|
let validateList = []
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
}
|
|
189
|
-
})
|
|
190
|
-
.catch(() => {
|
|
150
|
+
for (let i = 0; i < length; i++) {
|
|
151
|
+
let el = nodeList[i]
|
|
152
|
+
if (typeof el[VALIDATE] === 'function') {
|
|
153
|
+
validateList.push(el[VALIDATE]('submit'))
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
try {
|
|
157
|
+
let res = await Promise.all(validateList)
|
|
158
|
+
if (res.includes(false)) {
|
|
191
159
|
fn && fn(false)
|
|
192
|
-
}
|
|
160
|
+
} else {
|
|
161
|
+
fn && fn(true)
|
|
162
|
+
}
|
|
163
|
+
} catch (err) {
|
|
164
|
+
fn && fn(false)
|
|
165
|
+
}
|
|
193
166
|
} else {
|
|
194
167
|
fn && fn(true)
|
|
195
168
|
return Promise.resolve()
|