# 中铁二局专版-网关调整

项目内网关认证请按照以下步骤进行调整

# 接口规范

项目所有接口需在 common/global.const.js 内进行定义,即使前缀为空,也需要进行 EMPTY 定义。
示例:

// 接口前缀
const PROJECT_API_BASE = `${process.env.VUE_APP_PROJECT_API_BASE}`?`${process.env.VUE_APP_PROJECT_API_BASE}/`:''
export const API_PREFIX = {
  SAAS_INTERGATION: `${PROJECT_API_BASE}ztejMMS-intergation`, //saas云-集成管理
  SAAS_SYSTEM: `${PROJECT_API_BASE}ztejMMS-system`, //saas云业务-系统管理
  SAAS_MSGC: `${PROJECT_API_BASE}ztejMMS-msgc`, //saas云业务-消息中心
  SAAS_TECHNOLOGY: `${PROJECT_API_BASE}ztejMMS-technology`, //saas云业务-技术中心
  SAAS_PORTAL: `${PROJECT_API_BASE}ztejMMS-portal`, //saas云业务-门户
  FILE: `${PROJECT_API_BASE}ztejMMS-file`, // 文件服务
  EMPTY: `${PROJECT_API_BASE}` // 无二级接口前缀
}

1
2
3
4
5
6
7
8
9
10
11
12

使用时在对应 api 文件进行引入。
示例:

import { API_PREFIX } from '@/common/global.const'
const SAAS_SYSTEM = `/${API_PREFIX.SAAS_SYSTEM}`
export const getBaseInfo = params => {
  return get(`${SAAS_SYSTEM}/${params.id}`)
}
1
2
3
4
5

⚠️注意:定义,引入,使用前缀务必保持一致

# 应用名调整

env文件内添加配置

# 应用网关前缀
VUE_APP_PROJECT_API_BASE = 'ztejMMS-user'
1
2

global.const.js内的代理名称修改

// 接口前缀
const PROJECT_API_BASE = `${process.env.VUE_APP_PROJECT_API_BASE}`?`${process.env.VUE_APP_PROJECT_API_BASE}/`:''
export const API_PREFIX = {
  SAAS_INTERGATION: `${PROJECT_API_BASE}ztejMMS-intergation`, //saas云-集成管理
  SAAS_SYSTEM: `${PROJECT_API_BASE}ztejMMS-system`, //saas云业务-系统管理
  SAAS_MSGC: `${PROJECT_API_BASE}ztejMMS-msgc`, //saas云业务-消息中心
  SAAS_TECHNOLOGY: `${PROJECT_API_BASE}ztejMMS-technology`, //saas云业务-技术中心
  SAAS_PORTAL: `${PROJECT_API_BASE}ztejMMS-portal`, //saas云业务-门户
  FILE: `${PROJECT_API_BASE}ztejMMS-file`, // 文件服务
  EMPTY: `${PROJECT_API_BASE}` // 无二级接口前缀
}
1
2
3
4
5
6
7
8
9
10
11

# TOKN 存取逻辑调整

\src\utils\request.js 在请求头添加 token

config.headers = {
  ...headers,
  'Authorization':sessionStorage.getItem('TOKEN')
}
1
2
3
4

# 代理调整

项目内原本网关前缀 api 修改为 gateway-api
api 前缀抽离为公用文件,可供部分文件使用
⚠️部分修改可能不涉及子应用,请按需调整。各自系统按以下修改完成后,请全局搜索/api,如存在未修改部分,请自行调整

  • 修改 env 的配置文件
# 认证地址
VUE_APP_AUTH_URL = '/api/oauth2/authorization/glink-cloud-platform'
1
2

修改为

# 认证地址
VUE_APP_AUTH_URL = '/gateway-api/oauth2/authorization/glink-cloud-platform'
1
2
  • 修改 vue.config.js
proxy = {
  '/api/': {
    target: API_TARGET,
    changeOrigin: true,
    pathRewrite: {
      '^/api': ''
    }
  }
}
1
2
3
4
5
6
7
8
9

修改为

proxy = {
  '/gateway-api/': {
    target: API_TARGET,
    changeOrigin: true,
    pathRewrite: {
      '^/gateway-api': ''
    }
  }
}
1
2
3
4
5
6
7
8
9
  • 退出登录(主应用) \src\base\gd-layout\components\header\index.vue
logout() {
  // 移除数据库字典
  this.$indexedDB.deleteDBAll('GlinkDic')
  this.clearAllCache()
  window.location.href = window.location.origin + '/api/logout'
}
1
2
3
4
5
6

修改为

logout() {
  // 移除数据库字典
  this.$indexedDB.deleteDBAll('GlinkDic')
  this.clearAllCache()
  window.location.href = window.location.origin + `/${process.env.VUE_APP_BASE_URL}/logout`
}
1
2
3
4
5
6

\src\views\common\views\unAuthorized\index.vue

handleLogin() {
  window.location.href = window.location.origin + '/api/logout'
}
1
2
3

修改为

handleLogin() {
  window.location.href = window.location.origin + `/${process.env.VUE_APP_BASE_URL}/logout`
}
1
2
3
  • 上传下载 \src\mixins\uploadMixin.js
axios({
  url: `/api/file/files/download/${item.id}`,
  method: 'get',
  responseType: 'blob'
})
1
2
3
4
5

修改为

axios({
  url: `/${process.env.VUE_APP_BASE_URL}/file/files/download/${item.id}`,
  method: 'get',
  responseType: 'blob'
})
1
2
3
4
5
  • 请求配置 \src\plugins\index.js
const requestOptions = {
  baseURL: '/api/',
  timeout: 16000,
  headers: {
    'x-nepoch-org': storage.getItem(CACHE.DEPT_ID_CACHE)
  }
}
1
2
3
4
5
6
7

修改为

const requestOptions = {
  baseURL: `/${process.env.VUE_APP_BASE_URL}/`,
  timeout: 16000,
  headers: {
    'x-nepoch-org': storage.getItem(CACHE.DEPT_ID_CACHE)
  }
}
1
2
3
4
5
6
7
  • 多项目配置文件 \src\views\business-management\config.json
"baseURL": "/api/",
1

修改为

"baseURL": "/gateway-api/",
1
  • auth 文件修改 \src\views\common\store\modules\auth.js
// 更新Glink的请求头
setHeaderOpition({
  baseURL: '/api/',
  timeout: 16000,
  headers: {
    'x-nepoch-org': defaultProgram.id
  }
})
1
2
3
4
5
6
7
8

修改为

setHeaderOpition({
  headers: {
    'x-nepoch-org': defaultProgram.id
  }
})
1
2
3
4
5