@vxe-ui/core 4.4.12 → 4.4.14
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 +43 -43
- package/README.md +43 -43
- package/README.zh-TW.md +43 -43
- package/dist/all.esm.js +920 -0
- package/es/src/core.js +1 -1
- package/es/src/log.js +1 -1
- package/lib/index.umd.js +173 -73
- 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/package.json +82 -79
- package/packages/index.ts +149 -149
- package/packages/src/clipboard.ts +56 -56
- package/packages/src/commands.ts +56 -56
- package/packages/src/config.ts +30 -30
- package/packages/src/configStore.ts +8 -8
- package/packages/src/core.ts +11 -11
- package/packages/src/dataStore.ts +4 -4
- package/packages/src/event.ts +160 -160
- package/packages/src/formats.ts +56 -56
- package/packages/src/hooks.ts +5 -5
- package/packages/src/i18n.ts +63 -63
- package/packages/src/i18nStore.ts +11 -11
- package/packages/src/icon.ts +32 -32
- package/packages/src/iconStore.ts +3 -3
- package/packages/src/interceptor.ts +64 -64
- package/packages/src/log.ts +19 -19
- package/packages/src/menus.ts +56 -56
- package/packages/src/permission.ts +61 -61
- package/packages/src/renderer.ts +48 -48
- package/packages/src/resize.ts +89 -89
- package/packages/src/store.ts +47 -47
- package/packages/src/theme.ts +20 -20
- package/packages/src/themeStore.ts +7 -7
- package/packages/src/useFns.ts +34 -34
- package/packages/src/validators.ts +7 -7
- package/packages/src/vm.ts +10 -10
- package/types/core/clipboard.d.ts +22 -22
- package/types/core/commands.d.ts +19 -19
- package/types/core/components.d.ts +5 -5
- package/types/core/formats.d.ts +19 -19
- package/types/core/global-config.d.ts +70 -70
- package/types/core/global-data.d.ts +7 -7
- package/types/core/global-event.d.ts +47 -47
- package/types/core/global-icon.d.ts +10 -10
- package/types/core/global-lang.d.ts +27 -27
- 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 +294 -294
- 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 +13 -13
- package/types/tool/common.d.ts +150 -150
- package/types/tool/index.d.ts +2 -2
- package/types/tool/util.d.ts +4 -4
package/packages/src/i18n.ts
CHANGED
|
@@ -1,63 +1,63 @@
|
|
|
1
|
-
import XEUtils from 'xe-utils'
|
|
2
|
-
import { VxeCore } from './core'
|
|
3
|
-
import { i18nConfigStore } from './i18nStore'
|
|
4
|
-
import { globalConfigStore } from './configStore'
|
|
5
|
-
|
|
6
|
-
import { VxeGlobalI18nLocale } from '../../types'
|
|
7
|
-
|
|
8
|
-
let checkInstall = false
|
|
9
|
-
let cacheMaps: Record<string, string> = {}
|
|
10
|
-
|
|
11
|
-
function getDefaultExport (mod: any) {
|
|
12
|
-
if (mod && mod.__esModule) {
|
|
13
|
-
return mod.default
|
|
14
|
-
}
|
|
15
|
-
return mod
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function getI18n (key: string, args?: any) {
|
|
19
|
-
const { langMaps, language } = i18nConfigStore
|
|
20
|
-
const { i18n } = globalConfigStore
|
|
21
|
-
if (i18n) {
|
|
22
|
-
return `${i18n(key, args) || ''}`
|
|
23
|
-
}
|
|
24
|
-
if (!checkInstall) {
|
|
25
|
-
if (!langMaps[language]) {
|
|
26
|
-
console.error(`[vxe core] 语言包未安装。Language not installed. https://${VxeCore.uiVersion ? 'vxeui.com' : 'vxetable.cn'}/#/start/i18n`)
|
|
27
|
-
}
|
|
28
|
-
checkInstall = true
|
|
29
|
-
}
|
|
30
|
-
if (!args && cacheMaps[key]) {
|
|
31
|
-
return cacheMaps[key]
|
|
32
|
-
}
|
|
33
|
-
const i18nLabel = XEUtils.toFormatString(XEUtils.get(langMaps[language], key, key), args)
|
|
34
|
-
if (!args) {
|
|
35
|
-
cacheMaps[key] = i18nLabel
|
|
36
|
-
}
|
|
37
|
-
return i18nLabel
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export function setLanguage (locale: VxeGlobalI18nLocale) {
|
|
41
|
-
const { language } = i18nConfigStore
|
|
42
|
-
const targetlang = locale || 'zh-CN'
|
|
43
|
-
if (language !== targetlang) {
|
|
44
|
-
i18nConfigStore.language = targetlang
|
|
45
|
-
cacheMaps = {}
|
|
46
|
-
}
|
|
47
|
-
return VxeCore
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function setI18n (locale: VxeGlobalI18nLocale, data: Record<string, any>) {
|
|
51
|
-
i18nConfigStore.langMaps[locale] = Object.assign({}, getDefaultExport(data))
|
|
52
|
-
return VxeCore
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export function hasLanguage (language: VxeGlobalI18nLocale) {
|
|
56
|
-
const { langMaps } = i18nConfigStore
|
|
57
|
-
return !!langMaps[language]
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export function getLanguage () {
|
|
61
|
-
const { language } = i18nConfigStore
|
|
62
|
-
return language
|
|
63
|
-
}
|
|
1
|
+
import XEUtils from 'xe-utils'
|
|
2
|
+
import { VxeCore } from './core'
|
|
3
|
+
import { i18nConfigStore } from './i18nStore'
|
|
4
|
+
import { globalConfigStore } from './configStore'
|
|
5
|
+
|
|
6
|
+
import { VxeGlobalI18nLocale } from '../../types'
|
|
7
|
+
|
|
8
|
+
let checkInstall = false
|
|
9
|
+
let cacheMaps: Record<string, string> = {}
|
|
10
|
+
|
|
11
|
+
function getDefaultExport (mod: any) {
|
|
12
|
+
if (mod && mod.__esModule) {
|
|
13
|
+
return mod.default
|
|
14
|
+
}
|
|
15
|
+
return mod
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function getI18n (key: string, args?: any) {
|
|
19
|
+
const { langMaps, language } = i18nConfigStore
|
|
20
|
+
const { i18n } = globalConfigStore
|
|
21
|
+
if (i18n) {
|
|
22
|
+
return `${i18n(key, args) || ''}`
|
|
23
|
+
}
|
|
24
|
+
if (!checkInstall) {
|
|
25
|
+
if (!langMaps[language]) {
|
|
26
|
+
console.error(`[vxe core] 语言包未安装。Language not installed. https://${VxeCore.uiVersion ? 'vxeui.com' : 'vxetable.cn'}/#/start/i18n`)
|
|
27
|
+
}
|
|
28
|
+
checkInstall = true
|
|
29
|
+
}
|
|
30
|
+
if (!args && cacheMaps[key]) {
|
|
31
|
+
return cacheMaps[key]
|
|
32
|
+
}
|
|
33
|
+
const i18nLabel = XEUtils.toFormatString(XEUtils.get(langMaps[language], key, key), args)
|
|
34
|
+
if (!args) {
|
|
35
|
+
cacheMaps[key] = i18nLabel
|
|
36
|
+
}
|
|
37
|
+
return i18nLabel
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function setLanguage (locale: VxeGlobalI18nLocale) {
|
|
41
|
+
const { language } = i18nConfigStore
|
|
42
|
+
const targetlang = locale || 'zh-CN'
|
|
43
|
+
if (language !== targetlang) {
|
|
44
|
+
i18nConfigStore.language = targetlang
|
|
45
|
+
cacheMaps = {}
|
|
46
|
+
}
|
|
47
|
+
return VxeCore
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function setI18n (locale: VxeGlobalI18nLocale, data: Record<string, any>) {
|
|
51
|
+
i18nConfigStore.langMaps[locale] = Object.assign({}, getDefaultExport(data))
|
|
52
|
+
return VxeCore
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function hasLanguage (language: VxeGlobalI18nLocale) {
|
|
56
|
+
const { langMaps } = i18nConfigStore
|
|
57
|
+
return !!langMaps[language]
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function getLanguage () {
|
|
61
|
+
const { language } = i18nConfigStore
|
|
62
|
+
return language
|
|
63
|
+
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { reactive } from 'vue'
|
|
2
|
-
|
|
3
|
-
import { VxeGlobalI18nLocale } from '../../types'
|
|
4
|
-
|
|
5
|
-
export const i18nConfigStore: {
|
|
6
|
-
language: VxeGlobalI18nLocale,
|
|
7
|
-
langMaps: Partial<Record<VxeGlobalI18nLocale, any>>
|
|
8
|
-
} = reactive({
|
|
9
|
-
language: '',
|
|
10
|
-
langMaps: {}
|
|
11
|
-
})
|
|
1
|
+
import { reactive } from 'vue'
|
|
2
|
+
|
|
3
|
+
import { VxeGlobalI18nLocale } from '../../types'
|
|
4
|
+
|
|
5
|
+
export const i18nConfigStore: {
|
|
6
|
+
language: VxeGlobalI18nLocale,
|
|
7
|
+
langMaps: Partial<Record<VxeGlobalI18nLocale, any>>
|
|
8
|
+
} = reactive({
|
|
9
|
+
language: '',
|
|
10
|
+
langMaps: {}
|
|
11
|
+
})
|
package/packages/src/icon.ts
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import { h } from 'vue'
|
|
2
|
-
import XEUtils from 'xe-utils'
|
|
3
|
-
import { VxeCore } from './core'
|
|
4
|
-
import { iconConfigStore } from './iconStore'
|
|
5
|
-
import { getSlotVNs } from './vm'
|
|
6
|
-
|
|
7
|
-
import { VxeGlobalIcon, VxeGlobalIconConfig } from '../../types'
|
|
8
|
-
|
|
9
|
-
export function setIcon (options?: VxeGlobalIcon) {
|
|
10
|
-
if (options) {
|
|
11
|
-
Object.assign(iconConfigStore, options)
|
|
12
|
-
}
|
|
13
|
-
return VxeCore
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function getIcon (key: keyof VxeGlobalIcon) {
|
|
17
|
-
return arguments.length ? XEUtils.get(iconConfigStore, key) : iconConfigStore
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function renderGlobalIcon (name: keyof VxeGlobalIcon) {
|
|
21
|
-
const icon = getIcon(name) as VxeGlobalIconConfig
|
|
22
|
-
return renderCustomIcon(icon, name)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function renderCustomIcon (icon: VxeGlobalIconConfig, name: string) {
|
|
26
|
-
if (XEUtils.isFunction(icon)) {
|
|
27
|
-
return h('span', {}, getSlotVNs(icon({ name })))
|
|
28
|
-
}
|
|
29
|
-
return h('i', {
|
|
30
|
-
class: icon
|
|
31
|
-
})
|
|
32
|
-
}
|
|
1
|
+
import { h } from 'vue'
|
|
2
|
+
import XEUtils from 'xe-utils'
|
|
3
|
+
import { VxeCore } from './core'
|
|
4
|
+
import { iconConfigStore } from './iconStore'
|
|
5
|
+
import { getSlotVNs } from './vm'
|
|
6
|
+
|
|
7
|
+
import { VxeGlobalIcon, VxeGlobalIconConfig } from '../../types'
|
|
8
|
+
|
|
9
|
+
export function setIcon (options?: VxeGlobalIcon) {
|
|
10
|
+
if (options) {
|
|
11
|
+
Object.assign(iconConfigStore, options)
|
|
12
|
+
}
|
|
13
|
+
return VxeCore
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function getIcon (key: keyof VxeGlobalIcon) {
|
|
17
|
+
return arguments.length ? XEUtils.get(iconConfigStore, key) : iconConfigStore
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function renderGlobalIcon (name: keyof VxeGlobalIcon) {
|
|
21
|
+
const icon = getIcon(name) as VxeGlobalIconConfig
|
|
22
|
+
return renderCustomIcon(icon, name)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function renderCustomIcon (icon: VxeGlobalIconConfig, name: string) {
|
|
26
|
+
if (XEUtils.isFunction(icon)) {
|
|
27
|
+
return h('span', {}, getSlotVNs(icon({ name })))
|
|
28
|
+
}
|
|
29
|
+
return h('i', {
|
|
30
|
+
class: icon
|
|
31
|
+
})
|
|
32
|
+
}
|
|
@@ -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,64 +1,64 @@
|
|
|
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
|
-
if (type) {
|
|
17
|
-
return storeMap[type] || []
|
|
18
|
-
}
|
|
19
|
-
return []
|
|
20
|
-
},
|
|
21
|
-
add (type, render) {
|
|
22
|
-
// 兼容
|
|
23
|
-
if (XEUtils.isFunction(render)) {
|
|
24
|
-
// log.warn('vxe.error.delProp', ['interceptor -> callback', 'tableInterceptorMethod'])
|
|
25
|
-
render = {
|
|
26
|
-
tableInterceptorMethod: render
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
const callback = render.tableInterceptorMethod
|
|
30
|
-
|
|
31
|
-
if (callback) {
|
|
32
|
-
let eList = storeMap[type]
|
|
33
|
-
if (!eList) {
|
|
34
|
-
eList = storeMap[type] = []
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// 检测重复
|
|
38
|
-
if (eList.indexOf(callback) > -1) {
|
|
39
|
-
log.warn('vxe.error.coverProp', ['Interceptor', type])
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
eList.push(callback)
|
|
43
|
-
}
|
|
44
|
-
return interceptor
|
|
45
|
-
},
|
|
46
|
-
delete (type: string, render) {
|
|
47
|
-
const eList = storeMap[type]
|
|
48
|
-
if (eList) {
|
|
49
|
-
// 兼容
|
|
50
|
-
if (XEUtils.isFunction(render)) {
|
|
51
|
-
render = {
|
|
52
|
-
tableInterceptorMethod: render
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
const callback = render ? render.tableInterceptorMethod : null
|
|
56
|
-
|
|
57
|
-
if (callback) {
|
|
58
|
-
XEUtils.remove(eList, fn => fn === callback)
|
|
59
|
-
} else {
|
|
60
|
-
delete storeMap[type]
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
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
|
+
if (type) {
|
|
17
|
+
return storeMap[type] || []
|
|
18
|
+
}
|
|
19
|
+
return []
|
|
20
|
+
},
|
|
21
|
+
add (type, render) {
|
|
22
|
+
// 兼容
|
|
23
|
+
if (XEUtils.isFunction(render)) {
|
|
24
|
+
// log.warn('vxe.error.delProp', ['interceptor -> callback', 'tableInterceptorMethod'])
|
|
25
|
+
render = {
|
|
26
|
+
tableInterceptorMethod: render
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const callback = render.tableInterceptorMethod
|
|
30
|
+
|
|
31
|
+
if (callback) {
|
|
32
|
+
let eList = storeMap[type]
|
|
33
|
+
if (!eList) {
|
|
34
|
+
eList = storeMap[type] = []
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// 检测重复
|
|
38
|
+
if (eList.indexOf(callback) > -1) {
|
|
39
|
+
log.warn('vxe.error.coverProp', ['Interceptor', type])
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
eList.push(callback)
|
|
43
|
+
}
|
|
44
|
+
return interceptor
|
|
45
|
+
},
|
|
46
|
+
delete (type: string, render) {
|
|
47
|
+
const eList = storeMap[type]
|
|
48
|
+
if (eList) {
|
|
49
|
+
// 兼容
|
|
50
|
+
if (XEUtils.isFunction(render)) {
|
|
51
|
+
render = {
|
|
52
|
+
tableInterceptorMethod: render
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const callback = render ? render.tableInterceptorMethod : null
|
|
56
|
+
|
|
57
|
+
if (callback) {
|
|
58
|
+
XEUtils.remove(eList, fn => fn === callback)
|
|
59
|
+
} else {
|
|
60
|
+
delete storeMap[type]
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
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
|
+
}
|
package/packages/src/menus.ts
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
import XEUtils from 'xe-utils'
|
|
2
|
-
import { log } from './log'
|
|
3
|
-
|
|
4
|
-
import { VxeGlobalMenus } from '../../types'
|
|
5
|
-
|
|
6
|
-
class VXEMenusStore {
|
|
7
|
-
private store: any = {}
|
|
8
|
-
|
|
9
|
-
mixin (options: any): VXEMenusStore {
|
|
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): VXEMenusStore {
|
|
25
|
-
const conf = this.store[name]
|
|
26
|
-
// 兼容
|
|
27
|
-
if (XEUtils.isFunction(render)) {
|
|
28
|
-
log.warn('vxe.error.delProp', ['menus -> callback', 'menuMethod'])
|
|
29
|
-
render = {
|
|
30
|
-
menuMethod: render
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// 检测是否覆盖
|
|
35
|
-
const confKeys = XEUtils.keys(conf)
|
|
36
|
-
XEUtils.each(render, (item, key) => {
|
|
37
|
-
if (confKeys.includes(key)) {
|
|
38
|
-
log.warn('vxe.error.coverProp', [name, key])
|
|
39
|
-
}
|
|
40
|
-
})
|
|
41
|
-
this.store[name] = conf ? XEUtils.merge(conf, render) : render
|
|
42
|
-
return this
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
delete (name: string): void {
|
|
46
|
-
delete this.store[name]
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
forEach (callback: any): void {
|
|
50
|
-
XEUtils.objectEach(this.store, callback)
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export const menus = new VXEMenusStore() as VxeGlobalMenus
|
|
55
|
-
|
|
56
|
-
Object.assign(menus, { _name: 'Menus' })
|
|
1
|
+
import XEUtils from 'xe-utils'
|
|
2
|
+
import { log } from './log'
|
|
3
|
+
|
|
4
|
+
import { VxeGlobalMenus } from '../../types'
|
|
5
|
+
|
|
6
|
+
class VXEMenusStore {
|
|
7
|
+
private store: any = {}
|
|
8
|
+
|
|
9
|
+
mixin (options: any): VXEMenusStore {
|
|
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): VXEMenusStore {
|
|
25
|
+
const conf = this.store[name]
|
|
26
|
+
// 兼容
|
|
27
|
+
if (XEUtils.isFunction(render)) {
|
|
28
|
+
log.warn('vxe.error.delProp', ['menus -> callback', 'menuMethod'])
|
|
29
|
+
render = {
|
|
30
|
+
menuMethod: render
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// 检测是否覆盖
|
|
35
|
+
const confKeys = XEUtils.keys(conf)
|
|
36
|
+
XEUtils.each(render, (item, key) => {
|
|
37
|
+
if (confKeys.includes(key)) {
|
|
38
|
+
log.warn('vxe.error.coverProp', [name, key])
|
|
39
|
+
}
|
|
40
|
+
})
|
|
41
|
+
this.store[name] = conf ? XEUtils.merge(conf, render) : render
|
|
42
|
+
return this
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
delete (name: string): void {
|
|
46
|
+
delete this.store[name]
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
forEach (callback: any): void {
|
|
50
|
+
XEUtils.objectEach(this.store, callback)
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export const menus = new VXEMenusStore() as VxeGlobalMenus
|
|
55
|
+
|
|
56
|
+
Object.assign(menus, { _name: 'Menus' })
|
|
@@ -1,61 +1,61 @@
|
|
|
1
|
-
import { globalConfigStore } from './configStore'
|
|
2
|
-
import XEUtils from 'xe-utils'
|
|
3
|
-
|
|
4
|
-
import type { VxeGlobalPermission, VxeComponentPermissionCodeType, VxeComponentPermissionInfo, VxeComponentPermissionMethod } from '../../types'
|
|
5
|
-
|
|
6
|
-
export function handleCheckInfo (permissionCode?: VxeComponentPermissionCodeType, permissionMethod?: VxeComponentPermissionMethod) {
|
|
7
|
-
let checkVisible = true
|
|
8
|
-
let checkDisabled = false
|
|
9
|
-
const checkMethod = permissionMethod || globalConfigStore.permissionMethod
|
|
10
|
-
if (permissionCode && checkMethod) {
|
|
11
|
-
checkVisible = false
|
|
12
|
-
checkDisabled = true
|
|
13
|
-
let vDone = false
|
|
14
|
-
let dDone = false
|
|
15
|
-
// 或 使用 | 隔开:任意一个为可视,则可视;任意一个禁用,则禁用
|
|
16
|
-
const codeList = String(permissionCode).split('|')
|
|
17
|
-
for (let i = 0; i < codeList.length; i++) {
|
|
18
|
-
const code = codeList[i]
|
|
19
|
-
let visible = true
|
|
20
|
-
let disabled = false
|
|
21
|
-
const rest = checkMethod({ code })
|
|
22
|
-
if (XEUtils.isBoolean(rest)) {
|
|
23
|
-
visible = rest
|
|
24
|
-
} else if (rest) {
|
|
25
|
-
visible = !!rest.visible
|
|
26
|
-
disabled = !!rest.disabled
|
|
27
|
-
}
|
|
28
|
-
if (!disabled && !dDone) {
|
|
29
|
-
dDone = true
|
|
30
|
-
checkDisabled = disabled
|
|
31
|
-
}
|
|
32
|
-
if (visible && !vDone) {
|
|
33
|
-
vDone = true
|
|
34
|
-
checkVisible = visible
|
|
35
|
-
}
|
|
36
|
-
if (vDone && dDone) {
|
|
37
|
-
break
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
const info: VxeComponentPermissionInfo = {
|
|
42
|
-
code: permissionCode,
|
|
43
|
-
visible: checkVisible,
|
|
44
|
-
disabled: checkDisabled
|
|
45
|
-
}
|
|
46
|
-
return info
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
export const permission: VxeGlobalPermission = {
|
|
50
|
-
getCheckInfo (code) {
|
|
51
|
-
return handleCheckInfo(code)
|
|
52
|
-
},
|
|
53
|
-
checkVisible (code) {
|
|
54
|
-
const permissionInfo = handleCheckInfo(code)
|
|
55
|
-
return permissionInfo.visible
|
|
56
|
-
},
|
|
57
|
-
checkDisable (code) {
|
|
58
|
-
const permissionInfo = handleCheckInfo(code)
|
|
59
|
-
return permissionInfo.disabled
|
|
60
|
-
}
|
|
61
|
-
}
|
|
1
|
+
import { globalConfigStore } from './configStore'
|
|
2
|
+
import XEUtils from 'xe-utils'
|
|
3
|
+
|
|
4
|
+
import type { VxeGlobalPermission, VxeComponentPermissionCodeType, VxeComponentPermissionInfo, VxeComponentPermissionMethod } from '../../types'
|
|
5
|
+
|
|
6
|
+
export function handleCheckInfo (permissionCode?: VxeComponentPermissionCodeType, permissionMethod?: VxeComponentPermissionMethod) {
|
|
7
|
+
let checkVisible = true
|
|
8
|
+
let checkDisabled = false
|
|
9
|
+
const checkMethod = permissionMethod || globalConfigStore.permissionMethod
|
|
10
|
+
if (permissionCode && checkMethod) {
|
|
11
|
+
checkVisible = false
|
|
12
|
+
checkDisabled = true
|
|
13
|
+
let vDone = false
|
|
14
|
+
let dDone = false
|
|
15
|
+
// 或 使用 | 隔开:任意一个为可视,则可视;任意一个禁用,则禁用
|
|
16
|
+
const codeList = String(permissionCode).split('|')
|
|
17
|
+
for (let i = 0; i < codeList.length; i++) {
|
|
18
|
+
const code = codeList[i]
|
|
19
|
+
let visible = true
|
|
20
|
+
let disabled = false
|
|
21
|
+
const rest = checkMethod({ code })
|
|
22
|
+
if (XEUtils.isBoolean(rest)) {
|
|
23
|
+
visible = rest
|
|
24
|
+
} else if (rest) {
|
|
25
|
+
visible = !!rest.visible
|
|
26
|
+
disabled = !!rest.disabled
|
|
27
|
+
}
|
|
28
|
+
if (!disabled && !dDone) {
|
|
29
|
+
dDone = true
|
|
30
|
+
checkDisabled = disabled
|
|
31
|
+
}
|
|
32
|
+
if (visible && !vDone) {
|
|
33
|
+
vDone = true
|
|
34
|
+
checkVisible = visible
|
|
35
|
+
}
|
|
36
|
+
if (vDone && dDone) {
|
|
37
|
+
break
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const info: VxeComponentPermissionInfo = {
|
|
42
|
+
code: permissionCode,
|
|
43
|
+
visible: checkVisible,
|
|
44
|
+
disabled: checkDisabled
|
|
45
|
+
}
|
|
46
|
+
return info
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export const permission: VxeGlobalPermission = {
|
|
50
|
+
getCheckInfo (code) {
|
|
51
|
+
return handleCheckInfo(code)
|
|
52
|
+
},
|
|
53
|
+
checkVisible (code) {
|
|
54
|
+
const permissionInfo = handleCheckInfo(code)
|
|
55
|
+
return permissionInfo.visible
|
|
56
|
+
},
|
|
57
|
+
checkDisable (code) {
|
|
58
|
+
const permissionInfo = handleCheckInfo(code)
|
|
59
|
+
return permissionInfo.disabled
|
|
60
|
+
}
|
|
61
|
+
}
|