Browse Source

add dict cache process when start page

木子李·De 4 years ago
parent
commit
68080e46fb
2 changed files with 58 additions and 4 deletions
  1. 34 4
      report-ui/src/App.vue
  2. 24 0
      report-ui/src/api/dict-data.js

+ 34 - 4
report-ui/src/App.vue

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

+ 24 - 0
report-ui/src/api/dict-data.js

@@ -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()
+    }
+  })
+}