datasource-add-or-update.vue 5.61 KB
Newer Older
geqilin's avatar
geqilin committed
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
<template lang="pug">
    el-dialog( :close-on-click-modal='false'  :visible.sync='visible' :append-to-body='true' :before-close="handleClose")
        div.title-bold(slot='title') {{dataForm.id ? '修改' :'新增'}}
        el-form(:model='dataForm' :rules='dataRule' ref='dataForm' label-width='100px' v-loading='dataLoading')
            el-row(:span='24')
                el-col(:span='24')
                    el-form-item(label='数据源url:', prop='url')
                        el-input(v-model='dataForm.url', placeholder='请填写数据源url(包含地址端口以及参数)' clearable)
                el-col(:span='12')
                    el-form-item(label='用户名:', prop='username')
                        el-input(v-model='dataForm.username', placeholder='请填写数据源用户名' clearable)
                el-col(:span='12' )
                    el-form-item(label='密码:', prop='password')
                        el-input(, v-model='dataForm.password', placeholder='请填写密码' clearable)
                el-col(:span='12' )
                    el-form-item(label='系统标识:', prop='sysSign')
                        el-input(, v-model='dataForm.sysSign', placeholder='请填写系统标识' clearable)
                el-col(:span='12' )
                    el-form-item(label='数据源ip:', prop='ip')
                        el-input(v-model='dataForm.ip', placeholder='请填写数据源服务器ip' clearable)
                el-col(:span='12')
                    el-form-item(label='数据源端口:', prop='port')
                        el-input(v-model='dataForm.port', placeholder='请填写数据源端口' clearable)
                el-col(:span='12')
                    el-form-item(label='说明信息:', prop='detail')
                        el-input(v-model='dataForm.detail' placeholder='请填写说明信息' clearable)
        div(slot='footer' align='center')
            el-button(type='primary' size='medium' @click='handleClose') 取消
            el-button(type='primary' size='medium' @click='dataFormSubmit()' v-prevent-re-click) 保存
</template>

<script>
    export default {
        data() {
            return {
                visible: false,
                dataLoading: false,
                dataForm: {},
                dataRule: {
                    url: [
                        { required: true, message: '数据源url不能为空', trigger: ['change', 'blur'] },
                        { min: 1, max: 200, message: '长度在 1 到 200 个字符', trigger: ['change', 'blur'] }
                    ],
                    username: [
                        { required: true, message: '数据源用户名不能为空', trigger: ['change', 'blur'] },
                        { min: 1, max: 100, message: '长度在 1 到 100 个字符', trigger: ['change', 'blur'] }
                    ],
                    password: [
                        { required: true, message: '密码不能为空', trigger: ['change', 'blur'] },
                        { min: 1, max: 100, message: '长度在 1 到 100 个字符', trigger: ['change', 'blur'] }
                    ],
                    sysSign: [
                        { required: true, message: '系统标识不能为空', trigger: ['change', 'blur'] },
                        { min: 1, max: 25, message: '长度在 1 到 25 个字符', trigger: ['change', 'blur'] }
                    ],
                    ip: [
                        { min: 1, max: 100, message: '长度在 1 到 100 个字符', trigger: ['change', 'blur'] }
                    ],
                    port: [
                        { min: 1, max: 10, message: '长度在 1 到 10 个字符', trigger: ['change', 'blur'] }
                    ],
                    detail: [
                        { min: 1, max: 100, message: '长度在 1 到 100 个字符', trigger: ['change', 'blur'] }
                    ]
                }
            }
        },
        mounted() {
        },
        methods: {
            init(row) {
                this.visible = true
                this.dataForm = { ...row }
            },
            //关闭前
            handleClose() {
                this.$refs.dataForm.resetFields()
                this.visible = false
            },
            // 表单提交
            dataFormSubmit() {
                this.$refs['dataForm'].validate(valid => {
                    if (valid) {
                        this.dataLoading = true
                        this.$http({
                            url: this.$http.adornUrl(
                                `/sysDatasource/${!this.dataForm.id ? 'save' : 'update'}`
                            ),
                            method: 'post',
                            data: this.dataForm
                        }).then(data => {
                            console.log(data)
                            if (data && data.code === 0) {
                                this.$message({
                                    message: '操作成功',
                                    type: 'success',
                                    duration: 1500
                                })
                                this.dataLoading = false
                                this.handleClose()
                                this.$emit('refreshdatalist')
                            }
                        }).catch(data => {
                            this.$message.error(data.msg)
                        })
                    }
                })
            }
        }
    }
</script>
<style>
    .el-table__header {
        width: 100% !important;
    }

    .el-table__body {
        width: 100% !important;
    }
</style>