From a0330ec8782412b531e7bba3b3edb409ec1eb26e Mon Sep 17 00:00:00 2001 From: imeepos Date: Mon, 1 Sep 2025 17:08:42 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E5=85=A8=E5=B1=8F=E5=B1=95=E7=A4=BA=E6=96=B9=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 使用aspectFill模式最大化图片利用屏幕空间 - 添加精美相框和渐变背景突出图片效果 - 优化图片容器尺寸计算保持完美比例 - 增强视觉层次感和用户体验 --- src/pages/index/index.css | 44 +++++++++++++++++++++++++++++++++------ src/pages/index/index.tsx | 18 +++++++++------- src/sdk/index.ts | 6 ++++++ 3 files changed, 54 insertions(+), 14 deletions(-) diff --git a/src/pages/index/index.css b/src/pages/index/index.css index c523522..2813f76 100644 --- a/src/pages/index/index.css +++ b/src/pages/index/index.css @@ -204,7 +204,10 @@ left: 0; width: 100vw; height: 100vh; - background: #000; + background: linear-gradient(135deg, #2c3e50, #34495e); + background-image: + radial-gradient(circle at 25% 25%, rgba(255, 255, 255, 0.1) 0%, transparent 50%), + radial-gradient(circle at 75% 75%, rgba(255, 255, 255, 0.05) 0%, transparent 50%); display: flex; flex-direction: column; z-index: 1000; @@ -274,15 +277,44 @@ justify-content: center; width: 100%; height: 100%; - padding: 0rpx; + padding: 0; box-sizing: border-box; + position: relative; + background: radial-gradient(ellipse at center, rgba(0, 0, 0, 0.1) 0%, rgba(0, 0, 0, 0.8) 100%); +} + +.swiper-item::before { + content: ""; + position: absolute; + top: 20rpx; + left: 20rpx; + right: 20rpx; + bottom: 160rpx; + border-radius: 24rpx; + border: 4rpx solid rgba(255, 255, 255, 0.2); + box-shadow: + 0 0 0 1rpx rgba(255, 255, 255, 0.1), + inset 0 0 40rpx rgba(255, 255, 255, 0.05), + 0 20rpx 60rpx rgba(0, 0, 0, 0.3); + pointer-events: none; + z-index: 1; + background: linear-gradient( + 135deg, + rgba(255, 255, 255, 0.02) 0%, + rgba(255, 255, 255, 0.05) 50%, + rgba(255, 255, 255, 0.02) 100% + ); } .fullscreen-image { - width: 100%; - height: 100%; - max-width: 100%; - max-height: 100%; + width: calc(100% - 40rpx); + height: calc(100% - 180rpx); + border-radius: 20rpx; + position: relative; + z-index: 2; + margin-top: 20rpx; + object-fit: cover; + box-shadow: 0 15rpx 50rpx rgba(0, 0, 0, 0.4); } /* 全屏底部 */ diff --git a/src/pages/index/index.tsx b/src/pages/index/index.tsx index 46e56e1..c2d5340 100644 --- a/src/pages/index/index.tsx +++ b/src/pages/index/index.tsx @@ -1,5 +1,5 @@ import { View, Text, Button, Image, Swiper, SwiperItem } from '@tarojs/components' -import { useLoad, saveImageToPhotosAlbum, downloadFile, showToast } from '@tarojs/taro' +import { saveImageToPhotosAlbum, downloadFile, showToast } from '@tarojs/taro' import { useState } from 'react' import './index.css' import { useSdk } from '../../hooks/index' @@ -34,15 +34,17 @@ export default function Index() { } }) - useLoad(() => { - return () => { } - }) - const chooseAndGenerateImage = async () => { - setState({ step: 'loading', images: [], error: null }) - try { - const task_id = await sdk.chooseAndGenerateImage() + // 选择图片,选择完成后会自动触发loading状态 + const task_id = await sdk.chooseAndGenerateImage({ + onImageSelected: () => { + // 选择图片完成后立即显示loading + setState({ step: 'loading', images: [], error: null }) + } + }) + + // 等待生成完成 await new Promise((resolve) => setTimeout(resolve, 5000)) const urls = await sdk.getTaskStatus(task_id) diff --git a/src/sdk/index.ts b/src/sdk/index.ts index d6d16bc..a6f66d5 100644 --- a/src/sdk/index.ts +++ b/src/sdk/index.ts @@ -146,11 +146,14 @@ export class BowongAISDK { sizeType?: ('original' | 'compressed')[]; /** 选择图片的来源,默认为 ['album', 'camera'] */ sourceType?: ('album' | 'camera')[]; + /** 选择图片完成后的回调 */ + onImageSelected?: () => void; }): Promise { const { count = 1, sizeType = ['original', 'compressed'], sourceType = ['album', 'camera'], + onImageSelected, } = options || {}; try { @@ -161,6 +164,9 @@ export class BowongAISDK { sourceType }); + // 选择图片完成后触发回调 + onImageSelected?.(); + if (!chooseResult.tempFilePaths || chooseResult.tempFilePaths.length === 0) { throw new Error('未选择图片'); }