Просмотр исходного кода

菜单路由优化, 物品信息详情bug

quwangxin 3 лет назад
Родитель
Сommit
035f1b04e9

+ 13 - 1
src/router/index.js

@@ -45,7 +45,19 @@ router.beforeEach((to, from, next) => {
           next();
         });
     } else {
-      next();
+      // console.log(router.getRoutes(), 'router', routes);
+      if (routes.length >= router.getRoutes()?.length) {
+        router.addRoute(
+          getMenuRoutes([
+            ...store.state.user.menus,
+            ...store.state.user.authoritiesRouter,
+            to.fullPath
+          ])
+        );
+        next({ ...to });
+      } else {
+        next();
+      }
     }
   } else if (WHITE_LIST.includes(to.path)) {
     next();

+ 5 - 5
src/router/routes.js

@@ -17,12 +17,12 @@ export const routes = [
     path: '/forget',
     component: () => import('@/views/forget/index.vue'),
     meta: { title: '忘记密码' }
-  },
-  // 404
-  {
-    path: '*',
-    component: () => import('@/views/exception/404/index.vue')
   }
+  // 404
+  // {
+  //   path: '*',
+  //   component: () => import('@/views/exception/404/index.vue')
+  // }
   // {
   //   path: '/system/role',
   //   component: () => import('@/views/system/role/index.vue'),

+ 26 - 19
src/store/modules/user.js

@@ -42,24 +42,30 @@ export default {
     menus: null,
     // 当前登录用户的权限
     authorities: [],
+    // 当前登录用户的权限路由
+    authoritiesRouter: [],
     // 当前登录用户的角色
     roles: []
   },
   mutations: {
     // 设置登录用户的信息
-    setUserInfo(state, info) {
+    setUserInfo (state, info) {
       state.info = info;
     },
     // 设置登录用户的菜单
-    setMenus(state, menus) {
+    setMenus (state, menus) {
       state.menus = menus;
     },
     // 设置登录用户的权限
-    setAuthorities(state, authorities) {
+    setAuthorities (state, authorities) {
       state.authorities = authorities;
     },
+    // 设置登录用户的权限路由
+    setAuthoritiesRouter (state, authoritiesRouter) {
+      state.authoritiesRouter = authoritiesRouter;
+    },
     // 设置登录用户的角色
-    setRoles(state, roles) {
+    setRoles (state, roles) {
       state.roles = roles;
     }
   },
@@ -97,8 +103,8 @@ export default {
     //   return { menus, homePath };
     // },
     //动态路由
-    async fetchUserInfo({ commit }) {
-      const result = await getResourcesTree().catch(() => { });
+    async fetchUserInfo ({ commit }) {
+      const result = await getResourcesTree().catch(() => {});
       if (!result) {
         return {};
       }
@@ -118,23 +124,24 @@ export default {
       // 用户菜单, 过滤掉按钮类型并转为 children 形式
       const { menus, homePath } = formatMenus(
         USER_MENUS ??
-        toTreeData({
-          data: menuList,
-          idField: 'id',
-          parentIdField: 'parentId'
-        })
+          toTreeData({
+            data: menuList,
+            idField: 'id',
+            parentIdField: 'parentId'
+          })
       );
       // 用户路由按钮
       const { menus: authoritiesRouter } = formatMenus(
         USER_MENUS ??
-        toTreeData({
-          data: authorities.filter((i) => i.path),
-          idField: 'id',
-          parentIdField: 'parentId'
-        })
+          toTreeData({
+            data: authorities.filter((i) => i.path),
+            idField: 'id',
+            parentIdField: 'parentId'
+          })
       );
       console.log('menus--', menus);
       commit('setMenus', menus);
+      commit('setAuthoritiesRouter', authoritiesRouter);
       // const menus = result;
       // const homePath = '/dashboard/workplace';
       return {
@@ -147,19 +154,19 @@ export default {
     /**
      * 更新用户信息
      */
-    setInfo({ commit }, value) {
+    setInfo ({ commit }, value) {
       commit('setUserInfo', value);
     },
     /**
      * 更新菜单数据
      */
-    setMenus({ commit }, value) {
+    setMenus ({ commit }, value) {
       commit('setMenus', value);
     },
     /**
      * 更新菜单的badge
      */
-    setMenuBadge({ commit, state }, { path, value, color }) {
+    setMenuBadge ({ commit, state }, { path, value, color }) {
       const menus = formatTreeData(state.menus, (m) => {
         if (path === m.path) {
           return {

+ 11 - 3
src/views/classifyManage/itemInformation/add.vue

@@ -180,14 +180,20 @@
         } else {
           this.$set(this.itemForm, 'expirationDate', 'null');
         }
-        this.$set(this.itemForm, 'info', JSON.parse(data.extendField));
+        this.$set(
+          this.itemForm,
+          'info',
+          data.extendField ? JSON.parse(data.extendField) : { angle: 'notA' }
+        );
         this.$set(this.itemForm, 'name', data.name);
         this.$set(
           this.itemForm,
           'addList',
-          JSON.parse(data.selfDefinedParameter)
+          data.selfDefinedParameter ? JSON.parse(data.selfDefinedParameter) : []
         );
-        this.itemForm.urlIdList = JSON.parse(data.categoryLevelPathId);
+        this.itemForm.urlIdList = data.categoryLevelPathId
+          ? JSON.parse(data.categoryLevelPathId)
+          : [];
         if (this.pageTitle == '编辑物品') {
           // this.itemForm.itemCode = data.code.substring(3)
           this.$set(this.itemForm, 'itemCode', data.code.substring(3));
@@ -206,6 +212,8 @@
               this.itemForm.categoryVoRelationMap
             );
         }
+
+        console.log(this.itemForm, 'itemForm');
       },
 
       // 改变物品类型

+ 1 - 1
src/views/classifyManage/itemInformation/components/RowForm.vue

@@ -234,7 +234,7 @@
           </div>
         </el-form-item>
       </el-col>
-      <el-col :span="8" v-if="itemForm.addList.length < 10">
+      <el-col :span="8" v-if="itemForm.addList && itemForm.addList.length < 10">
         <el-form-item label-width="20px">
           <el-button type="primary" @click="addItem">增加自定义参数</el-button>
         </el-form-item>

+ 4 - 4
src/views/ledgerAssets/equipment/components/equipment-list.vue

@@ -6,8 +6,8 @@
       ref="table"
       :columns="columns"
       :datasource="datasource"
-      height="calc(100vh - 265px)"
-      full-height="calc(100vh - 116px)"
+      height="calc(100vh - 265px - 102px)"
+      full-height="calc(100vh - 116px - 102px)"
       tool-class="ele-toolbar-form"
       cache-key="systemOrgUserTable"
     >
@@ -40,7 +40,7 @@
 
 <script>
   import EquipmentSearch from './equipment-search.vue';
-  import { getBoatList } from '@/api/ledgerAssets';
+  import { getAssetList } from '@/api/ledgerAssets';
 
   export default {
     components: { EquipmentSearch },
@@ -123,7 +123,7 @@
     methods: {
       /* 表格数据源 */
       datasource ({ page, limit, where, order }) {
-        return getBoatList({
+        return getAssetList({
           ...where,
           ...order,
           pageNum: page,

+ 5 - 1
src/views/ledgerAssets/equipment/index.vue

@@ -63,7 +63,11 @@
 
 <style lang="scss" scoped>
   .sys-organization-list {
-    height: calc(100vh - 264px);
+    position: absolute;
+    top: 0;
+    bottom: 0;
+    left: 0;
+    right: 0;
     box-sizing: border-box;
     border-width: 1px;
     border-style: solid;

+ 1 - 1
src/views/login/index.vue

@@ -161,7 +161,7 @@
         this.goHome();
       } else {
         // 重置菜单权限
-        this.$store.commit('user/setMenus', []);
+        this.$store.commit('user/setMenus', null);
       }
     },
     methods: {