Browse Source

fix: add click event invoke window: 300ms

Acathur 5 years ago
parent
commit
4449d70680
1 changed files with 11 additions and 8 deletions
  1. 11 8
      kaifain_v2/components/Carousel.vue

+ 11 - 8
kaifain_v2/components/Carousel.vue

@@ -14,7 +14,7 @@
         )
         .pic(
             :style="{backgroundImage: `url('${item.image_url}')`, backgroundColor: item.theme_color || 'transparent'}"
-            @click="onClick($event, item, false)"
+            @click="onClick(item, false)"
             )
         .container.is-content(v-if="item.title || item.desc" :style="{textAlign: item.cont_position || 'left'}")
           .text-content
@@ -22,7 +22,7 @@
             .desc {{item.desc}}
             .button.is-primary.is-inverted.is-outlined(
               v-if="item.button_text"
-              @click.stop.prevent="onClick($event, item, true)"
+              @click.stop.prevent="onClick(item, true)"
               ) {{item.button_text}}
 
 </template>
@@ -50,6 +50,8 @@ const insertOrUpdateStyleTag = (item) => {
   }
 }
 
+let lastClickedAt = 0
+
 export default Vue.extend({
   name: 'Carousel',
   components: {
@@ -66,15 +68,16 @@ export default Vue.extend({
   },
 
   methods: {
-    onClick(e: Event, item: any, isButton: boolean) {
-      e.stopPropagation()
-      e.preventDefault()
-
-      if (!isButton && item.button_text || !item.jump_target) {
+    onClick(item: any, isButton: boolean) {
+      if (!isButton && item.button_text || !item.jump_target || Date.now() - lastClickedAt < 300) {
         return false
       }
 
-      window.open(item.jump_target, '_blank')
+      const win = window.open(item.jump_target, '_blank')
+
+      if (win) {
+        lastClickedAt = Date.now()
+      }
     },
 
     onChange(idx: number) {