From 06c8aa18a41393b564f48b42fe49db9fa761336c Mon Sep 17 00:00:00 2001
From: loulijun2021 <1694218219@qq.com>
Date: 星期日, 23 四月 2023 13:19:21 +0800
Subject: [PATCH] 1.MES产品对接云平台

---
 src/utils/request.js            |   17 ++++++--
 src/store/modules/user.js       |   38 +++++++++++++-----
 src/api/user.js                 |    8 ++++
 src/main.js                     |   22 ++++++++++
 src/store/modules/permission.js |   22 ++++++-----
 src/router/index.js             |    4 +-
 6 files changed, 83 insertions(+), 28 deletions(-)

diff --git a/src/api/user.js b/src/api/user.js
index 319f928..cf9dd41 100644
--- a/src/api/user.js
+++ b/src/api/user.js
@@ -15,6 +15,14 @@
   })
 }
 
+export function LoginMenuCloud(data) {
+  return request({
+    url: 'http://182.61.13.206/prod-api/enterprise/user/getModulesByEnterpriseUserName',
+    method: 'get',
+    params: data
+  })
+}
+
 export function getInfo(token) {
   return request({
     url: '/vue-admin-template/user/info',
diff --git a/src/main.js b/src/main.js
index 099145e..e52d375 100644
--- a/src/main.js
+++ b/src/main.js
@@ -51,18 +51,38 @@
 // 鎵撳嵃
 // import Print from 'vue-print-nb'
 import Print from './components/Print/vue-print-nb'
+
 Vue.use(Print)
 
 // 姘村嵃
 import watermark from './utils/watermark.js'
+
 Vue.prototype.$watermark = watermark
 
 import clearTabIndex from './utils/clearTabIndex.js' // 鍒犻櫎el-tooltip tabindex
 clearTabIndex.install(Vue)
 
-import vGanttChart from './lib/v-gantt-chart/index' // 寮曠敤淇敼杩囩殑gantt
+import vGanttChart from './lib/v-gantt-chart/index'
+// 寮曠敤淇敼杩囩殑gantt
 Vue.use(vGanttChart)
 
+import { setCookie } from '@/utils/auth' // 寮曠敤淇敼杩囩殑gantt
+// 鍒ゆ柇鏄惁璧板師骞冲彴杩囨潵
+if (window.location.hash.indexOf('guid') !== -1) {
+  setCookie('cloud', true)// 璧颁簯骞冲彴
+
+  const url = window.location.hash.split('?')[1]
+  const arr = url.split('&')
+  setCookie('guid', arr[0].split('=')[1])
+  setCookie('userid', arr[1].split('=')[1])
+  setCookie('admin', arr[2].split('=')[1])
+  setCookie('navTabId', arr[2].split('=')[1])
+  setCookie('username', decodeURIComponent(arr[3].split('=')[1]))
+  setCookie('password', arr[4].split('=')[1])
+  setCookie('usertype', arr[5].split('=')[1])
+  setCookie('rediskey', arr[6].split('=')[1])
+}
+
 new Vue({
   el: '#app',
   router,
diff --git a/src/router/index.js b/src/router/index.js
index af1a90a..c1ac213 100644
--- a/src/router/index.js
+++ b/src/router/index.js
@@ -616,9 +616,9 @@
     path: '/otherErp',
     component: Layout,
     redirect: '/otherErp/InventoryList',
-    name: '鍏跺畠ERP闆嗘垚',
+    name: '鍏朵粬浜у搧ERP闆嗘垚',
     code: '2018',
-    meta: { code: '2018', title: '鍏跺畠ERP闆嗘垚', icon: 'erpjc' },
+    meta: { code: '2018', title: '鍏朵粬浜у搧ERP闆嗘垚', icon: 'erpjc' },
     alwaysShow: true,
     children: [
       {
diff --git a/src/store/modules/permission.js b/src/store/modules/permission.js
index 291aa11..f6beae8 100644
--- a/src/store/modules/permission.js
+++ b/src/store/modules/permission.js
@@ -1,5 +1,6 @@
 import { asyncRoutes, commonRoutes } from '@/router'
 import Layout from '@/layout'
+import { getCookie } from '@/utils/auth'
 
 // 鍒ゆ柇鏄惁鏈夋潈闄�
 function hasPermission(roles, route) {
@@ -98,17 +99,18 @@
 const actions = {
   generateRoutes({ commit }, menu) {
     return new Promise(resolve => {
-      // console.log(menu, 'menu')
       // const newRoutes = getAsyncRoutes(asyncRoutes, menu)
-      // const arr = ['1001', '1002', '1004']
-      // const newRoutes = asyncRoutes.filter(i => {
-      //   if (arr.includes(i.code)) {
-      //     return i
-      //   }
-      // })
-
-      const newRoutes = asyncRoutes
-
+      let newRoutes
+      if (getCookie('cloud')) {
+        const arr = menu.map(i => i.code)
+        newRoutes = asyncRoutes.filter(i => {
+          if (arr.includes(i.code)) {
+            return i
+          }
+        })
+      } else {
+        newRoutes = getAsyncRoutes(asyncRoutes, menu)
+      }
       commit('SET_ROUTES', newRoutes)
       resolve(newRoutes)
     })
diff --git a/src/store/modules/user.js b/src/store/modules/user.js
index 74362ea..8bc6bd3 100644
--- a/src/store/modules/user.js
+++ b/src/store/modules/user.js
@@ -1,4 +1,4 @@
-import { login, logout, getInfo, LoginMenu } from '@/api/user'
+import { login, logout, getInfo, LoginMenu, LoginMenuCloud } from '@/api/user'
 import { getToken, setToken, removeToken, setCookie, removeCookie, getCookie } from '@/utils/auth'
 import { resetRouter } from '@/router'
 
@@ -87,15 +87,28 @@
   // get user menu
   getMenu({ commit, state }) {
     return new Promise((resolve, reject) => {
-      LoginMenu({ usertype: 'PC', usercode: getCookie('admin') }).then(res => {
-        if (res.code === '200') {
-          commit('SET_NAME', res.Message)
-          commit('SET_MENU', res.data)
-          resolve(res.data)
-        }
-      }).catch(error => {
-        reject(error)
-      })
+      console.log('杩涙潵浜�11111')
+      if (getCookie('cloud')) { // 璧颁簯
+        LoginMenuCloud({ enterpriseUserName: getCookie('admin') }).then(res => {
+          if (res.code === 200) {
+            commit('SET_NAME', res.msg)
+            commit('SET_MENU', res.data)
+            resolve(res.data)
+          }
+        }).catch(error => {
+          reject(error)
+        })
+      } else {
+        LoginMenu({ usertype: 'PC', usercode: getCookie('admin') }).then(res => {
+          if (res.code === '200') {
+            commit('SET_NAME', res.Message)
+            commit('SET_MENU', res.data)
+            resolve(res.data)
+          }
+        }).catch(error => {
+          reject(error)
+        })
+      }
     })
   },
 
@@ -132,7 +145,10 @@
           // reset visited views and cached views
           dispatch('tagsView/delAllViews', null, { root: true })
           sessionStorage.removeItem('tabViews')
-
+          if (getCookie('cloud')) {
+            removeCookie('cloud')
+            window.location.href = 'http://182.61.13.206/choose'
+          }
           commit('RESET_STATE')
 
           resolve()
diff --git a/src/utils/request.js b/src/utils/request.js
index 79227b2..3bcab4c 100644
--- a/src/utils/request.js
+++ b/src/utils/request.js
@@ -68,10 +68,19 @@
         removeCookie('rediskey')
         removeCookie('code')
         removeCookie('guid')
-        setTimeout(() => {
-          sessionStorage.removeItem('tabViews')
-          window.location.reload()
-        }, 1000 * 2)
+
+        if (getCookie('cloud')) {
+          removeCookie('cloud')
+          setTimeout(() => {
+            sessionStorage.removeItem('tabViews')
+            window.location.href = 'http://182.61.13.206/choose'
+          }, 1000 * 2)
+        } else {
+          setTimeout(() => {
+            sessionStorage.removeItem('tabViews')
+            window.location.reload()
+          }, 1000 * 2)
+        }
       }
       // 50008: Illegal token; 50012: Other clients logged in; 50014: Token expired;
       // if (res.code === 50008 || res.code === 50012 || res.code === 50014) {

--
Gitblit v1.9.3