xinfeng 5 лет назад
Родитель
Сommit
2a3337a0b1
4 измененных файлов с 46 добавлено и 83 удалено
  1. 0 32
      middleware/SeoRouter/kaifain.js
  2. 24 21
      middleware/initialize.js
  3. 18 28
      plugins/router.js
  4. 4 2
      store/index.js

+ 0 - 32
middleware/SeoRouter/kaifain.js

@@ -1,35 +1,3 @@
 export default function (context) {
-  if (process.server) {
-    return
-  }
-  console.log('context......', context);
-  const {
-    kaifainUrl
-  } = context.store.state.domainConfig
-  const host = location.host;
 
-  console.log("********", host, kaifainUrl)
-  if (kaifainUrl.indexOf(host) !== -1) {
-    context.app.router.options.routes.unshift({
-      name: 'kaifainSeoDetails',
-      path: '/s/:tid',
-      component: () => import('@/pages/kaifain/detail/_tid/index.vue')
-    })
-    context.app.router.options.routes.unshift({
-      name: 'kaifainCaseSeoDetails',
-      path: '/d/:tid',
-      component: () => import('@/pages/kaifain/case/_tid.vue')
-    })
-    context.app.router.matcher.addRoutes([{
-      name: 'kaifainSeoDetails',
-      path: '/s/:tid',
-      component: () => import('@/pages/kaifain/detail/_tid/index.vue')
-    }, {
-      name: 'kaifainCaseSeoDetails',
-      path: '/d/:tid',
-      component: () => import('@/pages/kaifain/case/_tid.vue')
-    }])
-    const route = context.app.router.matcher.match('/kaifain/' + location.path, context.app.router.currentRoute)
-    console.log(route)
-  }
 }

+ 24 - 21
middleware/initialize.js

