2020-09-05 15:38:55 +08:00
|
|
|
import { TransferCheckedState, Key } from './transfer'
|
2020-08-30 20:33:21 +08:00
|
|
|
|
|
|
|
import { LEFT_CHECK_CHANGE_EVENT, RIGHT_CHECK_CHANGE_EVENT } from './index.vue'
|
|
|
|
|
2020-09-05 15:38:55 +08:00
|
|
|
export const useCheckedChange = (checkedState: TransferCheckedState, emit) => {
|
2020-08-30 20:33:21 +08:00
|
|
|
const onSourceCheckedChange = (val: Key[], movedKeys: Key[]) => {
|
2020-09-05 15:38:55 +08:00
|
|
|
checkedState.leftChecked = val
|
2020-08-30 20:33:21 +08:00
|
|
|
if (movedKeys === undefined) return
|
|
|
|
emit(LEFT_CHECK_CHANGE_EVENT, val, movedKeys)
|
|
|
|
}
|
|
|
|
|
|
|
|
const onTargetCheckedChange = (val: Key[], movedKeys: Key[]) => {
|
2020-09-05 15:38:55 +08:00
|
|
|
checkedState.rightChecked = val
|
2020-08-30 20:33:21 +08:00
|
|
|
if (movedKeys === undefined) return
|
|
|
|
emit(RIGHT_CHECK_CHANGE_EVENT, val, movedKeys)
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
onSourceCheckedChange,
|
|
|
|
onTargetCheckedChange,
|
|
|
|
}
|
|
|
|
}
|