This commit is contained in:
陈裕财
2024-07-10 05:53:07 +08:00
parent ed62803181
commit faf1a50b2b
4 changed files with 34 additions and 31 deletions

4
.env
View File

@@ -5,13 +5,13 @@ VITE_APP_TITLE=唛盟项目管理系统
VITE_CONTEXT=xm
# 首页页面访问路径版本
VITE_UI_VERSION=m1
VITE_UI_VERSION=
# 接口前缀
VITE_API_BASE_PATH=/api
# API版本号一般指api版本号
VITE_API_VERSION=m1
VITE_API_VERSION=
# 项目本地运行端口号
VITE_PORT=8067

View File

@@ -30,4 +30,4 @@ VITE_OUT_DIR=dist
VITE_APP_CAPTCHA_ENABLE=false
# 登录相关如果后端启用oauth2,则返回 oauth2client 如果后端不启用oauth2,后端账户使用mdp-lcode服务则返回 lcode ,如果使用mdp-sys提供服务则返回sys
VITE_CTX_LOGIN=oauth2client
VITE_CTX_LOGIN=lcode

View File

@@ -14,7 +14,7 @@
</a>
</p>
<p align="center">
👉 <a target="_blank" href="https://maimengcloud.com/xm/m1/">https://maimengcloud.com</a> 👈
👉 <a target="_blank" href="https://maimengcloud.com/xm">https://maimengcloud.com</a> 👈
</p>
@@ -23,7 +23,7 @@
- [前端组件](https://gitee.com/maimengcloud/xm-ui-web)
- [后端服务](https://gitee.com/maimengcloud/xm-backend)
- [体验环境](https://maimengcloud.com/xm/m1/)
- [体验环境](https://maimengcloud.com/xm)
登陆界面上选择演示账号登陆(账号密码demo-branch-01 888888)或者直接扫码登陆,无须注册
- 相关教程b站上搜素[唛盟9哥教你撸前后端代码](https://www.bilibili.com/video/BV111421S72r/?spm_id_from=333.337.search-card.all.click&vd_source=93be23d03863773d50b81112985b9237)
@@ -363,38 +363,38 @@ pnpm run dev
此种情况下前端如何把请求转发到本地起的后端工程?主要修改[vite.config.js](vite.config.ts)中的代理实现
假设后端mdp-lcode启动并监听7014端口
```js
['/api/m1/lcode']: {
['/api/lcode']: {
target: 'http://localhost:7014',
ws: false,
changeOrigin: true,
rewrite: (path) => path.replace(new RegExp(`^/api/m1/lcode`), '/'),
rewrite: (path) => path.replace(new RegExp(`^/api/lcode`), '/'),
},
['/api/m1/xm']: {
['/api/xm']: {
target: 'http://localhost:7067',
ws: false,
changeOrigin: true,
rewrite: (path) => path.replace(new RegExp(`^/api/m1/xm`), '/'),
rewrite: (path) => path.replace(new RegExp(`^/api/xm`), '/'),
},
```
上述代理实现把以/api/m1/lcode 开头的请求地址(举例/api/m1/lcode/user/list)替换为/user/list,并转发到http://localhost:7014地址
上述代理实现把以/api/m1/xm 开头的请求地址(举例/api/m1/xm/user/list)替换为/user/list,并转发到http://localhost:7067地址
上述代理实现把以/api/lcode 开头的请求地址(举例/api/lcode/user/list)替换为/user/list,并转发到http://localhost:7014地址
上述代理实现把以/api/xm 开头的请求地址(举例/api/xm/user/list)替换为/user/list,并转发到http://localhost:7067地址
2. 只启动前端页面工程,后端工程不启动,后端工程使用服务器上的已启动的服务
此种情况下前端如何把请求转发到服务上起的后端服务?主要修改[vite.config.js](vite.config.ts)中的代理实现
```js
['/api/m1/lcode']: {
['/api/lcode']: {
target: '服务器上的ip:7014',
ws: false,
changeOrigin: true,
rewrite: (path) => path.replace(new RegExp(`^/api/m1/lcode`), '/'),
rewrite: (path) => path.replace(new RegExp(`^/api/lcode`), '/'),
},
['/api/m1/xm']: {
['/api/xm']: {
target: '服务器上的ip:7067',
ws: false,
changeOrigin: true,
rewrite: (path) => path.replace(new RegExp(`^/api/m1/xm`), '/'),
rewrite: (path) => path.replace(new RegExp(`^/api/xm`), '/'),
},
```
@@ -455,7 +455,7 @@ unrar x dist.rar
server 192.168.0.222:7067;
}
location /api/m1/xm/ {
location /api/xm/ {
#proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
@@ -475,7 +475,7 @@ unrar x dist.rar
server 192.168.0.222:7014;
}
location /api/m1/lcode/ {
location /api/lcode/ {
#proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
@@ -487,7 +487,7 @@ unrar x dist.rar
proxy_next_upstream_tries 1;
}
```
需要特别注意的是 http://api-gate-lcode/后面的这个/不能省略,带/代表将“/api/m1/lcode/”替换成“/”,再转发上送到目标服务器
需要特别注意的是 http://api-gate-lcode/后面的这个/不能省略,带/代表将“/api/lcode/”替换成“/”,再转发上送到目标服务器
##### 同理其它子系统的api也类似lcode一样配置比如工作流相关的api可以按如下方式配置
```
@@ -495,7 +495,7 @@ unrar x dist.rar
server 192.168.0.222:7080;
}
location /api/m1/workflow/ {
location /api/workflow/ {
#proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
@@ -516,7 +516,7 @@ unrar x dist.rar
upstream api-gate {
server 192.168.0.222:6101;
}
location /api/m1/ {
location /api/ {
#proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;

View File

@@ -208,27 +208,30 @@ export default {
* @param {...any} uri
* @returns
*/
getUri:function(curlDomain,...uri){
debugger
if(curlDomain.endsWith("/")){
curlDomain=curlDomain.substr(0,curlDomain.length-1);
}
getUri:function(...uri){
if(!uri||uri.length==0){
return curlDomain
return ""
}
var uris=uri.filter(k=>k && k!="null")
var paths=uris.join("/");
var pathArr=paths.split("://")
if(pathArr.length>1){
paths=pathArr[1]
}
paths=paths.replaceAll(/\/{2,}/g,"/")
paths=paths.replaceAll(/#\/#/g,"#")
debugger
if(paths.startsWith("/")){
paths=paths.substring(1)
}
if(paths){
return curlDomain+"/"+paths
if(paths.endsWith("/")){
paths=paths.substring(0,paths.length-1)
}
if(pathArr.length>1){
return pathArr[0]+"://"+paths
}else{
return curlDomain
}
return paths
}
},