@vxe-ui/core 1.0.12 → 4.0.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 -21
- package/README.en.md +31 -31
- package/README.md +31 -31
- package/README.zh-TW.md +31 -31
- package/es/src/core.js +1 -1
- package/es/src/log.js +1 -1
- package/es/src/permission.js +36 -14
- package/lib/index.umd.js +59 -34
- package/lib/index.umd.min.js +1 -1
- package/lib/src/clipboard.min.js +1 -1
- package/lib/src/commands.min.js +1 -1
- package/lib/src/core.js +1 -1
- package/lib/src/core.min.js +1 -1
- package/lib/src/event.min.js +1 -1
- package/lib/src/formats.min.js +1 -1
- package/lib/src/globalStore.min.js +1 -1
- package/lib/src/hooks.min.js +1 -1
- package/lib/src/i18n.min.js +1 -1
- package/lib/src/i18nStore.min.js +1 -1
- package/lib/src/iconStore.min.js +1 -1
- package/lib/src/interceptor.min.js +1 -1
- package/lib/src/log.js +1 -1
- package/lib/src/log.min.js +1 -1
- package/lib/src/menus.min.js +1 -1
- package/lib/src/permission.js +37 -15
- package/lib/src/permission.min.js +1 -1
- package/lib/src/renderer.min.js +1 -1
- package/lib/src/resize.min.js +1 -1
- package/lib/src/store.min.js +1 -1
- package/lib/src/themeStore.min.js +1 -1
- package/lib/src/useFns.min.js +1 -1
- package/lib/src/validators.min.js +1 -1
- package/package.json +78 -78
- package/packages/index.ts +4 -4
- package/packages/src/clipboard.ts +53 -53
- package/packages/src/commands.ts +62 -62
- package/packages/src/core.ts +167 -167
- package/packages/src/event.ts +113 -113
- package/packages/src/formats.ts +62 -62
- package/packages/src/globalStore.ts +8 -8
- package/packages/src/hooks.ts +5 -5
- package/packages/src/i18n.ts +19 -19
- package/packages/src/i18nStore.ts +11 -11
- 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/permission.ts +61 -39
- package/packages/src/renderer.ts +50 -50
- package/packages/src/resize.ts +89 -89
- package/packages/src/store.ts +49 -49
- package/packages/src/themeStore.ts +7 -7
- package/packages/src/useFns.ts +34 -34
- 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 +55 -55
- 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 +1 -1
- package/types/core/global-resize.d.ts +3 -3
- package/types/core/global-theme.d.ts +1 -1
- package/types/core/hooks.d.ts +14 -14
- package/types/core/index.d.ts +224 -224
- 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/permission.d.ts +10 -10
- package/types/core/renderer.d.ts +14 -14
- package/types/core/useFn.d.ts +27 -27
- package/types/core/validators.d.ts +19 -19
- package/types/index.d.ts +10 -10
- package/types/tool/common.d.ts +99 -99
- package/types/tool/index.d.ts +2 -2
- package/types/tool/util.d.ts +4 -4
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/core.ts
CHANGED
|
@@ -1,167 +1,167 @@
|
|
|
1
|
-
import XEUtils from 'xe-utils'
|
|
2
|
-
import DomZIndex from 'dom-zindex'
|
|
3
|
-
import { globalConfigStore } from './globalStore'
|
|
4
|
-
import { iconConfigStore } from './iconStore'
|
|
5
|
-
import { themeConfigStore } from './themeStore'
|
|
6
|
-
import { i18nConfigStore } from './i18nStore'
|
|
7
|
-
import { globalEvents, GLOBAL_EVENT_KEYS, createEvent } from './event'
|
|
8
|
-
import { globalResize } from './resize'
|
|
9
|
-
import { getI18n, hasLanguage, getLanguage } from './i18n'
|
|
10
|
-
import { renderer } from './renderer'
|
|
11
|
-
import { validators } from './validators'
|
|
12
|
-
import { menus } from './menus'
|
|
13
|
-
import { formats } from './formats'
|
|
14
|
-
import { commands } from './commands'
|
|
15
|
-
import { interceptor } from './interceptor'
|
|
16
|
-
import { clipboard } from './clipboard'
|
|
17
|
-
import { permission } from './permission'
|
|
18
|
-
import { log } from './log'
|
|
19
|
-
import { hooks } from './hooks'
|
|
20
|
-
import { useFns } from './useFns'
|
|
21
|
-
|
|
22
|
-
import { VxeUIExport, VxeGlobalConfig, VxeGlobalThemeName, VxeGlobalComponents, VxeGlobalIcon, VxeUIPluginObject, VxeGlobalI18nLocale } from '../../types'
|
|
23
|
-
|
|
24
|
-
export function setTheme (name?: VxeGlobalThemeName) {
|
|
25
|
-
const theme = !name || name === 'default' ? 'light' : name
|
|
26
|
-
themeConfigStore.theme = theme
|
|
27
|
-
if (typeof document !== 'undefined') {
|
|
28
|
-
const documentElement = document.documentElement
|
|
29
|
-
if (documentElement) {
|
|
30
|
-
documentElement.setAttribute('data-vxe-ui-theme', theme)
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return VxeUI
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export function getTheme () {
|
|
37
|
-
return themeConfigStore.theme
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export function setLanguage (locale: VxeGlobalI18nLocale) {
|
|
41
|
-
i18nConfigStore.language = locale || 'zh-CN'
|
|
42
|
-
return VxeUI
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export function setI18n (locale: VxeGlobalI18nLocale, data: Record<string, any>) {
|
|
46
|
-
i18nConfigStore.langMaps[locale] = Object.assign({}, data)
|
|
47
|
-
return VxeUI
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* 全局参数设置
|
|
52
|
-
*/
|
|
53
|
-
export function setConfig (options?: VxeGlobalConfig) {
|
|
54
|
-
if (options) {
|
|
55
|
-
if (options.zIndex) {
|
|
56
|
-
DomZIndex.setCurrent(options.zIndex)
|
|
57
|
-
}
|
|
58
|
-
if (options.theme) {
|
|
59
|
-
setTheme(options.theme)
|
|
60
|
-
}
|
|
61
|
-
XEUtils.merge(globalConfigStore, options)
|
|
62
|
-
}
|
|
63
|
-
return VxeUI
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* 获取全局参数
|
|
68
|
-
*/
|
|
69
|
-
export function getConfig (key: keyof VxeGlobalConfig, defaultValue?: any) {
|
|
70
|
-
return arguments.length ? XEUtils.get(globalConfigStore, key, defaultValue) : globalConfigStore
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export function setIcon (options?: VxeGlobalIcon) {
|
|
74
|
-
if (options) {
|
|
75
|
-
Object.assign(iconConfigStore, options)
|
|
76
|
-
}
|
|
77
|
-
return VxeUI
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export function getIcon (key: keyof VxeGlobalIcon) {
|
|
81
|
-
return arguments.length ? XEUtils.get(iconConfigStore, key) : iconConfigStore
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export const coreVersion = process.env.VUE_APP_VXE_VERSION as string
|
|
85
|
-
|
|
86
|
-
const installedPlugins: VxeUIPluginObject[] = []
|
|
87
|
-
|
|
88
|
-
export function use (Plugin: VxeUIPluginObject, options: any[]) {
|
|
89
|
-
if (Plugin && Plugin.install) {
|
|
90
|
-
if (installedPlugins.indexOf(Plugin) === -1) {
|
|
91
|
-
Plugin.install(VxeUI, options)
|
|
92
|
-
installedPlugins.push(Plugin)
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
return VxeUI
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const components: Record<string, any> = {}
|
|
99
|
-
|
|
100
|
-
export function getComponent (name: keyof VxeGlobalComponents) {
|
|
101
|
-
return components[name] || null
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export function component (comp: any) {
|
|
105
|
-
if (comp && comp.name) {
|
|
106
|
-
components[comp.name] = comp
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
export const VxeUI: VxeUIExport = {
|
|
111
|
-
coreVersion,
|
|
112
|
-
|
|
113
|
-
setTheme,
|
|
114
|
-
getTheme,
|
|
115
|
-
setConfig,
|
|
116
|
-
getConfig: getConfig as any,
|
|
117
|
-
setIcon,
|
|
118
|
-
getIcon: getIcon as any,
|
|
119
|
-
setLanguage,
|
|
120
|
-
hasLanguage,
|
|
121
|
-
getLanguage,
|
|
122
|
-
setI18n,
|
|
123
|
-
getI18n,
|
|
124
|
-
|
|
125
|
-
globalEvents,
|
|
126
|
-
GLOBAL_EVENT_KEYS,
|
|
127
|
-
createEvent,
|
|
128
|
-
|
|
129
|
-
globalResize,
|
|
130
|
-
renderer,
|
|
131
|
-
validators,
|
|
132
|
-
menus,
|
|
133
|
-
formats,
|
|
134
|
-
commands,
|
|
135
|
-
interceptor,
|
|
136
|
-
clipboard,
|
|
137
|
-
log,
|
|
138
|
-
permission,
|
|
139
|
-
|
|
140
|
-
hooks,
|
|
141
|
-
component,
|
|
142
|
-
getComponent,
|
|
143
|
-
useFns,
|
|
144
|
-
|
|
145
|
-
use
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
setTheme()
|
|
149
|
-
|
|
150
|
-
export * from './event'
|
|
151
|
-
export * from './resize'
|
|
152
|
-
|
|
153
|
-
export * from './i18n'
|
|
154
|
-
export * from './renderer'
|
|
155
|
-
export * from './validators'
|
|
156
|
-
export * from './menus'
|
|
157
|
-
export * from './formats'
|
|
158
|
-
export * from './commands'
|
|
159
|
-
export * from './interceptor'
|
|
160
|
-
export * from './clipboard'
|
|
161
|
-
export * from './permission'
|
|
162
|
-
|
|
163
|
-
export * from './useFns'
|
|
164
|
-
export * from './log'
|
|
165
|
-
export * from './hooks'
|
|
166
|
-
|
|
167
|
-
export default VxeUI
|
|
1
|
+
import XEUtils from 'xe-utils'
|
|
2
|
+
import DomZIndex from 'dom-zindex'
|
|
3
|
+
import { globalConfigStore } from './globalStore'
|
|
4
|
+
import { iconConfigStore } from './iconStore'
|
|
5
|
+
import { themeConfigStore } from './themeStore'
|
|
6
|
+
import { i18nConfigStore } from './i18nStore'
|
|
7
|
+
import { globalEvents, GLOBAL_EVENT_KEYS, createEvent } from './event'
|
|
8
|
+
import { globalResize } from './resize'
|
|
9
|
+
import { getI18n, hasLanguage, getLanguage } from './i18n'
|
|
10
|
+
import { renderer } from './renderer'
|
|
11
|
+
import { validators } from './validators'
|
|
12
|
+
import { menus } from './menus'
|
|
13
|
+
import { formats } from './formats'
|
|
14
|
+
import { commands } from './commands'
|
|
15
|
+
import { interceptor } from './interceptor'
|
|
16
|
+
import { clipboard } from './clipboard'
|
|
17
|
+
import { permission } from './permission'
|
|
18
|
+
import { log } from './log'
|
|
19
|
+
import { hooks } from './hooks'
|
|
20
|
+
import { useFns } from './useFns'
|
|
21
|
+
|
|
22
|
+
import { VxeUIExport, VxeGlobalConfig, VxeGlobalThemeName, VxeGlobalComponents, VxeGlobalIcon, VxeUIPluginObject, VxeGlobalI18nLocale } from '../../types'
|
|
23
|
+
|
|
24
|
+
export function setTheme (name?: VxeGlobalThemeName) {
|
|
25
|
+
const theme = !name || name === 'default' ? 'light' : name
|
|
26
|
+
themeConfigStore.theme = theme
|
|
27
|
+
if (typeof document !== 'undefined') {
|
|
28
|
+
const documentElement = document.documentElement
|
|
29
|
+
if (documentElement) {
|
|
30
|
+
documentElement.setAttribute('data-vxe-ui-theme', theme)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return VxeUI
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function getTheme () {
|
|
37
|
+
return themeConfigStore.theme
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function setLanguage (locale: VxeGlobalI18nLocale) {
|
|
41
|
+
i18nConfigStore.language = locale || 'zh-CN'
|
|
42
|
+
return VxeUI
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function setI18n (locale: VxeGlobalI18nLocale, data: Record<string, any>) {
|
|
46
|
+
i18nConfigStore.langMaps[locale] = Object.assign({}, data)
|
|
47
|
+
return VxeUI
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* 全局参数设置
|
|
52
|
+
*/
|
|
53
|
+
export function setConfig (options?: VxeGlobalConfig) {
|
|
54
|
+
if (options) {
|
|
55
|
+
if (options.zIndex) {
|
|
56
|
+
DomZIndex.setCurrent(options.zIndex)
|
|
57
|
+
}
|
|
58
|
+
if (options.theme) {
|
|
59
|
+
setTheme(options.theme)
|
|
60
|
+
}
|
|
61
|
+
XEUtils.merge(globalConfigStore, options)
|
|
62
|
+
}
|
|
63
|
+
return VxeUI
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* 获取全局参数
|
|
68
|
+
*/
|
|
69
|
+
export function getConfig (key: keyof VxeGlobalConfig, defaultValue?: any) {
|
|
70
|
+
return arguments.length ? XEUtils.get(globalConfigStore, key, defaultValue) : globalConfigStore
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function setIcon (options?: VxeGlobalIcon) {
|
|
74
|
+
if (options) {
|
|
75
|
+
Object.assign(iconConfigStore, options)
|
|
76
|
+
}
|
|
77
|
+
return VxeUI
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function getIcon (key: keyof VxeGlobalIcon) {
|
|
81
|
+
return arguments.length ? XEUtils.get(iconConfigStore, key) : iconConfigStore
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export const coreVersion = process.env.VUE_APP_VXE_VERSION as string
|
|
85
|
+
|
|
86
|
+
const installedPlugins: VxeUIPluginObject[] = []
|
|
87
|
+
|
|
88
|
+
export function use (Plugin: VxeUIPluginObject, options: any[]) {
|
|
89
|
+
if (Plugin && Plugin.install) {
|
|
90
|
+
if (installedPlugins.indexOf(Plugin) === -1) {
|
|
91
|
+
Plugin.install(VxeUI, options)
|
|
92
|
+
installedPlugins.push(Plugin)
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return VxeUI
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const components: Record<string, any> = {}
|
|
99
|
+
|
|
100
|
+
export function getComponent (name: keyof VxeGlobalComponents) {
|
|
101
|
+
return components[name] || null
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function component (comp: any) {
|
|
105
|
+
if (comp && comp.name) {
|
|
106
|
+
components[comp.name] = comp
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export const VxeUI: VxeUIExport = {
|
|
111
|
+
coreVersion,
|
|
112
|
+
|
|
113
|
+
setTheme,
|
|
114
|
+
getTheme,
|
|
115
|
+
setConfig,
|
|
116
|
+
getConfig: getConfig as any,
|
|
117
|
+
setIcon,
|
|
118
|
+
getIcon: getIcon as any,
|
|
119
|
+
setLanguage,
|
|
120
|
+
hasLanguage,
|
|
121
|
+
getLanguage,
|
|
122
|
+
setI18n,
|
|
123
|
+
getI18n,
|
|
124
|
+
|
|
125
|
+
globalEvents,
|
|
126
|
+
GLOBAL_EVENT_KEYS,
|
|
127
|
+
createEvent,
|
|
128
|
+
|
|
129
|
+
globalResize,
|
|
130
|
+
renderer,
|
|
131
|
+
validators,
|
|
132
|
+
menus,
|
|
133
|
+
formats,
|
|
134
|
+
commands,
|
|
135
|
+
interceptor,
|
|
136
|
+
clipboard,
|
|
137
|
+
log,
|
|
138
|
+
permission,
|
|
139
|
+
|
|
140
|
+
hooks,
|
|
141
|
+
component,
|
|
142
|
+
getComponent,
|
|
143
|
+
useFns,
|
|
144
|
+
|
|
145
|
+
use
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
setTheme()
|
|
149
|
+
|
|
150
|
+
export * from './event'
|
|
151
|
+
export * from './resize'
|
|
152
|
+
|
|
153
|
+
export * from './i18n'
|
|
154
|
+
export * from './renderer'
|
|
155
|
+
export * from './validators'
|
|
156
|
+
export * from './menus'
|
|
157
|
+
export * from './formats'
|
|
158
|
+
export * from './commands'
|
|
159
|
+
export * from './interceptor'
|
|
160
|
+
export * from './clipboard'
|
|
161
|
+
export * from './permission'
|
|
162
|
+
|
|
163
|
+
export * from './useFns'
|
|
164
|
+
export * from './log'
|
|
165
|
+
export * from './hooks'
|
|
166
|
+
|
|
167
|
+
export default VxeUI
|
package/packages/src/event.ts
CHANGED
|
@@ -1,113 +1,113 @@
|
|
|
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
|
-
constructor (evnt: Event, params1: any, params2?: any) {
|
|
64
|
-
this.$event = evnt
|
|
65
|
-
Object.assign(this, params1, params2)
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
stopPropagation () {
|
|
69
|
-
const evnt = this.$event
|
|
70
|
-
if (evnt) {
|
|
71
|
-
evnt.stopPropagation()
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
preventDefault () {
|
|
76
|
-
const evnt = this.$event
|
|
77
|
-
if (evnt) {
|
|
78
|
-
evnt.preventDefault()
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export const createEvent: VxeGlobalCreateEventMethod = (evnt, params1, params2) => {
|
|
84
|
-
return new VxeComponentEvent(evnt as Event, params1, params2)
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export const globalEvents: VxeGlobalEvents = {
|
|
88
|
-
on (comp, type, cb) {
|
|
89
|
-
eventStore.push({ comp, type, cb })
|
|
90
|
-
},
|
|
91
|
-
off (comp, type) {
|
|
92
|
-
XEUtils.remove(eventStore, item => item.comp === comp && item.type === type)
|
|
93
|
-
},
|
|
94
|
-
hasKey (evnt, targetKey) {
|
|
95
|
-
const { key } = evnt
|
|
96
|
-
targetKey = targetKey.toLowerCase()
|
|
97
|
-
return key ? (targetKey === key.toLowerCase() || !!(convertEventKeys[key] && convertEventKeys[key].toLowerCase() === targetKey)) : false
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (browse.isDoc) {
|
|
102
|
-
if (!browse.msie) {
|
|
103
|
-
window.addEventListener('copy', triggerEvent, false)
|
|
104
|
-
window.addEventListener('cut', triggerEvent, false)
|
|
105
|
-
window.addEventListener('paste', triggerEvent, false)
|
|
106
|
-
}
|
|
107
|
-
document.addEventListener('keydown', triggerEvent, false)
|
|
108
|
-
document.addEventListener('contextmenu', triggerEvent, false)
|
|
109
|
-
window.addEventListener('mousedown', triggerEvent, false)
|
|
110
|
-
window.addEventListener('blur', triggerEvent, false)
|
|
111
|
-
window.addEventListener('resize', triggerEvent, false)
|
|
112
|
-
window.addEventListener(wheelName, XEUtils.throttle(triggerEvent, 100, { leading: true, trailing: false }), { passive: true, capture: false })
|
|
113
|
-
}
|
|
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
|
+
constructor (evnt: Event, params1: any, params2?: any) {
|
|
64
|
+
this.$event = evnt
|
|
65
|
+
Object.assign(this, params1, params2)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
stopPropagation () {
|
|
69
|
+
const evnt = this.$event
|
|
70
|
+
if (evnt) {
|
|
71
|
+
evnt.stopPropagation()
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
preventDefault () {
|
|
76
|
+
const evnt = this.$event
|
|
77
|
+
if (evnt) {
|
|
78
|
+
evnt.preventDefault()
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export const createEvent: VxeGlobalCreateEventMethod = (evnt, params1, params2) => {
|
|
84
|
+
return new VxeComponentEvent(evnt as Event, params1, params2)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export const globalEvents: VxeGlobalEvents = {
|
|
88
|
+
on (comp, type, cb) {
|
|
89
|
+
eventStore.push({ comp, type, cb })
|
|
90
|
+
},
|
|
91
|
+
off (comp, type) {
|
|
92
|
+
XEUtils.remove(eventStore, item => item.comp === comp && item.type === type)
|
|
93
|
+
},
|
|
94
|
+
hasKey (evnt, targetKey) {
|
|
95
|
+
const { key } = evnt
|
|
96
|
+
targetKey = targetKey.toLowerCase()
|
|
97
|
+
return key ? (targetKey === key.toLowerCase() || !!(convertEventKeys[key] && convertEventKeys[key].toLowerCase() === targetKey)) : false
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (browse.isDoc) {
|
|
102
|
+
if (!browse.msie) {
|
|
103
|
+
window.addEventListener('copy', triggerEvent, false)
|
|
104
|
+
window.addEventListener('cut', triggerEvent, false)
|
|
105
|
+
window.addEventListener('paste', triggerEvent, false)
|
|
106
|
+
}
|
|
107
|
+
document.addEventListener('keydown', triggerEvent, false)
|
|
108
|
+
document.addEventListener('contextmenu', triggerEvent, false)
|
|
109
|
+
window.addEventListener('mousedown', triggerEvent, false)
|
|
110
|
+
window.addEventListener('blur', triggerEvent, false)
|
|
111
|
+
window.addEventListener('resize', triggerEvent, false)
|
|
112
|
+
window.addEventListener(wheelName, XEUtils.throttle(triggerEvent, 100, { leading: true, trailing: false }), { passive: true, capture: false })
|
|
113
|
+
}
|