add dict cache process when start page

木子李·De 3 years ago
parent 081c2a9d9a
commit 68080e46fb

@ -1,12 +1,42 @@
<template>
<div id="app">
<router-view/>
<router-view v-if="isRouterAlive" />
</div>
</template>
<script>
import '@/assets/iconfont/iconfont.css'
import { initDictToLocalstorage } from '@/api/dict-data'
export default {
name: 'App'
name: 'App',
provide () {
return {
reload: this.reload,
}
},
data () {
return {
isRouterAlive: false,
}
},
computed: {},
created () {
//
initDictToLocalstorage(() => {
this.isRouterAlive = true
})
},
mounted () {
},
beforeDestroy () {
},
methods: {
reload () {
this.isRouterAlive = false
this.$nextTick(function () {
this.isRouterAlive = true
})
},
}
}
</script>

@ -52,3 +52,27 @@ export function getBaseDataList (typeList) {
params: { types },
})
}
// 查询所有数据字典接口
export function getAllDict() {
return request({
url: '/gaeaDict/all',
method: 'GET',
})
}
// 将所有接口初始化到浏览器本地缓存
export function initDictToLocalstorage(callback) {
getAllDict().then((res) => {
if (res.code != 200) {
console.error('初始化数据字典到local storage失败: ' + res.message)
return
}
// 保存数据字典到localStorage
localStorage.setItem('gaeaDict', JSON.stringify(res.data))
if (callback != null) {
callback()
}
})
}

Loading…
Cancel
Save