From f5e2ab063cef271e4b63ecca65e1789763011e16 Mon Sep 17 00:00:00 2001 From: neverland Date: Thu, 27 Dec 2018 22:05:22 +0800 Subject: [PATCH] [improvement] ImagePreview: optimize static methods (#2396) --- packages/image-preview/ImagePreview.vue | 22 +++++++++++----------- packages/pagination/index.vue | 14 +++++++------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/packages/image-preview/ImagePreview.vue b/packages/image-preview/ImagePreview.vue index 843c58e09..9e7214111 100644 --- a/packages/image-preview/ImagePreview.vue +++ b/packages/image-preview/ImagePreview.vue @@ -51,6 +51,15 @@ import { range } from '../utils'; const MAX_ZOOM = 3; const MIN_ZOOM = 1 / 3; +function getDistance(touches) { + return Math.sqrt( + Math.abs( + (touches[0].clientX - touches[1].clientX) * + (touches[0].clientY - touches[1].clientY) + ) + ); +} + export default create({ name: 'image-preview', @@ -156,15 +165,6 @@ export default create({ } }, - getDistance(touches) { - return Math.sqrt( - Math.abs( - (touches[0].clientX - touches[1].clientX) * - (touches[0].clientY - touches[1].clientY) - ) - ); - }, - startMove(event) { const image = event.currentTarget; const rect = image.getBoundingClientRect(); @@ -183,7 +183,7 @@ export default create({ this.moving = false; this.zooming = true; this.startScale = this.scale; - this.startDistance = this.getDistance(event.touches); + this.startDistance = getDistance(event.touches); }, onTouchStart(event) { @@ -213,7 +213,7 @@ export default create({ } if (this.zooming && touches.length === 2) { - const distance = this.getDistance(touches); + const distance = getDistance(touches); const scale = (this.startScale * distance) / this.startDistance; this.scale = range(scale, MIN_ZOOM, MAX_ZOOM); } diff --git a/packages/pagination/index.vue b/packages/pagination/index.vue index 672591acf..f9caebc4a 100644 --- a/packages/pagination/index.vue +++ b/packages/pagination/index.vue @@ -34,6 +34,10 @@