@vxe-ui/core 4.4.42 → 4.5.1
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/dist/all.esm.js +1594 -1389
- package/dist/all.esm.min.js +1 -0
- package/es/index.d.ts +138 -0
- package/es/index.esm.js +138 -125
- package/es/index.js +150 -0
- package/es/src/base-utils.d.ts +2 -0
- package/es/src/base-utils.js +40 -37
- package/es/src/clipboard.d.ts +2 -0
- package/es/src/clipboard.js +48 -45
- package/es/src/commands.d.ts +2 -0
- package/es/src/commands.js +47 -48
- package/es/src/config.d.ts +13 -0
- package/es/src/config.js +21 -23
- package/es/src/configStore.d.ts +2 -0
- package/es/src/configStore.js +8 -5
- package/es/src/core.d.ts +3 -0
- package/es/src/core.js +11 -7
- package/es/src/dataStore.d.ts +2 -0
- package/es/src/dataStore.js +4 -1
- package/es/src/db-utils.d.ts +2 -0
- package/es/src/db-utils.js +234 -0
- package/es/src/dom-utils.d.ts +2 -0
- package/es/src/dom-utils.js +65 -68
- package/es/src/event.d.ts +4 -0
- package/es/src/event.js +133 -147
- package/es/src/formats.d.ts +2 -0
- package/es/src/formats.js +47 -48
- package/es/src/hooks.d.ts +2 -0
- package/es/src/hooks.js +5 -2
- package/es/src/i18n.d.ts +6 -0
- package/es/src/i18n.js +51 -44
- package/es/src/i18nStore.d.ts +5 -0
- package/es/src/i18nStore.js +7 -4
- package/es/src/icon.d.ts +9 -0
- package/es/src/icon.js +28 -22
- package/es/src/iconStore.d.ts +2 -0
- package/es/src/iconStore.js +4 -1
- package/es/src/interceptor.d.ts +2 -0
- package/es/src/interceptor.js +52 -54
- package/es/src/log.d.ts +2 -0
- package/es/src/log.js +14 -11
- package/es/src/menus.d.ts +2 -0
- package/es/src/menus.js +47 -48
- package/es/src/permission.d.ts +3 -0
- package/es/src/permission.js +57 -55
- package/es/src/popper-utils.d.ts +2 -0
- package/es/src/popper-utils.js +159 -179
- package/es/src/renderer.d.ts +5 -0
- package/es/src/renderer.js +37 -42
- package/es/src/resize.d.ts +2 -0
- package/es/src/resize.js +60 -70
- package/es/src/scrollbar-utils.d.ts +2 -0
- package/es/src/scrollbar-utils.js +57 -54
- package/es/src/store.d.ts +13 -0
- package/es/src/store.js +43 -45
- package/es/src/theme.d.ts +3 -0
- package/es/src/theme.js +17 -13
- package/es/src/themeStore.d.ts +4 -0
- package/es/src/themeStore.js +5 -2
- package/es/src/useFns.d.ts +40 -0
- package/es/src/useFns.js +212 -231
- package/es/src/validators.d.ts +2 -0
- package/es/src/validators.js +6 -3
- package/es/src/vm.d.ts +2 -0
- package/es/src/vm.js +9 -6
- package/es/src/z-index.d.ts +2 -0
- package/es/src/z-index.js +29 -26
- package/lib/index.common.js +136 -365
- package/lib/index.js +181 -0
- package/lib/index.umd.js +819 -3343
- package/lib/index.umd.min.js +1 -1
- package/lib/src/base-utils.js +39 -13
- package/lib/src/clipboard.js +50 -23
- package/lib/src/commands.js +46 -27
- package/lib/src/config.js +43 -23
- package/lib/src/configStore.js +24 -7
- package/lib/src/core.js +29 -11
- package/lib/src/dataStore.js +22 -5
- package/lib/src/db-utils.js +263 -0
- package/lib/src/dom-utils.js +40 -20
- package/lib/src/event.js +95 -102
- package/lib/src/formats.js +46 -27
- package/lib/src/hooks.js +33 -7
- package/lib/src/i18n.js +53 -38
- package/lib/src/i18nStore.js +25 -8
- package/lib/src/icon.js +46 -22
- package/lib/src/iconStore.js +22 -5
- package/lib/src/interceptor.js +40 -18
- package/lib/src/log.js +29 -12
- package/lib/src/menus.js +46 -27
- package/lib/src/permission.js +40 -17
- package/lib/src/popper-utils.js +71 -71
- package/lib/src/renderer.js +40 -21
- package/lib/src/resize.js +48 -42
- package/lib/src/scrollbar-utils.js +23 -6
- package/lib/src/store.js +44 -25
- package/lib/src/theme.js +31 -14
- package/lib/src/themeStore.js +24 -7
- package/lib/src/useFns.js +87 -124
- package/lib/src/validators.js +34 -10
- package/lib/src/vm.js +34 -8
- package/lib/src/z-index.js +38 -12
- package/package.json +14 -3
- package/packages/index.ts +171 -168
- package/packages/src/base-utils.ts +42 -43
- 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 +3 -4
- package/packages/src/db-utils.ts +267 -0
- package/packages/src/dom-utils.ts +86 -87
- package/packages/src/event.ts +161 -161
- 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/popper-utils.ts +197 -194
- package/packages/src/renderer.ts +50 -50
- package/packages/src/resize.ts +89 -89
- package/packages/src/scrollbar-utils.ts +58 -58
- 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 +270 -275
- package/packages/src/validators.ts +7 -7
- package/packages/src/vm.ts +10 -10
- package/packages/src/z-index.ts +30 -30
- package/types/core/base-utils.d.ts +39 -40
- package/types/core/clipboard.d.ts +22 -22
- package/types/core/commands.d.ts +17 -19
- package/types/core/components.d.ts +5 -5
- package/types/core/db-utils.d.ts +44 -0
- package/types/core/dom-utils.d.ts +36 -37
- package/types/core/formats.d.ts +17 -19
- package/types/core/global-config.d.ts +67 -74
- package/types/core/global-data.d.ts +7 -7
- package/types/core/global-event.d.ts +48 -48
- package/types/core/global-icon.d.ts +10 -10
- package/types/core/global-lang.d.ts +28 -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 +12 -14
- package/types/core/index.d.ts +343 -336
- package/types/core/interceptor.d.ts +20 -22
- package/types/core/log.d.ts +8 -8
- package/types/core/menus.d.ts +17 -19
- package/types/core/permission.d.ts +10 -10
- package/types/core/popper-utils.d.ts +44 -44
- package/types/core/renderer.d.ts +14 -14
- package/types/core/scrollbar-utils.d.ts +37 -38
- package/types/core/useFn.d.ts +121 -126
- package/types/core/validators.d.ts +17 -19
- package/types/core/z-index.d.ts +18 -18
- package/types/index.d.ts +13 -13
- package/types/tool/common.d.ts +146 -155
- package/types/tool/index.d.ts +2 -2
- package/types/tool/util.d.ts +4 -4
- package/lib/src/base-utils.min.js +0 -1
- package/lib/src/clipboard.min.js +0 -1
- package/lib/src/commands.min.js +0 -1
- package/lib/src/config.min.js +0 -1
- package/lib/src/configStore.min.js +0 -1
- package/lib/src/core.min.js +0 -1
- package/lib/src/dataStore.min.js +0 -1
- package/lib/src/dom-utils.min.js +0 -1
- package/lib/src/event.min.js +0 -1
- package/lib/src/formats.min.js +0 -1
- package/lib/src/hooks.min.js +0 -1
- package/lib/src/i18n.min.js +0 -1
- package/lib/src/i18nStore.min.js +0 -1
- package/lib/src/icon.min.js +0 -1
- package/lib/src/iconStore.min.js +0 -1
- package/lib/src/interceptor.min.js +0 -1
- package/lib/src/log.min.js +0 -1
- package/lib/src/menus.min.js +0 -1
- package/lib/src/permission.min.js +0 -1
- package/lib/src/popper-utils.min.js +0 -1
- package/lib/src/renderer.min.js +0 -1
- package/lib/src/resize.min.js +0 -1
- package/lib/src/scrollbar-utils.min.js +0 -1
- package/lib/src/store.min.js +0 -1
- package/lib/src/theme.min.js +0 -1
- package/lib/src/themeStore.min.js +0 -1
- package/lib/src/useFns.min.js +0 -1
- package/lib/src/validators.min.js +0 -1
- package/lib/src/vm.min.js +0 -1
- package/lib/src/z-index.min.js +0 -1
package/packages/src/commands.ts
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
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
|
|
10
|
-
XEUtils.each(options, (item, key) => {
|
|
11
|
-
this.add(key, item)
|
|
12
|
-
})
|
|
13
|
-
return this
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
has
|
|
17
|
-
return !!this.get(name)
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
get
|
|
21
|
-
return this.store[name]
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
add
|
|
25
|
-
const conf = this.store[name]
|
|
26
|
-
// 兼容
|
|
27
|
-
if (XEUtils.isFunction(render)) {
|
|
28
|
-
log.warn('vxe.error.delProp', ['commands -> callback', 'commandMethod'])
|
|
29
|
-
render = {
|
|
30
|
-
commandMethod: 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
|
|
46
|
-
delete this.store[name]
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
forEach
|
|
50
|
-
XEUtils.objectEach(this.store, callback)
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export const commands = new VXECommandsStore() as VxeGlobalCommands
|
|
55
|
-
|
|
56
|
-
Object.assign(commands, { _name: 'Commands' })
|
|
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
|
+
log.warn('vxe.error.delProp', ['commands -> callback', 'commandMethod'])
|
|
29
|
+
render = {
|
|
30
|
+
commandMethod: 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 commands = new VXECommandsStore() as VxeGlobalCommands
|
|
55
|
+
|
|
56
|
+
Object.assign(commands, { _name: 'Commands' })
|
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
|
|
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
|
|
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,11 +1,11 @@
|
|
|
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
|
-
designVersion: '',
|
|
10
|
-
ganttVersion: ''
|
|
11
|
-
} 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
|
+
designVersion: '',
|
|
10
|
+
ganttVersion: ''
|
|
11
|
+
} as VxeUIExport
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { VxeGlobalData } from '../../types'
|
|
2
|
-
|
|
3
|
-
export const globalStore: VxeGlobalData = {
|
|
4
|
-
}
|
|
1
|
+
import { VxeGlobalData } from '../../types'
|
|
2
|
+
|
|
3
|
+
export const globalStore: VxeGlobalData = {}
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import XEUtils from 'xe-utils'
|
|
2
|
+
import { globalConfigStore } from './configStore'
|
|
3
|
+
|
|
4
|
+
import type { VxeDBUtils, VxeDBStore, VxeDBOptions } from '../../types'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* IndexedDB 存储
|
|
8
|
+
* - 库名 = `${key}_${version}`,version 变化 => 换库
|
|
9
|
+
*/
|
|
10
|
+
class IdbStore implements VxeDBStore {
|
|
11
|
+
private storeName = 'Storage'
|
|
12
|
+
private key: string
|
|
13
|
+
private version: string | number
|
|
14
|
+
private dbPromise: Promise<IDBDatabase> | null = null
|
|
15
|
+
private dbName = ''
|
|
16
|
+
|
|
17
|
+
constructor(key: string, version: string | number) {
|
|
18
|
+
this.key = key
|
|
19
|
+
this.version = version
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
private getDBName() {
|
|
23
|
+
return `${this.key}_${this.version}`
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 重置连接缓存,下次调用 openDB 会重新建立连接
|
|
28
|
+
*/
|
|
29
|
+
private resetDB() {
|
|
30
|
+
this.dbPromise = null
|
|
31
|
+
this.dbName = ''
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
private openDB(): Promise<IDBDatabase> {
|
|
35
|
+
const name = this.getDBName()
|
|
36
|
+
if (this.dbPromise && this.dbName === name) {
|
|
37
|
+
return this.dbPromise
|
|
38
|
+
}
|
|
39
|
+
this.dbName = name
|
|
40
|
+
this.dbPromise = new Promise<IDBDatabase>((resolve, reject) => {
|
|
41
|
+
const request = indexedDB.open(name, 1)
|
|
42
|
+
request.onupgradeneeded = () => {
|
|
43
|
+
const db = request.result
|
|
44
|
+
if (!db.objectStoreNames.contains(this.storeName)) {
|
|
45
|
+
db.createObjectStore(this.storeName, { keyPath: 'id' })
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
request.onsuccess = () => {
|
|
49
|
+
const db = request.result
|
|
50
|
+
// 连接失效时清缓存,下次自动重建
|
|
51
|
+
db.onversionchange = () => {
|
|
52
|
+
db.close()
|
|
53
|
+
this.resetDB()
|
|
54
|
+
}
|
|
55
|
+
db.onclose = () => {
|
|
56
|
+
this.resetDB()
|
|
57
|
+
}
|
|
58
|
+
resolve(db)
|
|
59
|
+
}
|
|
60
|
+
// 失败时先 reject,由外层 catch 统一清缓存
|
|
61
|
+
request.onerror = () => {
|
|
62
|
+
reject(request.error || new Error(`IdbStore open failed: ${name}`))
|
|
63
|
+
}
|
|
64
|
+
// blocked 仅警告,不 reject:其他连接关闭后仍可能 onsuccess
|
|
65
|
+
request.onblocked = () => {
|
|
66
|
+
console.warn(`[IdbStore] open blocked: ${name}`)
|
|
67
|
+
}
|
|
68
|
+
}).catch((err) => {
|
|
69
|
+
// 覆盖 request.onerror 和同步抛错两种情况,避免缓存 rejected Promise
|
|
70
|
+
this.resetDB()
|
|
71
|
+
throw err
|
|
72
|
+
})
|
|
73
|
+
return this.dbPromise
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
getById(id: string): Promise<{ id: string; data: any } | undefined> {
|
|
77
|
+
return this.openDB().then((db) =>
|
|
78
|
+
new Promise<{ id: string; data: any } | undefined>((resolve, reject) => {
|
|
79
|
+
const req = db.transaction(this.storeName, 'readonly').objectStore(this.storeName).get(id)
|
|
80
|
+
req.onsuccess = () => resolve(req.result)
|
|
81
|
+
req.onerror = () => reject(req.error)
|
|
82
|
+
})
|
|
83
|
+
)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
getAll(): Promise<{ id: string; data: any }[]> {
|
|
87
|
+
return this.openDB().then((db) =>
|
|
88
|
+
new Promise<{ id: string; data: any }[]>((resolve, reject) => {
|
|
89
|
+
const store = db.transaction(this.storeName, 'readonly').objectStore(this.storeName)
|
|
90
|
+
if (XEUtils.isFunction(store.getAll)) {
|
|
91
|
+
const req = store.getAll()
|
|
92
|
+
req.onsuccess = () => resolve(req.result || [])
|
|
93
|
+
req.onerror = () => reject(req.error)
|
|
94
|
+
return
|
|
95
|
+
}
|
|
96
|
+
const list: { id: string; data: any }[] = []
|
|
97
|
+
const req = store.openCursor()
|
|
98
|
+
req.onsuccess = () => {
|
|
99
|
+
const cursor = req.result
|
|
100
|
+
if (cursor) {
|
|
101
|
+
list.push(cursor.value)
|
|
102
|
+
cursor.continue()
|
|
103
|
+
} else {
|
|
104
|
+
resolve(list)
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
req.onerror = () => reject(req.error)
|
|
108
|
+
})
|
|
109
|
+
)
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
updateById(id: string, data: any): Promise<void> {
|
|
113
|
+
// 与 LocalStorageStore 对齐:null / undefined 等价删除
|
|
114
|
+
if (data == null) {
|
|
115
|
+
return this.deleteById(id)
|
|
116
|
+
}
|
|
117
|
+
return this.openDB().then((db) =>
|
|
118
|
+
new Promise<void>((resolve, reject) => {
|
|
119
|
+
const tx = db.transaction(this.storeName, 'readwrite')
|
|
120
|
+
tx.objectStore(this.storeName).put({ id, data })
|
|
121
|
+
tx.oncomplete = () => resolve()
|
|
122
|
+
tx.onerror = () => reject(tx.error)
|
|
123
|
+
})
|
|
124
|
+
)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
deleteById(id: string): Promise<void> {
|
|
128
|
+
return this.openDB().then((db) =>
|
|
129
|
+
new Promise<void>((resolve, reject) => {
|
|
130
|
+
const tx = db.transaction(this.storeName, 'readwrite')
|
|
131
|
+
tx.objectStore(this.storeName).delete(id)
|
|
132
|
+
tx.oncomplete = () => resolve()
|
|
133
|
+
tx.onerror = () => reject(tx.error)
|
|
134
|
+
})
|
|
135
|
+
)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* 清空当前库的数据
|
|
140
|
+
*/
|
|
141
|
+
clear(): Promise<void> {
|
|
142
|
+
return this.openDB().then((db) =>
|
|
143
|
+
new Promise<void>((resolve, reject) => {
|
|
144
|
+
const tx = db.transaction(this.storeName, 'readwrite')
|
|
145
|
+
tx.objectStore(this.storeName).clear()
|
|
146
|
+
tx.oncomplete = () => resolve()
|
|
147
|
+
tx.onerror = () => reject(tx.error)
|
|
148
|
+
})
|
|
149
|
+
)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* 清理非当前版本的旧库
|
|
154
|
+
*/
|
|
155
|
+
cleanupOldDBs(): Promise<void> {
|
|
156
|
+
if (!indexedDB.databases) {
|
|
157
|
+
return Promise.resolve()
|
|
158
|
+
}
|
|
159
|
+
const current = this.getDBName()
|
|
160
|
+
const prefix = `${this.key}_`
|
|
161
|
+
return indexedDB.databases().then((dbs) => {
|
|
162
|
+
dbs.forEach((db) => {
|
|
163
|
+
const n = db.name
|
|
164
|
+
if (!n || n === current || !n.startsWith(prefix)) {
|
|
165
|
+
return
|
|
166
|
+
}
|
|
167
|
+
const rest = n.slice(prefix.length)
|
|
168
|
+
if (!rest.includes('_')) {
|
|
169
|
+
indexedDB.deleteDatabase(n)
|
|
170
|
+
}
|
|
171
|
+
})
|
|
172
|
+
})
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* localStorage 存储
|
|
178
|
+
* - 储存结构:{ _v: version, [id]: data },靠 _v 区分版本
|
|
179
|
+
* - version 变化 => 读取时视为空{} => 重置
|
|
180
|
+
*/
|
|
181
|
+
class LocalStorageStore implements VxeDBStore {
|
|
182
|
+
private key: string
|
|
183
|
+
private version: string | number
|
|
184
|
+
|
|
185
|
+
constructor(key: string, version: string | number) {
|
|
186
|
+
this.key = key
|
|
187
|
+
this.version = version
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
private readAll(): Record<string, any> {
|
|
191
|
+
const storageData = XEUtils.toStringJSON(localStorage.getItem(this.key) || '')
|
|
192
|
+
return storageData && String(storageData._v) === String(this.version) ? storageData : { _v: this.version }
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
private writeAll(map: Record<string, any>) {
|
|
196
|
+
localStorage.setItem(this.key, XEUtils.toJSONString(map))
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
getById(id: string): Promise<{ id: string; data: any } | undefined> {
|
|
200
|
+
const map = this.readAll()
|
|
201
|
+
const has = Object.prototype.hasOwnProperty.call(map, id)
|
|
202
|
+
return Promise.resolve(has && map[id] != null ? { id, data: map[id] } : undefined)
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
getAll(): Promise<{ id: string; data: any }[]> {
|
|
206
|
+
const map = this.readAll()
|
|
207
|
+
const list: { id: string; data: any }[] = []
|
|
208
|
+
Object.keys(map).forEach((k) => {
|
|
209
|
+
if (k !== '_v' && map[k] != null) {
|
|
210
|
+
list.push({ id: k, data: map[k] })
|
|
211
|
+
}
|
|
212
|
+
})
|
|
213
|
+
return Promise.resolve(list)
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
updateById(id: string, data: any): Promise<void> {
|
|
217
|
+
// null / undefined 等价删除
|
|
218
|
+
if (data == null) {
|
|
219
|
+
return this.deleteById(id)
|
|
220
|
+
}
|
|
221
|
+
const map = this.readAll()
|
|
222
|
+
map[id] = data
|
|
223
|
+
this.writeAll(map)
|
|
224
|
+
return Promise.resolve()
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
deleteById(id: string): Promise<void> {
|
|
228
|
+
const map = this.readAll()
|
|
229
|
+
delete map[id]
|
|
230
|
+
this.writeAll(map)
|
|
231
|
+
return Promise.resolve()
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
clear(): Promise<void> {
|
|
235
|
+
this.writeAll({ _v: this.version })
|
|
236
|
+
return Promise.resolve()
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
cleanupOldDBs(): Promise<void> {
|
|
240
|
+
const raw = localStorage.getItem(this.key)
|
|
241
|
+
if (!raw) {
|
|
242
|
+
return Promise.resolve()
|
|
243
|
+
}
|
|
244
|
+
const storageData = XEUtils.toStringJSON(raw)
|
|
245
|
+
if (!storageData || String(storageData._v) !== String(this.version)) {
|
|
246
|
+
localStorage.removeItem(this.key)
|
|
247
|
+
}
|
|
248
|
+
return Promise.resolve()
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export const dbUtils: VxeDBUtils = {
|
|
253
|
+
/**
|
|
254
|
+
* 创建存储实例
|
|
255
|
+
* - driver = 'indexedDB' 且环境支持 => IdbStore
|
|
256
|
+
* - 其余情况(未传 / 不支持)=> LocalStorageStore
|
|
257
|
+
*/
|
|
258
|
+
createStore(key: string, options?: VxeDBOptions): VxeDBStore {
|
|
259
|
+
const opts = Object.assign({}, options)
|
|
260
|
+
const version = opts.version || globalConfigStore.version || 0
|
|
261
|
+
const driver = opts.driver
|
|
262
|
+
if ((!driver || driver === 'indexedDB') && typeof indexedDB !== 'undefined') {
|
|
263
|
+
return new IdbStore(key, version)
|
|
264
|
+
}
|
|
265
|
+
return new LocalStorageStore(key, version)
|
|
266
|
+
}
|
|
267
|
+
}
|
|
@@ -1,87 +1,86 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
1
|
+
import XEUtils from 'xe-utils'
|
|
2
|
+
|
|
3
|
+
import { VxeDomUtils } from '../../types'
|
|
4
|
+
|
|
5
|
+
const reClsMap: { [key: string]: any } = {}
|
|
6
|
+
|
|
7
|
+
function getClsRE(cls: any) {
|
|
8
|
+
if (!reClsMap[cls]) {
|
|
9
|
+
reClsMap[cls] = new RegExp(`(?:^|\\s)${cls}(?!\\S)`, 'g')
|
|
10
|
+
}
|
|
11
|
+
return reClsMap[cls]
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 判断元素是否包含 class
|
|
16
|
+
*/
|
|
17
|
+
function hasClass(elem: any, cls: any) {
|
|
18
|
+
if (elem) {
|
|
19
|
+
if (elem.classList) {
|
|
20
|
+
return elem.classList.contains(cls)
|
|
21
|
+
}
|
|
22
|
+
return !!(elem.className && elem.className.match && elem.className.match(getClsRE(cls)))
|
|
23
|
+
}
|
|
24
|
+
return false
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 给元素删除 class
|
|
29
|
+
*/
|
|
30
|
+
function removeClass(elem: any, cls: any) {
|
|
31
|
+
if (elem && hasClass(elem, cls)) {
|
|
32
|
+
elem.className = elem.className.replace(getClsRE(cls), '')
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const domUtils: VxeDomUtils = {
|
|
37
|
+
/**
|
|
38
|
+
* 判断是否像素px单位 '100px' | 100
|
|
39
|
+
*/
|
|
40
|
+
isPx(val: any) {
|
|
41
|
+
return val && /^\d+(\.\d+)?(px)?$/.test(val)
|
|
42
|
+
},
|
|
43
|
+
/**
|
|
44
|
+
* 判断是否百分比%单位 '100%'
|
|
45
|
+
*/
|
|
46
|
+
isScale(val: any) {
|
|
47
|
+
return val && /^\d+(\.\d+)?%$/.test(val)
|
|
48
|
+
},
|
|
49
|
+
/**
|
|
50
|
+
* 判断元素是否包含 class
|
|
51
|
+
*/
|
|
52
|
+
hasClass,
|
|
53
|
+
/**
|
|
54
|
+
* 给元素删除 class
|
|
55
|
+
*/
|
|
56
|
+
removeClass,
|
|
57
|
+
/**
|
|
58
|
+
* 给元素增加 class
|
|
59
|
+
*/
|
|
60
|
+
addClass(elem: any, cls: string) {
|
|
61
|
+
if (elem && !hasClass(elem, cls)) {
|
|
62
|
+
removeClass(elem, cls)
|
|
63
|
+
elem.className = elem.className + ' ' + cls
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
/**
|
|
67
|
+
* 生成 className
|
|
68
|
+
*/
|
|
69
|
+
buildClass(staticClassNames, mapClassName) {
|
|
70
|
+
const parts: string[] = []
|
|
71
|
+
if (staticClassNames) {
|
|
72
|
+
for (let i = 0; i < staticClassNames.length; i++) {
|
|
73
|
+
const val = staticClassNames[i]
|
|
74
|
+
if (val) {
|
|
75
|
+
parts.push('' + val)
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
XEUtils.each(mapClassName, (val, key) => {
|
|
80
|
+
if (val) {
|
|
81
|
+
parts.push(key)
|
|
82
|
+
}
|
|
83
|
+
})
|
|
84
|
+
return parts.join(' ')
|
|
85
|
+
}
|
|
86
|
+
}
|