表格中附件的上传、显示以及文件下载#Vue3#后端接口数据

news2024/10/7 16:19:52

表格中附件的上传及显示#Vue3#后端接口数据

一、图片上传并显示在表格中实现效果:
在这里插入图片描述

表格中上传附件

代码:

<!-- 文件的上传及显示 -->
<template>
  <!-- 演示地址 -->
  <div class="dem-add">
    <!-- Search start -->
    <div class="dem-title">
      <p>演示地址</p>
      <el-input
        class="query-input"
        v-model="tableForm.demoDevice"
        placeholder="搜索"
        @keyup.enter="handleQueryName"
      >
        <template #prefix>
          <el-icon class="el-input__icon"><search /></el-icon>
        </template>
      </el-input>
      <el-button type="primary" :icon="Plus" circle @click="handleAdd" />
    </div>
    <!-- Search end -->
    <!-- Table start -->
    <div class="bs-page-table">
      <el-table :data="tableData" ref="multipleTableRef">
        <el-table-column prop="sort" label="排序" width="60" />
        <el-table-column prop="demoDevice" label="演示端" width="150" />
        <el-table-column prop="address" label="地址" width="180" />
        <el-table-column prop="description" label="特殊说明" width="180" />
        <el-table-column prop="fileIds" label="附加" width="100">
          <template #default="scope">
            <img
              width="80px"
              height="80px"
              :src="`http://192.168.1.214:5050${scope.row.files[0].filePath}`"
            />
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="100">
          <template #default="scope">
            <el-button
              type="danger"
              @click="handleRowDel(scope.$index)"
              :icon="Delete"
              circle
            />
          </template>
        </el-table-column>
      </el-table>
      <el-dialog v-model="dialogFormVisible" title="新增" width="500">
        <el-form :model="tableForm">
          <el-form-item label="排序" :label-width="80">
            <el-input v-model="tableForm.sort" autocomplete="off" />
          </el-form-item>
          <el-form-item label="演示端" :label-width="80">
            <el-input v-model="tableForm.demoDevice" autocomplete="off" />
          </el-form-item>
          <el-form-item label="地址" :label-width="80">
            <el-input v-model="tableForm.address" autocomplete="off" />
          </el-form-item>
          <el-form-item label="特殊说明" :label-width="80">
            <el-input v-model="tableForm.description" autocomplete="off" />
          </el-form-item>
          <el-form-item label="附加" :label-width="80">
            <el-upload
              multiple
              class="upload-demo"
              action=""
              :http-request="uploadFile"
              list-type="picture"
            >
              <el-button type="primary">上传文件</el-button>
            </el-upload>
          </el-form-item>
        </el-form>
        <template #footer>
          <div class="dialog-footer">
            <el-button @click="dialogFormVisible = false"> 取消 </el-button>
            <el-button type="primary" @click="dialogConfirm"> 确认 </el-button>
          </div>
        </template>
      </el-dialog>
    </div>
    <!-- Table end -->
  </div>
</template>

<script setup lang="ts">
import { Plus } from "@element-plus/icons-vue";
import { ref, onMounted, toRaw } from "vue";
import axios from "axios";
import { useRouter } from "vue-router";
import { Search } from "@element-plus/icons-vue";
import { Delete } from "@element-plus/icons-vue";

const router = useRouter();
console.log(router.currentRoute.value.path); //当前路由路径
sessionStorage.setItem("path", router.currentRoute.value.path);
// 演示地址
// 定义表格
const tableData = ref<any>([]);
// 定义弹窗表单
let tableForm = ref({
  sort: "",
  demoDevice: "",
  address: "",
  description: "",
  fileIds: <any>[],
  file: "",
});
// 默认对话框关闭状态
const dialogFormVisible = ref(false);
// 调用接口数据在表单显示
const port = async () => {
  await axios
    .post("http://192.168.1.214:5050/api/Project/DemoGetTable", {
      pageIndex: 1,
      pageSize: 100,
      projectId: "1",
    })
    .then((response) => {
      // 将找到的数据返回给表单显示
      tableData.value = response.data.data.list;
    })
    .catch((error) => {
      console.error(error);
    });
};
// 挂载
onMounted(() => {
  port();
});
// 搜索(通过name值查找)
const handleQueryName = () => {
  console.log("搜索");
};
// 新增
const handleAdd = async () => {
  // 打开新增对话框
  dialogFormVisible.value = true;
  // 设置空的绑定对象
  tableForm.value = {
    demoDevice: "",
    address: "",
    description: "",
    sort: "",
    fileIds: [],
    file: "",
  };
};
// 上传文件
const uploadFile = async (val: any) => {
  tableForm.value.file = val.file;
  // 数据交互
  let formdata = new FormData();
  formdata.append("File", tableForm.value.file);
  axios
    // 上传文件接口
    .post("http://192.168.1.214:5050/api/File/UploadFile", formdata, {
      headers: { "Content-Type": "multipart/form-data" },
    })
    .then((res) => {
      // 将文件id值传给tableForm的属性fileIds
      tableForm.value.fileIds.push(res.data.data.id);
      const newobj = Object.assign({ projectId: "1" }, toRaw(tableForm.value));
      axios
        // 添加演示地址接口
        .post("http://192.168.1.214:5050/api/Project/DemoAdd", newobj);
    });
};
// 删除
const handleRowDel = async (index: any) => {
  // 找到要删除的接口中对应的对象
  await axios.post("http://192.168.1.214:5050/api/Project/DemoDel", {
    // 获取到当前索引index下的id值,toRaw()方法获取原始对象
    id: toRaw(tableData.value[index]).id,
  });
  // 从index位置开始,删除一行即可
  tableData.value.splice(index, 1);
};
// 确认表单弹窗
const dialogConfirm = () => {
  dialogFormVisible.value = false;
  port();
};
</script>

