version: v4.8.9

This commit is contained in:
XiaoDaiGua-Ray 2024-06-28 16:38:13 +08:00
parent 6975af2368
commit 8405cc5709
3 changed files with 47 additions and 8 deletions

View File

@ -1,5 +1,11 @@
# CHANGE LOG
## 4.8.9
## Fixes
- 修复 `useCheckedRowKeys``getRows` 方法在异步分页获取数据的时候,会导致切换页面后勾选项丢失问题
## 4.8.8
## Feats

View File

@ -1,7 +1,7 @@
{
"name": "ray-template",
"private": false,
"version": "4.8.8",
"version": "4.8.9",
"type": "module",
"engines": {
"node": "^18.0.0 || >=20.0.0",

View File

@ -3,11 +3,7 @@ import { effectDispose } from '@/utils'
import type { Recordable } from '@/types'
import type { MaybeRef } from '@vueuse/core'
import type {
DataTableColumns,
DataTableColumn,
DataTableSelectionColumn,
} from 'naive-ui'
import type { DataTableColumns, DataTableSelectionColumn } from 'naive-ui'
export type RowKey = string | number
@ -99,6 +95,41 @@ const isMultiple = (columns: MaybeRef<DataTableColumns<any> | undefined>) => {
return true
}
const matchRowsBySelectionKeys = <T extends Recordable>(
data: MaybeRef<T[] | undefined>,
keys: RowKey[],
currentRows: MaybeRef<T[]>,
bindRowKey: string,
) => {
const unrefData = unref(data)
if (!unrefData) {
return currentRows
}
return keys.reduce((pre, key) => {
const findByCurrentRows = unref(currentRows).findIndex(
(f) => f[bindRowKey] === key,
)
if (findByCurrentRows !== -1) {
pre.push(unref(currentRows)[findByCurrentRows])
return pre
}
const findByData = unrefData.findIndex((f) => f[bindRowKey] === key)
if (findByData !== -1) {
pre.push(unrefData[findByData])
return pre
}
return pre
}, [] as T[])
}
/**
*
* @param data DataTable
@ -160,11 +191,13 @@ const useCheckedRowKeys = <
},
) => {
keysRef.value = keys
rowsRef.value = rows
rowsRef.value = unref(
matchRowsBySelectionKeys(data, keys, rowsRef, bindRowKey),
)
onChange?.(
keys,
rows as any,
rowsRef.value,
meta as {
row: any | undefined
action: Action