zhou zhou
16 小时以前 fec285d150b377d004e47f0973d298b92fe4c711
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
class StorageConfig {
  /**
   * 生成版本化的存储键名
   * @param storeId 存储ID
   * @param version 版本号,默认使用当前版本
   */
  static generateStorageKey(storeId, version = this.CURRENT_VERSION) {
    return `${this.STORAGE_PREFIX}${version}-${storeId}`
  }
  /**
   * 生成旧版本的存储键名(不带分隔符)
   * @param version 版本号,默认使用当前版本
   */
  static generateLegacyKey(version = this.CURRENT_VERSION) {
    return `${this.STORAGE_PREFIX}${version}`
  }
  /**
   * 创建存储键匹配的正则表达式
   * @param storeId 存储ID
   */
  static createKeyPattern(storeId) {
    return new RegExp(`^${this.STORAGE_PREFIX}[^-]+-${storeId}$`)
  }
  /**
   * 创建当前版本存储键匹配的正则表达式
   */
  static createCurrentVersionPattern() {
    return new RegExp(`^${this.STORAGE_PREFIX}${this.CURRENT_VERSION}-`)
  }
  /**
   * 创建任意版本存储键匹配的正则表达式
   */
  static createVersionPattern() {
    return new RegExp(`^${this.STORAGE_PREFIX}`)
  }
  /**
   * 检查是否为当前版本的键
   */
  static isCurrentVersionKey(key) {
    return key.startsWith(`${this.STORAGE_PREFIX}${this.CURRENT_VERSION}`)
  }
  /**
   * 检查是否为版本化的键
   */
  static isVersionedKey(key) {
    return key.startsWith(this.STORAGE_PREFIX)
  }
  /**
   * 从存储键中提取版本号
   */
  static extractVersionFromKey(key) {
    const match = key.match(new RegExp(`^${this.STORAGE_PREFIX}([^-]+)`))
    return match ? match[1] : null
  }
  /**
   * 从存储键中提取存储ID
   */
  static extractStoreIdFromKey(key) {
    const match = key.match(new RegExp(`^${this.STORAGE_PREFIX}[^-]+-(.+)$`))
    return match ? match[1] : null
  }
}
 
StorageConfig.CURRENT_VERSION = __APP_VERSION__
StorageConfig.STORAGE_PREFIX = 'sys-v'
StorageConfig.VERSION_KEY = 'sys-version'
StorageConfig.THEME_KEY = 'sys-theme'
StorageConfig.LAST_USER_ID_KEY = 'sys-last-user-id'
StorageConfig.RESPONSIVE_MENU_TYPE_KEY = 'sys-responsive-menu-type'
StorageConfig.SKIP_UPGRADE_VERSION = '1.0.0'
StorageConfig.UPGRADE_DELAY = 1e3
StorageConfig.LOGOUT_DELAY = 1e3
 
export { StorageConfig }