All checks were successful
构建并部署前端到测试环境 / build-and-deploy (push) Successful in 7m52s
Constraint: 后端订单套餐作废接口使用 /api/admin/order-package-invalidate-tasks,上传 purpose 只能使用 attachment。 Rejected: 继续提交逗号拼接凭证字符串 | 新提交路径必须使用 string[],历史字符串只做读取归一化。 Confidence: high Scope-risk: broad Directive: 新增订单套餐作废权限时需同时配置菜单 URL 与 order_package_invalidate_task:create/detail 按钮权限。 Tested: bun run build;development 真实后端联调上传、创建、列表、详情通过;复机接口未触发。 Not-tested: 未逐一手工覆盖所有历史凭证数据、全部角色权限组合和所有文件扩展名预览
58 lines
1.3 KiB
TypeScript
58 lines
1.3 KiB
TypeScript
/**
|
|
* 表格选择管理 Composable
|
|
*/
|
|
|
|
import { computed, shallowRef } from 'vue'
|
|
|
|
export function useTableSelection<T = any>() {
|
|
// 选中的行
|
|
const selectedRows = shallowRef<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 = selectedRows.value.filter((_, itemIndex) => itemIndex !== index)
|
|
} else {
|
|
selectedRows.value = [...selectedRows.value, row]
|
|
}
|
|
}
|
|
|
|
return {
|
|
selectedRows,
|
|
selectedIds,
|
|
selectedCount,
|
|
hasSelected,
|
|
handleSelectionChange,
|
|
clearSelection,
|
|
isSelected,
|
|
toggleSelection
|
|
}
|
|
}
|