cbvirtua 1.0.89 → 1.0.90
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
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { Directive, DirectiveBinding } from 'vue'
|
|
2
|
+
import { useTestStore } from '@/store/index'
|
|
3
|
+
|
|
4
|
+
// 存储高度
|
|
5
|
+
let originHeight = 0
|
|
6
|
+
|
|
7
|
+
// 视口变化 监听函数
|
|
8
|
+
const hanlderResize = (): void => {
|
|
9
|
+
const resizeHeight =
|
|
10
|
+
document.documentElement.clientHeight || document.body.clientHeight
|
|
11
|
+
if (originHeight < resizeHeight) {
|
|
12
|
+
// 安卓机下 用户收起键盘 同时input还有焦点
|
|
13
|
+
// 执行失去焦点逻辑
|
|
14
|
+
hanlderblur()
|
|
15
|
+
} else {
|
|
16
|
+
// 安卓机下 用户展开键盘 同时input还有焦点
|
|
17
|
+
// 执行获取焦点逻辑
|
|
18
|
+
handlerfocus()
|
|
19
|
+
}
|
|
20
|
+
originHeight = resizeHeight
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
// pinia 存储
|
|
25
|
+
const testStore = useTestStore()
|
|
26
|
+
|
|
27
|
+
// 失去焦点 展示 底部按钮
|
|
28
|
+
const hanlderblur = (): void => {
|
|
29
|
+
testStore.setFooterMenuType(true)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// 获取焦点 隐藏 底部按钮
|
|
33
|
+
const handlerfocus = (): void => {
|
|
34
|
+
testStore.setFooterMenuType(false)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
// 自定义指令
|
|
39
|
+
const keyboardExpansion: Directive = {
|
|
40
|
+
/**
|
|
41
|
+
el:指令绑定到的元素。这可以用于直接操作 DOM。
|
|
42
|
+
binding:一个对象,包含以下属性。
|
|
43
|
+
value:传递给指令的值。例如在 v-my-directive="1 + 1" 中,值是 2。
|
|
44
|
+
oldValue:之前的值,仅在 beforeUpdate 和 updated 中可用。无论值是否更改,它都可用。
|
|
45
|
+
arg:传递给指令的参数 (如果有的话)。例如在 v-my-directive:foo 中,参数是 "foo"。
|
|
46
|
+
modifiers:一个包含修饰符的对象 (如果有的话)。例如在 v-my-directive.foo.bar 中,修饰符对象是 { foo: true, bar: true }。
|
|
47
|
+
instance:使用该指令的组件实例。
|
|
48
|
+
dir:指令的定义对象。
|
|
49
|
+
**/
|
|
50
|
+
mounted (el: Element, binding: DirectiveBinding<any>) {
|
|
51
|
+
// 查找 目标元素
|
|
52
|
+
// 这里 inputElement 指的是 input/textarea
|
|
53
|
+
const inputElement: Element | null = ['INPUT', 'TEXTAREA'].includes(el.tagName)
|
|
54
|
+
? el
|
|
55
|
+
: el.querySelector('input') || el.querySelector('textarea')
|
|
56
|
+
// 绑定事件
|
|
57
|
+
inputElement?.addEventListener('blur', hanlderblur)
|
|
58
|
+
|
|
59
|
+
inputElement?.addEventListener('focus', handlerfocus)
|
|
60
|
+
|
|
61
|
+
// 判断 安卓机情况下 添加视口监听
|
|
62
|
+
if ((/android/i).test(navigator.userAgent)) {
|
|
63
|
+
originHeight = document.documentElement.clientHeight || document.body.clientHeight
|
|
64
|
+
window.addEventListener('resize', hanlderResize, false)
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
unmounted() {
|
|
68
|
+
if ((/android/i).test(navigator.userAgent)) {
|
|
69
|
+
// 指令元素 销毁前remove上面绑定的事件
|
|
70
|
+
window.removeEventListener('resize', hanlderResize, false)
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}bind:只调用一次,指令第一次绑定到元素时调用。在这里可以进行一次性的初始化设置。
|
|
74
|
+
|
|
75
|
+
inserted:被绑定元素插入父节点时调用 (仅保证父节点存在,但不一定已被插入文档中)。
|
|
76
|
+
|
|
77
|
+
update:所在组件的 VNode 更新时调用,但是可能发生在其子 VNode 更新之前。指令的值可能发生了改变,也可能没有。但是你可以通过比较更新前后的值来忽略不必要的模板更新 (详细的钩子函数参数见下)。
|
|
78
|
+
|
|
79
|
+
我们会在稍后讨论渲染函数时介绍更多 VNodes 的细节。
|
|
80
|
+
|
|
81
|
+
componentUpdated:指令所在组件的 VNode 及其子 VNode 全部更新后调用。
|
|
82
|
+
|
|
83
|
+
unbind:只调用一次,指令与元素解绑时调用。
|
|
84
|
+
|
|
85
|
+
@media (min-aspect-ratio: 13/20) {
|
|
86
|
+
.button {
|
|
87
|
+
display: none;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|