add dict cache process when start page

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

@ -1,12 +1,42 @@
<template> <template>
<div id="app"> <div id="app">
<router-view/> <router-view v-if="isRouterAlive" />
</div> </div>
</template> </template>
<script> <script>
import '@/assets/iconfont/iconfont.css' import '@/assets/iconfont/iconfont.css'
export default { import { initDictToLocalstorage } from '@/api/dict-data'
name: 'App' export default {
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> </script>

@ -52,3 +52,27 @@ export function getBaseDataList (typeList) {
params: { types }, 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