lex 8 miesięcy temu
rodzic
commit
929191d5f7

+ 11 - 0
package-lock.json

@@ -20,6 +20,7 @@
         "eventemitter3": "^5.0.1",
         "howler": "^2.2.3",
         "html2canvas": "^1.4.1",
+        "mobile-drag-drop": "^3.0.0-rc.0",
         "moveable": "^0.52.0",
         "naive-ui": "^2.34.4",
         "numeral": "^2.0.6",
@@ -6500,6 +6501,11 @@
         "node": ">=10"
       }
     },
+    "node_modules/mobile-drag-drop": {
+      "version": "3.0.0-rc.0",
+      "resolved": "https://registry.npmmirror.com/mobile-drag-drop/-/mobile-drag-drop-3.0.0-rc.0.tgz",
+      "integrity": "sha512-f8wIDTbBYLBW/+5sei1cqUE+StyDpf/LP+FRZELlVX6tmOOmELk84r3wh1z3woxCB9G5octhF06K5COvFjGgqg=="
+    },
     "node_modules/moveable": {
       "version": "0.52.0",
       "resolved": "https://registry.npmmirror.com/moveable/-/moveable-0.52.0.tgz",
@@ -14247,6 +14253,11 @@
       "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==",
       "dev": true
     },
+    "mobile-drag-drop": {
+      "version": "3.0.0-rc.0",
+      "resolved": "https://registry.npmmirror.com/mobile-drag-drop/-/mobile-drag-drop-3.0.0-rc.0.tgz",
+      "integrity": "sha512-f8wIDTbBYLBW/+5sei1cqUE+StyDpf/LP+FRZELlVX6tmOOmELk84r3wh1z3woxCB9G5octhF06K5COvFjGgqg=="
+    },
     "moveable": {
       "version": "0.52.0",
       "resolved": "https://registry.npmmirror.com/moveable/-/moveable-0.52.0.tgz",

+ 1 - 0
package.json

@@ -34,6 +34,7 @@
     "eventemitter3": "^5.0.1",
     "howler": "^2.2.3",
     "html2canvas": "^1.4.1",
+    "mobile-drag-drop": "^3.0.0-rc.0",
     "moveable": "^0.52.0",
     "naive-ui": "^2.34.4",
     "numeral": "^2.0.6",

+ 22 - 12
src/hooks/useDrag/index.ts

@@ -105,19 +105,22 @@ export default function useDrag(
 
 // 拖动
 function drag(el: HTMLElement, parentElement: HTMLElement, pos: Ref<posType>) {
-  function mousedown(e: MouseEvent) {
+  function onDown(e: MouseEvent | TouchEvent) {
+    const isTouchEv = isTouchEvent(e);
+    const event = isTouchEv ? e.touches[0] : e;
     const parentElementRect = parentElement.getBoundingClientRect();
-    const downX = e.clientX;
-    const downY = e.clientY;
+    const downX = event.clientX;
+    const downY = event.clientY;
     const clientWidth = document.documentElement.clientWidth;
     const clientHeight = document.documentElement.clientHeight;
     const maxLeft = clientWidth - parentElementRect.width;
     const maxTop = clientHeight - parentElementRect.height;
     const minLeft = 0;
     const minTop = 0;
-    function onMousemove(e: MouseEvent) {
-      let moveX = parentElementRect.left + (e.clientX - downX);
-      let moveY = parentElementRect.top + (e.clientY - downY);
+    function onMove(e: MouseEvent | TouchEvent) {
+      const event = isTouchEvent(e) ? e.touches[0] : e;
+      let moveX = parentElementRect.left + (event.clientX - downX);
+      let moveY = parentElementRect.top + (event.clientY - downY);
       moveX = moveX < minLeft ? minLeft : moveX > maxLeft ? maxLeft : moveX;
       moveY = moveY < minTop ? minTop : moveY > maxTop ? maxTop : moveY;
       pos.value = {
@@ -125,16 +128,23 @@ function drag(el: HTMLElement, parentElement: HTMLElement, pos: Ref<posType>) {
         left: moveX
       };
     }
-    function onMouseup() {
-      document.removeEventListener('mousemove', onMousemove);
-      document.removeEventListener('mouseup', onMouseup);
+    function onUp() {
+      document.removeEventListener(
+        isTouchEv ? 'touchmove' : 'mousemove',
+        onMove
+      );
+      document.removeEventListener(isTouchEv ? 'touchend' : 'mouseup', onUp);
     }
-    document.addEventListener('mousemove', onMousemove);
-    document.addEventListener('mouseup', onMouseup);
+    document.addEventListener(isTouchEv ? 'touchmove' : 'mousemove', onMove);
+    document.addEventListener(isTouchEv ? 'touchend' : 'mouseup', onUp);
   }
-  el.addEventListener('mousedown', mousedown);
+  el.addEventListener('mousedown', onDown);
+  el.addEventListener('touchstart', onDown);
 }
 
+function isTouchEvent(e: MouseEvent | TouchEvent): e is TouchEvent {
+  return window.TouchEvent && e instanceof window.TouchEvent;
+}
 // 缓存
 const localStorageName = 'dragCachePos';
 function getCachePos(useIdDargClass: string): null | undefined | posType {

+ 7 - 0
src/main.ts

@@ -31,6 +31,13 @@ setToastDefaultOptions({ duration: 3000 });
 // // 初始化polyfill
 // polyfill(options);
 
+// document.addEventListener('dragstart', (event: any) => {
+//   if (!event.target.classList.contains('draggable')) {
+//     event.preventDefault();
+//   }
+// });
+
+
 
 // 获取token
 promisefiyPostMessage({ api: 'getToken' }).then((res: any) => {

+ 5 - 5
src/views/tempo-practice/index.module.less

@@ -45,7 +45,7 @@
 .pc {
   .container {
     max-width: 1200px;
-    gap: 30px 0;
+    gap: 20px 0;
   }
 
   .beatSection {
@@ -60,11 +60,11 @@
 
     &.small {
       .beat {
-        width: 139px !important;
-        height: 191px !important;
+        width: 117px !important;
+        height: 161px !important;
 
         img {
-          width: 108px;
+          width: 80px;
         }
       }
     }
@@ -379,7 +379,7 @@
 :global {
   .settingBoxClass_drag .settingContainer_pc {
     border-radius: 16px;
-    height: 55vh !important;
+    height: 60vh !important;
   }
 }
 

+ 1 - 0
src/views/tempo-practice/index.tsx

@@ -646,6 +646,7 @@ export default defineComponent({
           style={
             state.platform === 'modal' ? settingBoxDragData.styleDrag.value : {}
           }
+          closeOnClickOverlay={false}
           v-model:show={state.settingPcStatus}
           class={[styles.settingPopup, settingBoxClass]}>
           <SettingPcModal

+ 1 - 0
src/views/tempo-practice/setting-modal/index.tsx

@@ -324,6 +324,7 @@ export default defineComponent({
                           }}
                           onClick={() => onChangeTempo(item)}>
                           <img
+                            class={'draggable'}
                             // class={state.tempo.includes(item) && styles.active}
                             src={getImage(
                               (state.element === 'jianpu' ? 'j-' : 'f-') +

+ 1 - 1
vite.config.ts

@@ -16,7 +16,7 @@ function resolve(dir: string) {
 // const proxyUrl = 'https://test.lexiaoya.cn/';
 // const proxyUrl = 'https://kt.colexiu.com/';
 // const proxyUrl = 'http://192.168.3.143:7093/';
-const proxyUrl = 'https://dev.kt.colexiu.com/';
+const proxyUrl = 'https://test.kt.colexiu.com/';
 export default defineConfig({
   base: './',
   plugins: [