Draft
As a 小程序用户, I want 在首页使用微信小程序分享功能, so that 可以方便地分享小程序给朋友,提升小程序的传播能力。
process.env.TARO_APP_PUBLIC_IMAGE_BASE_URL + '/images/wp_home_share.jpg'mini/src/pages/home/index.config.ts 中启用分享功能mini/src/pages/home/index.tsx 中添加 onShareAppMessage 生命周期函数onShareTimeline 函数支持分享到朋友圈mini/tests/pages/HomePage.test.tsx (已存在)mini/src/pages/home/index.tsx [Source: architecture/source-tree.md#实际项目结构]mini/src/pages/home/index.config.ts [Source: architecture/source-tree.md#实际项目结构]mini/tests/pages/HomePage.test.tsx [Source: architecture/testing-strategy.md#taro小程序测试体系]TARO_APP_PUBLIC_IMAGE_BASE_URL 配置的图片路径基于 Taro小程序开发规范,分享功能需要:
index.config.ts 中启用分享功能 [Source: architecture/taro-mini-program-standards.md#页面组件规范]onShareAppMessage 和 onShareTimeline 函数 [Source: architecture/taro-mini-program-standards.md#小程序API使用规范]基于对 mini/src/pages/home/index.tsx 的分析:
页面配置文件 (mini/src/pages/home/index.config.ts):
export default {
navigationBarTitleText: '首页',
enablePullDownRefresh: true,
backgroundTextStyle: 'dark',
backgroundColor: '#f5f5f5',
enableShareAppMessage: true, // 新增:启用分享功能
enableShareTimeline: true, // 新增:启用分享到朋友圈
}
首页组件 (mini/src/pages/home/index.tsx):
// 在组件中添加分享生命周期函数
const HomePage: React.FC = () => {
// ... 现有代码
// 分享到好友
const onShareAppMessage = () => {
return {
title: '开心去看,就用去看出行',
path: '/pages/home/index',
imageUrl: process.env.TARO_APP_PUBLIC_IMAGE_BASE_URL + '/images/wp_home_share.jpg'
}
}
// 分享到朋友圈
const onShareTimeline = () => {
return {
title: '开心去看,就用去看出行',
imageUrl: process.env.TARO_APP_PUBLIC_IMAGE_BASE_URL + '/images/wp_home_share.jpg'
}
}
// ... 现有代码
}
TARO_APP_PUBLIC_IMAGE_BASE_URL - 已在项目中配置wp_home_share.jpg 图片文件存在于配置的路径中taroMock.ts 而不是手动mock [Source: architecture/testing-strategy.md#统一Mock]mini/tests/pages/HomePage.test.tsx [Source: architecture/testing-strategy.md#taro小程序测试体系]基于最新的测试文件模式 [Source: architecture/testing-strategy.md#最新测试模式和最佳实践]:
// 测试环境设置
const createTestQueryClient = () => new QueryClient({
defaultOptions: {
queries: { retry: false },
},
})
// 组件包装器
const Wrapper = ({ children }: { children: React.ReactNode }) => (
<QueryClientProvider client={createTestQueryClient()}>
{children}
</QueryClientProvider>
)
// 导入统一的Taro mock
import taroMock from '../../tests/__mocks__/taroMock'
TARO_APP_PUBLIC_IMAGE_BASE_URL 环境变量| Date | Version | Description | Author |
|---|---|---|---|
| 2025-10-31 | 1.0 | 初始故事创建 | Bob (Scrum Master) |
此部分将由开发代理在实施过程中填写
此部分将由QA代理在质量保证过程中填写