<style scoped lang="scss">
// 演示地址
.dem-add {
  width: 800px;
  margin: 20px 50px;
  background-color: rgba(255, 255, 255, 0.333);
  box-shadow: 0 8px 16px #0005;
  border-radius: 16px;
  overflow: hidden;
  // 标签
  .dem-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: rgba(207, 204, 204, 0.267);
    padding: 0 20px;
    p {
      float: left;
      width: 150px;
      color: #000;
    }
    // 搜索
    ::v-deep .el-input__wrapper {
      border-radius: 100px;
    }
    .query-input {
      width: 240px;
      height: 35px;
      margin: 10px auto;
      margin-left: 330px;
      background-color: transparent;
      transition: 0.2s;
    }
    ::v-deep .el-input__wrapper:hover {
      background-color: #fff8;
      box-shadow: 0 5px 40px #0002;
    }
    // 增加按钮
    .el-button {
      float: left;
      margin-top: 3px;
      margin-left: 10px;
    }
  }
  // 表格
  .bs-page-table {
    .el-table {
      width: 100%;
      border: 1px solid rgb(219, 219, 219);
      padding: 10px;
      .el-table-column {
        border-collapse: collapse;
        text-align: left;
      }
    }
  }
  // 分页
  .demo-pagination-block {
    padding: 9px 20px;
  }
}
</style>

二、文件上传并下载文件效果:
在这里插入图片描述

表格中附件的上传并下载

代码: (这里受到这篇文章的启发:HTML点击按钮button跳转页面的几种实现方法)

<!-- 文件的上传及显示 -->
<template>
  <!-- 演示地址 -->
  <div class="dem-add">
    <!-- Search start -->
    <div class="dem-title">
      <p>演示地址</p>
      <el-input
        class="query-input"
        v-model="tableForm.demoDevice"
        placeholder="搜索"
        @keyup.enter="handleQueryName"
      >
        <template #prefix>
          <el-icon class="el-input__icon"><search /></el-icon>
        </template>
      </el-input>
      <el-button type="primary" :icon="Plus" circle @click="handleAdd" />
    </div>
    <!-- Search end -->
    <!-- Table start -->
    <div class="bs-page-table">
      <el-table :data="tableData" ref="multipleTableRef">
        <el-table-column prop="sort" label="排序" width="60" />
        <el-table-column prop="demoDevice" label="演示端" width="150" />
        <el-table-column prop="address" label="地址" width="180" />
        <el-table-column prop="description" label="特殊说明" width="180" />
        <el-table-column prop="fileIds" label="附加" width="100">
          <template #default="scope">
            <a
              :href="`http://192.168.1.214:5050${scope.row.files[0].filePath}`"
              style="color: blue; text-decoration: none"
              target="_blank"
            >
              <el-button
                circle
                size="default"
                type="default"
                :icon="FolderChecked"
              ></el-button>
            </a>
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="100">
          <template #default="scope">
            <el-button
              type="danger"
              @click="handleRowDel(scope.$index)"
              :icon="Delete"
              circle
            />
          </template>
        </el-table-column>
      </el-table>
      <el-dialog v-model="dialogFormVisible" title="新增" width="500">
        <el-form :model="tableForm">
          <el-form-item label="排序" :label-width="80">
            <el-input v-model="tableForm.sort" autocomplete="off" />
          </el-form-item>
          <el-form-item label="演示端" :label-width="80">
            <el-input v-model="tableForm.demoDevice" autocomplete="off" />
          </el-form-item>
          <el-form-item label="地址" :label-width="80">
            <el-input v-model="tableForm.address" autocomplete="off" />
          </el-form-item>
          <el-form-item label="特殊说明" :label-width="80">
            <el-input v-model="tableForm.description" autocomplete="off" />
          </el-form-item>
          <el-form-item label="附加" :label-width="80">
            <el-upload
              multiple
              class="upload-demo"
              action=""
              :http-request="uploadFile"
              list-type="picture"
            >
              <el-button type="primary">上传文件</el-button>
            </el-upload>
          </el-form-item>
        </el-form>
        <template #footer>
          <div class="dialog-footer">
            <el-button @click="dialogFormVisible = false"> 取消 </el-button>
            <el-button type="primary" @click="dialogConfirm"> 确认 </el-button>
          </div>
        </template>
      </el-dialog>
    </div>
    <!-- Table end -->
  </div>