@@ -12,10 +12,10 @@ export default function (context) {
     let host = req.headers.host;
     console.log("initialize...........req.............header");
     let proto = "https";
-    if (req.headers["x-forwarded-proto"]) {
-      proto = req.headers["x-forwarded-proto"];
-    } else if (req.headers["x-scheme"]) {
-      proto = req.headers["x-scheme"];
+    if (req.headers[ "x-forwarded-proto" ]) {
+      proto = req.headers[ "x-forwarded-proto" ];
+    } else if (req.headers[ "x-scheme" ]) {
+      proto = req.headers[ "x-scheme" ];
     } else if (host.indexOf("local.") != -1) {
       proto = "http";
     }
@@ -43,9 +43,9 @@ export default function (context) {
     console.log(regx);
     console.log(url);
     groups = regx.exec(url).groups;
-  } catch (e) {
+  } catch ( e ) {
     //失败默认设置为线上环境
-    const {app} = context.app.$deviceType
+    const { app } = context.app.$deviceType
     if (app) {
       groups = {
         env: "app"
@@ -56,18 +56,12 @@ export default function (context) {
       }
     }
   }
-  let api = "";
-  let jishuinUrl = "";
-  let rooterUrl = "";
-  let siteUrl = "";
-  let kaifainUrl = "";
+  
+  let api = "", jishuinUrl = "", rooterUrl = "", siteUrl = "", kaifainUrl = "", urlType = "";
+  
   console.log(groups);
   if (groups) {
-    let {
-      branch,
-      env,
-      port
-    } = groups;
+    let { branch, env, port } = groups;
     switch (env) {
       case "www":
         api = "https://www.proginn.com";
@@ -77,7 +71,9 @@ export default function (context) {
         rooterUrl = "https://rooter.proginn.com";
         break;
       case "jishuin":
+        !urlType && (urlType = 'jishuin')
       case "kaifain":
+        !urlType && (urlType = 'kaifain')
         api = "https://jishuin.proginn.com";
         siteUrl = "https://www.proginn.com";
         jishuinUrl = "https://jishuin.proginn.com";
@@ -85,6 +81,7 @@ export default function (context) {
         rooterUrl = "https://rooter.proginn.com";
         break;
       case "app":
+        !urlType && (urlType = 'app')
         api = "https://app.proginn.com";
         siteUrl = "https://app.proginn.com";
         jishuinUrl = "https://jishuin.proginn.com";
@@ -92,16 +89,21 @@ export default function (context) {
         rooterUrl = "https://rooter.proginn.com";
         break;
       case "test":
+        !urlType && (urlType = 'www')
       case "test-jishuin":
+        !urlType && (urlType = 'jishuin')
       case "test-rooter":
+        !urlType && (urlType = 'rooter')
       case "test-kaifain":
         api = "https://" + branch + ".test.proginn.com";
         siteUrl = "https://" + branch + ".test.proginn.com";
         jishuinUrl = "https://" + branch + ".test-jishuin.proginn.com";
         kaifainUrl = "https://" + branch + ".test-kaifain.proginn.com";
         rooterUrl = "https://" + branch + ".test-rooter.proginn.com";
+        !urlType && (urlType = 'kaifain')
         break;
       case "local":
+        !urlType && (urlType = 'local')
         if (port && port != "80") {
           api = "http://local.proginn.com";
           siteUrl = "http://local.proginn.com:" + port;
@@ -117,9 +119,13 @@ export default function (context) {
         }
         break;
       case "prod":
+        !urlType && (urlType = 'www')
       case "prod-jishuin":
+        !urlType && (urlType = 'jishuin')
       case "prod-rooter":
+        !urlType && (urlType = 'rooter')
       case "prod-kaifain":
+        !urlType && (urlType = 'kaifain')
         api = "https://" + branch + ".prod.proginn.com";
         siteUrl = "https://" + branch + ".prod.proginn.com";
         jishuinUrl = "https://" + branch + ".prod-jishuin.proginn.com";
@@ -128,6 +134,7 @@ export default function (context) {
         break;
       default:
         // 按生产处理
+        !urlType && (urlType = 'www')
         api = "https://www.proginn.com";
         siteUrl = "https://www.proginn.com";
         jishuinUrl = "https://jishuin.proginn.com";
@@ -144,11 +151,7 @@ export default function (context) {
     rooterUrl = "https://rooter.proginn.com";
   }
   context.store.commit("updateDomainConfig", {
-    api: api,
-    siteUrl: siteUrl,
-    jishuinUrl: jishuinUrl,
-    kaifainUrl: kaifainUrl,
-    rooterUrl: rooterUrl
+    api, siteUrl, jishuinUrl, kaifainUrl, rooterUrl, urlType
   });
   context.store.commit("updateDeviceType", context.app.$deviceType || {});
   context.store.commit("updateIsPC", context.app.$deviceType.pc || false);

+ 18 - 28
plugins/router.js

@@ -1,33 +1,23 @@
 export default ({app, store}) => {
-  
   if (process.client) {
-    app.router.options.routes.unshift({
-      name: 'kaifainSeoDetails_$',
-      path: '/s/:tid',
-      component: () => import('@/pages/kaifain/detail/_tid/index.vue')
-    })
-    app.router.options.routes.unshift({
-      name: 'kaifainCaseSeoDetails_$',
-      path: '/d/:tid',
-      component: () => import('@/pages/kaifain/case/_tid.vue')
-    })
-    app.router.matcher.addRoutes([{
-      name: 'kaifainSeoDetails_$',
-      path: '/s/:tid',
-      component: () => import('@/pages/kaifain/detail/_tid/index.vue')
-    }, {
-      name: 'kaifainCaseSeoDetails_$',
-      path: '/d/:tid',
-      component: () => import('@/pages/kaifain/case/_tid.vue')
-    }])
+    const {urlType} = store.state.domainConfig || {}
+    
+    switch (urlType) {
+      case 'kaifain': {
+        app.router.options.routes.unshift({
+          name: 'kaifainSeoDetails_$',
+          path: '/s/:tid',
+          component: () => import('@/pages/kaifain/detail/_tid/index.vue')
+        })
+        app.router.options.routes.unshift({
+          name: 'kaifainCaseSeoDetails_$',
+          path: '/d/:tid',
+          component: () => import('@/pages/kaifain/case/_tid.vue')
+        })
+        break;
+      }
+    }
+    
     console.log('router', app.router)
   }
-  
-  app.router.beforeEach((to, from, next)=> {
-    if (process.client) {
-      console.log("location.href", to, from)
-      
-    }
-    next()
-  })
 }

+ 4 - 2
store/index.js

@@ -12,7 +12,8 @@ export const state = () => ({
     siteUrl: "",
     rooterUrl: "",
     jishuinUrl: "",
-    kaifainUrl: ""
+    kaifainUrl: "",
+    urlType: ""
   },
   noneCommonFooter: false
 });
@@ -30,7 +31,8 @@ export const mutations = {
       siteUrl: config.siteUrl,
       jishuinUrl: config.jishuinUrl,
       rooterUrl: config.rooterUrl,
-      kaifainUrl: config.kaifainUrl
+      kaifainUrl: config.kaifainUrl,
+      urlType: config.urlType
     };
   },
   updateUserinfo(state, payload) {