当前位置: 首页 > news >正文

zdppy+vue3+antd 实现表格单元格编辑功能

初步实现

<template><a-button class="editable-add-btn" style="margin-bottom: 8px" @click="handleAdd">Add</a-button><a-table bordered :data-source="dataSource" :columns="columns"><template #bodyCell="{ column, text, record }"><!--make the name column editable--><template v-if="column.dataIndex === 'name'"><div class="editable-cell"><div v-if="editableData[record.key]" class="editable-cell-input-wrapper"><a-input v-model:value="editableData[record.key].name" @pressEnter="save(record.key)"/><check-outlined class="editable-cell-icon-check" @click="save(record.key)"/></div><div v-else class="editable-cell-text-wrapper">{{ text || ' ' }}<edit-outlined class="editable-cell-icon" @click="edit(record.key)"/></div></div></template><!--Action column--><template v-else-if="column.dataIndex === 'operation'"><a-popconfirmv-if="dataSource.length"title="Sure to delete?"@confirm="onDelete(record.key)"><a>Delete</a></a-popconfirm></template></template></a-table>
</template>
<script setup>
import {computed, reactive, ref} from 'vue';
import {CheckOutlined, EditOutlined} from "@ant-design/icons-vue";
import {cloneDeep} from 'lodash-es';const columns = [{title: 'name',dataIndex: 'name',width: '30%',},{title: 'age',dataIndex: 'age',},{title: 'address',dataIndex: 'address',},{title: 'operation',dataIndex: 'operation',},
];
const dataSource = ref([{key: '0',name: 'Edward King 0',age: 32,address: 'London, Park Lane no. 0',},{key: '1',name: 'Edward King 1',age: 32,address: 'London, Park Lane no. 1',},
]);
const count = computed(() => dataSource.value.length + 1);
const editableData = reactive({});// make the row editable
const edit = key => {editableData[key] = cloneDeep(dataSource.value.filter(item => key === item.key)[0]);
};// save the edit result
const save = key => {Object.assign(dataSource.value.filter(item => key === item.key)[0], editableData[key]);delete editableData[key];
};// delete the row
const onDelete = key => {dataSource.value = dataSource.value.filter(item => item.key !== key);
};// add a row to data source
const handleAdd = () => {const newData = {key: `${count.value}`,name: `Edward King ${count.value}`,age: 32,address: `London, Park Lane no. ${count.value}`,};dataSource.value.push(newData);
};
</script>
<style lang="less" scoped>
.editable-cell {position: relative;.editable-cell-input-wrapper,.editable-cell-text-wrapper {padding-right: 24px;}.editable-cell-text-wrapper {padding: 5px 24px 5px 5px;}.editable-cell-icon,.editable-cell-icon-check {position: absolute;right: 0;width: 20px;cursor: pointer;}.editable-cell-icon {margin-top: 4px;display: none;}.editable-cell-icon-check {line-height: 28px;}.editable-cell-icon:hover,.editable-cell-icon-check:hover {color: #108ee9;}.editable-add-btn {margin-bottom: 8px;}
}.editable-cell:hover .editable-cell-icon {display: inline-block;
}
</style>

渲染后端接口数据

<script setup>
import {computed, onMounted, reactive, ref} from 'vue';
import {CheckOutlined, EditOutlined} from "@ant-design/icons-vue";
import {cloneDeep} from 'lodash-es';
import axios from "axios";const columns = [{name: '姓名',dataIndex: 'name',key: 'name',},{name: '性别',dataIndex: 'gender',key: 'gender',},{title: '年龄',dataIndex: 'age',key: 'age',},{title: '电话',dataIndex: 'phone',key: 'phone',},{title: '邮箱',key: 'email',dataIndex: 'email',},{title: '薪资',key: 'salary',dataIndex: 'salary',},{title: '操作',key: 'action',},
];const dataSource = ref([]);onMounted(() => {axios.get("http://127.0.0.1:8889/zdppy_amuserdetail").then((response) => {console.log("response.data", response.data);dataSource.value = response.data.data.results;})
})const count = computed(() => dataSource.value.length + 1);
const editableData = reactive({});// make the row editable
const edit = id => {console.log("edit", editableData, id)editableData[id] = cloneDeep(dataSource.value.filter(item => id === item.id)[0]);
};// save the edit result
const save = id => {Object.assign(dataSource.value.filter(item => id === item.id)[0], editableData[id]);delete editableData[id];
};// add a row to data source
const handleAdd = () => {const newData = {key: `${count.value}`,name: `Edward King ${count.value}`,age: 32,address: `London, Park Lane no. ${count.value}`,};dataSource.value.push(newData);
};
</script><template><a-button class="editable-add-btn" style="margin-bottom: 8px" @click="handleAdd">Add</a-button><a-tablebordered:data-source="dataSource":columns="columns":row-key="record => record.id"><template #headerCell="{ column }"><template v-if="column.key === 'name'"><span>{{ column.name }}</span></template><template v-else-if="column.key === 'gender'"><span>{{ column.name }}</span></template></template><template #bodyCell="{ column, text, record }"><!--make the name column editable--><template v-if="column.dataIndex === 'name'"><div class="editable-cell"><div v-if="editableData[record.id]" class="editable-cell-input-wrapper"><a-input v-model:value="editableData[record.id].name" @pressEnter="save(record.id)"/><check-outlined class="editable-cell-icon-check" @click="save(record.id)"/></div><div v-else class="editable-cell-text-wrapper">{{ text || ' ' }}<edit-outlined class="editable-cell-icon" @click="edit(record.id)"/></div></div></template><!--Action column--><template v-else-if="column.key === 'action'"><a-space wrap><a-button size="small" type="primary" block>编辑</a-button><a-button size="small" block>详情</a-button><a-button size="small" danger block>删除</a-button></a-space></template></template></a-table>
</template>
<style lang="less" scoped>
.editable-cell {position: relative;.editable-cell-input-wrapper,.editable-cell-text-wrapper {padding-right: 24px;}.editable-cell-text-wrapper {padding: 5px 24px 5px 5px;}.editable-cell-icon,.editable-cell-icon-check {position: absolute;right: 0;width: 20px;cursor: pointer;}.editable-cell-icon {margin-top: 4px;display: none;}.editable-cell-icon-check {line-height: 28px;}.editable-cell-icon:hover,.editable-cell-icon-check:hover {color: #108ee9;}.editable-add-btn {margin-bottom: 8px;}
}.editable-cell:hover .editable-cell-icon {display: inline-block;
}
</style>

将修改的数据保存到数据库

<script setup>
import {computed, onMounted, reactive, ref} from 'vue';
import {CheckOutlined, EditOutlined} from "@ant-design/icons-vue";
import {cloneDeep} from 'lodash-es';
import axios from "axios";const columns = [{name: '姓名',dataIndex: 'name',key: 'name',},{name: '性别',dataIndex: 'gender',key: 'gender',},{title: '年龄',dataIndex: 'age',key: 'age',},{title: '电话',dataIndex: 'phone',key: 'phone',},{title: '邮箱',key: 'email',dataIndex: 'email',},{title: '薪资',key: 'salary',dataIndex: 'salary',},{title: '操作',key: 'action',},
];const dataSource = ref([]);onMounted(() => {axios.get("http://127.0.0.1:8889/zdppy_amuserdetail").then((response) => {console.log("response.data", response.data);dataSource.value = response.data.data.results;})
})const count = computed(() => dataSource.value.length + 1);
const editableData = reactive({});// make the row editable
const edit = id => {console.log("edit", editableData, id)editableData[id] = cloneDeep(dataSource.value.filter(item => id === item.id)[0]);
};// save the edit result
const save = id => {const data = editableData[id]console.log("updated data", data)// backend updateaxios({method: "put",url: "http://127.0.0.1:8889/zdppy_amuserdetail/" + id,contentType: "application/json",data,}).then(resp => {console.log("update", resp.data);})// frontedn updateObject.assign(dataSource.value.filter(item => id === item.id)[0], editableData[id]);delete editableData[id];
};// add a row to data source
const handleAdd = () => {const newData = {key: `${count.value}`,name: `Edward King ${count.value}`,age: 32,address: `London, Park Lane no. ${count.value}`,};dataSource.value.push(newData);
};
</script><template><a-button class="editable-add-btn" style="margin-bottom: 8px" @click="handleAdd">Add</a-button><a-tablebordered:data-source="dataSource":columns="columns":row-key="record => record.id"><template #headerCell="{ column }"><template v-if="column.key === 'name'"><span>{{ column.name }}</span></template><template v-else-if="column.key === 'gender'"><span>{{ column.name }}</span></template></template><template #bodyCell="{ column, text, record }"><!--make the name column editable--><template v-if="column.dataIndex === 'name'"><div class="editable-cell"><div v-if="editableData[record.id]" class="editable-cell-input-wrapper"><a-input v-model:value="editableData[record.id].name" @pressEnter="save(record.id)"/><check-outlined class="editable-cell-icon-check" @click="save(record.id)"/></div><div v-else class="editable-cell-text-wrapper">{{ text || ' ' }}<edit-outlined class="editable-cell-icon" @click="edit(record.id)"/></div></div></template><!--Action column--><template v-else-if="column.key === 'action'"><a-space wrap><a-button size="small" type="primary" block>编辑</a-button><a-button size="small" block>详情</a-button><a-button size="small" danger block>删除</a-button></a-space></template></template></a-table>
</template>
<style lang="less" scoped>
.editable-cell {position: relative;.editable-cell-input-wrapper,.editable-cell-text-wrapper {padding-right: 24px;}.editable-cell-text-wrapper {padding: 5px 24px 5px 5px;}.editable-cell-icon,.editable-cell-icon-check {position: absolute;right: 0;width: 20px;cursor: pointer;}.editable-cell-icon {margin-top: 4px;display: none;}.editable-cell-icon-check {line-height: 28px;}.editable-cell-icon:hover,.editable-cell-icon-check:hover {color: #108ee9;}.editable-add-btn {margin-bottom: 8px;}
}.editable-cell:hover .editable-cell-icon {display: inline-block;
}
</style>

相关文章:

zdppy+vue3+antd 实现表格单元格编辑功能

初步实现 <template><a-button class"editable-add-btn" style"margin-bottom: 8px" click"handleAdd">Add</a-button><a-table bordered :data-source"dataSource" :columns"columns"><templa…...

elasticsearch索引怎么设计

Primary Shard&#xff08;主分片&#xff09; Primary Shard&#xff08;主分片&#xff09;是索引数据存储的基本单位&#xff0c;承担着数据写入和查询的职责。以下是关于Primary Shard的一些关键点&#xff1a; 1. 数据分布&#xff1a;每个索引在创建时会被分成多个主分…...

React 中 useState 和 useReducer 的联系和区别

文章目录 使用场景使用 useState使用 useReducer 联系区别用法状态更新逻辑适用场景可读性和可维护性 使用场景 使用 useState 状态逻辑简单。只涉及少量的状态更新。需要快速和简单的状态管理。 使用 useReducer 状态逻辑复杂。涉及多个子状态或多种状态更新逻辑。需要更好…...

Linux 定时任务详解:全面掌握 cron 和 at 命令

Linux 定时任务详解&#xff1a;全面掌握 cron 和 at 命令 Linux 系统中定时任务的管理对于运维和开发人员来说都是至关重要的。通过定时任务&#xff0c;可以在特定时间自动执行脚本或命令&#xff0c;提高系统自动化程度。本文将详细介绍 Linux 中常用的定时任务管理工具 cr…...

力扣考研经典题 反转链表

核心思想 头插法&#xff1a; 不断的将cur指针所指向的节点放到头节点之前&#xff0c;然后头节点指向cur节点&#xff0c;因为最后返回的是head.next 。 解题思路 1.如果头节点是空的&#xff0c;或者是只有一个节点&#xff0c;只需要返回head节点即可。 if (head null …...

opencv 设置超时时间

经常爬视频数据&#xff0c;然后用opencv做成图片 因此设置超时时间很重要 cap.set(cv2.CAP_PROP_FPS, timeout_ms) for idx, row in data.iterrows(): if idx < 400: continue try: # 打开视频文件 timeout_ms 5000 cap cv2.VideoCapture(row[PLAY_URL]) cap.set(cv2.C…...

2024年7月6日随笔

期末考试全部结束了&#xff0c;这个月是真累啊&#xff0c;一堆事&#xff0c;好在都熬过来了&#xff0c;上次参加的那个码题杯自己居然进国赛了&#xff0c;我看了一下职业赛道和本科赛道的题&#xff0c;本科赛道的感觉要难上不少&#xff0c;比赛时间是一周后&#xff0c;…...

Ubuntu 打开或关闭界面

设置开机默认关闭图形界面 1. 设置系统默认启动到多用户目标&#xff08;命令行界面&#xff09;&#xff1a; o 使用以下命令将系统默认启动目标设置为多用户目标&#xff08;这会关闭图形界面&#xff09;&#xff1a; sudo systemctl set-default multi-use…...

使用京东云主机搭建幻兽帕鲁游戏联机服务器全流程,0基础教程

使用京东云服务器搭建幻兽帕鲁Palworld游戏联机服务器教程&#xff0c;非常简单&#xff0c;京东云推出幻兽帕鲁镜像系统&#xff0c;镜像直接选择幻兽帕鲁镜像即可一键自动部署&#xff0c;不需要手动操作&#xff0c;真正的新手0基础部署幻兽帕鲁&#xff0c;阿腾云整理基于京…...

Python和MATLAB微机电健康推导算法和系统模拟优化设计

&#x1f3af;要点 &#x1f3af;惯性测量身体活动特征推导健康状态算法 | &#x1f3af;卷积网络算法学习惯性测量数据估计六自由度姿态 | &#x1f3af;全球导航卫星系统模拟&#xff0c;及惯性测量动态测斜仪算法、动态倾斜算法、融合算法 | &#x1f3af;微机电系统加速度…...

IT之家最新科技热点 | 小米 AI 研究院开创多模态通用模型

人不走空 &#x1f308;个人主页&#xff1a;人不走空 &#x1f496;系列专栏&#xff1a;算法专题 ⏰诗词歌赋&#xff1a;斯是陋室&#xff0c;惟吾德馨 目录 &#x1f308;个人主页&#xff1a;人不走空 &#x1f496;系列专栏&#xff1a;算法专题 ⏰诗词歌…...

黑色矩形块检测数据集VOC+YOLO格式2000张1类别

数据集格式&#xff1a;Pascal VOC格式YOLO格式(不包含分割路径的txt文件&#xff0c;仅仅包含jpg图片以及对应的VOC格式xml文件和yolo格式txt文件) 图片数量(jpg文件个数)&#xff1a;2000 标注数量(xml文件个数)&#xff1a;2000 标注数量(txt文件个数)&#xff1a;2000 标注…...

Linux内存管理--系列文章柒——硬件架构

一、引子 之前文章讲解的是系统的虚拟内存&#xff0c;本章讲述这些硬件的架构和系统怎样统一管理这些硬件的。 二、物理内存模型 物理内存模型描述了计算机系统中的物理内存如何由操作系统组织和管理。它定义了物理内存如何划分为单元&#xff0c;如何寻址这些单元以及如何…...

QQ音乐Android一面凉经

最近面试了不少公司, 近期告一段落, 整理一下各家的面试问题, 打算陆续发布出来, 供有缘人参考。今天给大家带来的是QQ音乐Android一面凉经。 面试岗位: QQ音乐Android开发工程师面试时长: 50min(提问40min 反问10min)代码考核: 无 面试问题(40min) 自我介绍 工作经历, 重点…...

浅谈进程隐藏技术

前言 在之前几篇文章已经学习了解了几种钩取的方法 浅谈调试模式钩取浅谈热补丁浅谈内联钩取原理与实现导入地址表钩取技术 这篇文章就利用钩取方式完成进程隐藏的效果。 进程遍历方法 在实现进程隐藏时&#xff0c;首先需要明确遍历进程的方法。 CreateToolhelp32Snapsh…...

【C++】Google Test(gtest)单元测试

文章目录 Google Test&#xff08;gtest&#xff09;单元测试使用示例更多用法测试夹具 Google Test&#xff08;gtest&#xff09;单元测试 单元测试是一种软件测试方法&#xff0c;它旨在将应用程序的各个部分&#xff08;通常是方法或函数&#xff09;分离出来并独立测试&a…...

水箱高低水位浮球液位开关

水箱高低水位浮球液位开关概述 水箱高低水位浮球液位开关是一种用于监测和控制水箱中液位的自动化设备&#xff0c;它能够在水箱液位达到预设的高低限制时&#xff0c;输出开关信号&#xff0c;以控制水泵或电磁阀的开闭&#xff0c;从而维持水箱液位在一个安全的范围内。这类设…...

Autoware内容学习与初步探索(一)

0. 简介 之前作者主要是基于ROS2&#xff0c;CyberRT还有AutoSar等中间件完成搭建的。有一说一&#xff0c;这种从头开发当然有从头开发的好处&#xff0c;但是如果说绝大多数的公司还是基于现成的Apollo以及Autoware来完成的。这些现成的框架中也有很多非常好的方法。目前作者…...

【手写数据库内核组件】01 解析树的结构,不同类型的数据结构组多层的链表树,抽象类型统一引用格式

不同类型的链表 ​专栏内容&#xff1a; postgresql使用入门基础手写数据库toadb并发编程 个人主页&#xff1a;我的主页 管理社区&#xff1a;开源数据库 座右铭&#xff1a;天行健&#xff0c;君子以自强不息&#xff1b;地势坤&#xff0c;君子以厚德载物. 文章目录 不同类型…...

Pandas 进阶 —— 数据转换、聚合与可视化

引言 在数据分析的旅程中&#xff0c;Pandas 库提供了从数据转换到聚合再到可视化的全面解决方案。上篇我们掌握了数据的导入和清洗&#xff0c;本篇我们将探索如何通过 Pandas 对数据进行更高级的处理&#xff0c;包括数据转换、聚合分析以及可视化展示。 数据转换 数据转换…...

解决99%开发者痛点:Segmentio完全排坑指南(2025最新版)

解决99%开发者痛点&#xff1a;Segmentio完全排坑指南&#xff08;2025最新版&#xff09; 【免费下载链接】Segmentio Animated top/bottom segmented control written in Swift. 项目地址: https://gitcode.com/gh_mirrors/se/Segmentio &#x1f680; 终极iOS分段控件…...

PM2008 I2C嵌入式驱动设计与高可靠性通信实践

1. PM2008 I2C 嵌入式驱动库技术解析1.1 项目定位与工程价值PM2008 是 Cubic Sensor & Instrument Co., Ltd. 推出的一款高精度、低功耗激光散射式颗粒物&#xff08;PM&#xff09;传感器&#xff0c;专为室内空气质量监测、便携式检测设备及智能环境终端设计。其核心优势…...

Unity编辑器脚本批量替换预制体Text组件字体方案

1. 为什么需要批量替换预制体中的字体&#xff1f; 在Unity项目开发中&#xff0c;我们经常会遇到需要统一修改UI字体的情况。比如项目从旧版本升级到Unity 2022后&#xff0c;原先使用的Arial字体被移除&#xff0c;Text组件也被标记为Legacy组件。这时候如果手动一个个修改预…...

Stable Yogi Leather-Dress-Collection开源模型实践:SD 1.5生态LoRA工程最佳范例

Stable Yogi Leather-Dress-Collection开源模型实践&#xff1a;SD 1.5生态LoRA工程最佳范例 你是不是也遇到过这样的问题&#xff1a;想用Stable Diffusion生成特定风格的动漫角色&#xff0c;比如穿着酷炫皮衣的2.5D人物&#xff0c;但要么生成的服装不对味&#xff0c;要么…...

OpenClaw核心内容总结

目录 一、OpenClaw 是什么 二、核心概念与架构 1. 基础核心机制 2. 架构与核心组件 三、安装与基础配置 1. 环境要求与安装 2. 初始化配置 四、进阶配置 1. 模型接入与切换 2. 接入飞书&#xff08;国内推荐&#xff09; 3. 安装技能&#xff08;Skills&#xff09; …...

从C到汇编:深入理解Linux系统调用的底层实现原理

从C到汇编&#xff1a;深入理解Linux系统调用的底层实现原理 当你在C语言中调用write()函数向屏幕输出文字时&#xff0c;背后究竟发生了什么&#xff1f;这个看似简单的操作&#xff0c;实际上经历了一场从用户态到内核态的复杂旅程。本文将带你穿越高级语言与机器指令的边界&…...

面向设计师的AI工具|NEURAL MASK幻镜本地部署+PS插件联动教程

面向设计师的AI工具&#xff5c;NEURAL MASK幻镜本地部署PS插件联动教程 对于设计师和视觉创作者来说&#xff0c;抠图是日常工作中最耗时、也最考验耐心的环节之一。无论是处理飞扬的发丝、透明的婚纱&#xff0c;还是复杂的背景边缘&#xff0c;传统工具往往需要反复调整&am…...

BGE-Large-Zh模型安全:对抗样本防御策略

BGE-Large-Zh模型安全&#xff1a;对抗样本防御策略 1. 引言 在人工智能技术快速发展的今天&#xff0c;语义向量模型已经成为搜索、推荐和知识检索等领域的核心组件。BGE-Large-Zh作为优秀的中文语义向量模型&#xff0c;在处理文本理解和语义匹配任务中表现出色。然而&…...

Tao-8k多轮对话效果展示:复杂任务规划与分解

Tao-8k多轮对话效果展示&#xff1a;复杂任务规划与分解 最近体验了不少大模型&#xff0c;发现一个挺有意思的现象&#xff1a;很多模型在单轮问答上表现不错&#xff0c;但一旦进入需要连续思考、层层递进的多轮对话&#xff0c;就容易“掉链子”。要么是记不住前面的对话&a…...

GLM-4-9B-Chat-1M显存优化指南:低成本部署方案

GLM-4-9B-Chat-1M显存优化指南&#xff1a;低成本部署方案 1. 引言 最近很多朋友在尝试部署GLM-4-9B-Chat-1M时遇到了显存不足的问题&#xff0c;特别是使用消费级显卡的用户。这个模型虽然参数只有90亿&#xff0c;但支持100万token的上下文长度&#xff0c;确实对显存要求比…...