前言:哈嘍,大家好,今天給大家分享一篇文章!并提供具體代碼幫助大家深入理解,徹底掌握!創作不易,如果能幫助到大家或者給大家一些靈感和啟發,歡迎收藏+關注哦 ??
目錄
- DeepSeek 助力 Vue3 開發:打造絲滑的表格(Table)之添加行拖拽排序功能示例9,TableView16_09 嵌套表格拖拽排序
- ??前言
- ??頁面效果
- ??組件代碼
- ??代碼測試
- ??測試代碼正常跑通,附其他基本代碼
- ??編寫路由 src\router\index.js
- ??編寫展示入口 src\App.vue
- ??頁面效果
??????????????????????????????????????????????????????·正文開始
??·???????????????????????????????? ??0??1??2??3??4??5??6??7??8??9??????*??#??
DeepSeek 助力 Vue3 開發:打造絲滑的表格(Table)之添加行拖拽排序功能示例9,TableView16_09 嵌套表格拖拽排序
??前言
Transformer 架構自 2017 年被提出以來,憑借其在自然語言處理任務中的卓越表現,成為了眾多先進模型的底層基石。DeepSeek 也深深扎根于 Transformer 架構,并在其基礎上進行了大膽創新和優化,形成了獨具特色的模型架構。
??頁面效果
??組件代碼
<!-- TableView16_09.vue 嵌套表格拖拽示例 -->
<template><div class="drag-demo"><h2>09. 嵌套表格拖拽排序</h2><Table:data="parentTasks":columns="columns"draggable@update:data="handleParentUpdate"row-key="id"borderstripeexpandable: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"borderclass="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
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