autoDrag.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // AUTO-INJECTED DRAG LOGIC
  2. const __autoDragElement = ref(null)
  3. const __autoDropInfo = ref({
  4. targetId: null,
  5. direction: null
  6. })
  7. const __autoDragStart = (e, id) => {
  8. __autoDragElement.value = id
  9. e.dataTransfer.effectAllowed = 'move'
  10. }
  11. const __autoDragOver = (e, targetId) => {
  12. e.preventDefault()
  13. const rect = e.currentTarget.getBoundingClientRect()
  14. __autoDropInfo.value = {
  15. targetId,
  16. direction: e.clientX - rect.left < rect.width / 2 ? 'left' : 'right'
  17. }
  18. }
  19. const __autoDragLeave = () => {
  20. __autoDropInfo.value = { targetId: null, direction: null }
  21. }
  22. const __autoDragDrop = (e, targetId) => {
  23. e.preventDefault()
  24. if (!__autoDragElement.value || !targetId) return
  25. // 构造请求数据
  26. const data = `${__autoDragElement.value}-${targetId}-${__autoDropInfo.value.direction}`;
  27. // 发送 POST 请求
  28. fetch('http://localhost:8080/test/changecode', {
  29. method: 'POST',
  30. headers: {
  31. 'Content-Type': 'application/x-www-form-urlencoded', // 或 'text/plain' 根据后端需求
  32. },
  33. body: data
  34. })
  35. .catch(error => {
  36. console.error('请求失败:', error);
  37. });
  38. __autoDragElement.value = null
  39. __autoDropInfo.value = { targetId: null, direction: null }
  40. }