VUE3-form表单保存附件与基本信息

element-ui代码

<el-dialog :title="上传附件" v-model="dialogAdds.visible" width="500px" append-to-body>

<el-form-item label="唯一标识">

<dict-tag v-if="form.groupId" :options="unique_identification" :value="form.identification" />

<el-input v-else v-model="form.identification" disabled style="width:260px;" />

</el-form-item>

<el-form-item label="设备" prop="file">

<template #default>

<div>

<div>

<label for="fileUpload">

<div class="lBut"><span>选择文件</span></div>

</label>

<div class="el-upload__tip text-red">允许上传.xls .xlsx</div>

<input id="fileUpload" type="file" style="display: none;" accept=".xls,.xlsx" @change="handleFileChange" />

<div class="el-upload__tip text-red" v-if="uploadFileName">{{ uploadFileName }}</div>

</div>

</div>

</template>

</el-form-item>

</el-form>

<template #footer>

<div class="dialog-footer">

<el-button :loading="buttonLoading" type="primary" @click="submitFormMul">确 定</el-button>

<el-button @click="cancelAdds">取 消</el-button>

</div>

</template>

</el-dialog>

js代码

<script setup lang="ts">

import axios from 'axios';

const dialogAdds = reactive<DialogOption>({

visible: false,

title: ''

});

// 文件上传

const handleFileChange = (event:any) => {

if(event.target.files0.size > 1024*1024*40){

return proxy?.$modal.msgSuccess("上传文件不能大于40M");

}

// 附件名称

uploadFileName.value=event.target.files0.name;

form.value.file= event.target.files0;

}

// 保存操作

const submitFormMul = ()=>{

deviceFormRef.value?.validate(async (valid: boolean) => {

if (valid) {

buttonLoading.value = true;

const result=await axios.post(import.meta.env.VITE_APP_BASE_API+'/device/device/deviceImportByExcel', form.value, {

headers: {

'Content-Type': 'multipart/form-data',

},

});

if(result.data.code==601){

proxy?.$modal.alertErrorTitle(result.data.data,"导入错误提示");

}

// 重置

uploadFileName.value='';

dialogAdds.visible = false;

buttonLoading.value = false;

}

});

}

</script>

style样式

<style>

.lBut{

width: 87px;

height: 32px;

font-size: 14px;

line-height: 1.15;

display: flex;

justify-content: center;

align-items: center;

border-radius: 4px;

padding: 8px 10px;

margin-left: 2px;

transition: all 0.5s;

white-space: nowrap;

background-color: #409eff;

color: white;

border: 1px solid #409eff;

}

</style>

结果展示

相关推荐
事圆则缓10 分钟前
Flutter 状态管理框架对比(一):先看地图,再选工具
前端·javascript·flutter
IMPYLH22 分钟前
HTML 的 <tfoot> 元素
前端·javascript·html
鬼手点金28 分钟前
Claude Code示范案例-修复 Bug 工作流
java·服务器·前端·javascript·bug·openclaw
paopaokaka_luck1 小时前
个人综合管理小程序(echarts数据看板、健康数据记录与趋势查看、目标拆解和进度管理、日程待办与番茄钟、习惯打卡、收支统计、个人生活记录、跨模块智能提醒)
前端·javascript·spring·小程序·数据分析·echarts·生活
福兮说9 小时前
前端下载大文件,点了按钮半天没反应:fetch + blob 的三个问题和三种替代写法
前端·javascript·性能优化·文件下载
今年下半年12 小时前
【VUE】整合腾讯地图、自定义区域边界、村委名称及资产统计(放大显示资产点位)
前端·javascript·vue.js
可乐鸡翅yeah_14 小时前
hls.js 切换多个视频源,新手开发常见踩坑
开发语言·前端·javascript·ios·ffmpeg·音视频·safari
kyriewen14 小时前
我实测了前端日期的 5 个坑:差 8 小时只是开始
前端·javascript·程序员
anew___15 小时前
《从零手写操作系统 (11):文件系统初探——initrd与VFS抽象层》
java·javascript·算法
今年下半年15 小时前
【VUE3】移动端:使用腾讯地图显示区域统计与放大显示资产点位
javascript·前端框架·vue·地图