@vxe-ui/core 3.0.20 → 3.0.22
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 -21
- package/README.md +29 -29
- package/es/src/core.js +1 -1
- package/es/src/log.js +1 -1
- package/es/src/mixins.js +2 -2
- package/lib/index.umd.js +856 -88
- package/lib/index.umd.min.js +1 -1
- package/lib/src/core.js +1 -1
- package/lib/src/core.min.js +1 -1
- package/lib/src/log.js +1 -1
- package/lib/src/log.min.js +1 -1
- package/lib/src/mixins.js +2 -2
- package/lib/src/mixins.min.js +1 -1
- package/package.json +80 -80
- package/packages/index.ts +115 -115
- package/packages/src/clipboard.ts +53 -53
- package/packages/src/commands.ts +62 -62
- package/packages/src/config.ts +30 -30
- package/packages/src/configStore.ts +8 -8
- package/packages/src/core.ts +9 -9
- package/packages/src/dataStore.ts +4 -4
- package/packages/src/event.ts +127 -127
- package/packages/src/formats.ts +62 -62
- package/packages/src/i18n.ts +46 -46
- package/packages/src/i18nStore.ts +16 -16
- package/packages/src/icon.ts +16 -16
- package/packages/src/iconStore.ts +3 -3
- package/packages/src/interceptor.ts +65 -65
- package/packages/src/log.ts +19 -19
- package/packages/src/menus.ts +62 -62
- package/packages/src/mixins.ts +39 -39
- package/packages/src/permission.ts +61 -61
- package/packages/src/renderer.ts +50 -50
- package/packages/src/resize.ts +89 -89
- package/packages/src/store.ts +49 -49
- package/packages/src/theme.ts +20 -20
- package/packages/src/themeStore.ts +7 -7
- package/packages/src/validators.ts +9 -9
- package/types/core/clipboard.d.ts +13 -13
- package/types/core/commands.d.ts +19 -19
- package/types/core/components.d.ts +4 -4
- package/types/core/formats.d.ts +19 -19
- package/types/core/global-config.d.ts +62 -62
- package/types/core/global-data.d.ts +7 -7
- package/types/core/global-event.d.ts +39 -39
- package/types/core/global-icon.d.ts +6 -6
- package/types/core/global-lang.d.ts +22 -22
- package/types/core/global-resize.d.ts +3 -3
- package/types/core/global-theme.d.ts +1 -1
- package/types/core/index.d.ts +246 -246
- package/types/core/interceptor.d.ts +22 -22
- package/types/core/log.d.ts +8 -8
- package/types/core/menus.d.ts +19 -19
- package/types/core/mixins.d.ts +16 -16
- package/types/core/permission.d.ts +10 -10
- package/types/core/renderer.d.ts +14 -14
- package/types/core/validators.d.ts +19 -19
- package/types/index.d.ts +13 -13
- package/types/tool/common.d.ts +105 -105
- package/types/tool/index.d.ts +2 -2
- package/types/tool/util.d.ts +4 -4
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
import XEUtils from 'xe-utils'
|
|
2
|
-
|
|
3
|
-
import { VxeGlobalClipboard } from '../../types'
|
|
4
|
-
|
|
5
|
-
let copyElem: HTMLTextAreaElement
|
|
6
|
-
const clipStore = {
|
|
7
|
-
text: '',
|
|
8
|
-
html: ''
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
function handleText (text: string) {
|
|
12
|
-
if (!copyElem) {
|
|
13
|
-
copyElem = document.createElement('textarea')
|
|
14
|
-
copyElem.id = '$VxeCopy'
|
|
15
|
-
const styles = copyElem.style
|
|
16
|
-
styles.width = '48px'
|
|
17
|
-
styles.height = '24px'
|
|
18
|
-
styles.position = 'fixed'
|
|
19
|
-
styles.zIndex = '0'
|
|
20
|
-
styles.left = '-500px'
|
|
21
|
-
styles.top = '-500px'
|
|
22
|
-
document.body.appendChild(copyElem)
|
|
23
|
-
}
|
|
24
|
-
copyElem.value = text
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export const clipboard: VxeGlobalClipboard = {
|
|
28
|
-
getStore () {
|
|
29
|
-
return clipStore
|
|
30
|
-
},
|
|
31
|
-
setStore (data) {
|
|
32
|
-
Object.assign(clipStore, data || {})
|
|
33
|
-
},
|
|
34
|
-
/**
|
|
35
|
-
* 复制内容到剪贴板
|
|
36
|
-
*
|
|
37
|
-
* @param {String} content Text 内容
|
|
38
|
-
*/
|
|
39
|
-
copy (content) {
|
|
40
|
-
let result = false
|
|
41
|
-
try {
|
|
42
|
-
const text = XEUtils.toValueString(content)
|
|
43
|
-
handleText(text)
|
|
44
|
-
copyElem.select()
|
|
45
|
-
copyElem.setSelectionRange(0, copyElem.value.length)
|
|
46
|
-
result = document.execCommand('copy')
|
|
47
|
-
copyElem.blur()
|
|
48
|
-
clipStore.text = text
|
|
49
|
-
clipStore.html = ''
|
|
50
|
-
} catch (e) {}
|
|
51
|
-
return result
|
|
52
|
-
}
|
|
53
|
-
}
|
|
1
|
+
import XEUtils from 'xe-utils'
|
|
2
|
+
|
|
3
|
+
import { VxeGlobalClipboard } from '../../types'
|
|
4
|
+
|
|
5
|
+
let copyElem: HTMLTextAreaElement
|
|
6
|
+
const clipStore = {
|
|
7
|
+
text: '',
|
|
8
|
+
html: ''
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function handleText (text: string) {
|
|
12
|
+
if (!copyElem) {
|
|
13
|
+
copyElem = document.createElement('textarea')
|
|
14
|
+
copyElem.id = '$VxeCopy'
|
|
15
|
+
const styles = copyElem.style
|
|
16
|
+
styles.width = '48px'
|
|
17
|
+
styles.height = '24px'
|
|
18
|
+
styles.position = 'fixed'
|
|
19
|
+
styles.zIndex = '0'
|
|
20
|
+
styles.left = '-500px'
|
|
21
|
+
styles.top = '-500px'
|
|
22
|
+
document.body.appendChild(copyElem)
|
|
23
|
+
}
|
|
24
|
+
copyElem.value = text
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const clipboard: VxeGlobalClipboard = {
|
|
28
|
+
getStore () {
|
|
29
|
+
return clipStore
|
|
30
|
+
},
|
|
31
|
+
setStore (data) {
|
|
32
|
+
Object.assign(clipStore, data || {})
|
|
33
|
+
},
|
|
34
|
+
/**
|
|
35
|
+
* 复制内容到剪贴板
|
|
36
|
+
*
|
|
37
|
+
* @param {String} content Text 内容
|
|
38
|
+
*/
|
|
39
|
+
copy (content) {
|
|
40
|
+
let result = false
|
|
41
|
+
try {
|
|
42
|
+
const text = XEUtils.toValueString(content)
|
|
43
|
+
handleText(text)
|
|
44
|
+
copyElem.select()
|
|
45
|
+
copyElem.setSelectionRange(0, copyElem.value.length)
|
|
46
|
+
result = document.execCommand('copy')
|
|
47
|
+
copyElem.blur()
|
|
48
|
+
clipStore.text = text
|
|
49
|
+
clipStore.html = ''
|
|
50
|
+
} catch (e) {}
|
|
51
|
+
return result
|
|
52
|
+
}
|
|
53
|
+
}
|
package/packages/src/commands.ts
CHANGED
|
@@ -1,62 +1,62 @@
|
|
|
1
|
-
import XEUtils from 'xe-utils'
|
|
2
|
-
import { log } from './log'
|
|
3
|
-
|
|
4
|
-
import { VxeGlobalCommands } from '../../types'
|
|
5
|
-
|
|
6
|
-
class VXECommandsStore {
|
|
7
|
-
private store: any = {}
|
|
8
|
-
|
|
9
|
-
mixin (options: any): VXECommandsStore {
|
|
10
|
-
XEUtils.each(options, (item, key) => {
|
|
11
|
-
this.add(key, item)
|
|
12
|
-
})
|
|
13
|
-
return this
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
has (name: string): boolean {
|
|
17
|
-
return !!this.get(name)
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
get (name: string): any {
|
|
21
|
-
return this.store[name]
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
add (name: string, render: any): VXECommandsStore {
|
|
25
|
-
const conf = this.store[name]
|
|
26
|
-
// 兼容
|
|
27
|
-
if (XEUtils.isFunction(render)) {
|
|
28
|
-
if (process.env.VUE_APP_VXE_ENV === 'development') {
|
|
29
|
-
log.warn('vxe.error.delProp', ['commands -> callback', 'commandMethod'])
|
|
30
|
-
}
|
|
31
|
-
render = {
|
|
32
|
-
commandMethod: render
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// 检测是否覆盖
|
|
37
|
-
if (process.env.VUE_APP_VXE_ENV === 'development') {
|
|
38
|
-
const confKeys = XEUtils.keys(conf)
|
|
39
|
-
XEUtils.each(render, (item, key) => {
|
|
40
|
-
if (confKeys.includes(key)) {
|
|
41
|
-
log.warn('vxe.error.coverProp', [name, key])
|
|
42
|
-
}
|
|
43
|
-
})
|
|
44
|
-
}
|
|
45
|
-
this.store[name] = conf ? XEUtils.merge(conf, render) : render
|
|
46
|
-
return this
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
delete (name: string): void {
|
|
50
|
-
delete this.store[name]
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
forEach (callback: any): void {
|
|
54
|
-
XEUtils.objectEach(this.store, callback)
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export const commands = new VXECommandsStore() as VxeGlobalCommands
|
|
59
|
-
|
|
60
|
-
if (process.env.VUE_APP_VXE_ENV === 'development') {
|
|
61
|
-
Object.assign(commands, { _name: 'Commands' })
|
|
62
|
-
}
|
|
1
|
+
import XEUtils from 'xe-utils'
|
|
2
|
+
import { log } from './log'
|
|
3
|
+
|
|
4
|
+
import { VxeGlobalCommands } from '../../types'
|
|
5
|
+
|
|
6
|
+
class VXECommandsStore {
|
|
7
|
+
private store: any = {}
|
|
8
|
+
|
|
9
|
+
mixin (options: any): VXECommandsStore {
|
|
10
|
+
XEUtils.each(options, (item, key) => {
|
|
11
|
+
this.add(key, item)
|
|
12
|
+
})
|
|
13
|
+
return this
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
has (name: string): boolean {
|
|
17
|
+
return !!this.get(name)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
get (name: string): any {
|
|
21
|
+
return this.store[name]
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
add (name: string, render: any): VXECommandsStore {
|
|
25
|
+
const conf = this.store[name]
|
|
26
|
+
// 兼容
|
|
27
|
+
if (XEUtils.isFunction(render)) {
|
|
28
|
+
if (process.env.VUE_APP_VXE_ENV === 'development') {
|
|
29
|
+
log.warn('vxe.error.delProp', ['commands -> callback', 'commandMethod'])
|
|
30
|
+
}
|
|
31
|
+
render = {
|
|
32
|
+
commandMethod: render
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// 检测是否覆盖
|
|
37
|
+
if (process.env.VUE_APP_VXE_ENV === 'development') {
|
|
38
|
+
const confKeys = XEUtils.keys(conf)
|
|
39
|
+
XEUtils.each(render, (item, key) => {
|
|
40
|
+
if (confKeys.includes(key)) {
|
|
41
|
+
log.warn('vxe.error.coverProp', [name, key])
|
|
42
|
+
}
|
|
43
|
+
})
|
|
44
|
+
}
|
|
45
|
+
this.store[name] = conf ? XEUtils.merge(conf, render) : render
|
|
46
|
+
return this
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
delete (name: string): void {
|
|
50
|
+
delete this.store[name]
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
forEach (callback: any): void {
|
|
54
|
+
XEUtils.objectEach(this.store, callback)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export const commands = new VXECommandsStore() as VxeGlobalCommands
|
|
59
|
+
|
|
60
|
+
if (process.env.VUE_APP_VXE_ENV === 'development') {
|
|
61
|
+
Object.assign(commands, { _name: 'Commands' })
|
|
62
|
+
}
|
package/packages/src/config.ts
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import XEUtils from 'xe-utils'
|
|
2
|
-
import DomZIndex from 'dom-zindex'
|
|
3
|
-
import { VxeCore } from './core'
|
|
4
|
-
import { globalConfigStore } from './configStore'
|
|
5
|
-
import { setTheme } from './theme'
|
|
6
|
-
|
|
7
|
-
import { VxeGlobalConfig } from '../../types'
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* 全局参数设置
|
|
11
|
-
*/
|
|
12
|
-
export function setConfig (options?: VxeGlobalConfig) {
|
|
13
|
-
if (options) {
|
|
14
|
-
if (options.zIndex) {
|
|
15
|
-
DomZIndex.setCurrent(options.zIndex)
|
|
16
|
-
}
|
|
17
|
-
if (options.theme) {
|
|
18
|
-
setTheme(options.theme)
|
|
19
|
-
}
|
|
20
|
-
XEUtils.merge(globalConfigStore, options)
|
|
21
|
-
}
|
|
22
|
-
return VxeCore
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* 获取全局参数
|
|
27
|
-
*/
|
|
28
|
-
export function getConfig (key: keyof VxeGlobalConfig, defaultValue?: any) {
|
|
29
|
-
return arguments.length ? XEUtils.get(globalConfigStore, key, defaultValue) : globalConfigStore
|
|
30
|
-
}
|
|
1
|
+
import XEUtils from 'xe-utils'
|
|
2
|
+
import DomZIndex from 'dom-zindex'
|
|
3
|
+
import { VxeCore } from './core'
|
|
4
|
+
import { globalConfigStore } from './configStore'
|
|
5
|
+
import { setTheme } from './theme'
|
|
6
|
+
|
|
7
|
+
import { VxeGlobalConfig } from '../../types'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 全局参数设置
|
|
11
|
+
*/
|
|
12
|
+
export function setConfig (options?: VxeGlobalConfig) {
|
|
13
|
+
if (options) {
|
|
14
|
+
if (options.zIndex) {
|
|
15
|
+
DomZIndex.setCurrent(options.zIndex)
|
|
16
|
+
}
|
|
17
|
+
if (options.theme) {
|
|
18
|
+
setTheme(options.theme)
|
|
19
|
+
}
|
|
20
|
+
XEUtils.merge(globalConfigStore, options)
|
|
21
|
+
}
|
|
22
|
+
return VxeCore
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 获取全局参数
|
|
27
|
+
*/
|
|
28
|
+
export function getConfig (key: keyof VxeGlobalConfig, defaultValue?: any) {
|
|
29
|
+
return arguments.length ? XEUtils.get(globalConfigStore, key, defaultValue) : globalConfigStore
|
|
30
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { VxeGlobalConfig } from '../../types'
|
|
2
|
-
|
|
3
|
-
export const globalConfigStore: VxeGlobalConfig = {
|
|
4
|
-
size: '',
|
|
5
|
-
version: 1,
|
|
6
|
-
zIndex: 999,
|
|
7
|
-
resizeInterval: 500
|
|
8
|
-
}
|
|
1
|
+
import { VxeGlobalConfig } from '../../types'
|
|
2
|
+
|
|
3
|
+
export const globalConfigStore: VxeGlobalConfig = {
|
|
4
|
+
size: '',
|
|
5
|
+
version: 1,
|
|
6
|
+
zIndex: 999,
|
|
7
|
+
resizeInterval: 500
|
|
8
|
+
}
|
package/packages/src/core.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { VxeUIExport } from '../../types'
|
|
2
|
-
|
|
3
|
-
export const coreVersion = process.env.VUE_APP_VXE_VERSION as string
|
|
4
|
-
|
|
5
|
-
export const VxeCore = {
|
|
6
|
-
coreVersion,
|
|
7
|
-
uiVersion: '',
|
|
8
|
-
tableVersion: ''
|
|
9
|
-
} as VxeUIExport
|
|
1
|
+
import { VxeUIExport } from '../../types'
|
|
2
|
+
|
|
3
|
+
export const coreVersion = process.env.VUE_APP_VXE_VERSION as string
|
|
4
|
+
|
|
5
|
+
export const VxeCore = {
|
|
6
|
+
coreVersion,
|
|
7
|
+
uiVersion: '',
|
|
8
|
+
tableVersion: ''
|
|
9
|
+
} as VxeUIExport
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { VxeGlobalData } from '../../types'
|
|
2
|
-
|
|
3
|
-
export const globalStore: VxeGlobalData = {
|
|
4
|
-
}
|
|
1
|
+
import { VxeGlobalData } from '../../types'
|
|
2
|
+
|
|
3
|
+
export const globalStore: VxeGlobalData = {
|
|
4
|
+
}
|
package/packages/src/event.ts
CHANGED
|
@@ -1,127 +1,127 @@
|
|
|
1
|
-
import XEUtils from 'xe-utils'
|
|
2
|
-
|
|
3
|
-
import type { VxeGlobalEvents, VxeComponentBaseOptions, VxeGlobalCreateEventMethod, VxeGlobalEventKey } from '../../types'
|
|
4
|
-
|
|
5
|
-
export const GLOBAL_EVENT_KEYS: VxeGlobalEventKey = {
|
|
6
|
-
F2: 'F2',
|
|
7
|
-
ESCAPE: 'Escape',
|
|
8
|
-
ENTER: 'Enter',
|
|
9
|
-
TAB: 'Tab',
|
|
10
|
-
DELETE: 'Delete',
|
|
11
|
-
BACKSPACE: 'Backspace',
|
|
12
|
-
SPACEBAR: ' ',
|
|
13
|
-
CONTEXT_MENU: 'ContextMenu',
|
|
14
|
-
ARROW_UP: 'ArrowUp',
|
|
15
|
-
ARROW_DOWN: 'ArrowDown',
|
|
16
|
-
ARROW_LEFT: 'ArrowLeft',
|
|
17
|
-
ARROW_RIGHT: 'ArrowRight',
|
|
18
|
-
PAGE_UP: 'PageUp',
|
|
19
|
-
PAGE_DOWN: 'PageDown',
|
|
20
|
-
R: 'R',
|
|
21
|
-
P: 'P',
|
|
22
|
-
Z: 'Z',
|
|
23
|
-
X: 'X',
|
|
24
|
-
C: 'C',
|
|
25
|
-
V: 'V',
|
|
26
|
-
M: 'M'
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const browse = XEUtils.browse()
|
|
30
|
-
|
|
31
|
-
const convertEventKeys: { [key: string]: string } = {
|
|
32
|
-
' ': 'Spacebar',
|
|
33
|
-
Apps: GLOBAL_EVENT_KEYS.CONTEXT_MENU,
|
|
34
|
-
Del: GLOBAL_EVENT_KEYS.DELETE,
|
|
35
|
-
Up: GLOBAL_EVENT_KEYS.ARROW_UP,
|
|
36
|
-
Down: GLOBAL_EVENT_KEYS.ARROW_DOWN,
|
|
37
|
-
Left: GLOBAL_EVENT_KEYS.ARROW_LEFT,
|
|
38
|
-
Right: GLOBAL_EVENT_KEYS.ARROW_RIGHT
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// 监听全局事件
|
|
42
|
-
const wheelName = browse.firefox ? 'DOMMouseScroll' : 'mousewheel'
|
|
43
|
-
const eventStore: {
|
|
44
|
-
comp: VxeComponentBaseOptions;
|
|
45
|
-
type: string;
|
|
46
|
-
cb: (evnt: Event) => void;
|
|
47
|
-
}[] = []
|
|
48
|
-
|
|
49
|
-
function triggerEvent (evnt: Event) {
|
|
50
|
-
const isWheel = evnt.type === wheelName
|
|
51
|
-
eventStore.forEach(({ type, cb }) => {
|
|
52
|
-
// 如果被取消冒泡,不再执行
|
|
53
|
-
if (!evnt.cancelBubble) {
|
|
54
|
-
if (type === evnt.type || (isWheel && type === 'mousewheel')) {
|
|
55
|
-
cb(evnt)
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
})
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
class VxeComponentEvent {
|
|
62
|
-
$event: Event
|
|
63
|
-
type = ''
|
|
64
|
-
key = ''
|
|
65
|
-
code = ''
|
|
66
|
-
constructor (evnt: Event, params1: any, params2?: any) {
|
|
67
|
-
this.$event = evnt
|
|
68
|
-
if (evnt) {
|
|
69
|
-
if ((evnt as KeyboardEvent).type) {
|
|
70
|
-
this.type = (evnt as KeyboardEvent).type
|
|
71
|
-
}
|
|
72
|
-
if ((evnt as KeyboardEvent).key) {
|
|
73
|
-
this.key = (evnt as KeyboardEvent).key
|
|
74
|
-
}
|
|
75
|
-
if ((evnt as KeyboardEvent).code) {
|
|
76
|
-
this.code = (evnt as KeyboardEvent).code
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
Object.assign(this, params1, params2)
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
stopPropagation () {
|
|
83
|
-
const evnt = this.$event
|
|
84
|
-
if (evnt) {
|
|
85
|
-
evnt.stopPropagation()
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
preventDefault () {
|
|
90
|
-
const evnt = this.$event
|
|
91
|
-
if (evnt) {
|
|
92
|
-
evnt.preventDefault()
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export const createEvent: VxeGlobalCreateEventMethod = (evnt, params1, params2) => {
|
|
98
|
-
return new VxeComponentEvent(evnt as Event, params1, params2)
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
export const globalEvents: VxeGlobalEvents = {
|
|
102
|
-
on (comp, type, cb) {
|
|
103
|
-
eventStore.push({ comp, type, cb })
|
|
104
|
-
},
|
|
105
|
-
off (comp, type) {
|
|
106
|
-
XEUtils.remove(eventStore, item => item.comp === comp && item.type === type)
|
|
107
|
-
},
|
|
108
|
-
hasKey (evnt, targetKey) {
|
|
109
|
-
const { key } = evnt
|
|
110
|
-
targetKey = targetKey.toLowerCase()
|
|
111
|
-
return key ? (targetKey === key.toLowerCase() || !!(convertEventKeys[key] && convertEventKeys[key].toLowerCase() === targetKey)) : false
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
if (browse.isDoc) {
|
|
116
|
-
if (!browse.msie) {
|
|
117
|
-
window.addEventListener('copy', triggerEvent, false)
|
|
118
|
-
window.addEventListener('cut', triggerEvent, false)
|
|
119
|
-
window.addEventListener('paste', triggerEvent, false)
|
|
120
|
-
}
|
|
121
|
-
document.addEventListener('keydown', triggerEvent, false)
|
|
122
|
-
document.addEventListener('contextmenu', triggerEvent, false)
|
|
123
|
-
window.addEventListener('mousedown', triggerEvent, false)
|
|
124
|
-
window.addEventListener('blur', triggerEvent, false)
|
|
125
|
-
window.addEventListener('resize', triggerEvent, false)
|
|
126
|
-
window.addEventListener(wheelName, XEUtils.throttle(triggerEvent, 100, { leading: true, trailing: false }), { passive: true, capture: false })
|
|
127
|
-
}
|
|
1
|
+
import XEUtils from 'xe-utils'
|
|
2
|
+
|
|
3
|
+
import type { VxeGlobalEvents, VxeComponentBaseOptions, VxeGlobalCreateEventMethod, VxeGlobalEventKey } from '../../types'
|
|
4
|
+
|
|
5
|
+
export const GLOBAL_EVENT_KEYS: VxeGlobalEventKey = {
|
|
6
|
+
F2: 'F2',
|
|
7
|
+
ESCAPE: 'Escape',
|
|
8
|
+
ENTER: 'Enter',
|
|
9
|
+
TAB: 'Tab',
|
|
10
|
+
DELETE: 'Delete',
|
|
11
|
+
BACKSPACE: 'Backspace',
|
|
12
|
+
SPACEBAR: ' ',
|
|
13
|
+
CONTEXT_MENU: 'ContextMenu',
|
|
14
|
+
ARROW_UP: 'ArrowUp',
|
|
15
|
+
ARROW_DOWN: 'ArrowDown',
|
|
16
|
+
ARROW_LEFT: 'ArrowLeft',
|
|
17
|
+
ARROW_RIGHT: 'ArrowRight',
|
|
18
|
+
PAGE_UP: 'PageUp',
|
|
19
|
+
PAGE_DOWN: 'PageDown',
|
|
20
|
+
R: 'R',
|
|
21
|
+
P: 'P',
|
|
22
|
+
Z: 'Z',
|
|
23
|
+
X: 'X',
|
|
24
|
+
C: 'C',
|
|
25
|
+
V: 'V',
|
|
26
|
+
M: 'M'
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const browse = XEUtils.browse()
|
|
30
|
+
|
|
31
|
+
const convertEventKeys: { [key: string]: string } = {
|
|
32
|
+
' ': 'Spacebar',
|
|
33
|
+
Apps: GLOBAL_EVENT_KEYS.CONTEXT_MENU,
|
|
34
|
+
Del: GLOBAL_EVENT_KEYS.DELETE,
|
|
35
|
+
Up: GLOBAL_EVENT_KEYS.ARROW_UP,
|
|
36
|
+
Down: GLOBAL_EVENT_KEYS.ARROW_DOWN,
|
|
37
|
+
Left: GLOBAL_EVENT_KEYS.ARROW_LEFT,
|
|
38
|
+
Right: GLOBAL_EVENT_KEYS.ARROW_RIGHT
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// 监听全局事件
|
|
42
|
+
const wheelName = browse.firefox ? 'DOMMouseScroll' : 'mousewheel'
|
|
43
|
+
const eventStore: {
|
|
44
|
+
comp: VxeComponentBaseOptions;
|
|
45
|
+
type: string;
|
|
46
|
+
cb: (evnt: Event) => void;
|
|
47
|
+
}[] = []
|
|
48
|
+
|
|
49
|
+
function triggerEvent (evnt: Event) {
|
|
50
|
+
const isWheel = evnt.type === wheelName
|
|
51
|
+
eventStore.forEach(({ type, cb }) => {
|
|
52
|
+
// 如果被取消冒泡,不再执行
|
|
53
|
+
if (!evnt.cancelBubble) {
|
|
54
|
+
if (type === evnt.type || (isWheel && type === 'mousewheel')) {
|
|
55
|
+
cb(evnt)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
})
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
class VxeComponentEvent {
|
|
62
|
+
$event: Event
|
|
63
|
+
type = ''
|
|
64
|
+
key = ''
|
|
65
|
+
code = ''
|
|
66
|
+
constructor (evnt: Event, params1: any, params2?: any) {
|
|
67
|
+
this.$event = evnt
|
|
68
|
+
if (evnt) {
|
|
69
|
+
if ((evnt as KeyboardEvent).type) {
|
|
70
|
+
this.type = (evnt as KeyboardEvent).type
|
|
71
|
+
}
|
|
72
|
+
if ((evnt as KeyboardEvent).key) {
|
|
73
|
+
this.key = (evnt as KeyboardEvent).key
|
|
74
|
+
}
|
|
75
|
+
if ((evnt as KeyboardEvent).code) {
|
|
76
|
+
this.code = (evnt as KeyboardEvent).code
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
Object.assign(this, params1, params2)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
stopPropagation () {
|
|
83
|
+
const evnt = this.$event
|
|
84
|
+
if (evnt) {
|
|
85
|
+
evnt.stopPropagation()
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
preventDefault () {
|
|
90
|
+
const evnt = this.$event
|
|
91
|
+
if (evnt) {
|
|
92
|
+
evnt.preventDefault()
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export const createEvent: VxeGlobalCreateEventMethod = (evnt, params1, params2) => {
|
|
98
|
+
return new VxeComponentEvent(evnt as Event, params1, params2)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export const globalEvents: VxeGlobalEvents = {
|
|
102
|
+
on (comp, type, cb) {
|
|
103
|
+
eventStore.push({ comp, type, cb })
|
|
104
|
+
},
|
|
105
|
+
off (comp, type) {
|
|
106
|
+
XEUtils.remove(eventStore, item => item.comp === comp && item.type === type)
|
|
107
|
+
},
|
|
108
|
+
hasKey (evnt, targetKey) {
|
|
109
|
+
const { key } = evnt
|
|
110
|
+
targetKey = targetKey.toLowerCase()
|
|
111
|
+
return key ? (targetKey === key.toLowerCase() || !!(convertEventKeys[key] && convertEventKeys[key].toLowerCase() === targetKey)) : false
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (browse.isDoc) {
|
|
116
|
+
if (!browse.msie) {
|
|
117
|
+
window.addEventListener('copy', triggerEvent, false)
|
|
118
|
+
window.addEventListener('cut', triggerEvent, false)
|
|
119
|
+
window.addEventListener('paste', triggerEvent, false)
|
|
120
|
+
}
|
|
121
|
+
document.addEventListener('keydown', triggerEvent, false)
|
|
122
|
+
document.addEventListener('contextmenu', triggerEvent, false)
|
|
123
|
+
window.addEventListener('mousedown', triggerEvent, false)
|
|
124
|
+
window.addEventListener('blur', triggerEvent, false)
|
|
125
|
+
window.addEventListener('resize', triggerEvent, false)
|
|
126
|
+
window.addEventListener(wheelName, XEUtils.throttle(triggerEvent, 100, { leading: true, trailing: false }), { passive: true, capture: false })
|
|
127
|
+
}
|