jabin 1 год назад
Родитель
Сommit
acd08263db
5 измененных файлов с 108 добавлено и 29 удалено
  1. 35 11
      src/router/index.js
  2. 7 2
      src/router/routes.js
  3. 23 13
      src/store/modules/user.js
  4. 40 0
      src/views/source/index.vue
  5. 3 3
      vue.config.js

+ 35 - 11
src/router/index.js

@@ -25,6 +25,8 @@ const router = new VueRouter({
  * 路由守卫
  */
 router.beforeEach((to, from, next) => {
+  console.log(to, 'beforeEach-to');
+  console.log(from, 'beforeEach-from');
   if (!from.path.includes(REDIRECT_PATH)) {
     NProgress.start();
   }
@@ -52,6 +54,16 @@ router.beforeEach((to, from, next) => {
           next();
         });
     } else {
+      // 判断外链并跳转
+      if (to.meta) {
+        if (to.meta.source && to.meta.source == 2) {
+          next({
+            path: `/page-main-data/source`,
+            query: { link: to.meta.path }
+          });
+          return;
+        }
+      }
       // console.log(router.getRoutes(), 'router', routes);
       if (routes.length >= router.getRoutes()?.length) {
         router.addRoute(
@@ -87,23 +99,35 @@ router.roleChange = async ({ menus, homePath, authoritiesRouter }) => {
   const currentUser = JSON.parse(sessionStorage['currentUser']);
 
   if (menus && menus.length > 0) {
-    router.addRoute(
-      getMenuRoutes([...menus, ...authoritiesRouter], homePath)
-    );
+    router.addRoute(getMenuRoutes([...menus, ...authoritiesRouter], homePath));
     if (router.currentRoute.path != (menus[0].redirect || menus[0].path)) {
       await router.replace({
-        path: menus[0].redirect || menus[0].path,
-      })
+        path: menus[0].redirect || menus[0].path
+      });
     }
-   
-    const newToken = await changeRole({ groupId: currentUser.currentGroupId, roleId: currentUser.currentRoleId })
-    setToken(newToken)
+
+    const newToken = await changeRole({
+      groupId: currentUser.currentGroupId,
+      roleId: currentUser.currentRoleId
+    });
+    setToken(newToken);
     setTimeout(() => {
-      ['vuex-eos','vuex-wt','vuex-aps','vuex-mes','vuex-eam','vuex-pro','vuex-fm','vuex-main-data','vuex-wms','vuex-qms','vuex-vis'].forEach((key) => {
+      [
+        'vuex-eos',
+        'vuex-wt',
+        'vuex-aps',
+        'vuex-mes',
+        'vuex-eam',
+        'vuex-pro',
+        'vuex-fm',
+        'vuex-main-data',
+        'vuex-wms',
+        'vuex-qms',
+        'vuex-vis'
+      ].forEach((key) => {
         sessionStorage.removeItem(key);
       });
-      window.location.reload()
-     
+      window.location.reload();
     }, 100);
   }
 

+ 7 - 2
src/router/routes.js

@@ -40,7 +40,7 @@ export const routes = [
  * @param menus 菜单数据
  * @param homePath 菜单数据的第一个页面地址
  */
-export function getMenuRoutes (menus, homePath) {
+export function getMenuRoutes(menus, homePath) {
   const routes = [
     // 用于刷新的路由
     {
@@ -48,6 +48,11 @@ export function getMenuRoutes (menus, homePath) {
       component: RedirectLayout,
       meta: { hideFooter: true }
     }
+    // {
+    //   path: '/source',
+    //   component: () => import('@/views/source/index.vue'),
+    //   meta: { hideFooter: true }
+    // }
   ];
   // 路由铺平处理
   eachTreeData(
@@ -68,7 +73,7 @@ export function getMenuRoutes (menus, homePath) {
  * 获取路由组件
  * @param component 组件名称
  */
-function getComponent (component) {
+function getComponent(component) {
   if (component) {
     return () => import('@/views/' + component);
   }

+ 23 - 13
src/store/modules/user.js

@@ -12,11 +12,15 @@ const formatRouter = (list) => {
   const fn = (list, pPath = '') => {
     let arr = [];
     for (const p of list) {
+      // if (p.name == '外链测试') {
+      //   console.log(p, 777778);
+      // }
       let curPath = pPath;
       p.path = curPath ? `${curPath}${p.path}` : p.path;
       if (p.parentId === '0') {
         curPath = p.path;
       }
+      p.link = p.component;
       p.component = '';
       if (p.menuType === 2) {
         // p.children = [];
@@ -30,8 +34,11 @@ const formatRouter = (list) => {
         p.children = [];
       }
       p.meta = {
-        secretLevel: p.secretLevel
+        secretLevel: p.secretLevel,
+        source: p.source,
+        path: p.link
       };
+      p.link = null;
       arr.push(p);
       // }
     }
@@ -128,8 +135,11 @@ export default {
     // },
     //动态路由
     async fetchUserInfo({ commit, state }) {
-      let currentUser = JSON.parse(sessionStorage['currentUser'])
-      const result = await getResourcesTree({ groupId: currentUser.currentGroupId, roleId: currentUser.currentRoleId }).catch(() => { });
+      let currentUser = JSON.parse(sessionStorage['currentUser']);
+      const result = await getResourcesTree({
+        groupId: currentUser.currentGroupId,
+        roleId: currentUser.currentRoleId
+      }).catch(() => {});
       if (!result) {
         return {};
       }
@@ -149,20 +159,20 @@ 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);

+ 40 - 0
src/views/source/index.vue

@@ -0,0 +1,40 @@
+<template>
+  <div>
+    <iframe style="width: 100%; height: 100vh" :src="link + `?token=${token}`">
+    </iframe>
+  </div>
+</template>
+  
+  <script>
+import { getToken } from '@/utils/token-util';
+export default {
+  data() {
+    return {
+      link: '',
+      token: ''
+    };
+  },
+  mounted() {
+    // console.log(this.$route, 11111);
+    // if (this.$route.query && this.$route.query.link) {
+    //   this.link = this.$route.query.link;
+    // }
+  },
+  watch: {
+    // 监视搜索词变化
+    '$route.query.link': {
+      immediate: true,
+      handler() {
+        // console.log(2222);
+        this.link = this.$route.query.link;
+        this.token = getToken();
+      }
+    }
+  },
+  methods: {}
+};
+</script>
+  
+  <style lang="scss" scoped>
+</style>
+  

+ 3 - 3
vue.config.js

@@ -2,7 +2,7 @@ const CompressionWebpackPlugin = require('compression-webpack-plugin');
 const { transformElementScss } = require('ele-admin/lib/utils/dynamic-theme');
 const path = require('path');
 
-function resolve (dir) {
+function resolve(dir) {
   return path.join(__dirname, dir);
 }
 
@@ -22,7 +22,7 @@ module.exports = {
       // 当我们的本地的请求 有/api的时候,就会代理我们的请求地址向另外一个服务器发出请求
       '/api': {
         // target: 'http://124.71.68.31:50001',
-        target: 'http://192.168.1.125:18086',
+        target: 'http://192.168.1.251:18086',
 
         changeOrigin: true, // 只有这个值为true的情况下 才表示开启跨域
         pathRewrite: {
@@ -31,7 +31,7 @@ module.exports = {
       }
     }
   },
-  chainWebpack (config) {
+  chainWebpack(config) {
     config.plugins.delete('prefetch');
 
     if (process.env.NODE_ENV !== 'development') {