wangzhibo
2026-07-16 b57020623cf0c946706573bf102e548c3a544423
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { nextTick, ref } from "vue";
import { useCore } from "../../../hooks";
 
export function useData({ config, Table }: { config: ClTable.Config; Table: Vue.Ref<any> }) {
    const { mitt, crud } = useCore();
 
    // 列表数据
    const data = ref<obj[]>([]);
 
    // 设置数据
    function setData(list: obj[]) {
        data.value = list;
    }
 
    // 监听刷新
    mitt.on("crud.refresh", ({ list }: ClCrud.Response["page"]) => {
        data.value = list;
 
        // 显示选中行
        nextTick(() => {
            crud.selection.forEach((e) => {
                const d = list.find((a) => a[config.rowKey] == e[config.rowKey]);
 
                if (d) {
                    Table.value.toggleRowSelection(d, true);
                }
            });
        });
    });
 
    return {
        data,
        setData
    };
}