审查视图

src/views/configuration/mq.vue 8.1 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
<template>
    <section>
        <!--工具条-->
        <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
            <el-form :inline="true" :model="filters">
                <el-form-item>
                    <el-button type="success" @click="applyAdd()">新  增</el-button>
                </el-form-item>
            </el-form>
        </el-col>
        <!--列表-->
        <el-table :data="tableData" highlight-current-row  style="width: 100%;"
                  row-key="ruleId">
            <el-table-column width="120" prop="hostid" label="服务器IP"  >
            </el-table-column>
            <el-table-column width="120" prop="port" label="端口"  >
            </el-table-column>
            <el-table-column width="120" prop="user" label="账号" >
            </el-table-column>
            <el-table-column width="120" prop="pass" label="密码" >
            </el-table-column>
            <el-table-column width="240" label="操作" fixed="right">
                <template slot-scope="scope">
                    <el-button type="danger"  @click="batchRemove(scope.$index,scope.row)">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
        <!--		分页-->
        <div class="block">
            <el-pagination
                    :current-page="filters.pageNum"
                    :page-sizes="[10, 50, 100, 500]"
                    :page-size="filters.pageSize"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="total"
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange"
            />
        </div>
        <el-row>
            <el-dialog :title="dialogMap[dialogApply]" :visible.sync="apply_dialog" width="50%">
                <el-form  :model="addForm"  :rules="rules" ref="addForm" style="margin-top: 20px">
                    <el-row>
                        <el-col :span="11">
                            <el-form-item label="服务器IP" :label-width="formLabelWidth"  prop="hostid">
                                <el-input v-model="addForm.hostid" autocomplete="off" size="small" style="width: 260px">
                                </el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="端口" :label-width="formLabelWidth"  prop="port">
                                <el-input v-model="addForm.port" autocomplete="off" size="small" style="width: 260px">
                                </el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="11">
                            <el-form-item label="账号" :label-width="formLabelWidth"  prop="user">
                                <el-input v-model="addForm.user" autocomplete="off" size="small" style="width: 260px">
                                </el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :span="12">
                            <el-form-item label="密码" :label-width="formLabelWidth"  prop="pass">
                                <el-input  v-model="addForm.pass" autocomplete="off" size="small" style="width: 260px">
                                </el-input>
                            </el-form-item>
                        </el-col>
                    </el-row>
                </el-form>
                <div slot="footer" class="dialog-footer">
                    <el-button @click="apply_dialog = false" size="small">取 消</el-button>
                    <el-button type="primary" @click="dialogApply==='create'?add():edit()" size="small">提 交</el-button>
                </div>
            </el-dialog>
        </el-row>

    </section>
</template>
<script>
    import {listRabbitConfigs,insertRabbitConfig,deleteRabbitConfig} from '../../api/configuration';
    export default {
        data() {
            return {
                filters: {
                    pageNum: 1,
                    pageSize: 10
                },
                total: 0,
                tableData: [],
                dialogMap: {
                    update: '编辑',
                    create: '新增'
                },
                dis: undefined,
                dialogApply: 'create',
                apply_dialog: false,
                addForm: {
                    hostid:'',
                    port: '',
                    user: '',
                    pass: '',
                    id:''
                },
                formLabelWidth: '200px',
                rules: {
                },

            }
        },
        mounted() {
            this.getList();
        },
        methods: {
            //分页
            handleSizeChange(val) {
                this.filters.pageSize = val
                this.getList()
            },
            handleCurrentChange(val) {
                this.filters.pageNum = val
                this.getList()
            },
            //获取列表
            getList() {
                const _this = this
                listRabbitConfigs().then((response) => {
                    const res = response.data
                    if (res.code !== '200') {
                        return _this.$message.error('获取消息收发记录,失败!')
                    }
                    // 获取列表数据
                    _this.tableData = res.data
                    // 获取列表的总记录数
                    _this.total = res.data.total
                    _this.$message.success('获取消息收发记录,成功!')
                }).catch(error => {
                    // 关闭加载
                    _this.$message.error(error.toString())
                })
            },
            // 添加对话框,打开事件
            applyAdd() {
                this.addForm = {
                    hostid:'',
                    port: '',
                    user: '',
                    pass: '',
                    id:''
                };
                this.dialogApply= 'create';
                this.dis= 'create';
                this.apply_dialog = true;
            },
            // 添加功能
            add() {
                this.$refs.addForm.validate(valid => {
                    // 未通过,表单预校验
                    if (!valid) return;
                    insertRabbitConfig(this.addForm).then((response) => {
                        let res = response.data;
                        // 添加失败
                        if (res.code !== '200') {
                            return this.$message.error(res.msg);
                        }
                        // 添加,成功
                        this.$message.success(res.msg);
                        // 隐藏对话框
                        this.apply_dialog = false;
                        // 刷新列表
                        this.getList();
                    }).catch(error => {
                        this.$message.error(error.toString());
                    });
                })
            },
            //删除
            batchRemove(index,row) {
                // 弹框询问是否删除?
                this.$confirm('此操作永久删除该消息, 是否继续?', '警告', {
                        confirmButtonText: '确定删除',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }
                ).then(() => {
                    deleteRabbitConfig({id:row.id}).then((response) => {
                        const res = response.data
                        this.$message.success(res.msg)
                        this.getList()
                    }).catch(error => {
                        this.$message.error(error)
                    })
                }).catch(() => {
                })
            },
        },


    }
</script>