作者 朱兆平

批量新增路由与加载已配置路由适配

@@ -130,3 +130,8 @@ export const getAlltype = params =>{return http.get(`${baseUrl}/message/type/lis @@ -130,3 +130,8 @@ export const getAlltype = params =>{return http.get(`${baseUrl}/message/type/lis
130 export const getTypesPage = params =>{return http.post(`${baseUrl}/message/type/list`, params);}; 130 export const getTypesPage = params =>{return http.post(`${baseUrl}/message/type/list`, params);};
131 export const addType = params =>{return http.post(`${baseUrl}/message/type/add`, params);}; 131 export const addType = params =>{return http.post(`${baseUrl}/message/type/add`, params);};
132 132
  133 +
  134 +//路由添加
  135 + //批量添加路由
  136 +export const api_batchAddRouter = params =>{return http.post(`${baseUrl}/router/batchAdd`, params);};
  137 +export const loadRouterBySndr = params =>{return http.get(`${baseUrl}/router/searchBysndr`, params);};
@@ -87,12 +87,9 @@ import UserInfo from "./views/bus/UserInfo.vue" @@ -87,12 +87,9 @@ import UserInfo from "./views/bus/UserInfo.vue"
87 import QueueView from "./views/bus/view/QueueView.vue" 87 import QueueView from "./views/bus/view/QueueView.vue"
88 import ExchangeView from "./views/bus/view/ExchangeView.vue" 88 import ExchangeView from "./views/bus/view/ExchangeView.vue"
89 import ElasticSearchInfo from "./views/bus/ElasticSearchInfo.vue" 89 import ElasticSearchInfo from "./views/bus/ElasticSearchInfo.vue"
90 -import ConfigureS from "./views/bus/Configure.vue" 90 +import RouterBatch from "./views/bus/RouterBatch.vue"
91 import MessageManagement from "./views/bus/MessageManagement.vue" 91 import MessageManagement from "./views/bus/MessageManagement.vue"
92 92
93 -//组件练习  
94 -import Page7 from "./views/nav3/Page7.vue"  
95 -  
96 93
97 94
98 95
@@ -166,7 +163,7 @@ let routes = [ @@ -166,7 +163,7 @@ let routes = [
166 {path: '/note', component: MessageNote, name: '消息记录管理'}, 163 {path: '/note', component: MessageNote, name: '消息记录管理'},
167 {path: '/note_search', component: MessageNoteSearch, name: '消息记录搜索'}, 164 {path: '/note_search', component: MessageNoteSearch, name: '消息记录搜索'},
168 {path: '/es', component: ElasticSearchInfo, name: 'ES信息管理'}, 165 {path: '/es', component: ElasticSearchInfo, name: 'ES信息管理'},
169 - {path: '/configures', component: ConfigureS, name: '消息路由批量配置'}, 166 + {path: '/configures', component: RouterBatch, name: '消息路由批量配置'},
170 {path: '/ms', component: MessageManagement, name: '消息分类管理'} 167 {path: '/ms', component: MessageManagement, name: '消息分类管理'}
171 168
172 ] 169 ]
@@ -181,15 +178,6 @@ let routes = [ @@ -181,15 +178,6 @@ let routes = [
181 // {path: '/exchangeView', component: ExchangeView, name: '交换机监控'}, 178 // {path: '/exchangeView', component: ExchangeView, name: '交换机监控'},
182 ] 179 ]
183 }, 180 },
184 - {  
185 - path: '/nav3',  
186 - component: Home,  
187 - name: '组件练习',  
188 - iconCls: 'el-icon-view',  
189 - children: [  
190 - {path: '/page7', component: Page7, name: '组件'},  
191 - ]  
192 - },  
193 181
194 182
195 // { 183 // {
1 -<template>  
2 - <el-container>  
3 - <el-main>  
4 - <div style="border: 6px solid #6F8294;">  
5 - <el-row style="margin: -2px">  
6 - <el-col :span="6">  
7 - <el-row class="bt">  
8 - <span>选择消息发送者</span>  
9 - </el-row>  
10 - <el-row>  
11 - <el-tree  
12 - :data="sndr"  
13 - show-checkbox  
14 - node-key="id"  
15 - :props="userProps">  
16 - </el-tree>  
17 - </el-row>  
18 - </el-col>  
19 - <el-col :span="6" align="center">  
20 - <el-row class="bt">  
21 - <span>选择要发送的消息</span>  
22 - </el-row>  
23 - <el-row>  
24 - <el-tree  
25 - :data="message_type"  
26 - show-checkbox  
27 - node-key="id"  
28 - :props="defaultProps">  
29 - </el-tree>  
30 - </el-row>  
31 - </el-col>  
32 - <el-col :span="6">  
33 - <el-row class="bt">  
34 - <span>选择消息接收者</span>  
35 - </el-row>  
36 - <el-row>  
37 - <el-tree  
38 - :data="rcvr"  
39 - show-checkbox  
40 - node-key="id"  
41 - :props="userProps">  
42 - </el-tree>  
43 - </el-row>  
44 - </el-col>  
45 - <el-col :span="6">  
46 - <el-row class="bt">  
47 - <span>消息路由配置其他属性</span>  
48 - </el-row>  
49 - <el-row>  
50 - <el-form :inline="true" :model="formInline" class="demo-form-inline" align="center" style="border:3px solid #6F8294;height: 800px;padding-top: 15px">  
51 - <el-form-item label="路由状态:">  
52 - <el-select v-model="formInline.state" placeholder="请选择" style="width: 150px" size="mini">  
53 - <el-option label="启用" value="01"></el-option>  
54 - <el-option label="关闭" value="02"></el-option>  
55 - </el-select>  
56 - </el-form-item>  
57 - <el-form-item label="路由用途:">  
58 - <el-select v-model="formInline.purpose" placeholder="请选择" style="width: 150px" size="mini">  
59 - <el-option label="生产用" value="03"></el-option>  
60 - </el-select>  
61 - </el-form-item>  
62 - <el-form-item label="路由描述:">  
63 - <el-input type="textarea" v-model="formInline.describe" style="width: 150px" size="mini"></el-input>  
64 - </el-form-item>  
65 - </el-form>  
66 - </el-row>  
67 - </el-col>  
68 - </el-row>  
69 -  
70 - </div>  
71 - </el-main>  
72 - </el-container>  
73 -</template>  
74 -  
75 -<script>  
76 - import {getAlltype} from "../../api/message_bus";  
77 - export default {  
78 - name: "Configure",  
79 -  
80 - data() {  
81 - return {  
82 - formInline: {  
83 - state: '',  
84 - purpose: '',  
85 - describe: ''  
86 - },  
87 - sndr: [{  
88 - id: 1,  
89 - label: '代理人系统接收账号(AGTR)',  
90 - }, {  
91 - id: 2,  
92 - label: '代理人接收中外运预配(AGTZ)',  
93 - }, {  
94 - id: 3,  
95 - label: '【测试】舱单自动化解析系统(AMDB)',  
96 - }],  
97 - rcvr: [{  
98 - id: 1,  
99 - label: '代理人系统接收账号(AGTR)',  
100 - }, {  
101 - id: 2,  
102 - label: '代理人接收中外运预配(AGTZ)',  
103 - }, {  
104 - id: 3,  
105 - label: '【测试】舱单自动化解析系统(AMDB)',  
106 - }],  
107 - queryInfo:{  
108 - pageNum:1,  
109 - pageSize:10,  
110 - name:"",  
111 - type:"",  
112 - },  
113 - message_type: [{  
114 - id: 1,  
115 - nameAndDes: '航班动态(1)',  
116 - children: [{  
117 - id: 7,  
118 - nameAndDes: '',  
119 - children: [{  
120 - id: 8,  
121 - nameAndDes: ''  
122 - }, {  
123 - id: 9,  
124 - nameAndDes: ''  
125 - }]  
126 - }]  
127 - }, {  
128 - id: 2,  
129 - nameAndDes: '航班历史(2)',  
130 - children: [{  
131 - id: 7,  
132 - nameAndDes: '',  
133 - children: [{  
134 - id: 8,  
135 - nameAndDes: ''  
136 - }, {  
137 - id: 9,  
138 - nameAndDes: ''  
139 - }]  
140 - }]  
141 - }, {  
142 - id: 3,  
143 - nameAndDes: '卡口业务交换信息(80)',  
144 - children: [{  
145 - id: 4,  
146 - nameAndDes: '卡口业务数据(KAKO)',  
147 - children: [{  
148 - id: 5,  
149 - nameAndDes: 'ALL'  
150 - }, {  
151 - id: 6,  
152 - nameAndDes: '卡口车单绑定关系数据(CARB)'  
153 - }]  
154 - }]  
155 - }],  
156 - defaultProps: {  
157 - children: 'children',  
158 - label: 'nameAndDes'  
159 - },  
160 - userProps: {  
161 - children: 'children',  
162 - label: 'label'  
163 - }  
164 - }  
165 - },  
166 - methods: {  
167 - onSubmit() {  
168 - console.log('submit!');  
169 - },  
170 - getAllType() {  
171 - let _this =this;  
172 - getAlltype().then((response) => {  
173 - let res = response.data;  
174 - if (res.code !== '200') {  
175 - return _this.$message.error('获取消息记录,失败!');  
176 - }  
177 - // 获取列表数据  
178 - _this.message_type = res.data;  
179 - // 关闭加载  
180 - _this.$message.success('获取消息收发记录,成功!');  
181 - }).catch(error => {  
182 - // 关闭加载  
183 - _this.$message.error(error.toString());  
184 - });  
185 - }  
186 - },  
187 - mounted() {  
188 - this.getAllType();  
189 - },  
190 -  
191 - }  
192 -</script>  
193 -  
194 -<style>  
195 - .bt {  
196 - font-weight: bold;  
197 - background-color: #6F8294;  
198 - color: #ffffff;  
199 - text-align: center  
200 - }  
201 - .el-col {  
202 - margin-right: 0px;  
203 - }  
204 - .el-tree {  
205 - padding-top: 15px;  
206 - border:3px solid #6F8294;  
207 - height: 800px  
208 - }  
209 - .el-row .el-col .el-row {  
210 - margin-top: 0px;  
211 - }  
212 -</style>  
  1 +<template>
  2 + <el-container>
  3 + <el-main>
  4 + <el-card style="background-color: #F5F7FA">
  5 + <!-- 搜素区域 -->
  6 + <el-row>
  7 + <el-col :span="24" align="left">
  8 + <el-button type="warning" size="medium" icon="el-icon-search" @click="loadRouter" :loading="loadingStatus">
  9 + 加载已配置消息
  10 + </el-button>
  11 + <el-button type="primary" size="medium" icon="el-icon-plus" @click="batchAddRouter" :loading="loadingStatus">
  12 + 生成路由
  13 + </el-button>
  14 + </el-col>
  15 + </el-row>
  16 + <el-divider></el-divider>
  17 + <el-row>
  18 + <div style="border: 6px solid #6F8294;">
  19 + <el-row style="margin: -2px">
  20 + <el-col :span="6">
  21 + <el-row class="bt">
  22 + <span>选择消息发送者</span>
  23 + </el-row>
  24 + <el-row>
  25 + <el-tree
  26 + :data="sndr"
  27 + show-checkbox
  28 + node-key="username"
  29 + :props="userProps"
  30 + ref="sndrTree"
  31 + @check-change="treeSndrCheckChange"
  32 +
  33 + >
  34 + </el-tree>
  35 + </el-row>
  36 + </el-col>
  37 + <el-col :span="6" align="center">
  38 + <el-row class="bt">
  39 + <span>选择要发送的消息类型</span>
  40 + </el-row>
  41 + <el-row>
  42 + <el-tree
  43 + :data="message_type"
  44 + show-checkbox
  45 + node-key="name"
  46 + default-expand-all
  47 + check-strictly
  48 + :props="defaultProps"
  49 + highlight-current
  50 + ref="typeTree"
  51 + @check-change="treeTypeCheckChange"
  52 + >
  53 + </el-tree>
  54 + </el-row>
  55 + </el-col>
  56 + <el-col :span="6">
  57 + <el-row class="bt">
  58 + <span>选择消息接收者</span>
  59 + </el-row>
  60 + <el-row>
  61 + <el-tree
  62 + :data="rcvr"
  63 + show-checkbox
  64 + node-key="id"
  65 + :props="userProps"
  66 + ref="rcvrTree"
  67 + @check-change="treeRcvrCheckChange"
  68 + >
  69 + </el-tree>
  70 + </el-row>
  71 + </el-col>
  72 + <el-col :span="6">
  73 + <el-row class="bt">
  74 + <span>消息路由配置其他属性</span>
  75 + </el-row>
  76 + <el-row>
  77 + <el-form :inline="true" :model="params" class="demo-form-inline" align="center" style="border:3px solid #6F8294;height: 800px;padding-top: 15px">
  78 + <el-form-item label="路由状态:">
  79 + <el-select v-model="params.status" placeholder="请选择" style="width: 150px" size="mini">
  80 + <el-option
  81 + v-for="item in status_options"
  82 + :key="item.value"
  83 + :label="item.label"
  84 + :value="item.value">
  85 + <span style="float: left">{{ item.label }}</span>
  86 + <span style="float: right; color: #8492a6; font-size: 13px">{{ item.value }}</span>
  87 + </el-option>
  88 + </el-select>
  89 + </el-form-item>
  90 + <el-form-item label="路由用途:">
  91 + <el-select v-model="params.usage" placeholder="请选择" style="width: 150px" size="mini">
  92 + <el-option
  93 + v-for="item in usage_options"
  94 + :key="item.value"
  95 + :label="item.label"
  96 + :value="item.value">
  97 + <span style="float: left">{{ item.label }}</span>
  98 + <span style="float: right; color: #8492a6; font-size: 13px">{{ item.value }}</span>
  99 + </el-option>
  100 + </el-select>
  101 + </el-form-item>
  102 + <el-form-item label="路由描述:">
  103 + <el-input type="textarea" v-model="params.des" style="width: 150px" size="mini"></el-input>
  104 + </el-form-item>
  105 + </el-form>
  106 + </el-row>
  107 + </el-col>
  108 + </el-row>
  109 +
  110 + </div>
  111 + </el-row>
  112 + </el-card>
  113 + </el-main>
  114 + </el-container>
  115 +</template>
  116 +
  117 +<script>
  118 + import { getAlltype,api_batchAddRouter,loadRouterBySndr } from "../../api/message_bus";
  119 + export default {
  120 + name: "Configure",
  121 +
  122 + data() {
  123 + return {
  124 + loadingStatus: false,
  125 + sndr: [],
  126 + rcvr: [],
  127 + api_back: [],
  128 + params:{
  129 + sndr: '',
  130 + sndrs: [],
  131 + types: [],
  132 + rcvrs: [],
  133 + status: 1,
  134 + usage: 2,
  135 + des: "",
  136 + ver: "1.0"
  137 + },
  138 + status_options:[
  139 + {
  140 + label: "启用",
  141 + value: 1
  142 + },
  143 + {
  144 + label:"关闭",
  145 + value: 0
  146 + }
  147 + ],
  148 + usage_options:[
  149 + {
  150 + label: "生产用",
  151 + value: 1
  152 + },
  153 + {
  154 + label:"测试用",
  155 + value: 2
  156 + }
  157 + ],
  158 + message_type: [{
  159 + id: 1,
  160 + name: '航班动态(1)',
  161 + children: [{
  162 + id: 7,
  163 + name: '',
  164 + children: [{
  165 + id: 8,
  166 + name: ''
  167 + }, {
  168 + id: 9,
  169 + name: ''
  170 + }]
  171 + }]
  172 + }, {
  173 + id: 2,
  174 + name: '航班历史(2)',
  175 + children: [{
  176 + id: 7,
  177 + name: '',
  178 + children: [{
  179 + id: 8,
  180 + name: ''
  181 + }, {
  182 + id: 9,
  183 + name: ''
  184 + }]
  185 + }]
  186 + }, {
  187 + id: 3,
  188 + name: '卡口业务交换信息(80)',
  189 + children: [{
  190 + id: 4,
  191 + name: '卡口业务数据(KAKO)',
  192 + children: [{
  193 + id: 5,
  194 + name: 'ALL'
  195 + }, {
  196 + id: 6,
  197 + name: '卡口车单绑定关系数据(CARB)'
  198 + }]
  199 + }]
  200 + }],
  201 + defaultProps: {
  202 + children: 'children',
  203 + label: function (data,node) {
  204 + return '[' + data.name+ ']' + data.des;
  205 + },
  206 + disabled: 'disabled'
  207 + },
  208 + userProps: {
  209 + children: 'children',
  210 + label: function (data, node) {
  211 + return '('+data.username + ')' + data.des;
  212 + }
  213 + }
  214 + }
  215 + },
  216 + methods: {
  217 + typeFilterNode(treeList) {
  218 + let _this = this;
  219 + if (Array.isArray(treeList)){
  220 + treeList.forEach(function(item,index){
  221 + if (item.type == 1 || item.type==2){
  222 + item.disabled = true;
  223 + }
  224 + if (item.children !== undefined){
  225 + _this.typeFilterNode(item.children);
  226 + }
  227 + })
  228 + }
  229 +
  230 + },
  231 + getAllType() {
  232 + let _this =this;
  233 + _this.loadingStatus = true;
  234 + getAlltype().then((response) => {
  235 + let res = response.data;
  236 + if (res.code !== '200') {
  237 + _this.loadingStatus = false;
  238 + return _this.$message.error('获取消息类型失败!');
  239 + }
  240 + // 获取列表数据
  241 + _this.message_type = res.data;
  242 + // _this.typeFilterNode(_this.message_type);
  243 + // 关闭加载
  244 + _this.$message.success('获取消息类型成功!');
  245 + _this.loadingStatus = false;
  246 + }).catch(error => {
  247 + // 关闭加载
  248 + _this.$message.error(error.toString());
  249 + _this.loadingStatus = false;
  250 + });
  251 + },
  252 + /**
  253 + * 访问用户服务,绑定用户列表,按组搜索
  254 + */
  255 + getUserInfo(){
  256 + let userResponse = [{
  257 + id: 1,
  258 + username: "zp260",
  259 + des: "测试用户1"
  260 + }, {
  261 + id: 2,
  262 + username: "test04",
  263 + des: "测试用户2"
  264 + },
  265 + {
  266 + id: 3,
  267 + username: "zp2505",
  268 + des: "测试用户3"
  269 + }
  270 + ];
  271 + this.sndr = userResponse;
  272 + this.rcvr = userResponse;
  273 + },
  274 + treeSndrCheckChange(data, checked, indeterminate) {
  275 + if (checked) {
  276 + this.params.sndrs.push(data.username);
  277 + } else {
  278 + this.params.sndrs.splice(this.params.sndrs.contains(data.username), 1);
  279 + }
  280 + },
  281 + treeRcvrCheckChange(data, checked, indeterminate) {
  282 + if (checked) {
  283 + this.params.rcvrs.push(data.username);
  284 + } else {
  285 + this.params.rcvrs.splice(this.params.rcvrs.contains(data.username), 1);
  286 + }
  287 + },
  288 + treeTypeCheckChange(data, checked, indeterminate) {
  289 + let mt = {
  290 + name:'',
  291 + type:0
  292 + };
  293 + mt.name = data.name;
  294 + mt.type = data.type;
  295 + if (checked) {
  296 + this.params.types.push(mt);
  297 + } else {
  298 + this.params.types.splice(this.params.types.contains(mt), 1);
  299 + }
  300 + console.log(this.params.types);
  301 + },
  302 + loadRouter(){
  303 + let _this = this;
  304 + this.loadingStatus = true;
  305 + if(this.params.sndrs.length !== 1){
  306 + this.$confirm('请选择单个发送者', '错误', {
  307 + confirmButtonText: '确定',
  308 + type: 'error',
  309 + center: true
  310 + }).then(() => {
  311 + _this.loadingStatus = false;
  312 + }).catch(() => {
  313 +
  314 + });
  315 + }else{
  316 + let pam = {
  317 + sndr: _this.params.sndrs[0]
  318 + };
  319 + loadRouterBySndr(pam).then(response => {
  320 + let res = response.data;
  321 + if (res.code !== '200') {
  322 + return _this.$message.error('读取用户路由,失败!');
  323 + }
  324 + _this.api_back = res.data;
  325 + _this.loadRouterHandle();
  326 + // 关闭加载
  327 + _this.$message.success('读取用户路由,成功!');
  328 + _this.loadingStatus = false;
  329 + }).catch(
  330 + error => {
  331 + // 关闭加载
  332 + _this.$message.error(error.toString());
  333 + _this.loadingStatus = false;
  334 + }
  335 + )
  336 + }
  337 + },
  338 + loadRouterHandle(){
  339 + if (Array.isArray(this.api_back) && this.api_back.length>0){
  340 + let typeList = [];
  341 + this.api_back.forEach(function(routerItem,index){
  342 + typeList.push({name:routerItem.stype});
  343 + });
  344 + this.typeTreeSet(typeList);
  345 + }
  346 + },
  347 + typeTreeSet(typeList){
  348 + this.$refs.typeTree.setCheckedNodes(typeList);
  349 + },
  350 + batchAddRouter() {
  351 + let _this = this;
  352 + _this.loadingStatus = true;
  353 + api_batchAddRouter(this.params).then(response => {
  354 + let res = response.data;
  355 + if (res.code !== '200') {
  356 + return _this.$message.error('批量添加路由,失败!');
  357 + }
  358 + // 关闭加载
  359 + _this.$message.success('批量添加路由,成功!');
  360 + _this.loadingStatus = false;
  361 + _this.resetPage();
  362 + }).catch(
  363 + error => {
  364 + // 关闭加载
  365 + _this.$message.error(error.toString());
  366 + _this.loadingStatus = false;
  367 + }
  368 + )
  369 + },
  370 + resetPage() {
  371 + this.$refs.sndrTree.setCheckedKeys([]);
  372 + this.$refs.typeTree.setCheckedKeys([]);
  373 + this.$refs.rcvrTree.setCheckedKeys([]);
  374 + }
  375 + },
  376 + mounted() {
  377 + this.getAllType();
  378 + this.getUserInfo();
  379 + }
  380 +
  381 + }
  382 +</script>
  383 +
  384 +<style scoped>
  385 + .bt {
  386 + font-weight: bold;
  387 + background-color: #6F8294;
  388 + color: #ffffff;
  389 + text-align: center
  390 + }
  391 + .el-col {
  392 + margin-right: 0px;
  393 + }
  394 + .el-tree {
  395 + padding-top: 15px;
  396 + border:3px solid #6F8294;
  397 + height: 800px
  398 + }
  399 + .el-row .el-col .el-row {
  400 + margin-top: 0px;
  401 + }
  402 +</style>