@vxe-ui/core 1.0.12 → 3.0.0-alpha.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.md +29 -31
- package/es/src/core.js +4 -4
- package/es/src/i18nStore.js +2 -3
- package/es/src/log.js +1 -1
- package/es/src/mixins.js +35 -0
- package/es/src/permission.js +36 -14
- package/lib/index.umd.js +187 -132
- package/lib/index.umd.min.js +1 -1
- package/lib/src/core.js +6 -6
- package/lib/src/core.min.js +1 -1
- package/lib/src/i18n.min.js +1 -1
- package/lib/src/i18nStore.js +2 -3
- package/lib/src/i18nStore.min.js +1 -1
- package/lib/src/log.js +1 -1
- package/lib/src/log.min.js +1 -1
- package/lib/src/mixins.js +44 -0
- package/lib/src/mixins.min.js +1 -0
- package/lib/src/permission.js +37 -15
- package/lib/src/permission.min.js +1 -1
- package/lib/src/resize.min.js +1 -1
- package/package.json +77 -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 +9 -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/mixins.ts +38 -0
- 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/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 +14 -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/mixins.d.ts +7 -0
- 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 +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/README.en.md +0 -31
- package/README.zh-TW.md +0 -31
- package/es/src/useFns.js +0 -23
- package/lib/src/useFns.js +0 -33
- package/lib/src/useFns.min.js +0 -1
- package/packages/src/useFns.ts +0 -34
- package/types/core/useFn.d.ts +0 -27
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
|
+
}
|
package/packages/src/formats.ts
CHANGED
|
@@ -1,62 +1,62 @@
|
|
|
1
|
-
import XEUtils from 'xe-utils'
|
|
2
|
-
import { log } from './log'
|
|
3
|
-
|
|
4
|
-
import { VxeGlobalFormats } from '../../types'
|
|
5
|
-
|
|
6
|
-
class VXEFormatsStore {
|
|
7
|
-
private store: any = {}
|
|
8
|
-
|
|
9
|
-
mixin (options: any): VXEFormatsStore {
|
|
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): VXEFormatsStore {
|
|
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', ['formats -> callback', 'cellFormatMethod'])
|
|
30
|
-
}
|
|
31
|
-
render = {
|
|
32
|
-
cellFormatMethod: 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 formats = new VXEFormatsStore() as VxeGlobalFormats
|
|
59
|
-
|
|
60
|
-
if (process.env.VUE_APP_VXE_ENV === 'development') {
|
|
61
|
-
Object.assign(formats, { _name: 'Formats' })
|
|
62
|
-
}
|
|
1
|
+
import XEUtils from 'xe-utils'
|
|
2
|
+
import { log } from './log'
|
|
3
|
+
|
|
4
|
+
import { VxeGlobalFormats } from '../../types'
|
|
5
|
+
|
|
6
|
+
class VXEFormatsStore {
|
|
7
|
+
private store: any = {}
|
|
8
|
+
|
|
9
|
+
mixin (options: any): VXEFormatsStore {
|
|
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): VXEFormatsStore {
|
|
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', ['formats -> callback', 'cellFormatMethod'])
|
|
30
|
+
}
|
|
31
|
+
render = {
|
|
32
|
+
cellFormatMethod: 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 formats = new VXEFormatsStore() as VxeGlobalFormats
|
|
59
|
+
|
|
60
|
+
if (process.env.VUE_APP_VXE_ENV === 'development') {
|
|
61
|
+
Object.assign(formats, { _name: 'Formats' })
|
|
62
|
+
}
|
|
@@ -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/hooks.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import VXEStore from './store'
|
|
2
|
-
|
|
3
|
-
import { VxeGlobalHooks } from '../../types'
|
|
4
|
-
|
|
5
|
-
export const hooks = new VXEStore() as VxeGlobalHooks
|
|
1
|
+
import VXEStore from './store'
|
|
2
|
+
|
|
3
|
+
import { VxeGlobalHooks } from '../../types'
|
|
4
|
+
|
|
5
|
+
export const hooks = new VXEStore() as VxeGlobalHooks
|
package/packages/src/i18n.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import XEUtils from 'xe-utils'
|
|
2
|
-
import { i18nConfigStore } from './i18nStore'
|
|
3
|
-
|
|
4
|
-
import { VxeGlobalI18nLocale } from '../../types'
|
|
5
|
-
|
|
6
|
-
export function getI18n (key: string, args?: any) {
|
|
7
|
-
const { langMaps, language } = i18nConfigStore
|
|
8
|
-
return XEUtils.toFormatString(XEUtils.get(langMaps[language], key, key), args)
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function hasLanguage (language: VxeGlobalI18nLocale) {
|
|
12
|
-
const { langMaps } = i18nConfigStore
|
|
13
|
-
return !!langMaps[language]
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function getLanguage () {
|
|
17
|
-
const { language } = i18nConfigStore
|
|
18
|
-
return language
|
|
19
|
-
}
|
|
1
|
+
import XEUtils from 'xe-utils'
|
|
2
|
+
import { i18nConfigStore } from './i18nStore'
|
|
3
|
+
|
|
4
|
+
import { VxeGlobalI18nLocale } from '../../types'
|
|
5
|
+
|
|
6
|
+
export function getI18n (key: string, args?: any) {
|
|
7
|
+
const { langMaps, language } = i18nConfigStore
|
|
8
|
+
return XEUtils.toFormatString(XEUtils.get(langMaps[language], key, key), args)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function hasLanguage (language: VxeGlobalI18nLocale) {
|
|
12
|
+
const { langMaps } = i18nConfigStore
|
|
13
|
+
return !!langMaps[language]
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function getLanguage () {
|
|
17
|
+
const { language } = i18nConfigStore
|
|
18
|
+
return language
|
|
19
|
+
}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
langMaps: {}
|
|
11
|
-
})
|
|
1
|
+
import { VxeGlobalI18nLocale } from '../../types'
|
|
2
|
+
|
|
3
|
+
export const i18nConfigStore: {
|
|
4
|
+
language: VxeGlobalI18nLocale,
|
|
5
|
+
langMaps: Partial<Record<VxeGlobalI18nLocale, any>>
|
|
6
|
+
} = {
|
|
7
|
+
language: '',
|
|
8
|
+
langMaps: {}
|
|
9
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { VxeGlobalIcon } from '../../types'
|
|
2
|
-
|
|
3
|
-
export const iconConfigStore: VxeGlobalIcon = {}
|
|
1
|
+
import { VxeGlobalIcon } from '../../types'
|
|
2
|
+
|
|
3
|
+
export const iconConfigStore: VxeGlobalIcon = {}
|
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
import XEUtils from 'xe-utils'
|
|
2
|
-
import { log } from './log'
|
|
3
|
-
|
|
4
|
-
import { VxeGlobalInterceptor, VxeGlobalInterceptorHandles } from '../../types'
|
|
5
|
-
|
|
6
|
-
const storeMap: { [type: string]: VxeGlobalInterceptorHandles.InterceptorCallback[] } = {}
|
|
7
|
-
|
|
8
|
-
export const interceptor: VxeGlobalInterceptor = {
|
|
9
|
-
mixin (options) {
|
|
10
|
-
XEUtils.each(options, (render, type) => {
|
|
11
|
-
interceptor.add(type, render)
|
|
12
|
-
})
|
|
13
|
-
return interceptor
|
|
14
|
-
},
|
|
15
|
-
get (type) {
|
|
16
|
-
return storeMap[type] || []
|
|
17
|
-
},
|
|
18
|
-
add (type, render) {
|
|
19
|
-
// 兼容
|
|
20
|
-
if (XEUtils.isFunction(render)) {
|
|
21
|
-
// if (process.env.VUE_APP_VXE_ENV === 'development') {
|
|
22
|
-
// log.warn('vxe.error.delProp', ['interceptor -> callback', 'tableInterceptorMethod'])
|
|
23
|
-
// }
|
|
24
|
-
render = {
|
|
25
|
-
tableInterceptorMethod: render
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
const callback = render.tableInterceptorMethod
|
|
29
|
-
|
|
30
|
-
if (callback) {
|
|
31
|
-
let eList = storeMap[type]
|
|
32
|
-
if (!eList) {
|
|
33
|
-
eList = storeMap[type] = []
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// 检测重复
|
|
37
|
-
if (process.env.VUE_APP_VXE_ENV === 'development') {
|
|
38
|
-
if (eList.indexOf(callback) > -1) {
|
|
39
|
-
log.warn('vxe.error.coverProp', ['Interceptor', type])
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
eList.push(callback)
|
|
44
|
-
}
|
|
45
|
-
return interceptor
|
|
46
|
-
},
|
|
47
|
-
delete (type, render) {
|
|
48
|
-
const eList = storeMap[type]
|
|
49
|
-
if (eList) {
|
|
50
|
-
// 兼容
|
|
51
|
-
if (XEUtils.isFunction(render)) {
|
|
52
|
-
render = {
|
|
53
|
-
tableInterceptorMethod: render
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
const callback = render ? render.tableInterceptorMethod : null
|
|
57
|
-
|
|
58
|
-
if (callback) {
|
|
59
|
-
XEUtils.remove(eList, fn => fn === callback)
|
|
60
|
-
} else {
|
|
61
|
-
delete storeMap[type]
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
1
|
+
import XEUtils from 'xe-utils'
|
|
2
|
+
import { log } from './log'
|
|
3
|
+
|
|
4
|
+
import { VxeGlobalInterceptor, VxeGlobalInterceptorHandles } from '../../types'
|
|
5
|
+
|
|
6
|
+
const storeMap: { [type: string]: VxeGlobalInterceptorHandles.InterceptorCallback[] } = {}
|
|
7
|
+
|
|
8
|
+
export const interceptor: VxeGlobalInterceptor = {
|
|
9
|
+
mixin (options) {
|
|
10
|
+
XEUtils.each(options, (render, type) => {
|
|
11
|
+
interceptor.add(type, render)
|
|
12
|
+
})
|
|
13
|
+
return interceptor
|
|
14
|
+
},
|
|
15
|
+
get (type) {
|
|
16
|
+
return storeMap[type] || []
|
|
17
|
+
},
|
|
18
|
+
add (type, render) {
|
|
19
|
+
// 兼容
|
|
20
|
+
if (XEUtils.isFunction(render)) {
|
|
21
|
+
// if (process.env.VUE_APP_VXE_ENV === 'development') {
|
|
22
|
+
// log.warn('vxe.error.delProp', ['interceptor -> callback', 'tableInterceptorMethod'])
|
|
23
|
+
// }
|
|
24
|
+
render = {
|
|
25
|
+
tableInterceptorMethod: render
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
const callback = render.tableInterceptorMethod
|
|
29
|
+
|
|
30
|
+
if (callback) {
|
|
31
|
+
let eList = storeMap[type]
|
|
32
|
+
if (!eList) {
|
|
33
|
+
eList = storeMap[type] = []
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// 检测重复
|
|
37
|
+
if (process.env.VUE_APP_VXE_ENV === 'development') {
|
|
38
|
+
if (eList.indexOf(callback) > -1) {
|
|
39
|
+
log.warn('vxe.error.coverProp', ['Interceptor', type])
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
eList.push(callback)
|
|
44
|
+
}
|
|
45
|
+
return interceptor
|
|
46
|
+
},
|
|
47
|
+
delete (type, render) {
|
|
48
|
+
const eList = storeMap[type]
|
|
49
|
+
if (eList) {
|
|
50
|
+
// 兼容
|
|
51
|
+
if (XEUtils.isFunction(render)) {
|
|
52
|
+
render = {
|
|
53
|
+
tableInterceptorMethod: render
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const callback = render ? render.tableInterceptorMethod : null
|
|
57
|
+
|
|
58
|
+
if (callback) {
|
|
59
|
+
XEUtils.remove(eList, fn => fn === callback)
|
|
60
|
+
} else {
|
|
61
|
+
delete storeMap[type]
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
package/packages/src/log.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { getI18n } from './i18n'
|
|
2
|
-
|
|
3
|
-
import { VxeGlobalLog } from '../../types'
|
|
4
|
-
|
|
5
|
-
function createLog (type: 'log' | 'warn' | 'error', name?: string) {
|
|
6
|
-
return function (key: string, args?: any) {
|
|
7
|
-
const msg = `[vxe ${name || ''}] ${getI18n(key, args)}`
|
|
8
|
-
console[type](msg)
|
|
9
|
-
return msg
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const version = process.env.VUE_APP_VXE_VERSION
|
|
14
|
-
|
|
15
|
-
export const log: VxeGlobalLog = {
|
|
16
|
-
create: createLog,
|
|
17
|
-
warn: createLog('warn', `v${version}`),
|
|
18
|
-
err: createLog('error', `v${version}`)
|
|
19
|
-
}
|
|
1
|
+
import { getI18n } from './i18n'
|
|
2
|
+
|
|
3
|
+
import { VxeGlobalLog } from '../../types'
|
|
4
|
+
|
|
5
|
+
function createLog (type: 'log' | 'warn' | 'error', name?: string) {
|
|
6
|
+
return function (key: string, args?: any) {
|
|
7
|
+
const msg = `[vxe ${name || ''}] ${getI18n(key, args)}`
|
|
8
|
+
console[type](msg)
|
|
9
|
+
return msg
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const version = process.env.VUE_APP_VXE_VERSION
|
|
14
|
+
|
|
15
|
+
export const log: VxeGlobalLog = {
|
|
16
|
+
create: createLog,
|
|
17
|
+
warn: createLog('warn', `v${version}`),
|
|
18
|
+
err: createLog('error', `v${version}`)
|
|
19
|
+
}
|