diff --git a/src/app.ts b/src/app.ts index a6355ef..3e020ab 100644 --- a/src/app.ts +++ b/src/app.ts @@ -6,6 +6,7 @@ import './app.css' function App({ children }: PropsWithChildren) { useLaunch(() => { console.log('App launched.') + }) // children 是将要会渲染的页面 diff --git a/src/components/DownloadSection/index.css b/src/components/DownloadSection/index.css index 8462c72..c418c0d 100644 --- a/src/components/DownloadSection/index.css +++ b/src/components/DownloadSection/index.css @@ -42,6 +42,27 @@ opacity: 1; } +.regenerate-btn { + width: 80%; + height: 100rpx; + background: linear-gradient(45deg, #52c41a, #73d13d); + color: white; + border: none; + border-radius: 50rpx; + font-size: 32rpx; + font-weight: bold; + margin-bottom: 20rpx; + display: flex; + align-items: center; + justify-content: center; + cursor: pointer; + transition: opacity 0.2s; +} + +.regenerate-btn:active { + opacity: 0.8; +} + .download-tip { color: #fff; font-size: 24rpx; diff --git a/src/components/DownloadSection/index.tsx b/src/components/DownloadSection/index.tsx index 43deeca..66774d9 100644 --- a/src/components/DownloadSection/index.tsx +++ b/src/components/DownloadSection/index.tsx @@ -4,10 +4,11 @@ import './index.css' interface DownloadSectionProps { onDownload: () => void + onRegenerate?: () => void loading: boolean } -const DownloadSection: React.FC = memo(({ onDownload, loading }) => { +const DownloadSection: React.FC = memo(({ onDownload, onRegenerate, loading }) => { return ( = memo(({ onDownload, load > {loading ? '广告加载中...' : '📱 看广告下载到相册'} + {onRegenerate && ( + + 🎨 再来一张 + + )} 观看完整广告即可免费下载所有图片 ) diff --git a/src/components/ErrorOverlay/index.css b/src/components/ErrorOverlay/index.css index 9f2e9f6..b52ce87 100644 --- a/src/components/ErrorOverlay/index.css +++ b/src/components/ErrorOverlay/index.css @@ -28,9 +28,11 @@ font-size: 40rpx; font-weight: bold; margin-bottom: 20rpx; + display: block; } .error-hint { font-size: 28rpx; opacity: 0.8; + display: block; } \ No newline at end of file diff --git a/src/pages/index/index.tsx b/src/pages/index/index.tsx index 3dbae78..eeebb47 100644 --- a/src/pages/index/index.tsx +++ b/src/pages/index/index.tsx @@ -6,6 +6,7 @@ import { useSdk } from '../../hooks/index' import UploadButton from '../../components/UploadButton' import LoadingOverlay from '../../components/LoadingOverlay' import ErrorOverlay from '../../components/ErrorOverlay' +import { createPlatformFactory } from '../../platforms' type PageStep = 'upload' | 'loading' | 'error' @@ -23,6 +24,9 @@ export default function Index() { const chooseAndGenerateImage = async () => { try { + const platformFactory = createPlatformFactory() + await platformFactory.createUserInfo().checkSession().catch(e => console.error(e)) + // 选择图片,选择完成后会自动触发loading状态 const task_id = await sdk.chooseAndGenerateImage({ onImageSelected: () => { @@ -30,7 +34,7 @@ export default function Index() { setState({ step: 'loading', error: null }) } }) - + // 等待生成完成 await new Promise((resolve) => setTimeout(resolve, 5000)) const urls = await sdk.getTaskStatus(task_id) @@ -39,7 +43,7 @@ export default function Index() { navigateTo({ url: `/pages/result/index?images=${encodeURIComponent(JSON.stringify(urls))}` }) - + // 重置状态 setState({ step: 'upload', error: null }) } catch (error) { @@ -54,13 +58,13 @@ export default function Index() { const renderCurrentStep = () => { switch (state.step) { - case 'upload': + case 'upload': return - case 'loading': + case 'loading': return - case 'error': + case 'error': return - default: + default: return } } diff --git a/src/pages/result/index.tsx b/src/pages/result/index.tsx index 4b6d5a1..160acb4 100644 --- a/src/pages/result/index.tsx +++ b/src/pages/result/index.tsx @@ -77,6 +77,11 @@ const ResultPage: React.FC = memo(() => { } } + // 再来一张 + const handleRegenerate = () => { + navigateBack() + } + if (!images.length) { return null } @@ -96,7 +101,7 @@ const ResultPage: React.FC = memo(() => { - + ) }) diff --git a/src/platforms/core.ts b/src/platforms/core.ts index a6057d8..bc62f67 100644 --- a/src/platforms/core.ts +++ b/src/platforms/core.ts @@ -123,4 +123,44 @@ export abstract class RewardedVideoAd { * @returns Promise 预加载完成的 Promise */ abstract preload(): Promise; +} + + +/** + * 获取用户信息 + */ +export interface IUserInfo { + avatarUrl: string; + city: string; + country: string; + gender: number; + language: string; + nickName: string; + province: string; +} + +export interface IUserProfile { + userInfo: IUserInfo; + cloudId: string; + encryptedData: string; + errMsg: string; + iv: string; + rawData: string; + signature: string; +} + +export interface ILogin { + anonymousCode: string; + code: string; + errMsg: string; + isLogin: boolean; +} + +export interface ICheckSession { + errMsg: string; +} +export abstract class UserInfo { + abstract getUserProfile(): Promise; + abstract login(): Promise; + abstract checkSession(): Promise; } \ No newline at end of file diff --git a/src/platforms/factory.ts b/src/platforms/factory.ts index 46bcb6d..1c1c307 100644 --- a/src/platforms/factory.ts +++ b/src/platforms/factory.ts @@ -1,5 +1,5 @@ -import { RewardedVideoAdTT } from "./tt"; -import { RewardedVideoAd, RewardedVideoAdOptions } from "./core"; +import { RewardedVideoAdTT, UserInfoTT } from "./tt"; +import { RewardedVideoAd, RewardedVideoAdOptions, UserInfo } from "./core"; /** * 小程序平台全局对象类型声明 @@ -54,6 +54,24 @@ export class PlatformFactory { } } + + createUserInfo(): UserInfo { + switch (this.platform) { + case 'tt': + return new UserInfoTT(); + case 'weapp': + throw new Error(`微信小程序平台暂未实现`); + case 'alipay': + throw new Error(`支付宝小程序平台暂未实现`); + case 'swan': + throw new Error(`百度智能小程序平台暂未实现`); + case 'qq': + throw new Error(`QQ 小程序平台暂未实现`); + default: + throw new Error(`不支持的平台类型: ${this.platform}`); + } + } + /** * 获取当前平台类型 * @returns Platform 当前平台 diff --git a/src/platforms/tt.ts b/src/platforms/tt.ts index 6e5b855..624f254 100644 --- a/src/platforms/tt.ts +++ b/src/platforms/tt.ts @@ -3,7 +3,11 @@ import { RewardedVideoCloseCb, RewardedVideoErrorCb, RewardedVideoLoadCb, - RewardedVideoAdOptions + RewardedVideoAdOptions, + UserInfo, + IUserInfo, + IUserProfile, + ICheckSession } from "./core"; /** @@ -194,4 +198,47 @@ export class RewardedVideoAdTT extends RewardedVideoAd { getNativeAd(): any { return this.ad; } +} + +export class UserInfoTT extends UserInfo { + getUserProfile(): Promise { + return new Promise((resolve, reject) => { + tt.getUserProfile({ + success: (res: any) => { + console.log({ res }) + resolve(res) + }, + fail: (res: any) => { + console.log({ res }) + reject(res) + } + }) + }) + } + + login(): Promise { + return new Promise((resolve, reject) => { + tt.login({ + success: (res: any) => { + resolve(res) + }, + fail: (res: any) => { + reject(res) + } + }) + }) + } + + checkSession(): Promise { + return new Promise((resolve, reject) => { + tt.checkSession({ + success: (res: any) => { + resolve(res) + }, + fail: (res: any) => { + reject(res) + } + }) + }) + } } \ No newline at end of file