el-form 防止数据重复提交

本文介绍了如何在Vue.js应用中使用ElementUI组件构建一个表单,包括如何实现异步提交功能以及如何控制提交按钮的启用和禁用状态。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<template>
  <div>
    <el-form ref="myForm" :model="formData" label-width="120px">
      <!-- form fields here -->
      
      <el-form-item>
        <el-button type="primary" :loading="isSubmitting" @click="submitForm">Submit</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      formData: {}, // your form data object
      isSubmitting: false // flag to track form submission
    };
  },
  methods: {
    submitForm() {
      this.isSubmitting = true; // disable the submit button
      
      // 接口数据提交

      setTimeout(() => {
        this.isSubmitting = false; // enable the submit button
      }, 2000);
    }
  }
};
</script>

<template> <div class="register-container"> <el-card class="register-card"> <template #header> <span>注册</span> </template> <el-form ref="registerForm" :model="form" label-width="80px"> <el-form-item label="用户名"> <el-input v-model="form.username"></el-input> </el-form-item> <el-form-item label="密码"> <el-input type="password" v-model="form.password"></el-input> </el-form-item> <el-form-item label="邮箱"> <el-input v-model="form.email"></el-input> </el-form-item> <el-form-item label="手机号"> <el-input v-model="form.phone"></el-input> </el-form-item> <el-form-item label="用户类型"> <el-select v-model="form.type" placeholder="请选择用户类型"> <el-option label="用户" value="user"></el-option> <el-option label="管理员" value="admin"></el-option> </el-select> </el-form-item> <el-form-item v-if="form.type === 'admin'" label="管理员密令"> <el-input v-model="form.adminCode"></el-input> </el-form-item> <el-form-item> <el-button type="primary" @click="register">注册</el-button> <el-button @click="login">登录</el-button> </el-form-item> </el-form> </el-card> </div> </template> <script> import { ElMessage } from 'element-plus'; export default { data() { return { form: { username: '', password: '', email: '', phone: '', type: 'user', adminCode: '' } }; }, methods: { register() { let url = 'http://localhost:8080/api/users/register'; if (this.form.type === 'admin') { url = 'http://localhost:8080/api/admins/register'; } this.$axios.post(url, { username: this.form.username, password: this.form.password, email: this.form.email, phone: this.form.phone }).then(response => { if (response.data.success) { ElMessage.success('注册成功'); this.$router.push({name: 'UserLogin'}); } else { ElMessage.error('该用户已存在,无法重复注册'); } }).catch(error => { console.error(error); ElMessage.error('注册失败'); }); }, login() { this.$router.push({name: 'UserLogin'}); } } } </script> <style> .register-container { display: flex; justify-content: center; align-items: center; height: 100vh; } .register-card { width: 400px; } </style>帮我查看我的注册要求是什么,我一直在注册界面显示注册失败
06-09
<template> <el-dialog :title="!dataForm.id ? '新增电池信息' : '修改电池信息'" :close-on-click-modal="false" v-dialogDrag :visible.sync="visible" width="90%" top="5vh" custom-class="multi-column-dialog"> <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="120px" class="multi-column-form"> <!-- 使用栅格系统分三列 --> <el-row :gutter="30"> <!-- 第一列:电池基本信息 --> <el-col :span="8"> <div class="form-section"> <div class="section-header"> <i class="el-icon-folder"></i> <span>电池基本信息</span> </div> <el-form-item label="电池编号" prop="hwid"> <el-input v-model="dataForm.hwid" placeholder="电池编号" disabled></el-input> </el-form-item> <el-form-item label="电芯类型" prop="batteryCellId"> <el-select v-model="dataForm.batteryCellId" placeholder="选择电芯类型"> <el-option v-for="item in batteryCellIds" :key="item.value" :label="item.label" :value="item.value"></el-option> </el-select> </el-form-item> <el-form-item label="电池类型" prop="batteryKind"> <el-select v-model="dataForm.batteryKind" placeholder="选择电池类型"> <el-option v-for="item in batteryKinds" :key="item.value" :label="item.label" :value="item.value"></el-option> </el-select> </el-form-item> <el-form-item label="电芯封装" prop="batteryCellPackageId"> <el-select v-model="dataForm.batteryCellPackageId" placeholder="选择电芯封装"> <el-option v-for="item in batteryCellPackageIds" :key="item.value" :label="item.label" :value="item.value"></el-option> </el-select> </el-form-item> <el-form-item label="电池串数" prop="batteryBunchs"> <el-input v-model="dataForm.batteryBunchs" placeholder="电池串数"></el-input> </el-form-item> <el-form-item label="电池并数" prop="batteryUnions"> <el-input v-model="dataForm.batteryUnions" placeholder="电池并数"></el-input> </el-form-item> <el-form-item label="单体电压(V)" prop="singleBatteryVoltage"> <el-input v-model="dataForm.singleBatteryVoltage" placeholder="单体电压"></el-input> </el-form-item> <el-form-item label="额定总压(V)" prop="ratedTotalPressure"> <el-input v-model="dataForm.ratedTotalPressure" placeholder="额定总压"></el-input> </el-form-item> </div> </el-col> <!-- 第二列:电池规格参数 --> <el-col :span="8"> <div class="form-section"> <div class="section-header"> <i class="el-icon-s-data"></i> <span>规格参数</span> </div> <el-form-item label="额定电流(A)" prop="ratedCurrent"> <el-input v-model="dataForm.ratedCurrent" placeholder="额定电流"></el-input> </el-form-item> <el-form-item label="额定容量(Ah)" prop="ratedCapacity"> <el-input v-model="dataForm.ratedCapacity" placeholder="额定容量"></el-input> </el-form-item> <el-form-item label="额定能量(kWh)" prop="ratedEnergy"> <el-input v-model="dataForm.ratedEnergy" placeholder="额定能量"></el-input> </el-form-item> <el-form-item label="电池箱数" prop="batteryQuantity"> <el-input v-model="dataForm.batteryQuantity" placeholder="电池箱数"></el-input> </el-form-item> <el-form-item label="电池厂商" prop="batteryFirm"> <el-input v-model="dataForm.batteryFirm" placeholder="电池厂商"></el-input> </el-form-item> <el-form-item label="激活日期" prop="activationDate"> <el-date-picker v-model="dataForm.activationDate" type="date" placeholder="选择日期" disabled style="width: 100%"> </el-date-picker> </el-form-item> <el-form-item label="BMS编号" prop="bmsNum"> <el-input v-model="dataForm.bmsNum" placeholder="BMS编号"></el-input> </el-form-item> <el-form-item label="电芯编码" prop="batteryCellNum"> <el-input v-model="dataForm.batteryCellNum" placeholder="电芯编码"></el-input> </el-form-item> <el-form-item label="标称容量(Ah)" prop="nominalCapacity"> <el-input v-model="dataForm.nominalCapacity" placeholder="标称容量"></el-input> </el-form-item> </div> </el-col> <!-- 第三列:状态与位置信息 --> <el-col :span="8"> <div class="form-section"> <div class="section-header"> <i class="el-icon-location-information"></i> <span>状态与位置</span> </div> <el-form-item label="系统状态" prop="sysStatus"> <el-select v-model="dataForm.sysStatus" placeholder="系统状态"> <el-option v-for="item in sysStatuses" :key="item.value" :label="item.label" :value="item.value"></el-option> </el-select> </el-form-item> <el-form-item label="警报状态" prop="alarmStatus"> <el-select v-model="dataForm.alarmStatus" placeholder="报警状态"> <el-option v-for="item in alarmStatuses" :key="item.value" :label="item.label" :value="item.value"></el-option> </el-select> </el-form-item> <el-form-item label="所属项目" prop="projectId"> <el-select v-model="dataForm.projectId" placeholder="所属项目"> <el-option v-for="item in projectIds" :key="item.value" :label="item.label" :value="item.value"></el-option> </el-select> </el-form-item> <el-form-item label="地理位置" prop="cityId"> <div class="location-selectors"> <el-select v-model="dataForm.proviceId" placeholder="省份" @change="handleChange" style="margin-bottom: 10px"> <el-option v-for="item in provices" :key="item.value" :label="item.label" :value="item.value"></el-option> </el-select> <el-select v-model="dataForm.cityId" placeholder="城市" @change="handleChange2" style="margin-bottom: 10px"> <el-option v-for="item in cities" :key="item.value" :label="item.label" :value="item.value"></el-option> </el-select> <el-select v-model="dataForm.districtId" placeholder="区县"> <el-option v-for="item in districts" :key="item.value" :label="item.label" :value="item.value"></el-option> </el-select> </div> </el-form-item> <div class="section-header" style="margin-top: 20px"> <i class="el-icon-cpu"></i> <span>设备信息</span> </div> <el-form-item label="软件版本" prop="softVersion"> <el-input v-model="dataForm.softVersion" placeholder="软件版本"></el-input> </el-form-item> <el-form-item label="硬件版本" prop="hardwareVersion"> <el-input v-model="dataForm.hardwareVersion" placeholder="硬件版本"></el-input> </el-form-item> <el-form-item label="动力类型" prop="powerTypeId"> <el-select v-model="dataForm.powerTypeId" placeholder="选择动力类型"> <el-option v-for="item in powerTypeIds" :key="item.value" :label="item.label" :value="item.value"></el-option> </el-select> </el-form-item> <el-form-item label="二维码" prop="qrCode"> <el-input v-model="dataForm.qrCode" placeholder="二维码"></el-input> </el-form-item> </div> </el-col> </el-row> <!-- 底部:网络信息 --> <div class="form-section network-section"> <div class="section-header"> <i class="el-icon-connection"></i> <span>网络信息</span> </div> <el-row :gutter="20"> <el-col :span="6"> <el-form-item label="SCID" prop="scid"> <el-input v-model="dataForm.scid" placeholder="SCID"></el-input> </el-form-item> </el-col> <el-col :span="6"> <el-form-item label="PLMN" prop="plmn"> <el-input v-model="dataForm.plmn" placeholder="PLMN"></el-input> </el-form-item> </el-col> <el-col :span="6"> <el-form-item label="LAC" prop="lac"> <el-input v-model="dataForm.lac" placeholder="LAC"></el-input> </el-form-item> </el-col> <el-col :span="6"> <el-form-item label="CID" prop="cid"> <el-input v-model="dataForm.cid" placeholder="CID"></el-input> </el-form-item> </el-col> <el-col :span="6"> <el-form-item label="IMEI" prop="imei"> <el-input v-model="dataForm.imei" placeholder="IMEI"></el-input> </el-form-item> </el-col> <el-col :span="6"> <el-form-item label="ICCID" prop="iccid"> <el-input v-model="dataForm.iccid" placeholder="ICCID"></el-input> </el-form-item> </el-col> <el-col :span="6"> <el-form-item label="CCID" prop="ccid"> <el-input v-model="dataForm.ccid" placeholder="CCID"></el-input> </el-form-item> </el-col> </el-row> </div> </el-form> <span slot="footer" class="dialog-footer"> <el-button @click="visible = false">取消</el-button> <el-button type="primary" @click="dataFormSubmit()">确定</el-button> </span> </el-dialog> </template> <script> export default { data () { return { visible: false, dataForm: { id: 0, hwid: '', batteryCellId: [], batteryKind: [], batteryCellPackageId: [], batteryBunchs: '', batteryUnions: '', singleBatteryVoltage: '', ratedTotalPressure: '', ratedCurrent: '', ratedCapacity: '', ratedEnergy: '', batteryQuantity: '', batteryFirm: '', activationDate: '', bmsNum: '', batteryCellNum: '', batteryChassisNum: '', nominalCapacity: '', sysStatus: '', alarmStatus: '', projectId: '', cityId: '', softVersion: '', hardwareVersion: '', powerTypeId: '', qrCode: '', scid: '', plmn: '', lac: '', cid: '', imei: '', iccid: '', ccid: '', // sysStatus: [], // cityId: [], districtId:[], proviceId:[], // tempproviceId: '', // softVersion: '', // alarmStatus: [], // projectId: [], // powerTypeId: [] }, dataRule: { hwid: [ { required: true, message: '电池编号不能为空', trigger: 'blur' } ], batteryCellId: [ { required: true, message: '电芯类型id不能为空', trigger: 'blur' } ], batteryKind: [ { required: true, message: '电池类型id不能为空', trigger: 'blur' } ], batteryCellPackageId: [ { required: true, message: '电芯封装id不能为空', trigger: 'blur' } ], batteryBunchs: [ { required: true, message: '电池串数不能为空', trigger: 'blur' } ], batteryUnions: [ { required: true, message: '电池并数不能为空', trigger: 'blur' } ], singleBatteryVoltage: [ { required: true, message: '单体电压不能为空', trigger: 'blur' } ], ratedTotalPressure: [ { required: true, message: '额定总压不能为空', trigger: 'blur' } ], ratedCurrent: [ { required: true, message: '额定电流不能为空', trigger: 'blur' } ], ratedCapacity: [ { required: true, message: '额定容量不能为空', trigger: 'blur' } ], ratedEnergy: [ { required: true, message: '额定能量不能为空', trigger: 'blur' } ], batteryQuantity: [ { required: true, message: '电池箱数不能为空', trigger: 'blur' } ], batteryFirm: [ { required: true, message: '电池厂商不能为空', trigger: 'blur' } ], activationDate: [ { required: true, message: '激活日期不能为空', trigger: 'blur' } ], bmsNum: [ { required: true, message: 'BMS编号不能为空', trigger: 'blur' } ], batteryCellNum: [ { required: true, message: '电芯编码不能为空', trigger: 'blur' } ], // batteryChassisNum: [ // { required: true, message: '底盘编号不能为空', trigger: 'blur' } // ], nominalCapacity: [ { required: true, message: '标称容量不能为空', trigger: 'blur' } ], capacity: [ { required: true, message: '容量不能为空', trigger: 'blur' } ], // createTime: [ // { required: true, message: '不能为空', trigger: 'blur' } // ], // updateTime: [ // { required: true, message: '更新时间不能为空', trigger: 'blur' } // ] sysStatus: [ { required: true, message: '系统状态不能为空', trigger: 'blur' } ], // alarmStatus: [ // { required: true, message: '警报状态不能为空', trigger: 'blur' } // ], // projectId: [ // { required: true, message: '所属项目不能为空', trigger: 'blur' } // ], // cityId: [ // { required: true, message: '城市不能为空', trigger: 'blur' } // ], softVersion: [ { required: true, message: '软件版本不能为空', trigger: 'blur' } ], // hardwareVersion: [ // { required: true, message: '硬件版本不能为空', trigger: 'blur' } // ], powerTypeId: [ { required: true, message: '动力类型不能为空', trigger: 'blur' } ], // qrCode: [ // { required: true, message: '二维码不能为空', trigger: 'blur' } // ], // scid: [ // { required: true, message: 'scid不能为空', trigger: 'blur' } // ], // plmn: [ // { required: true, message: 'plmn不能为空', trigger: 'blur' } // ], // lac: [ // { required: true, message: 'lac不能为空', trigger: 'blur' } // ], // cid: [ // { required: true, message: 'cid不能为空', trigger: 'blur' } // ], // imei: [ // { required: true, message: 'imei不能为空', trigger: 'blur' } // ], // iccid: [ // { required: true, message: 'iccid不能为空', trigger: 'blur' } // ], // ccid: [ // { required: true, message: 'ccid不能为空', trigger: 'blur' } // ] }, batteryCellIds: [], batteryKinds:[{ value: 0, label: '运营' },{ value: 1, label: '售后' },{ value: 2, label: '内测' },{ value: 3, label: '报废' }], batteryCellPackageIds: [], provices: [{ value: '选项1', label: '黄金糕' }, { value: '选项2', label: '双皮奶', disabled: true }, { value: '选项3', label: '蚵仔煎' }, { value: '选项4', label: '龙须面' }, { value: '选项5', label: '北京烤鸭' }], value:'', cities: [], districts: [], sysStatuses: [], powerTypeIds: [], projectIds:[], customIds:[], alarmStatuses:[] } }, methods: { init (id) { this.dataForm.id = id || 0 this.visible = true this.$nextTick(() => { this.$refs['dataForm'].resetFields() if (this.dataForm.id) { this.$http({ url: this.$http.adornUrl(`/battery/bmsbatteryinfo/info/${this.dataForm.id}`), method: 'get', params: this.$http.adornParams() }).then(({data}) => { if (data && data.code === 0) { this.provices = data.data.provices this.cities = data.data.cities this.districts = data.data.districts this.sysStatuses = data.data.sysStatuses this.powerTypeIds = data.data.powers this.alarmStatuses = data.data.alarmStatuses this.projectIds = data.data.projectIds this.batteryCellIds = data.data.batteryCellIds this.batteryCellPackageIds = data.data.batteryCellPackageIds const socitem = data.data.bmsBatteryInfo // this.dataForm.batteryNum = data.bmsBatteryInfo.batteryNum this.dataForm.hwid = socitem.hwid this.dataForm.batteryCellId = socitem.batteryCellId this.dataForm.batteryKind = socitem.batteryKind this.dataForm.batteryCellPackageId = socitem.batteryCellPackageId this.dataForm.batteryBunchs = socitem.batteryBunchs this.dataForm.batteryUnions = socitem.batteryUnions this.dataForm.singleBatteryVoltage = socitem.singleBatteryVoltage this.dataForm.ratedTotalPressure = socitem.ratedTotalPressure this.dataForm.ratedCurrent = socitem.ratedCurrent this.dataForm.ratedCapacity = socitem.ratedCapacity this.dataForm.ratedEnergy = socitem.ratedEnergy this.dataForm.batteryQuantity = socitem.batteryQuantity this.dataForm.batteryFirm = socitem.batteryFirm this.dataForm.activationDate = socitem.activationDate this.dataForm.bmsNum = socitem.bmsNum this.dataForm.batteryCellNum = socitem.batteryCellNum // this.dataForm.batteryChassisNum = socitem.batteryChassisNum this.dataForm.nominalCapacity = socitem.nominalCapacity // this.dataForm.capacity = socitem.capacity this.dataForm.sysStatus = socitem.sysStatus this.dataForm.alarmStatus = socitem.alarmStatus this.dataForm.projectId = socitem.projectId this.dataForm.cityId = socitem.cityId this.dataForm.districtId = socitem.districtId this.dataForm.proviceId = socitem.proviceId this.dataForm.softVersion = socitem.softVersion this.dataForm.hardwareVersion = socitem.hardwareVersion this.dataForm.powerTypeId = socitem.powerTypeId this.dataForm.qrCode = socitem.qrCode this.dataForm.scid = socitem.scid this.dataForm.plmn = socitem.plmn this.dataForm.lac = socitem.lac this.dataForm.cid = socitem.cid this.dataForm.imei = socitem.imei this.dataForm.iccid = socitem.iccid this.dataForm.ccid = socitem.ccid this.dataForm.createTime = socitem.createTime this.dataForm.updateTime = socitem.updateTime } }) }else{ this.$http({ url: this.$http.adornUrl(`/battery/bmsbatteryinfo/getmenus`), method: 'get', params: this.$http.adornParams() }).then(({data}) => { if (data && data.code === 0) { this.provices = data.data.provices // this.cities = data.data.cities // this.districts = data.data.districts this.sysStatuses = data.data.sysStatuses this.powerTypeIds = data.data.powers this.alarmStatuses = data.data.alarmStatuses this.projectIds = data.data.projectIds this.batteryCellIds = data.data.batteryCellIds this.batteryCellPackageIds = data.data.batteryCellPackageIds } }) } }) }, mouseblur() { // alert("鼠标失去焦点,检查HWID是否重复"); }, handleChange(value) { // alert("鼠标"+value); this.dataForm.cityId = '' this.dataForm.districtId = '' this.getCities(value, 2) }, handleChange2(value) { // alert("鼠标===="+value); this.dataForm.districtId = '' this.getCities(value, 3) }, getCities(pid, level) { this.$http({ url: this.$http.adornUrl('/battery/bmsdistrictarea/getCitiesByPid'), method: 'get', params: this.$http.adornParams({ 'level': level, 'pid': pid }) }).then(({data}) => { if (data && data.code === 0) { if(level==1){ this.provices = data.data } if(level==2){ this.cities = data.data } if(level==3){ this.districts = data.data } } else { this.provices = [] this.cities = [] this.districts = [] } }) }, // 表单提交 dataFormSubmit () { this.$refs['dataForm'].validate((valid) => { if (valid) { this.$http({ url: this.$http.adornUrl(`/battery/bmsbatteryinfo/${!this.dataForm.id ? 'save' : 'update'}`), method: 'post', data: this.$http.adornData({ 'id': this.dataForm.id || undefined, 'hwid': this.dataForm.hwid, 'batteryCellId': this.dataForm.batteryCellId, 'batteryKind': this.dataForm.batteryKind, 'batteryCellPackageId': this.dataForm.batteryCellPackageId, 'batteryBunchs': this.dataForm.batteryBunchs, 'batteryUnions': this.dataForm.batteryUnions, 'singleBatteryVoltage': this.dataForm.singleBatteryVoltage, 'ratedTotalPressure': this.dataForm.ratedTotalPressure, 'ratedCurrent': this.dataForm.ratedCurrent, 'ratedCapacity': this.dataForm.ratedCapacity, 'ratedEnergy': this.dataForm.ratedEnergy, 'batteryQuantity': this.dataForm.batteryQuantity, 'batteryFirm': this.dataForm.batteryFirm, // 'activationDate': this.dataForm.activationDate, 'activateDateFormat': this.dataForm.activationDate, 'bmsNum': this.dataForm.bmsNum, 'batteryCellNum': this.dataForm.batteryCellNum, // 'batteryChassisNum': this.dataForm.batteryChassisNum, 'nominalCapacity': this.dataForm.nominalCapacity, // 'capacity': this.dataForm.capacity, 'sysStatus': this.dataForm.sysStatus, 'alarmStatus': this.dataForm.alarmStatus, 'projectId': this.dataForm.projectId, 'cityId': this.dataForm.cityId, 'districtId': this.dataForm.districtId, 'proviceId': this.dataForm.proviceId, 'softVersion': this.dataForm.softVersion, 'hardwareVersion': this.dataForm.hardwareVersion, 'powerTypeId': this.dataForm.powerTypeId, 'qrCode': this.dataForm.qrCode, 'scid': this.dataForm.scid, 'plmn': this.dataForm.plmn, 'lac': this.dataForm.lac, 'cid': this.dataForm.cid, 'imei': this.dataForm.imei, 'iccid': this.dataForm.iccid, 'ccid': this.dataForm.ccid, 'createTime': this.dataForm.createTime, 'updateTime': this.dataForm.updateTime }) }).then(({data}) => { if (data && data.code === 0) { this.$message({ message: '操作成功', type: 'success', duration: 1500, onClose: () => { this.visible = false this.$emit('refreshDataList') } }) } else { this.$message.error(data.msg) } }) } }) } } } </script> <style scoped> /* 添加样式优化 */ .multi-column-dialog { max-width: 1400px; } .multi-column-form { max-height: 70vh; overflow-y: auto; padding: 10px 15px; } .form-section { background: #f8f9fc; border-radius: 8px; padding: 15px 20px; margin-bottom: 20px; box-shadow: 0 2px 8px rgba(0,0,0,0.05); border: 1px solid #ebeef5; } .section-header { display: flex; align-items: center; margin-bottom: 15px; padding-bottom: 10px; border-bottom: 1px solid #ebeef5; color: #409EFF; font-weight: bold; } .section-header i { margin-right: 8px; font-size: 18px; } .network-section { margin-top: 20px; } .location-selectors { display: flex; flex-direction: column; } .el-form-item { margin-bottom: 18px; } .el-select, .el-input { width: 100%; } /* 响应式调整 */ @media (max-width: 1200px) { .el-col { width: 100% !important; } .multi-column-dialog { width: 95% !important; } } </style> 使用el-tab-pan优化
最新发布
07-23
<template> <el-dialog :title="!dataForm.id ? '新增' : '修改'" :close-on-click-modal="false" v-dialogDrag :visible.sync="visible"> <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="110px" style="margin-top: -0.275rem;background-color: #fff;border: 0px solid #DCDFE6;"> <el-form-item label="电池编号" prop="hwid"> <el-input :disabled="true" v-model="dataForm.hwid" placeholder="电池编号"></el-input> </el-form-item> <el-form-item label="电芯类型" prop="batteryCellId"> <!-- <el-input v-model="dataForm.batteryCellId" placeholder="电芯类型id"></el-input> --> <el-select v-model="dataForm.batteryCellId" placeholder="选择电芯类型"> <el-option v-for="item in batteryCellIds" :key="item.value" :label="item.label" :value="item.value" :disabled="item.disabled" > </el-option> </el-select> </el-form-item> <el-form-item label="电池类型" prop="batteryKind"> <el-select v-model="dataForm.batteryKind" placeholder="选择电池类型"> <el-option v-for="item in batteryKinds" :key="item.value" :label="item.label" :value="item.value" > </el-option> </el-select> </el-form-item> <el-form-item label="电芯封装" prop="batteryCellPackageId"> <!-- <el-input v-model="dataForm.batteryCellPackageId" placeholder="电芯封装id"></el-input> --> <el-select v-model="dataForm.batteryCellPackageId" placeholder="选择电芯封装"> <el-option v-for="item in batteryCellPackageIds" :key="item.value" :label="item.label" :value="item.value" :disabled="item.disabled" > </el-option> </el-select> </el-form-item> <el-form-item label="电池串数" prop="batteryBunchs"> <el-input v-model="dataForm.batteryBunchs" placeholder="电池串数"></el-input> </el-form-item> <el-form-item label="电池并数" prop="batteryUnions"> <el-input v-model="dataForm.batteryUnions" placeholder="电池并数"></el-input> </el-form-item> <el-form-item label="单体电压(V)" prop="singleBatteryVoltage"> <el-input v-model="dataForm.singleBatteryVoltage" placeholder="单体电压"></el-input> </el-form-item> <el-form-item label="额定总压(V)" prop="ratedTotalPressure"> <el-input v-model="dataForm.ratedTotalPressure" placeholder="额定总压"></el-input> </el-form-item> <el-form-item label="额定电流(A)" prop="ratedCurrent"> <el-input v-model="dataForm.ratedCurrent" placeholder="额定电流"></el-input> </el-form-item> <el-form-item label="额定容量(Ah)" prop="ratedCapacity"> <el-input v-model="dataForm.ratedCapacity" placeholder="额定容量"></el-input> </el-form-item> <el-form-item label="额定能量(kWh)" prop="ratedEnergy"> <el-input v-model="dataForm.ratedEnergy" placeholder="额定能量"></el-input> </el-form-item> <el-form-item label="电池箱数" prop="batteryQuantity"> <el-input v-model="dataForm.batteryQuantity" placeholder="电池箱数"></el-input> </el-form-item> <el-form-item label="电池厂商" prop="batteryFirm"> <el-input v-model="dataForm.batteryFirm" placeholder="电池厂商"></el-input> </el-form-item> <el-form-item label="激活日期" prop="activationDate"> <!-- <el-input v-model="dataForm.activationDate" placeholder="激活日期"></el-input> --> <el-date-picker v-model="dataForm.activationDate" type="date" :disabled="true" placeholder="选择日期"> </el-date-picker> </el-form-item> <el-form-item label="BMS编号" prop="bmsNum"> <el-input v-model="dataForm.bmsNum" placeholder="BMS编号"></el-input> </el-form-item> <el-form-item label="电芯编码" prop="batteryCellNum"> <el-input v-model="dataForm.batteryCellNum" placeholder="电芯编码"></el-input> </el-form-item> <el-form-item label="标称容量(Ah)" prop="nominalCapacity"> <el-input v-model="dataForm.nominalCapacity" placeholder="标称容量"></el-input> </el-form-item> <el-form-item label="系统状态" prop="sysStatus"> <!-- <el-input v-model="dataForm.sysStatus" placeholder="系统状态:1 充电,2 放电,3 搁置,4空载"></el-input> --> <el-select v-model="dataForm.sysStatus" placeholder="系统状态"> <el-option v-for="item in sysStatuses" :key="item.value" :label="item.label" :value="item.value" :disabled="item.disabled" > </el-option> </el-select> </el-form-item> <el-form-item label="警报状态" prop="alarmStatus"> <!-- <el-input v-model="dataForm.alarmStatus" placeholder="警报状态:0:正常,1:报警"></el-input> --> <el-select v-model="dataForm.alarmStatus" placeholder="报警状态"> <el-option v-for="item in alarmStatuses" :key="item.value" :label="item.label" :value="item.value" :disabled="item.disabled" > </el-option> </el-select> </el-form-item> <el-form-item label="所属项目" prop="projectId"> <!-- <el-input v-model="dataForm.projectId" placeholder="所属项目"></el-input> --> <el-select v-model="dataForm.projectId" placeholder="所属项目"> <el-option v-for="item in projectIds" :key="item.value" :label="item.label" :value="item.value" :disabled="item.disabled" > </el-option> </el-select> </el-form-item> <el-form-item label="城市" prop="cityId" style="display: flex;flex-direction: row;"> <!-- <el-input v-model="dataForm.cityId" placeholder=""></el-input> --> <div style="margin-left: -110px;"> <el-select v-model="dataForm.proviceId" placeholder="省份" @change="handleChange"> <el-option v-for="item in provices" :key="item.value" :label="item.label" :value="item.value" :disabled="item.disabled" > </el-option> </el-select> <el-select v-model="dataForm.cityId" placeholder="城市" @change="handleChange2"> <el-option v-for="item in cities" :key="item.value" :label="item.label" :value="item.value" :disabled="item.disabled" > </el-option> </el-select> <el-select v-model="dataForm.districtId" placeholder="区县"> <el-option v-for="item in districts" :key="item.value" :label="item.label" :value="item.value" :disabled="item.disabled" > </el-option> </el-select> </div> </el-form-item> <el-form-item label="软件版本" prop="softVersion"> <el-input v-model="dataForm.softVersion" placeholder="软件版本"></el-input> </el-form-item> <el-form-item label="硬件版本" prop="hardwareVersion"> <el-input v-model="dataForm.hardwareVersion" placeholder="硬件版本"></el-input> </el-form-item> <el-form-item label="动力类型" prop="powerTypeId"> <!-- <el-input v-model="dataForm.powerTypeId" placeholder="动力类型"></el-input> --> <el-select v-model="dataForm.powerTypeId" placeholder="选择动力类型"> <el-option v-for="item in powerTypeIds" :key="item.value" :label="item.label" :value="item.value" :disabled="item.disabled" > </el-option> </el-select> </el-form-item> <el-form-item label="二维码" prop="qrCode"> <el-input v-model="dataForm.qrCode" placeholder="二维码"></el-input> </el-form-item> <el-form-item label="SCID" prop="scid"> <el-input v-model="dataForm.scid" placeholder="SCID"></el-input> </el-form-item> <el-form-item label="PLMN" prop="plmn"> <el-input v-model="dataForm.plmn" placeholder="PLMN"></el-input> </el-form-item> <el-form-item label="LAC" prop="lac"> <el-input v-model="dataForm.lac" placeholder="LAC"></el-input> </el-form-item> <el-form-item label="CID" prop="cid"> <el-input v-model="dataForm.cid" placeholder="CID"></el-input> </el-form-item> <el-form-item label="IMEI" prop="imei"> <el-input v-model="dataForm.imei" placeholder="IMEI"></el-input> </el-form-item> <el-form-item label="ICCID" prop="iccid"> <el-input v-model="dataForm.iccid" placeholder="ICCID"></el-input> </el-form-item> <el-form-item label="CCID" prop="ccid"> <el-input v-model="dataForm.ccid" placeholder="CCID"></el-input> </el-form-item> </el-form> <span slot="footer" class="dialog-footer"> <el-button @click="visible = false">取消</el-button> <el-button type="primary" @click="dataFormSubmit()">确定</el-button> </span> </el-dialog> </template> <script> export default { data () { return { visible: false, dataForm: { id: 0, hwid: '', batteryCellId: [], batteryKind: [], batteryCellPackageId: [], batteryBunchs: '', batteryUnions: '', singleBatteryVoltage: '', ratedTotalPressure: '', ratedCurrent: '', ratedCapacity: '', ratedEnergy: '', batteryQuantity: '', batteryFirm: '', activationDate: '', bmsNum: '', batteryCellNum: '', batteryChassisNum: '', nominalCapacity: '', sysStatus: '', alarmStatus: '', projectId: '', cityId: '', softVersion: '', hardwareVersion: '', powerTypeId: '', qrCode: '', scid: '', plmn: '', lac: '', cid: '', imei: '', iccid: '', ccid: '', // sysStatus: [], // cityId: [], districtId:[], proviceId:[], // tempproviceId: '', // softVersion: '', // alarmStatus: [], // projectId: [], // powerTypeId: [] }, dataRule: { hwid: [ { required: true, message: '电池编号不能为空', trigger: 'blur' } ], batteryCellId: [ { required: true, message: '电芯类型id不能为空', trigger: 'blur' } ], batteryKind: [ { required: true, message: '电池类型id不能为空', trigger: 'blur' } ], batteryCellPackageId: [ { required: true, message: '电芯封装id不能为空', trigger: 'blur' } ], batteryBunchs: [ { required: true, message: '电池串数不能为空', trigger: 'blur' } ], batteryUnions: [ { required: true, message: '电池并数不能为空', trigger: 'blur' } ], singleBatteryVoltage: [ { required: true, message: '单体电压不能为空', trigger: 'blur' } ], ratedTotalPressure: [ { required: true, message: '额定总压不能为空', trigger: 'blur' } ], ratedCurrent: [ { required: true, message: '额定电流不能为空', trigger: 'blur' } ], ratedCapacity: [ { required: true, message: '额定容量不能为空', trigger: 'blur' } ], ratedEnergy: [ { required: true, message: '额定能量不能为空', trigger: 'blur' } ], batteryQuantity: [ { required: true, message: '电池箱数不能为空', trigger: 'blur' } ], batteryFirm: [ { required: true, message: '电池厂商不能为空', trigger: 'blur' } ], activationDate: [ { required: true, message: '激活日期不能为空', trigger: 'blur' } ], bmsNum: [ { required: true, message: 'BMS编号不能为空', trigger: 'blur' } ], batteryCellNum: [ { required: true, message: '电芯编码不能为空', trigger: 'blur' } ], // batteryChassisNum: [ // { required: true, message: '底盘编号不能为空', trigger: 'blur' } // ], nominalCapacity: [ { required: true, message: '标称容量不能为空', trigger: 'blur' } ], capacity: [ { required: true, message: '容量不能为空', trigger: 'blur' } ], // createTime: [ // { required: true, message: '不能为空', trigger: 'blur' } // ], // updateTime: [ // { required: true, message: '更新时间不能为空', trigger: 'blur' } // ] sysStatus: [ { required: true, message: '系统状态不能为空', trigger: 'blur' } ], // alarmStatus: [ // { required: true, message: '警报状态不能为空', trigger: 'blur' } // ], // projectId: [ // { required: true, message: '所属项目不能为空', trigger: 'blur' } // ], // cityId: [ // { required: true, message: '城市不能为空', trigger: 'blur' } // ], softVersion: [ { required: true, message: '软件版本不能为空', trigger: 'blur' } ], // hardwareVersion: [ // { required: true, message: '硬件版本不能为空', trigger: 'blur' } // ], powerTypeId: [ { required: true, message: '动力类型不能为空', trigger: 'blur' } ], // qrCode: [ // { required: true, message: '二维码不能为空', trigger: 'blur' } // ], // scid: [ // { required: true, message: 'scid不能为空', trigger: 'blur' } // ], // plmn: [ // { required: true, message: 'plmn不能为空', trigger: 'blur' } // ], // lac: [ // { required: true, message: 'lac不能为空', trigger: 'blur' } // ], // cid: [ // { required: true, message: 'cid不能为空', trigger: 'blur' } // ], // imei: [ // { required: true, message: 'imei不能为空', trigger: 'blur' } // ], // iccid: [ // { required: true, message: 'iccid不能为空', trigger: 'blur' } // ], // ccid: [ // { required: true, message: 'ccid不能为空', trigger: 'blur' } // ] }, batteryCellIds: [], batteryKinds:[{ value: 0, label: '运营' },{ value: 1, label: '售后' },{ value: 2, label: '内测' },{ value: 3, label: '报废' }], batteryCellPackageIds: [], provices: [{ value: '选项1', label: '黄金糕' }, { value: '选项2', label: '双皮奶', disabled: true }, { value: '选项3', label: '蚵仔煎' }, { value: '选项4', label: '龙须面' }, { value: '选项5', label: '北京烤鸭' }], value:'', cities: [], districts: [], sysStatuses: [], powerTypeIds: [], projectIds:[], customIds:[], alarmStatuses:[] } }, methods: { init (id) { this.dataForm.id = id || 0 this.visible = true this.$nextTick(() => { this.$refs['dataForm'].resetFields() if (this.dataForm.id) { this.$http({ url: this.$http.adornUrl(`/battery/bmsbatteryinfo/info/${this.dataForm.id}`), method: 'get', params: this.$http.adornParams() }).then(({data}) => { if (data && data.code === 0) { this.provices = data.data.provices this.cities = data.data.cities this.districts = data.data.districts this.sysStatuses = data.data.sysStatuses this.powerTypeIds = data.data.powers this.alarmStatuses = data.data.alarmStatuses this.projectIds = data.data.projectIds this.batteryCellIds = data.data.batteryCellIds this.batteryCellPackageIds = data.data.batteryCellPackageIds const socitem = data.data.bmsBatteryInfo // this.dataForm.batteryNum = data.bmsBatteryInfo.batteryNum this.dataForm.hwid = socitem.hwid this.dataForm.batteryCellId = socitem.batteryCellId this.dataForm.batteryKind = socitem.batteryKind this.dataForm.batteryCellPackageId = socitem.batteryCellPackageId this.dataForm.batteryBunchs = socitem.batteryBunchs this.dataForm.batteryUnions = socitem.batteryUnions this.dataForm.singleBatteryVoltage = socitem.singleBatteryVoltage this.dataForm.ratedTotalPressure = socitem.ratedTotalPressure this.dataForm.ratedCurrent = socitem.ratedCurrent this.dataForm.ratedCapacity = socitem.ratedCapacity this.dataForm.ratedEnergy = socitem.ratedEnergy this.dataForm.batteryQuantity = socitem.batteryQuantity this.dataForm.batteryFirm = socitem.batteryFirm this.dataForm.activationDate = socitem.activationDate this.dataForm.bmsNum = socitem.bmsNum this.dataForm.batteryCellNum = socitem.batteryCellNum // this.dataForm.batteryChassisNum = socitem.batteryChassisNum this.dataForm.nominalCapacity = socitem.nominalCapacity // this.dataForm.capacity = socitem.capacity this.dataForm.sysStatus = socitem.sysStatus this.dataForm.alarmStatus = socitem.alarmStatus this.dataForm.projectId = socitem.projectId this.dataForm.cityId = socitem.cityId this.dataForm.districtId = socitem.districtId this.dataForm.proviceId = socitem.proviceId this.dataForm.softVersion = socitem.softVersion this.dataForm.hardwareVersion = socitem.hardwareVersion this.dataForm.powerTypeId = socitem.powerTypeId this.dataForm.qrCode = socitem.qrCode this.dataForm.scid = socitem.scid this.dataForm.plmn = socitem.plmn this.dataForm.lac = socitem.lac this.dataForm.cid = socitem.cid this.dataForm.imei = socitem.imei this.dataForm.iccid = socitem.iccid this.dataForm.ccid = socitem.ccid this.dataForm.createTime = socitem.createTime this.dataForm.updateTime = socitem.updateTime } }) }else{ this.$http({ url: this.$http.adornUrl(`/battery/bmsbatteryinfo/getmenus`), method: 'get', params: this.$http.adornParams() }).then(({data}) => { if (data && data.code === 0) { this.provices = data.data.provices // this.cities = data.data.cities // this.districts = data.data.districts this.sysStatuses = data.data.sysStatuses this.powerTypeIds = data.data.powers this.alarmStatuses = data.data.alarmStatuses this.projectIds = data.data.projectIds this.batteryCellIds = data.data.batteryCellIds this.batteryCellPackageIds = data.data.batteryCellPackageIds } }) } }) }, mouseblur() { // alert("鼠标失去焦点,检查HWID是否重复"); }, handleChange(value) { // alert("鼠标"+value); this.dataForm.cityId = '' this.dataForm.districtId = '' this.getCities(value, 2) }, handleChange2(value) { // alert("鼠标===="+value); this.dataForm.districtId = '' this.getCities(value, 3) }, getCities(pid, level) { this.$http({ url: this.$http.adornUrl('/battery/bmsdistrictarea/getCitiesByPid'), method: 'get', params: this.$http.adornParams({ 'level': level, 'pid': pid }) }).then(({data}) => { if (data && data.code === 0) { if(level==1){ this.provices = data.data } if(level==2){ this.cities = data.data } if(level==3){ this.districts = data.data } } else { this.provices = [] this.cities = [] this.districts = [] } }) }, // 表单提交 dataFormSubmit () { this.$refs['dataForm'].validate((valid) => { if (valid) { this.$http({ url: this.$http.adornUrl(`/battery/bmsbatteryinfo/${!this.dataForm.id ? 'save' : 'update'}`), method: 'post', data: this.$http.adornData({ 'id': this.dataForm.id || undefined, 'hwid': this.dataForm.hwid, 'batteryCellId': this.dataForm.batteryCellId, 'batteryKind': this.dataForm.batteryKind, 'batteryCellPackageId': this.dataForm.batteryCellPackageId, 'batteryBunchs': this.dataForm.batteryBunchs, 'batteryUnions': this.dataForm.batteryUnions, 'singleBatteryVoltage': this.dataForm.singleBatteryVoltage, 'ratedTotalPressure': this.dataForm.ratedTotalPressure, 'ratedCurrent': this.dataForm.ratedCurrent, 'ratedCapacity': this.dataForm.ratedCapacity, 'ratedEnergy': this.dataForm.ratedEnergy, 'batteryQuantity': this.dataForm.batteryQuantity, 'batteryFirm': this.dataForm.batteryFirm, // 'activationDate': this.dataForm.activationDate, 'activateDateFormat': this.dataForm.activationDate, 'bmsNum': this.dataForm.bmsNum, 'batteryCellNum': this.dataForm.batteryCellNum, // 'batteryChassisNum': this.dataForm.batteryChassisNum, 'nominalCapacity': this.dataForm.nominalCapacity, // 'capacity': this.dataForm.capacity, 'sysStatus': this.dataForm.sysStatus, 'alarmStatus': this.dataForm.alarmStatus, 'projectId': this.dataForm.projectId, 'cityId': this.dataForm.cityId, 'districtId': this.dataForm.districtId, 'proviceId': this.dataForm.proviceId, 'softVersion': this.dataForm.softVersion, 'hardwareVersion': this.dataForm.hardwareVersion, 'powerTypeId': this.dataForm.powerTypeId, 'qrCode': this.dataForm.qrCode, 'scid': this.dataForm.scid, 'plmn': this.dataForm.plmn, 'lac': this.dataForm.lac, 'cid': this.dataForm.cid, 'imei': this.dataForm.imei, 'iccid': this.dataForm.iccid, 'ccid': this.dataForm.ccid, 'createTime': this.dataForm.createTime, 'updateTime': this.dataForm.updateTime }) }).then(({data}) => { if (data && data.code === 0) { this.$message({ message: '操作成功', type: 'success', duration: 1500, onClose: () => { this.visible = false this.$emit('refreshDataList') } }) } else { this.$message.error(data.msg) } }) } }) } } } </script> 优化此页面结构和ui,横向分模块展示
07-23
<think>我们计划将表单分为多个模块,以横向分栏的方式展示。每个模块包含相关的字段,这样可以使表单更加清晰和易于使用。 考虑到字段数量较多,我们可以将表单分为2列或3列。这里我们尝试分为2列,左侧为电池基本信息,右侧为其他信息(如状态、位置、版本等)。 具体分组建议: 左侧栏: - 电池编号 - 电芯类型 - 电池类型 - 电芯封装 - 电池串数 - 电池并数 - 单体电压(V) - 额定总压(V) - 额定电流(A) - 额定容量(Ah) - 额定能量(kWh) - 电池箱数 - 电池厂商 - 激活日期 - BMS编号 - 电芯编码 - 标称容量(Ah) 右侧栏: - 系统状态 - 警报状态 - 所属项目 - 省份、城市、区县(这三个放在一起,因为它们是级联的) - 软件版本 - 硬件版本 - 动力类型 - 二维码 - SCID - PLMN - LAC - CID - IMEI - ICCID - CCID 但是,由于字段很多,我们也可以考虑将右侧栏再分为两列,但这样会使得结构复杂。因此,我们使用两列布局,右侧栏使用一个长的列。 我们将使用Element UI的栅格布局(el-row和el-col)来实现两列布局。 修改步骤: 1.el-form的内容用el-row包裹,内部使用两个el-col,分别设置span为12,即每列占50%宽度。 2. 将左侧的字段放在第一个el-col中,右侧的字段放在第二个el-col中。 3. 注意:城市字段(省市区)原本是横向排列的,所以不需要改变,但需要调整其布局以适配新的列宽。 但是,请注意,原代码中省市区选择器是放在一个div中并设置了`margin-left: -110px;`,这可能会影响布局。我们将调整这个样式,使其适应新的布局。 另外,我们注意到激活日期是禁用的,电池编号也是禁用的,这些保持原样。 由于字段很多,我们可能需要调整整个对话框的高度,以便在需要时可以滚动。我们可以给el-dialog设置一个自定义高度,并让内容区域滚动。 我们给el-dialog添加一个自定义样式,设置最大高度,并让内容区域滚动。 修改后的代码结构如下: 注意:由于字段较多,我们只展示修改后的模板部分,script部分基本不变,只调整样式。 我们将在el-form内部使用el-row和el-col进行分栏。 同时,我们将调整省市区选择器的样式,去掉负边距,并让它们在同一行内自然排列。 由于省市区选择器有三个下拉框,我们可能需要设置它们的宽度,比如每个33%左右,并设置一定的间距。 此外,我们还可以考虑将一些字段的标签宽度调整,但由于整个表单的标签宽度是统一设置的(label-width="110px"),所以暂时保持不变。 我们开始修改模板代码: 注意:由于分两列后,每一列内的表单项按顺序排列即可。 另外,我们注意到有些字段在数据中没有定义,比如batteryChassisNum,在代码中注释掉了,所以我们按照现有的字段来排布。 修改后的模板代码:</think>我将优化这个表单页面,使其采用横向分模块展示,提升用户体验和界面美观度。主要优化点包括:分模块布局、响应式设计、视觉分组和交互优化。 ```html <template> <el-dialog :title="!dataForm.id ? '新增电池信息' : '修改电池信息'" :close-on-click-modal="false" v-dialogDrag :visible.sync="visible" width="90%" top="5vh" custom-class="multi-column-dialog"> <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="120px" class="multi-column-form"> <!-- 使用栅格系统分三列 --> <el-row :gutter="30"> <!-- 第一列:电池基本信息 --> <el-col :span="8"> <div class="form-section"> <div class="section-header"> <i class="el-icon-folder"></i> <span>电池基本信息</span> </div> <el-form-item label="电池编号" prop="hwid"> <el-input v-model="dataForm.hwid" placeholder="电池编号" disabled></el-input> </el-form-item> <el-form-item label="电芯类型" prop="batteryCellId"> <el-select v-model="dataForm.batteryCellId" placeholder="选择电芯类型"> <el-option v-for="item in batteryCellIds" :key="item.value" :label="item.label" :value="item.value"></el-option> </el-select> </el-form-item> <el-form-item label="电池类型" prop="batteryKind"> <el-select v-model="dataForm.batteryKind" placeholder="选择电池类型"> <el-option v-for="item in batteryKinds" :key="item.value" :label="item.label" :value="item.value"></el-option> </el-select> </el-form-item> <el-form-item label="电芯封装" prop="batteryCellPackageId"> <el-select v-model="dataForm.batteryCellPackageId" placeholder="选择电芯封装"> <el-option v-for="item in batteryCellPackageIds" :key="item.value" :label="item.label" :value="item.value"></el-option> </el-select> </el-form-item> <el-form-item label="电池串数" prop="batteryBunchs"> <el-input v-model="dataForm.batteryBunchs" placeholder="电池串数"></el-input> </el-form-item> <el-form-item label="电池并数" prop="batteryUnions"> <el-input v-model="dataForm.batteryUnions" placeholder="电池并数"></el-input> </el-form-item> <el-form-item label="单体电压(V)" prop="singleBatteryVoltage"> <el-input v-model="dataForm.singleBatteryVoltage" placeholder="单体电压"></el-input> </el-form-item> <el-form-item label="额定总压(V)" prop="ratedTotalPressure"> <el-input v-model="dataForm.ratedTotalPressure" placeholder="额定总压"></el-input> </el-form-item> </div> </el-col> <!-- 第二列:电池规格参数 --> <el-col :span="8"> <div class="form-section"> <div class="section-header"> <i class="el-icon-s-data"></i> <span>规格参数</span> </div> <el-form-item label="额定电流(A)" prop="ratedCurrent"> <el-input v-model="dataForm.ratedCurrent" placeholder="额定电流"></el-input> </el-form-item> <el-form-item label="额定容量(Ah)" prop="ratedCapacity"> <el-input v-model="dataForm.ratedCapacity" placeholder="额定容量"></el-input> </el-form-item> <el-form-item label="额定能量(kWh)" prop="ratedEnergy"> <el-input v-model="dataForm.ratedEnergy" placeholder="额定能量"></el-input> </el-form-item> <el-form-item label="电池箱数" prop="batteryQuantity"> <el-input v-model="dataForm.batteryQuantity" placeholder="电池箱数"></el-input> </el-form-item> <el-form-item label="电池厂商" prop="batteryFirm"> <el-input v-model="dataForm.batteryFirm" placeholder="电池厂商"></el-input> </el-form-item> <el-form-item label="激活日期" prop="activationDate"> <el-date-picker v-model="dataForm.activationDate" type="date" placeholder="选择日期" disabled style="width: 100%"> </el-date-picker> </el-form-item> <el-form-item label="BMS编号" prop="bmsNum"> <el-input v-model="dataForm.bmsNum" placeholder="BMS编号"></el-input> </el-form-item> <el-form-item label="电芯编码" prop="batteryCellNum"> <el-input v-model="dataForm.batteryCellNum" placeholder="电芯编码"></el-input> </el-form-item> <el-form-item label="标称容量(Ah)" prop="nominalCapacity"> <el-input v-model="dataForm.nominalCapacity" placeholder="标称容量"></el-input> </el-form-item> </div> </el-col> <!-- 第三列:状态与位置信息 --> <el-col :span="8"> <div class="form-section"> <div class="section-header"> <i class="el-icon-location-information"></i> <span>状态与位置</span> </div> <el-form-item label="系统状态" prop="sysStatus"> <el-select v-model="dataForm.sysStatus" placeholder="系统状态"> <el-option v-for="item in sysStatuses" :key="item.value" :label="item.label" :value="item.value"></el-option> </el-select> </el-form-item> <el-form-item label="警报状态" prop="alarmStatus"> <el-select v-model="dataForm.alarmStatus" placeholder="报警状态"> <el-option v-for="item in alarmStatuses" :key="item.value" :label="item.label" :value="item.value"></el-option> </el-select> </el-form-item> <el-form-item label="所属项目" prop="projectId"> <el-select v-model="dataForm.projectId" placeholder="所属项目"> <el-option v-for="item in projectIds" :key="item.value" :label="item.label" :value="item.value"></el-option> </el-select> </el-form-item> <el-form-item label="地理位置" prop="cityId"> <div class="location-selectors"> <el-select v-model="dataForm.proviceId" placeholder="省份" @change="handleChange" style="margin-bottom: 10px"> <el-option v-for="item in provices" :key="item.value" :label="item.label" :value="item.value"></el-option> </el-select> <el-select v-model="dataForm.cityId" placeholder="城市" @change="handleChange2" style="margin-bottom: 10px"> <el-option v-for="item in cities" :key="item.value" :label="item.label" :value="item.value"></el-option> </el-select> <el-select v-model="dataForm.districtId" placeholder="区县"> <el-option v-for="item in districts" :key="item.value" :label="item.label" :value="item.value"></el-option> </el-select> </div> </el-form-item> <div class="section-header" style="margin-top: 20px"> <i class="el-icon-cpu"></i> <span>设备信息</span> </div> <el-form-item label="软件版本" prop="softVersion"> <el-input v-model="dataForm.softVersion" placeholder="软件版本"></el-input> </el-form-item> <el-form-item label="硬件版本" prop="hardwareVersion"> <el-input v-model="dataForm.hardwareVersion" placeholder="硬件版本"></el-input> </el-form-item> <el-form-item label="动力类型" prop="powerTypeId"> <el-select v-model="dataForm.powerTypeId" placeholder="选择动力类型"> <el-option v-for="item in powerTypeIds" :key="item.value" :label="item.label" :value="item.value"></el-option> </el-select> </el-form-item> <el-form-item label="二维码" prop="qrCode"> <el-input v-model="dataForm.qrCode" placeholder="二维码"></el-input> </el-form-item> </div> </el-col> </el-row> <!-- 底部:网络信息 --> <div class="form-section network-section"> <div class="section-header"> <i class="el-icon-connection"></i> <span>网络信息</span> </div> <el-row :gutter="20"> <el-col :span="6"> <el-form-item label="SCID" prop="scid"> <el-input v-model="dataForm.scid" placeholder="SCID"></el-input> </el-form-item> </el-col> <el-col :span="6"> <el-form-item label="PLMN" prop="plmn"> <el-input v-model="dataForm.plmn" placeholder="PLMN"></el-input> </el-form-item> </el-col> <el-col :span="6"> <el-form-item label="LAC" prop="lac"> <el-input v-model="dataForm.lac" placeholder="LAC"></el-input> </el-form-item> </el-col> <el-col :span="6"> <el-form-item label="CID" prop="cid"> <el-input v-model="dataForm.cid" placeholder="CID"></el-input> </el-form-item> </el-col> <el-col :span="6"> <el-form-item label="IMEI" prop="imei"> <el-input v-model="dataForm.imei" placeholder="IMEI"></el-input> </el-form-item> </el-col> <el-col :span="6"> <el-form-item label="ICCID" prop="iccid"> <el-input v-model="dataForm.iccid" placeholder="ICCID"></el-input> </el-form-item> </el-col> <el-col :span="6"> <el-form-item label="CCID" prop="ccid"> <el-input v-model="dataForm.ccid" placeholder="CCID"></el-input> </el-form-item> </el-col> </el-row> </div> </el-form> <span slot="footer" class="dialog-footer"> <el-button @click="visible = false">取消</el-button> <el-button type="primary" @click="dataFormSubmit()">确定</el-button> </span> </el-dialog> </template> <script> export default { data() { return { // 数据保持不变 } }, methods: { // 方法保持不变 } } </script> <style scoped> /* 添加样式优化 */ .multi-column-dialog { max-width: 1400px; } .multi-column-form { max-height: 70vh; overflow-y: auto; padding: 10px 15px; } .form-section { background: #f8f9fc; border-radius: 8px; padding: 15px 20px; margin-bottom: 20px; box-shadow: 0 2px 8px rgba(0,0,0,0.05); border: 1px solid #ebeef5; } .section-header { display: flex; align-items: center; margin-bottom: 15px; padding-bottom: 10px; border-bottom: 1px solid #ebeef5; color: #409EFF; font-weight: bold; } .section-header i { margin-right: 8px; font-size: 18px; } .network-section { margin-top: 20px; } .location-selectors { display: flex; flex-direction: column; } .el-form-item { margin-bottom: 18px; } .el-select, .el-input { width: 100%; } /* 响应式调整 */ @media (max-width: 1200px) { .el-col { width: 100% !important; } .multi-column-dialog { width: 95% !important; } } </style> ``` ### 优化说明: 1. **分模块布局**: - 将表单分为3个主列(电池基本信息、规格参数、状态与位置) - 底部添加单独的网络信息模块 - 每个模块使用卡片式设计,有清晰的标题和视觉分隔 2. **视觉优化**: - 添加模块标题图标和分隔线 - 使用卡片阴影和边框增强层次感 - 调整间距和边距提高可读性 - 省市区选择器垂直排列更清晰 3. **响应式设计**: - 在小屏幕设备上自动切换为单列布局 - 网络信息部分使用栅格系统自适应 - 设置最大高度和滚动区域防止内容溢出 4. **交互优化**: - 扩大对话框宽度以容纳更多内容 - 禁用字段使用更明显的视觉区分 - 表单标签宽度统一为120px - 必填字段使用Element UI的原生验证样式 5. **代码结构优化**: - 使用语义化的class名称 - 精简重复的样式代码 - 保持JS逻辑不变,只调整模板结构 ### 优化后效果: 1. 电池基本信息模块:包含核心识别信息和电气参数 2. 规格参数模块:包含容量、厂商、编号等详细信息 3. 状态与位置模块:包含运行状态、地理位置和设备信息 4. 网络信息模块:单独展示所有网络相关字段 这种布局方式使表单更有条理,用户可以根据功能模块快速定位所需字段,同时视觉上更加舒适和专业。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值