审查视图

src/views/bus/RouterBatch.vue 16.5 KB
1 2 3 4 5 6 7
<template>
    <el-container>
        <el-main>
            <el-card style="background-color: #F5F7FA">
                <!-- 搜素区域 -->
                <el-row>
                    <el-col :span="24" align="left">
朱兆平 authored
8 9
                        <el-button type="warning" size="medium" icon="el-icon-search" @click="loadRouter"
                                   :loading="loadingStatus">
10 11
                            加载已配置消息
                        </el-button>
朱兆平 authored
12 13
                        <el-button type="primary" size="medium" icon="el-icon-plus" @click="batchAddRouter"
                                   :loading="loadingStatus">
14 15 16 17 18 19 20
                            生成路由
                        </el-button>
                    </el-col>
                </el-row>
                <el-divider></el-divider>
                <el-row>
                    <div style="border: 6px solid #6F8294;">
朱兆平 authored
21 22 23 24 25 26 27 28 29 30 31 32 33
                        <el-row style="margin: -2px">
                            <el-col :span="6">
                                <el-row class="bt">
                                    <span>选择消息发送者</span>
                                </el-row>
                                <el-row>
                                    <el-tree
                                            :data="sndr"
                                            show-checkbox
                                            node-key="username"
                                            :props="userProps"
                                            ref="sndrTree"
                                            @check-change="treeSndrCheckChange"
34
朱兆平 authored
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
                                    >
                                    </el-tree>
                                </el-row>
                            </el-col>
                            <el-col :span="6" align="center">
                                <el-row class="bt">
                                    <span>选择要发送的消息类型</span>
                                </el-row>
                                <el-row>
                                    <el-tree
                                            :data="message_type"
                                            show-checkbox
                                            node-key="name"
                                            default-expand-all
                                            check-strictly
                                            :props="defaultProps"
                                            highlight-current
                                            ref="typeTree"
                                            @check-change="treeTypeCheckChange"
                                    >
                                    </el-tree>
                                </el-row>
                            </el-col>
                            <el-col :span="6">
                                <el-row class="bt">
                                    <span>选择消息接收者</span>
                                </el-row>
                                <el-row>
                                    <el-tree
                                            :data="rcvr"
                                            show-checkbox
                                            node-key="id"
                                            :props="queueProps"
                                            ref="rcvrTree"
                                            @check-change="treeRcvrCheckChange"
                                    >
                                    </el-tree>
                                </el-row>
                            </el-col>
                            <el-col :span="6">
                                <el-row class="bt">
                                    <span>消息路由配置其他属性</span>
                                </el-row>
                                <el-row>
                                    <el-form :inline="true" :model="params" class="demo-form-inline" align="center"
                                             style="border:3px solid #6F8294;height: 800px;padding-top: 15px">
                                        <el-form-item label="路由状态:">
                                            <el-select v-model="params.status" placeholder="请选择" style="width: 150px"
                                                       size="mini">
                                                <el-option
                                                        v-for="item in status_options"
                                                        :key="item.value"
                                                        :label="item.label"
                                                        :value="item.value">
                                                    <span style="float: left">{{ item.label }}</span>
                                                    <span style="float: right; color: #8492a6; font-size: 13px">{{ item.value }}</span>
                                                </el-option>
                                            </el-select>
                                        </el-form-item>
                                        <el-form-item label="路由用途:">
                                            <el-select v-model="params.usage" placeholder="请选择" style="width: 150px"
                                                       size="mini">
                                                <el-option
                                                        v-for="item in usage_options"
                                                        :key="item.value"
                                                        :label="item.label"
                                                        :value="item.value">
                                                    <span style="float: left">{{ item.label }}</span>
                                                    <span style="float: right; color: #8492a6; font-size: 13px">{{ item.value }}</span>
                                                </el-option>
                                            </el-select>
                                        </el-form-item>
                                        <el-form-item label="路由描述:">
                                            <el-input type="textarea" v-model="params.des" style="width: 150px"
                                                      size="mini"></el-input>
                                        </el-form-item>
                                    </el-form>
                                </el-row>
                            </el-col>
114 115
                        </el-row>
朱兆平 authored
116
                    </div>
117 118 119 120 121 122 123
                </el-row>
            </el-card>
        </el-main>
    </el-container>
</template>

