Initial commit: One Pipe System
完整的管理系统,包含账户管理、卡片管理、套餐管理、财务管理等功能模块。 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
57
src/composables/useTableSelection.ts
Normal file
57
src/composables/useTableSelection.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
/**
|
||||
* 表格选择管理 Composable
|
||||
*/
|
||||
|
||||
import { ref, computed } from 'vue'
|
||||
|
||||
export function useTableSelection<T = any>() {
|
||||
// 选中的行
|
||||
const selectedRows = ref<T[]>([])
|
||||
|
||||
// 选中的ID列表
|
||||
const selectedIds = computed(() => {
|
||||
return selectedRows.value.map((row: any) => row.id)
|
||||
})
|
||||
|
||||
// 选中的数量
|
||||
const selectedCount = computed(() => selectedRows.value.length)
|
||||
|
||||
// 是否有选中项
|
||||
const hasSelected = computed(() => selectedRows.value.length > 0)
|
||||
|
||||
// 处理选择变化
|
||||
const handleSelectionChange = (selection: T[]) => {
|
||||
selectedRows.value = selection
|
||||
}
|
||||
|
||||
// 清空选择
|
||||
const clearSelection = () => {
|
||||
selectedRows.value = []
|
||||
}
|
||||
|
||||
// 判断是否选中指定项
|
||||
const isSelected = (row: any) => {
|
||||
return selectedIds.value.includes(row.id)
|
||||
}
|
||||
|
||||
// 切换选中状态
|
||||
const toggleSelection = (row: T) => {
|
||||
const index = selectedRows.value.findIndex((item: any) => item.id === (row as any).id)
|
||||
if (index > -1) {
|
||||
selectedRows.value.splice(index, 1)
|
||||
} else {
|
||||
selectedRows.value.push(row)
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
selectedRows,
|
||||
selectedIds,
|
||||
selectedCount,
|
||||
hasSelected,
|
||||
handleSelectionChange,
|
||||
clearSelection,
|
||||
isSelected,
|
||||
toggleSelection
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user