From 81a735caa69952bc24e0fa3e08549974dc11ff21 Mon Sep 17 00:00:00 2001 From: Tevin <tingquanren@163.com> Date: Mon, 18 Mar 2024 20:02:36 +0800 Subject: [PATCH] 修复签名组件,小程序中,上传图片报错的问题 --- forms/imagePicker/CImagePreview.vue | 24 +++++++++++++----------- 1 files changed, 13 insertions(+), 11 deletions(-) diff --git a/forms/imagePicker/CImagePreview.vue b/forms/imagePicker/CImagePreview.vue index cb615de..b92fef7 100644 --- a/forms/imagePicker/CImagePreview.vue +++ b/forms/imagePicker/CImagePreview.vue @@ -12,10 +12,11 @@ import { $ } from '@tarojs/extend'; // 直线方程,点斜式参数 -const createLineEquation = (p1, p2) => ({ - k: (p1.y - p2.y) / (p1.x - p2.x), - b: p1.y - k * p1.x, -}); +const createLineEquation = (p1, p2) => { + const k = (p1.y - p2.y) / (p1.x - p2.x); + const b = p1.y - k * p1.x; + return { k, b }; +}; const winWidth = window.innerWidth; export default { @@ -24,6 +25,7 @@ return {}; }, methods: { + // option { current, urls } $preview(option) { // 网页模式下,增加缩放操作 if (process.env.TARO_ENV === 'h5') { @@ -38,8 +40,8 @@ // 小程序模式,直接支持缩放 else { Taro.previewImage({ - current: file.url, // 当前显示图片的http链接 - urls, // 需要预览的图片http链接列表 + current: option.current, // 当前显示图片的http链接 + urls: option.urls, // 需要预览的图片http链接列表 }); } }, @@ -67,8 +69,8 @@ let equationY = {}; $img.on({ touchstart: evt => { - startOffsetX = parseInt($img.css('left')); - startOffsetY = parseInt($img.css('top')); + startOffsetX = parseInt($img.css('left')) || 0; + startOffsetY = parseInt($img.css('top')) || 0; startWidth = parseInt($img.css('width')) * scale; if (evt.touches.length == 1) { const { clientX, clientY } = evt.touches[0]; @@ -92,7 +94,7 @@ { x: scale, y: startOffsetY } ); } - // 初始状态,不线性计算 + // 初始状态,不计算 else { equationX = equationY = { k: 0, b: 0 }; } @@ -142,8 +144,8 @@ } } // 修正位置 - const left = equationX.a * scale + equationX.b; - const top = equationY.a * scale + equationY.b; + const left = equationX.k * scale + equationX.b; + const top = equationY.k * scale + equationY.b; // 渲染 $img.css({ transform: 'scale(' + scale + ')', -- Gitblit v1.9.1