feat: npm部分内容

This commit is contained in:
chenjinsong
2021-07-05 17:40:43 +08:00
parent c35fb070a5
commit c426084934
10 changed files with 251 additions and 156 deletions

View File

@@ -1,8 +1,8 @@
import { ElMessageBox } from 'element-plus'
import i18n from '@/i18n'
import _ from 'lodash'
import { storageKey } from '@/utils/constants'
import { getCache, setCache } from '@/utils/cache'
import { storageKey, iso36112 } from '@/utils/constants'
import { getIso36112JsonData } from '@/utils/api'
export const tableSort = {
// 是否需要排序
@@ -399,7 +399,46 @@ export function humpToLine (name) {
return name.replace(/([A-Z])/g, '_$1').toLowerCase()
}
export function getCapitalGeo (countryId) {
!getCache('capitalGeo') && setCache('capitalGeo', JSON.parse(sessionStorage.getItem(storageKey.iso36112)))
return getCache('capitalGeo')[countryId]
// 加载geo数据
export function loadGeoData (key) {
const keys = []
if (key) {
keys.push(key)
} else {
keys.push(storageKey.iso36112Capital)
keys.push(storageKey.iso36112WorldLow)
}
keys.forEach(async k => {
if (!localStorage.getItem(k)) {
const data = await getIso36112JsonData(iso36112[k])
if (data) {
localStorage.setItem(k, JSON.stringify(data))
}
}
})
return localStorage.getItem(key)
}
/* 返回geodata对象 */
export function getGeoData (key) {
const data = localStorage.getItem(key)
if (data) {
return JSONParse(data)
} else {
return JSONParse(loadGeoData(key))
}
}
export function getCapitalGeo (countryId) {
const data = getGeoData(storageKey.iso36112Capital)
return data[countryId]
}
export function JSONParse (data) {
const firstParse = JSON.parse(data)
if (typeof firstParse === 'string') {
return JSON.parse(firstParse)
} else {
return firstParse
}
}