<template>
  <div>
    <div class="header-menu-item" @click="open">
      <img :src="connIcon" alt="">
      <p>连接</p>
    </div>
    <el-dialog
        title="新建连接"
        width="450px"
        center
        :before-close="handleClose"
        :visible.sync="dialogVisible"
        :close-on-click-modal="false"
        :append-to-body="true">
      <el-form ref="connForm" :model='connForm' label-width='90px'>
        <el-form-item label='连接名称：' prop="connectName">
          <el-input v-model='connForm.connectName'
                    type="text"
                    auto-complete="off"
                    placeholder="连接名称"></el-input>
        </el-form-item>
        <el-form-item label='主机：' prop="host">
          <el-input v-model='connForm.host'
                    type="text"
                    auto-complete="off"
                    placeholder="主机"></el-input>
        </el-form-item>
        <el-form-item label='端口：' prop="port">
          <el-input v-model.number='connForm.port'
                    type="text"
                    auto-complete="off"
                    placeholder="端口"
                    oninput="value=value.replace(/[^0-9.]/g,'')"></el-input>
        </el-form-item>
        <el-form-item label='用户名：' prop="userName">
          <el-input v-model='connForm.userName'
                    type="text"
                    auto-complete="off"
                    placeholder="用户名"></el-input>
        </el-form-item>
        <el-form-item label='密码：' prop="password">
          <el-input v-model='connForm.password'
                    type="password"
                    auto-complete="new-password"
                    placeholder="密码"></el-input>
        </el-form-item>
      </el-form>
      <span slot='footer'>
          <el-button type="primary" @click='handleTestConnect'>测试连接</el-button>
          <el-button type="success" @click='handleSaveConnect'>保存</el-button>
          <el-button type="warning" @click='handleCancel'>取消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import connIcon from '@/assets/images/conn.png'

export default {
  name: "HeaderMenu",
  data() {
    return {
      dialogVisible: false,
      connIcon: connIcon,
      connForm: {
        connectName: "",
        host: "",
        port: "",
        userName: "",
        password: "",
      },
    }
  },
  methods: {
    /**
     * 弹出层关闭事件
     * @param done
     */
    handleClose(done) {
      this.$refs['connForm'].resetFields()
      done()
    },
    /**
     * 弹出层取消事件
     */
    handleCancel() {
      this.$refs['connForm'].resetFields()
      this.dialogVisible = false;
    },
    /**
     * 弹出层保存事件
     */
    handleSaveConnect() {
    },
    /**
     * 弹出层测试连接事件
     */
    handleTestConnect() {
    },
    /**
     * 打开连接弹框
     */
    open() {
      this.dialogVisible = true;
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss">
.header-menu-item {
  color: white;
  width: 100%;
  height: 60px;
  line-height: 0;
  vertical-align: middle;
  text-align: center;
  cursor: pointer;
}

.header-menu-item img {
  width: 25px;
  object-fit: cover;
  margin-top: 10px;
}

.header-menu-item p {
  margin-top: 10px;
  font-size: 15px;
}

.el-dialog {
  border-radius: 6px;
}

.el-dialog__header {
  border-bottom: 1px solid #e2e2e2;
}
</style>