Browse Source

test: fix video

richard1015 3 years ago
parent
commit
4bc261d468

+ 4 - 4
src/packages/__VUE/badge/__test__/__snapshots__/badge.spec.ts.snap

@@ -6,27 +6,27 @@ exports[`should change dot position when using offset prop: 4px 1`] = `""`;
 
 exports[`should render content slot correctly 1`] = `
 "<view class=\\"nut-badge\\">
-  <view class=\\"slot-icons\\"></view>Custom Content<view class=\\"nut-badge__content sup\\" style=\\"top: 0px; right: 0px; z-index: 9; display: none;\\"></view>
+  <view class=\\"slot-icons\\" style=\\"top: 0px; right: 0px; z-index: 9;\\"></view>Custom Content<view class=\\"nut-badge__content sup\\" style=\\"top: 0px; right: 0px; z-index: 9; display: none;\\"></view>
 </view>"
 `;
 
 exports[`should render nothing when content is empty string 1`] = `
 "<view class=\\"nut-badge\\">
-  <view class=\\"slot-icons\\"></view>
+  <view class=\\"slot-icons\\" style=\\"top: 0px; right: 0px; z-index: 9;\\"></view>
   <view class=\\"nut-badge__content sup\\" style=\\"top: 0px; right: 0px; z-index: 9; display: none;\\"></view>
 </view>"
 `;
 
 exports[`should render nothing when content is undefined 1`] = `
 "<view class=\\"nut-badge\\">
-  <view class=\\"slot-icons\\"></view>
+  <view class=\\"slot-icons\\" style=\\"top: 0px; right: 0px; z-index: 9;\\"></view>
   <view class=\\"nut-badge__content sup\\" style=\\"top: 0px; right: 0px; z-index: 9; display: none;\\"></view>
 </view>"
 `;
 
 exports[`should render nothing when content is zero 1`] = `
 "<view class=\\"nut-badge\\">
-  <view class=\\"slot-icons\\"></view>
+  <view class=\\"slot-icons\\" style=\\"top: 0px; right: 0px; z-index: 9;\\"></view>
   <view class=\\"nut-badge__content sup\\" style=\\"top: 0px; right: 0px; z-index: 9; display: none;\\">0</view>
 </view>"
 `;

+ 4 - 4
src/packages/__VUE/noticebar/__tests__/__snapshots__/noticebar.spec.ts.snap

@@ -37,10 +37,10 @@ exports[`vertical scroll 1`] = `
   <!--v-if-->
   <view class=\\"nut-noticebar-vertical\\" style=\\"height: 40px;\\">
     <ul class=\\"horseLamp_list\\">
-      <li class=\\"horseLamp_list_item\\">惊喜红包免费领</li>
-      <li class=\\"horseLamp_list_item\\">爆款准点秒</li>
-      <li class=\\"horseLamp_list_item\\">买超值优惠</li>
-      <li class=\\"horseLamp_list_item\\">赢百万京豆</li>
+      <li class=\\"horseLamp_list_item\\" style=\\"height: 40px;\\">惊喜红包免费领</li>
+      <li class=\\"horseLamp_list_item\\" style=\\"height: 40px;\\">爆款准点秒</li>
+      <li class=\\"horseLamp_list_item\\" style=\\"height: 40px;\\">买超值优惠</li>
+      <li class=\\"horseLamp_list_item\\" style=\\"height: 40px;\\">赢百万京豆</li>
     </ul>
     <view class=\\"go\\">
       <!--v-if-->

+ 2 - 2
src/packages/__VUE/video/index.vue

@@ -59,7 +59,7 @@
 <script lang="ts">
 import { computed, reactive, ref, toRefs, watch, nextTick, onMounted } from 'vue';
 import { createComponent } from '@/packages/utils/create';
-import { throttle } from '@/packages/utils/throttle.js';
+import { throttle } from '@/packages/utils/throttle';
 const { create, translate } = createComponent('video');
 
 export default create({
@@ -187,7 +187,7 @@ export default create({
         });
         (state.videoElm as any).addEventListener('ended', playEnded);
 
-        (state.videoElm as any).addEventListener('timeupdate', throttle(getPlayTime, 1000, 1));
+        (state.videoElm as any).addEventListener('timeupdate', throttle(getPlayTime, 1000));
       }
     };
 

+ 0 - 32
src/packages/utils/throttle.js

@@ -1,32 +0,0 @@
-/**
- * @desc 函数节流
- * @param func 函数
- * @param wait 延迟执行毫秒数
- * @param type 1 表时间戳版,2 表定时器版
- */
-export const throttle = (func, wait, type) => {
-  if (type === 1) {
-    var previous = 0;
-  } else if (type === 2) {
-    var timeout;
-  }
-  return function() {
-    let context = this;
-    let args = arguments;
-    if (type === 1) {
-      let now = Date.now();
-
-      if (now - previous > wait) {
-        func.apply(context, args);
-        previous = now;
-      }
-    } else if (type === 2) {
-      if (!timeout) {
-        timeout = setTimeout(() => {
-          timeout = null;
-          func.apply(context, args);
-        }, wait);
-      }
-    }
-  };
-};

+ 36 - 0
src/packages/utils/throttle.ts

@@ -0,0 +1,36 @@
+/**
+ * 防抖
+ * @param fn
+ * @param delay
+ */
+export function debounce(fn: Function, delay: number) {
+  let timer: null | number = null;
+
+  return function () {
+    if (timer) clearTimeout(timer);
+
+    timer = setTimeout(fn, delay);
+  };
+}
+
+/**
+ * 节流
+ * @param fn
+ * @param delay
+ */
+export function throttle(fn: Function, delay: number) {
+  let timer: number | null = null;
+  let startTime = Date.now();
+
+  return function () {
+    let now = Date.now();
+    let remaining = delay - (now - startTime);
+    if (timer) clearTimeout(timer);
+    if (remaining <= 0) {
+      fn.apply(null, arguments);
+      startTime = Date.now();
+    } else {
+      timer = setTimeout(fn, remaining);
+    }
+  };
+}