【issues/I52J6R】gateway,在网关路由页面如何设置路由条件Header

默认不启用xxljob
pull/3621/head
zhangdaiscott 2022-04-22 19:12:10 +08:00
parent dfbbd1bd1f
commit 727b67a50d
4 changed files with 146 additions and 27 deletions

View File

@ -28,14 +28,15 @@
<a-divider>{{item.name}} <a-divider>{{item.name}}
<a-icon type="delete" size="22" @click="removePredicate(router,index)"/> <a-icon type="delete" size="22" @click="removePredicate(router,index)"/>
</a-divider> </a-divider>
<div> <!--name genKeyRouter keykey -->
<template v-for="(tag, index) in item.args"> <div v-if="genKeyRouter.includes(item.name)">
<a-input v-if="index==currentTagIndex" ref="input" type="text" size="small" <template v-for="(tag, tagIndex) in item.args">
<a-input v-if="tagIndex==currentTagIndex&&index==currentNameIndex" ref="input" type="text" size="small"
:style="{ width: '190px' }" :style="{ width: '190px' }"
:value="tag" :value="tag"
@change="handleInputChange" @blur="handleInputEditConfirm(item,tag,index)" @change="handleInputChange" @blur="handleInputEditConfirm(item,tag,tagIndex)"
@keyup.enter="handleInputEditConfirm(item,tag,index)"/> @keyup.enter="handleInputEditConfirm(item,tag,tagIndex)"/>
<a-tag v-else :key="tag" :closable="true" @close="() => removeTag(item,tag)" @click="editTag(tag,index)"> <a-tag v-else :key="tag" :closable="true" @close="() => removeTag(item,tag)" @click="editTag(tag,tagIndex,index)">
{{ tag }} {{ tag }}
</a-tag> </a-tag>
</template> </template>
@ -49,11 +50,27 @@
{{item.name}} {{item.name}}
</a-tag> </a-tag>
</div> </div>
<!--name genKeyRouter key-->
<div v-if="!genKeyRouter.includes(item.name)">
<template v-for="(value, key) in item.args">
<a-row>
<a-col :span="5" style="margin-top:2px">
<span v-if="key=='header'" >Header</span>
<span v-if="key=='regexp'"></span>
<span v-if="key=='param'"></span>
<span v-if="key=='name'">Cookie</span>
</a-col>
<a-col :span="18">
<a-input :defaultValue="value" placeholder="参数值" style="width: 70%; margin-right: 8px;margin-top: 3px" @change="(e)=>valueChange(e,item.args,key)"/>
</a-col>
</a-row>
</template>
</div>
</div> </div>
<p class="btn" style="padding-top: 10px"> <p class="btn" style="padding-top: 10px">
<a-dropdown> <a-dropdown>
<a-menu slot="overlay" @click="predicatesHandleMenuClick"> <a-menu slot="overlay">
<a-menu-item :key="item" v-for="item in tagArray">{{item}}</a-menu-item> <a-menu-item :key="item.name" v-for="item in tagArray" @click="predicatesHandleMenuClick(item)">{{item.name}}</a-menu-item>
</a-menu> </a-menu>
<a-button type="dashed" style="margin-left: 8px;width:100%"> <a-button type="dashed" style="margin-left: 8px;width:100%">
<a-icon type="down"/> <a-icon type="down"/>
@ -113,8 +130,55 @@
currentNameIndex: 0, currentNameIndex: 0,
currentTagIndex:-1, currentTagIndex:-1,
predicates: {}, predicates: {},
filterArray: [{ key: 0, name: '' }, { key: 1, name: '' }], filterArray: [ { key: 1, name: '' }],
tagArray: ['Path', 'Host', 'Cookie', 'Header', 'Method', 'Query', 'After', 'Before', 'Between', 'RemoteAddr'], //gateway对应的规则key
tagArray: [
{
name:'Header',
args:{
header:'',
regexp:''
}
},
{
name:'Query',
args:{
param:'',
regexp:''
}
},
{
name:'Method',
args:[]
},
{
name:'Host',
args:[]
},
{
name:'Cookie',
args:{
name:'',
regexp:''
}
},
{
name:'After',
args:[]
},
{
name:'Before',
args:[]
},
{
name:'Between',
args:[]
},
{
name:'RemoteAddr',
args:[]
}
],
inputVisible: false, inputVisible: false,
inputValue: '', inputValue: '',
url: { url: {
@ -124,7 +188,8 @@
router: this.getRouter(), router: this.getRouter(),
title: '', title: '',
visible: false, visible: false,
loading: false loading: false,
genKeyRouter:["Path","Host","Method","After","Before","Between","RemoteAddr"]
} }
}, },
methods: { methods: {
@ -163,12 +228,22 @@
//添加路由选项 //添加路由选项
predicatesHandleMenuClick(e) { predicatesHandleMenuClick(e) {
this.router.predicates.push({ this.router.predicates.push({
args: [], args: e.args,
name: e.key name: e.name,
}) })
}, },
editTag(tag,index){ editTag(tag, tagIndex,index){
this.currentTagIndex=index this.currentNameIndex = index;
this.currentTagIndex=tagIndex
},
/**
*
* @param e
* @param item
* @param key
*/
valueChange(e,item,key){
item[key]=e.target.value
}, },
//显示输入框 //显示输入框
showInput(item, index) { showInput(item, index) {
@ -226,7 +301,7 @@
value: 20 value: 20
}], }],
name:"RequestRateLimiter", name:"RequestRateLimiter",
title: this.filterArray[1].name title: this.filterArray[0].name
}) })
} }
}, },

