@94ai/nf-form-item 3.1.37 → 3.1.39
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/lib/nf-form-item.cjs.js +75 -1448
- package/lib/nf-form-item.esm-bundler.js +74 -1447
- package/package/index.ts +8 -0
- package/package/nf-form-item.vue +243 -0
- package/package/style/css.ts +1 -0
- package/package/style/index.ts +1 -0
- package/package/utils.ts +36 -0
- package/package.json +3 -3
package/package/index.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import NfFormItem from './nf-form-item.vue'
|
|
2
|
+
import { Vue2, PluginObject } from 'vue-demi'
|
|
3
|
+
|
|
4
|
+
NfFormItem.install = (app: typeof Vue2) => {
|
|
5
|
+
app!.component('nf-form-item', NfFormItem)
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export default NfFormItem as typeof NfFormItem & PluginObject<undefined>
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div
|
|
3
|
+
class="el-form-item nf-form-item"
|
|
4
|
+
:class="[{
|
|
5
|
+
'el-form-item--feedback': elForm && elForm.statusIcon,
|
|
6
|
+
'is-error': validateState === 'error',
|
|
7
|
+
'is-validating': validateState === 'validating',
|
|
8
|
+
'is-success': validateState === 'success',
|
|
9
|
+
'is-required': isRequired || required,
|
|
10
|
+
'is-no-asterisk': elForm && elForm.hideRequiredAsterisk,
|
|
11
|
+
},
|
|
12
|
+
sizeClass ? 'el-form-item--' + sizeClass : ''
|
|
13
|
+
]"
|
|
14
|
+
>
|
|
15
|
+
<label-wrap
|
|
16
|
+
:is-auto-width="labelStyle && labelStyle.width === 'auto'"
|
|
17
|
+
:update-all="form.labelWidth === 'auto'"
|
|
18
|
+
>
|
|
19
|
+
<label v-if="label || $slots.label" :for="labelFor" class="el-form-item__label" :style="labelStyle">
|
|
20
|
+
<slot name="label">{{ label + form.labelSuffix }}</slot>
|
|
21
|
+
</label>
|
|
22
|
+
</label-wrap>
|
|
23
|
+
<div class="el-form-item__content" :style="contentStyle">
|
|
24
|
+
<div v-if="isLastItem" class="nf-flex">
|
|
25
|
+
<slot />
|
|
26
|
+
<div v-if="showBtn" class="nf-ml10">
|
|
27
|
+
<el-button
|
|
28
|
+
class="nf-pointer"
|
|
29
|
+
@click="switchMode()"
|
|
30
|
+
:type="expandBtnType"
|
|
31
|
+
:icon="expandBtnIcon"
|
|
32
|
+
:plain="expandBtnPlain"
|
|
33
|
+
:size="expandBtnSize"
|
|
34
|
+
:round="expandBtnRound"
|
|
35
|
+
:circle="expandBtnCircle"
|
|
36
|
+
:loading="expandBtnLoading"
|
|
37
|
+
:disabled="expandBtnDisabled"
|
|
38
|
+
>
|
|
39
|
+
<i class="iconfont nf-fs12" :class="isExpand ? upIcon : downIcon" />
|
|
40
|
+
</el-button>
|
|
41
|
+
</div>
|
|
42
|
+
</div>
|
|
43
|
+
<slot v-else />
|
|
44
|
+
<transition name="el-zoom-in-top">
|
|
45
|
+
<slot
|
|
46
|
+
v-if="validateState === 'error' && showMessage && form.showMessage"
|
|
47
|
+
name="error"
|
|
48
|
+
:error="validateMessage"
|
|
49
|
+
>
|
|
50
|
+
<div
|
|
51
|
+
class="el-form-item__error"
|
|
52
|
+
:class="{
|
|
53
|
+
'el-form-item__error--inline': typeof inlineMessage === 'boolean'
|
|
54
|
+
? inlineMessage
|
|
55
|
+
: (elForm && elForm.inlineMessage || false)
|
|
56
|
+
}"
|
|
57
|
+
>
|
|
58
|
+
{{ validateMessage }}
|
|
59
|
+
</div>
|
|
60
|
+
</slot>
|
|
61
|
+
</transition>
|
|
62
|
+
</div>
|
|
63
|
+
</div>
|
|
64
|
+
</template>
|
|
65
|
+
|
|
66
|
+
<script lang="ts">
|
|
67
|
+
import { defineComponent, nextTick } from 'vue-demi'
|
|
68
|
+
import { FormItem } from 'element-ui'
|
|
69
|
+
|
|
70
|
+
export default defineComponent({
|
|
71
|
+
name: 'NfFormItem',
|
|
72
|
+
extends: FormItem,
|
|
73
|
+
props: {
|
|
74
|
+
hidden: {
|
|
75
|
+
type: Boolean,
|
|
76
|
+
default: false
|
|
77
|
+
},
|
|
78
|
+
expandBtnType: {
|
|
79
|
+
type: String,
|
|
80
|
+
default: 'default'
|
|
81
|
+
},
|
|
82
|
+
expandBtnIcon: {
|
|
83
|
+
type: String,
|
|
84
|
+
default: undefined
|
|
85
|
+
},
|
|
86
|
+
expandBtnPlain: {
|
|
87
|
+
type: Boolean,
|
|
88
|
+
default: false
|
|
89
|
+
},
|
|
90
|
+
expandBtnSize: {
|
|
91
|
+
type: String,
|
|
92
|
+
default: 'mini'
|
|
93
|
+
},
|
|
94
|
+
expandBtnRound: {
|
|
95
|
+
type: Boolean,
|
|
96
|
+
default: false
|
|
97
|
+
},
|
|
98
|
+
expandBtnCircle: {
|
|
99
|
+
type: Boolean,
|
|
100
|
+
default: false
|
|
101
|
+
},
|
|
102
|
+
expandBtnLoading: {
|
|
103
|
+
type: Boolean,
|
|
104
|
+
default: false
|
|
105
|
+
},
|
|
106
|
+
expandBtnDisabled: {
|
|
107
|
+
type: Boolean,
|
|
108
|
+
default: false
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
data() {
|
|
112
|
+
return {
|
|
113
|
+
isExpand: true,
|
|
114
|
+
initExpand: false,
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
watch: {
|
|
118
|
+
labelPosition() {
|
|
119
|
+
// @ts-ignore
|
|
120
|
+
this.refreshButtonList()
|
|
121
|
+
},
|
|
122
|
+
columns() {
|
|
123
|
+
// @ts-ignore
|
|
124
|
+
this.refreshButtonList()
|
|
125
|
+
},
|
|
126
|
+
inline() {
|
|
127
|
+
// @ts-ignore
|
|
128
|
+
this.refreshButtonList()
|
|
129
|
+
},
|
|
130
|
+
isCollapse() {
|
|
131
|
+
// @ts-ignore
|
|
132
|
+
this.isExpand = !this.form?.isCollapse
|
|
133
|
+
// @ts-ignore
|
|
134
|
+
if (this.initExpand) {
|
|
135
|
+
// @ts-ignore
|
|
136
|
+
this.switchMode()
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
mounted() {
|
|
141
|
+
// @ts-ignore
|
|
142
|
+
if (this.form?.init) {
|
|
143
|
+
// @ts-ignore
|
|
144
|
+
this.form?.getFormItems()
|
|
145
|
+
}
|
|
146
|
+
nextTick(() => {
|
|
147
|
+
if (!this.initExpand) {
|
|
148
|
+
// @ts-ignore
|
|
149
|
+
this.isExpand = !this.form?.isCollapse
|
|
150
|
+
if (!this.isExpand) {
|
|
151
|
+
// @ts-ignore
|
|
152
|
+
this.refreshButtonList()
|
|
153
|
+
}
|
|
154
|
+
this.initExpand = true
|
|
155
|
+
} else {
|
|
156
|
+
// @ts-ignore
|
|
157
|
+
this.refreshButtonList()
|
|
158
|
+
}
|
|
159
|
+
})
|
|
160
|
+
},
|
|
161
|
+
computed: {
|
|
162
|
+
downIcon() {
|
|
163
|
+
// @ts-ignore
|
|
164
|
+
return this.form?.downIcon
|
|
165
|
+
},
|
|
166
|
+
upIcon() {
|
|
167
|
+
// @ts-ignore
|
|
168
|
+
return this.form?.upIcon
|
|
169
|
+
},
|
|
170
|
+
isCollapse() {
|
|
171
|
+
// @ts-ignore
|
|
172
|
+
return this.form?.isCollapse
|
|
173
|
+
},
|
|
174
|
+
labelPosition() {
|
|
175
|
+
// @ts-ignore
|
|
176
|
+
return this.form?.labelPosition
|
|
177
|
+
},
|
|
178
|
+
inline() {
|
|
179
|
+
// @ts-ignore
|
|
180
|
+
return this.form?.inline
|
|
181
|
+
},
|
|
182
|
+
columns() {
|
|
183
|
+
// @ts-ignore
|
|
184
|
+
return this.form?.columns
|
|
185
|
+
},
|
|
186
|
+
showBtn() {
|
|
187
|
+
if (this.hidden) return false
|
|
188
|
+
// @ts-ignore
|
|
189
|
+
if (!this.form?.showBtn) return false
|
|
190
|
+
// @ts-ignore
|
|
191
|
+
return this.form?.formItems.length > this.columns
|
|
192
|
+
},
|
|
193
|
+
isLastItem() {
|
|
194
|
+
// @ts-ignore
|
|
195
|
+
if (!this.showBtn) return false
|
|
196
|
+
// const uIds = []
|
|
197
|
+
// // @ts-ignore
|
|
198
|
+
// this.form?.formItems.forEach(item => {
|
|
199
|
+
// // @ts-ignore
|
|
200
|
+
// uIds.push(item._uid)
|
|
201
|
+
// })
|
|
202
|
+
// // 取最大值
|
|
203
|
+
// const max = Math.max(...uIds)
|
|
204
|
+
// return this._uid === max
|
|
205
|
+
// @ts-ignore
|
|
206
|
+
const items = this.form?.formItems
|
|
207
|
+
return this._uid === items?.[items?.length - 1]?._uid
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
methods: {
|
|
211
|
+
refreshButtonList() {
|
|
212
|
+
// @ts-ignore
|
|
213
|
+
if (this.form?.showBtn) {
|
|
214
|
+
// @ts-ignore
|
|
215
|
+
this.form?.formItems.forEach((item, index) => {
|
|
216
|
+
const idx = index + 1
|
|
217
|
+
// getComputedStyle(item.$el).display
|
|
218
|
+
// @ts-ignore
|
|
219
|
+
item.$el.style.display = this.form?.inline ? 'inline-block' : 'block'
|
|
220
|
+
// @ts-ignore
|
|
221
|
+
if (idx > this.columns - 1 && idx < this.form?.formItems.length) {
|
|
222
|
+
if (!this.isExpand) {
|
|
223
|
+
// @ts-ignore
|
|
224
|
+
item.$el.style.display = 'none'
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
})
|
|
228
|
+
}
|
|
229
|
+
},
|
|
230
|
+
// 切换显示模式
|
|
231
|
+
switchMode() {
|
|
232
|
+
// @ts-ignore
|
|
233
|
+
this.isExpand = !this.isExpand
|
|
234
|
+
// @ts-ignore
|
|
235
|
+
this.form?.$emit('isCollapseChange', this.isExpand)
|
|
236
|
+
// @ts-ignore
|
|
237
|
+
this.refreshButtonList()
|
|
238
|
+
},
|
|
239
|
+
}
|
|
240
|
+
})
|
|
241
|
+
</script>
|
|
242
|
+
|
|
243
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@94ai/nf-theme-chalk/lib/css/nf-form-item.css'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@94ai/nf-theme-chalk/lib/nf-form-item.scss'
|
package/package/utils.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export function debounce(func, wait, immediate) {
|
|
2
|
+
let timeout, args, context, timestamp, result
|
|
3
|
+
|
|
4
|
+
const later = function() {
|
|
5
|
+
// 据上一次触发时间间隔
|
|
6
|
+
const last = +new Date() - timestamp
|
|
7
|
+
|
|
8
|
+
// 上次被包装函数被调用时间间隔last小于设定时间间隔wait
|
|
9
|
+
if (last < wait && last > 0) {
|
|
10
|
+
timeout = setTimeout(later, wait - last)
|
|
11
|
+
} else {
|
|
12
|
+
timeout = null
|
|
13
|
+
// 如果设定为immediate===true,因为开始边界已经调用过了此处无需调用
|
|
14
|
+
if (!immediate) {
|
|
15
|
+
result = func.apply(context, args)
|
|
16
|
+
if (!timeout) context = args = null
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return function(...args) {
|
|
22
|
+
// @ts-ignore
|
|
23
|
+
context = this
|
|
24
|
+
timestamp = +new Date()
|
|
25
|
+
const callNow = immediate && !timeout
|
|
26
|
+
// 如果延时不存在,重新设定延时
|
|
27
|
+
if (!timeout) timeout = setTimeout(later, wait)
|
|
28
|
+
if (callNow) {
|
|
29
|
+
result = func.apply(context, args)
|
|
30
|
+
// @ts-ignore
|
|
31
|
+
context = args = null
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return result
|
|
35
|
+
}
|
|
36
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@94ai/nf-form-item",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.39",
|
|
4
4
|
"description": "> TODO: description",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"author": "zoujiahe <zoujiahe@94ai.com>",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"url": "http://94ai.gitlab.com/zoujiahe/common-ui.git"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@94ai/nf-theme-chalk": "^
|
|
17
|
+
"@94ai/nf-theme-chalk": "^1.0.0",
|
|
18
18
|
"vue-demi": "^0.14.5"
|
|
19
19
|
},
|
|
20
20
|
"peerDependenciesMeta": {
|
|
@@ -30,5 +30,5 @@
|
|
|
30
30
|
"types": "lib/index.d.ts",
|
|
31
31
|
"main": "lib/nf-form-item.cjs.js",
|
|
32
32
|
"module": "lib/nf-form-item.esm-bundler.js",
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "2b60696b405feafbbaeed385e5bcf666ceefbf2c"
|
|
34
34
|
}
|