Prechádzať zdrojové kódy

职业库树缓存、路由bug修复

shilipojs 2 rokov pred
rodič
commit
bd3b27b466

+ 21 - 0
src/components/Cache/modules/mx-vocation-translate-mixin.js

@@ -0,0 +1,21 @@
+import cacheMixin from '@/components/Cache/mx-cache-mixin.js'
+
+export default {
+  mixins: [cacheMixin],
+  data() {
+    return {
+      vocationList: [],
+      vocationIsReady: false
+    }
+  },
+  beforeMount() {
+    this.loadVocationTree()
+  },
+  methods: {
+    async loadVocationTree() {
+      this.vocationList = await this.getAllVocationTree()
+      this.vocationIsReady = true
+      console.log('vocation-ready')
+    },
+  }
+}

+ 12 - 3
src/components/Cache/mx-cache-mixin.js

@@ -9,7 +9,7 @@ import {
 import consts from '@/common/mx-const.js'
 import { loadAllMajorSubjectTree } from '@/api/webApi/test-major'
 import { allMajor } from '@/api/webApi/professlib'
-
+import {getAllVocation} from '@/api/webApi/vocation';
 export default {
   // 类似全局缓存
   methods: {
@@ -115,7 +115,7 @@ export default {
         useCache)
     },
     // 本科专业树
-    getMasterMajorTree(useCache = true,type) {
+    getMasterMajorTree(useCache = true) {
       return this._getDataByCache('master_major_tree',
         _ => allMajor({
           type:'本科'
@@ -124,13 +124,22 @@ export default {
         useCache)
     },
     // 专科专业树
-    getSpecialtyMajorTree(useCache = true,type) {
+    getSpecialtyMajorTree(useCache = true) {
       return this._getDataByCache('specialty_major_tree',
         _ => allMajor({
           type:'专科'
         }),
         res => res.data,
         useCache)
+    },
+    // 职业树
+    getAllVocationTree(useCache = true,type) {
+      return this._getDataByCache('specialty_major_tree',
+        _ => getAllVocation({
+          level: 1
+        }),
+        res => res.data,
+        useCache)
     }
   }
 }

+ 1 - 1
src/views/career/plan/new-profess-detail.vue

@@ -387,7 +387,7 @@ export default {
     console.log(this.$route.query.code)
     this.code = this.$route.query.code
     this.type = this.$route.query.type || '本科'
-    if (this.$route.query.code) {
+    if (this.$router.query.code) {
       this.getOverView()
     }
   },

+ 6 - 22
src/views/career/vocation/new-detail.vue

@@ -7,7 +7,7 @@
          <div class="tree-wrap">
            <el-tree
            ref="tree"
-           :data="vocationTree"
+           :data="vocationList"
            node-key="code"
            :default-checked-keys="[code]"
            :default-expanded-keys="[code]"
@@ -172,13 +172,15 @@
 </template>
 <script>
 import MxChart from '@/components/MxChart/index'
-import { vocationalPostsDetail, vocationalOverview, vocationalPosts,getAllVocation } from '@/api/webApi/vocation'
+import { vocationalPostsDetail, vocationalOverview, vocationalPosts } from '@/api/webApi/vocation'
+import MxVocationTranslateMixin from '@/components/Cache/modules/mx-vocation-translate-mixin'
 
 export default {
   name: "Detail",
   components: {
     MxChart
   },
+  mixins:[MxVocationTranslateMixin],
   data(){
     return {
       loading:false,
@@ -188,7 +190,6 @@ export default {
         label: 'name'
       },
       tabActive: 0,
-      vocationTree: [], // 职业树
       vocationalPosts: [],  // 就业岗位
       vocationDetail:{},  // 职业概况
       jobActiveName: '',  // 激活状态的岗位
@@ -197,7 +198,8 @@ export default {
     }
   },
   created() {
-    this.getAllVocation()
+    this.code = this.$route.query.code
+    this.getVocationalOverview();
   },
   computed:{
     // 按工资分布
@@ -330,16 +332,6 @@ export default {
         if(newVal == 1)  this.getVocationalPosts();
       }
     },
-    '$route':{
-      immediate:true,
-      handler(val){
-        this.code=val.query.code;
-        if(val.query.code){
-          console.log(22222222222222222222)
-          this.getVocationalOverview();
-        }
-      }
-    }
   },
   methods:{
     toMajorDetail(row) {
@@ -408,14 +400,6 @@ export default {
       }).finally(_ => {
         this.loading = false
       })
-    },
-    getAllVocation() {
-      getAllVocation({
-        level: 1
-      }).then(res => {
-        console.log(res)
-        this.vocationTree = res.data
-      })
     }
   }
 }

+ 3 - 19
src/views/career/vocation/new-index.vue

@@ -36,16 +36,17 @@
 
 <script>
 import {mapState} from 'vuex';
-import {getAllVocation} from '@/api/webApi/vocation';
+import MxVocationTranslateMixin from '@/components/Cache/modules/mx-vocation-translate-mixin'
+
 export default {
   name: "index",
   data(){
     return {
       backimg:'url('+require('@/assets/images/career/icon_colleges.png')+')',
       levelOne: [],
-      vocationList: []
     }
   },
+  mixins:[MxVocationTranslateMixin],
   computed:{
     ...mapState({theme: state => state.settings.theme})
   },
@@ -59,27 +60,10 @@ export default {
       }
     },
   },
-  created(){
-    this.getAllVocation()
-  },
   methods:{
     goDetail(code){
       this.$router.push({name:'jobDetail',query:{code:code}})
     },
-    getAllVocation() {
-      getAllVocation({
-        level: 1
-      }).then(res => {
-        console.log(res)
-        this.vocationList = res.data
-        this.levelOne = res.data.map(item => {
-            return {
-              code: item.code,
-              name: item.name,
-            }
-        })
-      })
-    }
   }
 }
 </script>