File diff suppressed because one or more lines are too long

View File

@ -1,5 +1,6 @@
package org.jeecg.loader; package org.jeecg.loader;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
@ -35,6 +36,7 @@ import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
@ -55,7 +57,10 @@ public class DynamicRouteLoader implements ApplicationEventPublisherAware {
private DynamicRouteService dynamicRouteService; private DynamicRouteService dynamicRouteService;
private ConfigService configService; private ConfigService configService;
private RedisUtil redisUtil; private RedisUtil redisUtil;
/**
* key
*/
private static String[] GEN_KEY_ROUTERS = new String[]{"Path", "Host", "Method", "After", "Before", "Between", "RemoteAddr"};
public DynamicRouteLoader(MyInMemoryRouteDefinitionRepository repository, DynamicRouteService dynamicRouteService, RedisUtil redisUtil) { public DynamicRouteLoader(MyInMemoryRouteDefinitionRepository repository, DynamicRouteService dynamicRouteService, RedisUtil redisUtil) {
@ -195,11 +200,27 @@ public class DynamicRouteLoader implements ApplicationEventPublisherAware {
for (Object map : list) { for (Object map : list) {
JSONObject json = (JSONObject) map; JSONObject json = (JSONObject) map;
PredicateDefinition predicateDefinition = new PredicateDefinition(); PredicateDefinition predicateDefinition = new PredicateDefinition();
predicateDefinition.setName(json.getString("name")); //update-begin-author:zyf date:20220419 for:【VUEN-762】路由条件添加异常问题,原因是部分路由条件参数需要设置固定key
String name=json.getString("name");
predicateDefinition.setName(name);
//路由条件是否拼接Key
if(ArrayUtil.contains(GEN_KEY_ROUTERS,name)) {
JSONArray jsonArray = json.getJSONArray("args"); JSONArray jsonArray = json.getJSONArray("args");
for (int j = 0; j < jsonArray.size(); j++) { for (int j = 0; j < jsonArray.size(); j++) {
predicateDefinition.addArg("_genkey" + j, jsonArray.get(j).toString()); predicateDefinition.addArg("_genkey" + j, jsonArray.get(j).toString());
} }
}else{
JSONObject jsonObject = json.getJSONObject("args");
if(ObjectUtil.isNotEmpty(jsonObject)){
for (Map.Entry<String, Object> entry : jsonObject.entrySet()) {
Object valueObj=entry.getValue();
if(ObjectUtil.isNotEmpty(valueObj)) {
predicateDefinition.addArg(entry.getKey(), valueObj.toString());
}
}
}
}
//update-end-author:zyf date:20220419 for:【VUEN-762】路由条件添加异常问题,原因是部分路由条件参数需要设置固定key
predicateDefinitionList.add(predicateDefinition); predicateDefinitionList.add(predicateDefinition);
} }
route.setPredicates(predicateDefinitionList); route.setPredicates(predicateDefinitionList);

View File

@ -0,0 +1,20 @@
package com.alibaba.nacos.control;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
/**
* -
*/
@Controller
public class IndexController {
private Logger logger = LoggerFactory.getLogger(IndexController.class);
@GetMapping("/")
public String index(Model model) {
return "/nacos"; // 视图重定向 - 跳转
}
}