DeepSeek 助力 Vue3 开发:打造丝滑的表格(Table)之添加行拖拽排序功能示例9,TableView16_09 嵌套表格拖拽排序

前言:哈喽,大家好,今天给大家分享一篇文章!并提供具体代码帮助大家深入理解,彻底掌握!创作不易,如果能帮助到大家或者给大家一些灵感和启发,欢迎收藏+关注哦 💕

共同探索软件研发!敬请关注【宝码香车】
关注描述

csdngif标识


📚📗📕📘📖🕮💡📝🗂️✍️🛠️💻🚀🎉🏗️🌐🖼️🔗📊👉🔖⚠️🌟🔐⬇️·正文开始⬇️·🎥😊🎓📩😺🌈🤝🤖📜📋🔍✅🧰❓📄📢📈 🙋0️⃣1️⃣2️⃣3️⃣4️⃣5️⃣6️⃣7️⃣8️⃣9️⃣🔟🆗*️⃣#️⃣

DeepSeek 助力 Vue3 开发:打造丝滑的表格(Table)之添加行拖拽排序功能示例9,TableView16_09 嵌套表格拖拽排序

📚前言

Transformer 架构自 2017 年被提出以来,凭借其在自然语言处理任务中的卓越表现,成为了众多先进模型的底层基石。DeepSeek 也深深扎根于 Transformer 架构,并在其基础上进行了大胆创新和优化,形成了独具特色的模型架构。

📚页面效果

DeepSeek 助力 Vue3 开发:打造丝滑的表格(Table)之添加行拖拽排序功能示例9,TableView16_09 嵌套表格拖拽排序

📘组件代码

<!-- TableView16_09.vue 嵌套表格拖拽示例 -->
<template>
  <div class="drag-demo">
    <h2>09. 嵌套表格拖拽排序</h2>
    
    <Table
      :data="parentTasks"
      :columns="columns"
      draggable
      @update:data="handleParentUpdate"
      row-key="id"
      border
      stripe
      expandable
      :expanded-keys="expandedKeys"
      @update:expandedKeys="handleExpandChange"
    >
      <template #cell-task="{ row }">
        <div class="parent-task">
          <span 
            class="expand-icon" 
            @click.stop="toggleExpand(row)"
          >
            {
  { isExpanded(row) ? '▼' : '▶' }}
          </span>
          {
  { row.task }}
        </div>
      </template>
      
      <template #expanded-row="{ row }">
        <div class="sub-table-container">
          <h4>子任务列表</h4>
          <Table
            :data="row.children"
            :columns="subColumns"
            draggable
            @update:data="(newData) => handleSubUpdate(row, newData)"
            row-key="id"
            border
            class="sub-table"
          />
        </div>
      </template>
    </Table>
  </div>
</template>

<script setup>
import {
      ref } from 'vue'
import Table from '@/components/Table/Table.vue'

const parentTasks = ref([
  {
     
    id: 1,
    task: '设计阶段',
    children: [
      {
      id: 11, task: '原型设计', owner: '张三' },
      {
      id: 12, task: 'UI设计', owner: '李四' },
    ]
  },
  {
     
    id: 2,
    task: '开发阶段',
    children: [
      {
      id: 21, task: '前端开发', owner: '王五' },
      {
      id: 22, task: '后端开发', owner: '赵六' },
    ]
  },
  {
     
    id: 3,
    task: '测试阶段',
    children: [
      {
      id: 31, task: '单元测试', owner: '钱七' },
      {
      id: 32, task: '集成测试', owner: '孙八' },
    ]
  }
])

const columns = [
  {
      title: '父任务', dataIndex: 'task', width: '200px' }
]

const subColumns = [
  {
      title: '子任务', dataIndex: 'task', width: '180px' },
  {
      title: '负责人', dataIndex: 'owner', width: '120px' }
]

const expandedKeys = ref([1]) // 默认展开第一个节点

const isExpanded = (row) => {
     
  return expandedKeys.value.includes(row.id)
}

const toggleExpand = (row) => {
     
  const index = expandedKeys.value.indexOf(row.id)
  if (index > -1) {
     
    expandedKeys.value.splice(index, 1)
  } else {
     
    expandedKeys.value.push(row.id)
  }
}

const handleExpandChange = (keys) => {
     
  expandedKeys.value = keys
}

const handleParentUpdate = (newData) => {
     
  parentTasks.value = newData
}

const handleSubUpdate = (parentRow, newSubData) => {
     
  const parentIndex = parentTasks.value.findIndex(p => p.id === parentRow.id)
  if (parentIndex > -1) {
     
    // 创建新数组以触发响应式更新
    const newParentTasks = [...parentTasks.value]
    newParentTasks[parentIndex] = {
     
      ...newParentTasks[parentIndex],
      children: newSubData
    }
    parentTasks.value = newParentTasks
  }
}
</script>

<style scoped>
.drag-demo {
     
  padding: 20px;
  max-width: 800px;
  margin: 0 auto;
}

.parent-task {
     
  display: flex;
  align-items: center;
}

.expand-icon {
     
  width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-right: 8px;
  cursor: pointer;
  user-select: none;
}

.sub-table-container {
     
  padding: 15px;
  background: #f8f8f8;
  border-radius: 4px;
}

.sub-table-container h4 {
     
  margin-top: 0;
  margin-bottom: 12px;
  color: #555;
  font-size: 14px;
}

.sub-table {
     
  margin-bottom: 0;
}
</style>

📚代码测试

运行正常

📚测试代码正常跑通,附其他基本代码

  • 添加路由
  • 页面展示入口

📘编写路由 src\router\index.js

\router\index.js

import {
    createRouter, createWebHistory } from 'vue-router'
import RightClickMenuView from '../views/RightClickMenuView.vue'
import RangePickerView from '../views/RangePickerView.vue'


const router = createRouter({
   
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
   
      path: '/',
      name: 'progress',
      component:  () => import('../views/ProgressView.vue'),
    },
    {
   
      path: '/tabs',
      name: 'tabs',
      // route level code-splitting
      // this generates a separate chunk (About.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      // 标签页(Tabs)
      component: () => import('../views/TabsView.vue'),
    },
    {
   
      path: '/accordion',
      name: 'accordion',
      // 折叠面板(Accordion)
      component: () => import('../views/AccordionView.vue'),
    },
    {
   
      path: '/timeline',
      name: 'timeline',
      // 时间线(Timeline)
      component: () => import('../views/TimelineView.vue'),
    },
    {
   
      path: '/backToTop',
      name: 'backToTop',
      component: () => import('../views/BackToTopView.vue')
    },
    {
   
      path: '/notification',
      name: 'notification',
      component: () => import('../views/NotificationView.vue')
    },
    {
   
      path: '/card',
      name: 'card',
      component: () => import('../views/CardView.vue')
    },
    {
   
      path
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

宝码香车

你的鼓励将是我创作的最大动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值