feat: 登录时将下钻table配置改为在indexedDB中缓存

This commit is contained in:
chenjinsong
2022-09-27 11:08:38 +08:00
parent b7e0294d59
commit cea69bb71a
3 changed files with 15 additions and 6 deletions

View File

@@ -1,7 +1,8 @@
import { dbName, dbGeoDataTableName } from '@/utils/constants'
import { dbName, dbGeoDataTableName, dbDrilldownTableConfig } from '@/utils/constants'
import Dexie from 'dexie'
export const db = new Dexie(dbName)
db.version(1).stores({
[dbGeoDataTableName]: '++name, geo'
db.version(2).stores({
[dbGeoDataTableName]: '++name, geo',
[dbDrilldownTableConfig]: '++id, config'
})

View File

@@ -2,8 +2,9 @@ import { get, post } from '@/utils/http'
import router from '@/router'
import { sortByOrderNum, getWelcomeMenu } from '@/permission'
import { ElMessage } from 'element-plus' // dependent on utc plugin
import { storageKey } from '@/utils/constants'
import { storageKey, dbDrilldownTableConfig } from '@/utils/constants'
import { api } from '@/utils/api'
import { db } from '@/indexedDB'
const user = {
state () {
@@ -77,9 +78,15 @@ const user = {
}
}
})
get(api.config, { ckey: 'drill_down_table_config' }).then(res => {
get(api.config, { ckey: 'drill_down_table_config' }).then(async res => {
if (res.code === 200 && res.page.list && res.page.list.length > 0) {
localStorage.setItem(storageKey.drillDownTableConfig, res.page.list[0].cvalue)
await db[dbDrilldownTableConfig].put({
id: 'default',
config: res.page.list[0].cvalue
})
// const a = await db[dbDrilldownTableConfig].get({ id: 'default' })
// console.info(a)
// localStorage.setItem(storageKey.drillDownTableConfig, res.page.list[0].cvalue)
}
})
get(api.config, { ckey: 'link_info' }).then(res => {

View File

@@ -2,6 +2,7 @@ export const defaultPageSize = 20
export const dbName = 'cn-db'
export const dbGeoDataTableName = 'geodata'
export const dbDrilldownTableConfig = 'cn-drilldown-table-config'
export const storageKey = {
iso36112Capital: 'cn-iso3611-2-capital',
iso36112WorldLow: 'cn-iso3611-2-world-low',