feat(image): 全项目应用图片压缩优化

- 将图片显示统一替换为 getCompressedImageUrl 函数处理压缩
- 覆盖 35 个文件,包括 4 个组件和 31 个页面
- 主要组件:LazyImage、ProductCard、OrderCard、SkuSelector 内部自动压缩图片
- 主要页面:购物车、订单、积分、活动、拼团、秒杀、收藏、浏览历史等
- 跳过用户头像、二维码、商品详情大图及所有 Taro.previewImage 调用
- 调整压缩默认宽度为 300,保持质量90,启用压缩功能
This commit is contained in:
2026-07-06 12:21:39 +08:00
parent c3dd04fa03
commit 082646a613
41 changed files with 95 additions and 50 deletions

View File

@@ -5,6 +5,7 @@ import type { ShopGoods, ShopGoodsSku } from '@/api/shop/shopGoods/model'
import type { ShopGoodsSpec } from '@/api/shop/shopGoodsSpec/model'
import Price from '@/components/common/Price'
import { isVipMember } from '@/utils/vip'
import { getCompressedImageUrl } from '@/utils/image'
interface SkuSelectorProps {
visible: boolean
@@ -256,7 +257,7 @@ const SkuSelector: React.FC<SkuSelectorProps> = ({
{/* 商品信息 */}
<View className='flex gap-3 pb-4 border-b border-gray-100'>
<Image className='w-20 h-20 rounded-md bg-gray-100' src={currentImage} mode='aspectFill' />
<Image className='w-20 h-20 rounded-md bg-gray-100' src={getCompressedImageUrl(currentImage)} mode='aspectFill' />
<View className='flex-1'>
<Price price={currentPrice} size='large' />
<Text className='text-xs text-gray-500 block' style={{ marginTop: '4px' }}>: {currentStock}</Text>

View File

@@ -1,6 +1,7 @@
import { View, Image, Text } from '@tarojs/components';
import { useState, useEffect } from 'react';
import { useIntersectionObserver } from '@tarojs/taro';
import { getCompressedImageUrl } from '@/utils/image';
interface LazyImageProps {
src: string;
@@ -46,7 +47,7 @@ export default function LazyImage({ src, placeholder, className, style, mode = '
)}
{(inView || loaded) && (
<Image
src={src}
src={getCompressedImageUrl(src)}
className={`w-full h-full ${loaded ? 'block' : 'hidden'}`}
mode={mode}
onLoad={() => setLoaded(true)}

View File

@@ -3,6 +3,7 @@ import { View, Text, Image } from '@tarojs/components'
import Taro from '@tarojs/taro'
import type { ShopOrder } from '@/api/shop/shopOrder/model'
import Price from '../Price'
import { getCompressedImageUrl } from '@/utils/image'
interface OrderCardProps {
order: ShopOrder
@@ -67,7 +68,7 @@ const OrderCard: React.FC<OrderCardProps> = ({ order, onClick }) => {
{item.image ? (
<Image
className='w-full h-full'
src={item.image}
src={getCompressedImageUrl(item.image)}
mode='aspectFill'
/>
) : (
@@ -104,7 +105,7 @@ const OrderCard: React.FC<OrderCardProps> = ({ order, onClick }) => {
<View className='flex flex-row items-start mb-3'>
<View className='w-16 h-16 rounded-md bg-gray-100 flex-shrink-0 flex items-center justify-center overflow-hidden'>
{coverImage ? (
<Image className='w-full h-full' src={coverImage} mode='aspectFill' />
<Image className='w-full h-full' src={getCompressedImageUrl(coverImage)} mode='aspectFill' />
) : (
<Text className='text-xs text-gray-400'></Text>
)}

View File

@@ -4,6 +4,7 @@ import Taro from '@tarojs/taro'
import Price from '../Price'
import { isGuest } from '@/utils/auth'
import { isVipMember } from '@/utils/vip'
import { getCompressedImageUrl } from '@/utils/image'
import type { ShopGoods } from '@/api/shop/shopGoods/model'
interface ProductCardProps {
@@ -25,7 +26,7 @@ const ProductCard: React.FC<ProductCardProps> = ({ product, onClick }) => {
<View className='w-full' style={{ paddingTop: '100%', position: 'relative' }}>
<Image
className='absolute top-0 left-0 w-full h-full'
src={product.image || product.files || ''}
src={getCompressedImageUrl(product.image || product.files || '')}
mode='aspectFit'
lazyLoad
style={{ position: 'absolute', top: 0, left: 0, width: '100%', height: '100%' }}