yj-kikimore 0.1.0
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 +489 -0
- package/package.json +99 -0
- package/src/FormDialog/elementIsVisible.ts +7 -0
- package/src/FormDialog/highlightError.scss +85 -0
- package/src/FormDialog/highlightError.ts +84 -0
- package/src/FormDialog/index.vue +932 -0
- package/src/PopButton/index.vue +168 -0
- package/src/PopSwitch/index.vue +271 -0
- package/src/PopSwitch/utils.ts +9 -0
- package/src/Select/index.vue +480 -0
- package/src/index.ts +6 -0
- package/src/src/FormDialog/elementIsVisible.d.ts +2 -0
- package/src/src/FormDialog/highlightError.d.ts +2 -0
- package/src/src/PopSwitch/utils.d.ts +1 -0
- package/src/src/index.d.ts +5 -0
- package/src/src/utils.d.ts +8 -0
- package/src/utils.ts +80 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import './highlightError.scss'
|
|
2
|
+
import elementIsVisible from './elementIsVisible'
|
|
3
|
+
|
|
4
|
+
export default (
|
|
5
|
+
selectors: string | Element | NodeList = '.el-form .el-form-item.is-error',
|
|
6
|
+
container = window,
|
|
7
|
+
): void => {
|
|
8
|
+
const scrollIntoView = (element) => {
|
|
9
|
+
element.scrollIntoView({
|
|
10
|
+
behavior: 'smooth',
|
|
11
|
+
block: 'center',
|
|
12
|
+
})
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const animateCSS = (el, animationName) =>
|
|
16
|
+
new Promise<void>((resolve, reject) => {
|
|
17
|
+
if (el) {
|
|
18
|
+
// @ts-expect-error: none
|
|
19
|
+
for (const v of el instanceof NodeList ? el : [el]) {
|
|
20
|
+
v.classList.add('animate__animated', animationName)
|
|
21
|
+
|
|
22
|
+
const handleAnimationEnd = () => {
|
|
23
|
+
v.classList.remove('animate__animated', animationName)
|
|
24
|
+
v.removeEventListener('animationend', handleAnimationEnd)
|
|
25
|
+
resolve()
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
v.addEventListener('animationend', handleAnimationEnd)
|
|
29
|
+
}
|
|
30
|
+
} else {
|
|
31
|
+
reject()
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
// is-error类名需要异步才能获取到
|
|
36
|
+
setTimeout(() => {
|
|
37
|
+
const errFormItems =
|
|
38
|
+
typeof selectors === 'string' ? document.querySelectorAll(selectors) : selectors
|
|
39
|
+
|
|
40
|
+
// 打包后不生效
|
|
41
|
+
/* if (IntersectionObserver) {
|
|
42
|
+
const intersectionObserver = new IntersectionObserver((entries) => {
|
|
43
|
+
let [entry] = entries
|
|
44
|
+
if (entry.isIntersecting) {
|
|
45
|
+
console.log(entry)
|
|
46
|
+
// 对所有校验失败的表单项产生震动效果
|
|
47
|
+
setTimeout(() => {
|
|
48
|
+
animateCSS(errFormItems, 'animate__headShake').catch(e => {
|
|
49
|
+
console.warn(e)
|
|
50
|
+
})
|
|
51
|
+
}, 100)
|
|
52
|
+
}
|
|
53
|
+
})
|
|
54
|
+
intersectionObserver.observe(errFormItems[0])
|
|
55
|
+
} */
|
|
56
|
+
|
|
57
|
+
// 视图滚动至校验失败的第一个表单项
|
|
58
|
+
if (errFormItems[0]) {
|
|
59
|
+
if (elementIsVisible(errFormItems[0])) {
|
|
60
|
+
animateCSS(errFormItems, 'animate__headShake').catch((e) => {
|
|
61
|
+
console.warn(e)
|
|
62
|
+
})
|
|
63
|
+
} else {
|
|
64
|
+
let scrollTimeout: number
|
|
65
|
+
|
|
66
|
+
function shake() {
|
|
67
|
+
// 第二次触发会清除第一次,第三次触发会清除第二次...
|
|
68
|
+
// 直到最后一次超过100毫秒才清除,此时清除已经无效
|
|
69
|
+
// 100毫秒都没有触发,说明滚动停止
|
|
70
|
+
clearTimeout(scrollTimeout)
|
|
71
|
+
scrollTimeout = setTimeout(() => {
|
|
72
|
+
animateCSS(errFormItems, 'animate__headShake').catch((e) => {
|
|
73
|
+
console.warn(e)
|
|
74
|
+
})
|
|
75
|
+
container.removeEventListener('scroll', shake)
|
|
76
|
+
}, 100)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
container.addEventListener('scroll', shake)
|
|
80
|
+
scrollIntoView(errFormItems[0])
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}, 0)
|
|
84
|
+
}
|