useHistorySnapshot.ts 608 B

123456789101112131415161718192021222324252627
  1. import { debounce, throttle} from 'lodash'
  2. import { useSnapshotStore } from '@/store'
  3. export default () => {
  4. const snapshotStore = useSnapshotStore()
  5. // 添加历史快照(历史记录)
  6. const addHistorySnapshot = debounce(function() {
  7. snapshotStore.addSnapshot()
  8. }, 300, { trailing: true })
  9. // 重做
  10. const redo = throttle(function() {
  11. snapshotStore.reDo()
  12. }, 100, { leading: true, trailing: false })
  13. // 撤销
  14. const undo = throttle(function() {
  15. snapshotStore.unDo()
  16. }, 100, { leading: true, trailing: false })
  17. return {
  18. addHistorySnapshot,
  19. redo,
  20. undo,
  21. }
  22. }