</template>

<script setup lang="ts">
import { Plus } from "@element-plus/icons-vue";
import { ref, onMounted, toRaw } from "vue";
import axios from "axios";
import { useRouter } from "vue-router";
import { Search } from "@element-plus/icons-vue";
import { Delete } from "@element-plus/icons-vue";
import { FolderChecked } from "@element-plus/icons-vue";

const router = useRouter();
console.log(router.currentRoute.value.path); //当前路由路径
sessionStorage.setItem("path", router.currentRoute.value.path);
// 演示地址
// 定义表格
const tableData = ref<any>([]);
// 定义弹窗表单
let tableForm = ref({
  sort: "",
  demoDevice: "",
  address: "",
  description: "",
  fileIds: <any>[],
  file: "",
});
// 默认对话框关闭状态
const dialogFormVisible = ref(false);
// 调用接口数据在表单显示
const port = async () => {
  await axios
    .post("http://192.168.1.214:5050/api/Project/DemoGetTable", {
      pageIndex: 1,
      pageSize: 100,
      projectId: "1",
    })
    .then((response) => {
      // 将找到的数据返回给表单显示
      tableData.value = response.data.data.list;
      console.log(tableData.value);
    })
    .catch((error) => {
      console.error(error);
    });
};
// 挂载
onMounted(() => {
  port();
});
// 搜索(通过name值查找)
const handleQueryName = () => {
  console.log("搜索");
};
// 新增
const handleAdd = async () => {
  // 打开新增对话框
  dialogFormVisible.value = true;
  // 设置空的绑定对象
  tableForm.value = {
    demoDevice: "",
    address: "",
    description: "",
    sort: "",
    fileIds: [],
    file: "",
  };
};
// 上传文件
const uploadFile = async (val: any) => {
  tableForm.value.file = val.file;
  // 数据交互
  let formdata = new FormData();
  formdata.append("File", tableForm.value.file);
  axios
    // 上传文件接口
    .post("http://192.168.1.214:5050/api/File/UploadFile", formdata, {
      headers: { "Content-Type": "multipart/form-data" },
    })
    .then((res) => {
      // 将文件id值传给tableForm的属性fileIds
      tableForm.value.fileIds.push(res.data.data.id);
      const newobj = Object.assign({ projectId: "1" }, toRaw(tableForm.value));
      axios
        // 添加演示地址接口
        .post("http://192.168.1.214:5050/api/Project/DemoAdd", newobj);
    });
};
// 删除
const handleRowDel = async (index: any) => {
  // 找到要删除的接口中对应的对象
  await axios.post("http://192.168.1.214:5050/api/Project/DemoDel", {
    // 获取到当前索引index下的id值,toRaw()方法获取原始对象
    id: toRaw(tableData.value[index]).id,
  });
  // 从index位置开始,删除一行即可
  tableData.value.splice(index, 1);
};
// 确认表单弹窗
const dialogConfirm = () => {
  dialogFormVisible.value = false;
  port();
};
</script>