<script>
朱兆平 authored
124 125
    import {getAlltype, api_batchAddRouter, loadRouterBySndr, selectBusQueueList} from "../../api/message_bus";
126 127 128 129 130 131 132 133 134
    export default {
        name: "Configure",

        data() {
            return {
                loadingStatus: false,
                sndr: [],
                rcvr: [],
                api_back: [],
朱兆平 authored
135
                params: {
136 137 138 139 140 141 142 143 144
                    sndr: '',
                    sndrs: [],
                    types: [],
                    rcvrs: [],
                    status: 1,
                    usage: 2,
                    des: "",
                    ver: "1.0"
                },
朱兆平 authored
145
                status_options: [
146 147 148 149 150
                    {
                        label: "启用",
                        value: 1
                    },
                    {
朱兆平 authored
151
                        label: "关闭",
152 153 154
                        value: 0
                    }
                ],
朱兆平 authored
155
                usage_options: [
156 157 158 159 160
                    {
                        label: "生产用",
                        value: 1
                    },
                    {
朱兆平 authored
161
                        label: "测试用",
162 163 164
                        value: 2
                    }
                ],
朱兆平 authored
165
                message_type: [],
166 167
                defaultProps: {
                    children: 'children',
朱兆平 authored
168 169
                    label: function (data, node) {
                        return '[' + data.name + ']' + data.des;
170 171 172 173 174 175
                    },
                    disabled: 'disabled'
                },
                userProps: {
                    children: 'children',
                    label: function (data, node) {
朱兆平 authored
176 177 178 179 180 181 182
                        return '(' + data.username + ')' + data.des;
                    }
                },
                queueProps:{
                    children: 'children',
                    label: function (data, node) {
                        return '(' + data.queueName + ')' + data.description;
183 184 185 186 187 188 189
                    }
                }
            }
        },
        methods: {
            typeFilterNode(treeList) {
                let _this = this;
朱兆平 authored
190 191 192
                if (Array.isArray(treeList)) {
                    treeList.forEach(function (item, index) {
                        if (item.type == 1 || item.type == 2) {
193 194
                            item.disabled = true;
                        }
朱兆平 authored
195
                        if (item.children !== undefined) {
196 197 198 199 200 201 202
                            _this.typeFilterNode(item.children);
                        }
                    })
                }

            },
            getAllType() {
朱兆平 authored
203
                let _this = this;
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
                _this.loadingStatus = true;
                getAlltype().then((response) => {
                    let res = response.data;
                    if (res.code !== '200') {
                        _this.loadingStatus = false;
                        return _this.$message.error('获取消息类型失败!');
                    }
                    // 获取列表数据
                    _this.message_type = res.data;
                    // _this.typeFilterNode(_this.message_type);
                    // 关闭加载
                    _this.$message.success('获取消息类型成功!');
                    _this.loadingStatus = false;
                }).catch(error => {
                    // 关闭加载
                    _this.$message.error(error.toString());
                    _this.loadingStatus = false;
                });
            },
            /**
             * 访问用户服务,绑定用户列表,按组搜索
             */
朱兆平 authored
226
            getUserInfo() {
227 228 229 230 231 232 233 234 235
                let userResponse = [{
                    id: 1,
                    username: "zp260",
                    des: "测试用户1"
                }, {
                    id: 2,
                    username: "test04",
                    des: "测试用户2"
                },
朱兆平 authored
236 237 238 239 240
                    {
                        id: 3,
                        username: "zp2505",
                        des: "测试用户3"
                    }
241 242 243 244 245 246 247 248 249 250 251 252
                ];
                this.sndr = userResponse;
            },
            treeSndrCheckChange(data, checked, indeterminate) {
                if (checked) {
                    this.params.sndrs.push(data.username);
                } else {
                    this.params.sndrs.splice(this.params.sndrs.contains(data.username), 1);
                }
            },
            treeRcvrCheckChange(data, checked, indeterminate) {
                if (checked) {
朱兆平 authored
253
                    this.params.rcvrs.push(data.queueName);
254
                } else {
朱兆平 authored
255
                    this.params.rcvrs.splice(this.params.rcvrs.contains(data.queueName), 1);
256 257 258 259
                }
            },
            treeTypeCheckChange(data, checked, indeterminate) {
                let mt = {
朱兆平 authored
260 261
                    name: '',
                    type: 0
262 263 264 265 266 267 268 269 270 271
                };
                mt.name = data.name;
                mt.type = data.type;
                if (checked) {
                    this.params.types.push(mt);
                } else {
                    this.params.types.splice(this.params.types.contains(mt), 1);
                }
                console.log(this.params.types);
            },
朱兆平 authored
272
            loadRouter() {
273 274
                let _this = this;
                this.loadingStatus = true;
朱兆平 authored
275
                if (this.params.sndrs.length !== 1) {
276 277 278 279 280 281 282
                    this.$confirm('请选择单个发送者', '错误', {
                        confirmButtonText: '确定',
                        type: 'error',
                        center: true
                    }).then(() => {
                        _this.loadingStatus = false;
                    }).catch(() => {
朱兆平 authored
283
                        _this.loadingStatus = false;
284
                    });
朱兆平 authored
285
                } else {
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307
                    let pam = {
                        sndr: _this.params.sndrs[0]
                    };
                    loadRouterBySndr(pam).then(response => {
                        let res = response.data;
                        if (res.code !== '200') {
                            return _this.$message.error('读取用户路由,失败!');
                        }
                        _this.api_back = res.data;
                        _this.loadRouterHandle();
                        // 关闭加载
                        _this.$message.success('读取用户路由,成功!');
                        _this.loadingStatus = false;
                    }).catch(
                        error => {
                            // 关闭加载
                            _this.$message.error(error.toString());
                            _this.loadingStatus = false;
                        }
                    )
                }
            },
朱兆平 authored
308 309
            loadRouterHandle() {
                if (Array.isArray(this.api_back) && this.api_back.length > 0) {
310
                    let typeList = [];
朱兆平 authored
311 312
                    this.api_back.forEach(function (routerItem, index) {
                        typeList.push({name: routerItem.stype});
313 314 315 316
                    });
                    this.typeTreeSet(typeList);
                }
            },
朱兆平 authored
317
            typeTreeSet(typeList) {
318 319 320 321 322
                this.$refs.typeTree.setCheckedNodes(typeList);
            },
            batchAddRouter() {
                let _this = this;
                _this.loadingStatus = true;
朱兆平 authored
323
                //todo: 生产者列表,消费者列表,及路由类型判空后再访问接口
324 325
                api_batchAddRouter(this.params).then(response => {
                    let res = response.data;
326 327 328 329
                    console.log(res)
                    if (res.code != '200') {
                        return _this.$message.error(res.msg);
                        _this.loadingStatus = false;
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346
                    }
                    // 关闭加载
                    _this.$message.success('批量添加路由,成功!');
                    _this.loadingStatus = false;
                    _this.resetPage();
                }).catch(
                    error => {
                        // 关闭加载
                        _this.$message.error(error.toString());
                        _this.loadingStatus = false;
                    }
                )
            },
            resetPage() {
                this.$refs.sndrTree.setCheckedKeys([]);
                this.$refs.typeTree.setCheckedKeys([]);
                this.$refs.rcvrTree.setCheckedKeys([]);
朱兆平 authored
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367
            },
            queue_getList() {
                let queue_queryInfo = {
                        // 当前页数
                        pageNum: 1,
                        // 每页条数
                        pageSize: 100000
                    };
                selectBusQueueList(queue_queryInfo).then((response) => {
                    let res = response.data;
                    if (res.code !== '200') {
                        // 关闭加载
                        return this.$message.error(res.msg);
                    }
                    // 获取列表数据
                    this.rcvr = res.data.list;
                    this.$message.success(res.msg);
                }).catch(error => {
                    // 关闭加载
                    this.$message.error(error.toString());
                });
368 369 370 371 372
            }
        },
        mounted() {
            this.getAllType();
            this.getUserInfo();
朱兆平 authored
373
            this.queue_getList();
374 375 376 377 378 379 380 381 382 383 384 385
        }

    }
</script>

<style scoped>
    .bt {
        font-weight: bold;
        background-color: #6F8294;
        color: #ffffff;
        text-align: center
    }
朱兆平 authored
386
387 388 389
    .el-col {
        margin-right: 0px;
    }
朱兆平 authored
390
391 392
    .el-tree {
        padding-top: 15px;
朱兆平 authored
393
        border: 3px solid #6F8294;
394 395
        height: 800px
    }
朱兆平 authored
396
397 398 399 400
    .el-row .el-col .el-row {
        margin-top: 0px;
    }
</style>