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
36
37
38
39
40
import { ListController } from '@ibiz-template/controller';
import { ControlVO } from '@ibiz-template/service';
/**
* 使用列表
*
* @export
* @param {ListController} c
* @returns {*}
*/
export function useListEvent(c: ListController) {
// 处理单击
const handleClick = (data: ControlVO) => {
const selectIndex = c.selectedData.findIndex(selectData => {
return data.srfkey === selectData.srfkey;
});
if (!c.singleSelect) {
// 多选
const selections = c.selectedData;
// 没有加入,有就删除
if (selectIndex === -1) {
selections.push(data);
} else {
selections.splice(selectIndex, 1);
}
c.onSelectionChange(selections);
} else if (selectIndex === -1) {
// 单选,没有就放这一条,有就清空
c.onSelectionChange([data]);
} else {
c.onSelectionChange([]);
}
c.handleClick(data);
};
// 处理双击
const handleDblClick = (data: ControlVO) => {
c.handleDblClick(data);
};
return { handleClick, handleDblClick };
}