<style scoped lang="scss">
// 演示地址
.dem-add {
  width: 800px;
  margin: 20px 50px;
  background-color: rgba(255, 255, 255, 0.333);
  box-shadow: 0 8px 16px #0005;
  border-radius: 16px;
  overflow: hidden;
  // 标签
  .dem-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: rgba(207, 204, 204, 0.267);
    padding: 0 20px;
    p {
      float: left;
      width: 150px;
      color: #000;
    }
    // 搜索
    ::v-deep .el-input__wrapper {
      border-radius: 100px;
    }
    .query-input {
      width: 240px;
      height: 35px;
      margin: 10px auto;
      margin-left: 330px;
      background-color: transparent;
      transition: 0.2s;
    }
    ::v-deep .el-input__wrapper:hover {
      background-color: #fff8;
      box-shadow: 0 5px 40px #0002;
    }
    // 增加按钮
    .el-button {
      float: left;
      margin-top: 3px;
      margin-left: 10px;
    }
  }
  // 表格
  .bs-page-table {
    .el-table {
      width: 100%;
      border: 1px solid rgb(219, 219, 219);
      padding: 10px;
      .el-table-column {
        border-collapse: collapse;
        text-align: left;
      }
    }
  }
  // 分页
  .demo-pagination-block {
    padding: 9px 20px;
  }
}
</style>

#c,终于解决了,回家种地~

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1795851.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

手写节流throttle

节流throttle 应用场景 滚动事件监听scroll&#xff1a;例如监听页面滚动到底部加载更多数据时&#xff0c;使用节流技术减少检查滚动位置的频率&#xff0c;提高性能。鼠标移动事件mousemove&#xff1a;例如实现一个拖拽功能&#xff0c;使用节流技术减少鼠标移动事件的处理…

PHPStudy(xp 小皮)V8.1.1 通过cmd进入MySQL命令行模式

PHPStudy是一个PHP开发环境集成包&#xff0c;可用在本地电脑或者服务器上&#xff0c;该程序包集成最新的PHP/MySql/Apache/Nginx/Redis/FTP/Composer&#xff0c;一次性安装&#xff0c;无须配置即可使用。MySQL MySQL是一个关系型数据库管理系统&#xff0c;由瑞典 MySQL A…

MongoDB环境搭建

一.下载安装包 Download MongoDB Community Server | MongoDB 二、双击下载完成后的安装包开始安装&#xff0c;除了以下两个部分需要注意操作&#xff0c;其他直接next就行 三.可视化界面安装 下载MongoDB-compass&#xff0c;地址如下 MongoDB Compass Download (GUI) | M…

使用LeanCloud平台的即时通讯

LeanCloud 是领先的 Serverless 云服务&#xff0c;为产品开发提供强有力的后端支持&#xff0c;旨在帮助开发者降低研发、运营维护等阶段投入的精力和成本。 LeanCloud 整合了各项服务&#xff0c;让开发者能够聚焦在核心业务上&#xff0c;为客户创造更多价值。 *即时通讯 …

15、matlab绘图汇总(图例、标题、坐标轴、线条格式、颜色和散点格式设置)

1、plot()函数默认格式画图 代码&#xff1a; x0:0.1:20;%绘图默认格式 ysin(x); plot(x,y) 2、X轴和Y轴显示范围/axis()函数 代码&#xff1a; x0:0.1:20;%绘图默认格式 ysin(x); plot(x,y) axis([0 21 -1.1 1.1])%设置范围 3、网格显示/grid on函数 代码&#xff1a; …

设备上CCD功能增加(从接线到程序)

今天终于完成了一个上面交给我的一个小项目&#xff0c;给设备增加一个CCD拍照功能&#xff0c;首先先说明一下本次使用基恩士的CCD相机&#xff0c;控制器&#xff0c;还有软件&#xff08;三菱程序与基恩士程序&#xff09;。如果对你有帮助&#xff0c;欢迎评论收藏&#xf…

VMware Workstation中WinXP联网问题

我一直以为我的虚拟机上的XP没有联网 因为 蒙了半天&#xff0c;发现是因为这个网址打不开&#xff0c;不是没有网 太傻了 不如在cmd命令行中通过ping baidu.com来判断是否联网

Dubbo 自定义 Filter 编码实例

Dubbo的Filter机制为我们做应用的扩展设计提供了很多可能性&#xff0c;这里的Filter也是“责任链”机制的一种实现场景&#xff0c;作为Java码农&#xff0c;我们也经常接触到很多责任链的实现场景&#xff0c;如Tomcat进入Servlet前的filter&#xff0c;如Spring Aop代理的链…

语言模型解构——Tokenizer

1. 认识Tokenizer 1.1 为什么要有tokenizer&#xff1f; 计算机是无法理解人类语言的&#xff0c;它只会进行0和1的二进制计算。但是呢&#xff0c;大语言模型就是通过二进制计算&#xff0c;让你感觉计算机理解了人类语言。 举个例子&#xff1a;单1&#xff0c;双2&#x…

龙迅LT8712X TYPE-C或者DP转HDMI加VGA输出,内置MCU,只是IIS以及4K60HZ分辨率

龙迅LT8712X描述&#xff1a; LT8712X是一种高性能的Type-C/DP1.2到HDMI2.0和VGA转换器&#xff0c;设计用于将USB Type-C源或DP1.2源连接到HDMI2.0和VGA接收器。LT8712X集成了一个DP1.2兼容的接收器&#xff0c;一个HDMI2.0兼容的发射机和一个高速三角机窝视频DAC。此外&…

【论文速读】LM的文本生成方法,Top-p,温度,《The Curious Case of Neural Text Degeneration》

论文链接&#xff1a;https://arxiv.org/abs/1904.09751 https://ar5iv.labs.arxiv.org/html/1904.09751 这篇文章&#xff0c;描述的是语言模型的文本生成的核采样的方法&#xff0c;就是现在熟知的top-p 大概看看&#xff0c;还有几个地方比较有趣&#xff0c;值得记录一下。…

kotlin1.8.10问题导致gson报错TypeToken type argument must not contain a type variable

书接上回&#xff0c;https://blog.csdn.net/jzlhll123/article/details/139302991。 之前我发现gson报错后&#xff1a; gson在2.11.0给我的kotlin项目代码报错了。 IllegalArgumentException: TypeToken type argument must not contain a type variable 上次解释原因是因为&…

WALT算法简介

WALT(Windows-Assist Load Tracing)算法是由Qcom开发&#xff0c; 通过把时间划分为窗口&#xff0c;对 task运行时间和CPU负载进行跟踪计算的方法。为任务调度、迁移、负载均衡及CPU调频 提供输入。 WALT相对PELT算法&#xff0c;更能及时反映负载变化&#xff0c; 更适用于…

PasteCode系列系统说明

定义 PasteCode系列是指项目是基于PasteTemplate构建的五层以上项目&#xff0c;包括不仅限于 Domain EntityFrameworkCore Application.Contracts Application HttpApi.Host 熟悉ABP vNext就很好理解了&#xff0c;因为PasteTemplate就是基于ABP的框架精简而来&#xff01;在…

CVE-2022-4230

CVE-2022-4230 漏洞介绍 WP Statistics WordPress 插件13.2.9之前的版本不会转义参数&#xff0c;这可能允许经过身份验证的用户执行 SQL 注入攻击。默认情况下&#xff0c;具有管理选项功能 (admin) 的用户可以使用受影响的功能&#xff0c;但是该插件有一个设置允许低权限用…

绘画参数配置及使用

绘画参数配置及使用 路径&#xff1a;站点后台-功能-AI绘画 进入参数配置 接口选择&#xff1a;多种接口自主选择&#xff08;需自己准备key&#xff09;&#xff0c;对应接口的key对话和绘画通用 存储空间&#xff1a; 位置在超管后台-存储空间 自主选择存储&#xff08;需…

Python画图(多图展示在一个平面)

天行健&#xff0c;君子以自强不息&#xff1b;地势坤&#xff0c;君子以厚德载物。 每个人都有惰性&#xff0c;但不断学习是好好生活的根本&#xff0c;共勉&#xff01; 文章均为学习整理笔记&#xff0c;分享记录为主&#xff0c;如有错误请指正&#xff0c;共同学习进步。…

Go实战 | 使用Go-Fiber采用分层架构搭建一个简单的Web服务

前言 &#x1f4e2;博客主页&#xff1a;程序源⠀-CSDN博客 &#x1f4e2;欢迎点赞&#x1f44d;收藏⭐留言&#x1f4dd;如有错误敬请指正&#xff01; 一、环境准备、示例介绍 Go语言安装&#xff0c;GoLand编辑器 这个示例实现了一个简单的待办事项&#xff08;todo&#xf…

应用解析 | 面向智能网联汽车的产教融合解决方案

背景介绍 随着科技的飞速发展&#xff0c;智能网联汽车已成为汽车产业的新宠&#xff0c;引领着未来出行的潮流。然而&#xff0c;行业的高速发展也带来了对高素质技术技能人才的迫切需求。为满足这一需求&#xff0c;推动教育链、人才链与产业链、创新链的深度融合&#xff0…

【Java】static 修饰变量

static 一种java内置关键字&#xff0c;静态关键字&#xff0c;可以修饰成员变量、成员方法。 static 成员变量 1.static 成员变量2.类变量图解3.类变量的访问4.类变量的内存原理5.类变量的应用 1.static 成员变量 成员变量按照有无static修饰&#xff0c;可以分为 类变量…