Files
JianSu-Naming/miniprogram/pages/profile/profile.js
王鹏 be1f5722ab feat: 完成见素起名小程序核心功能
- 实现 AI 起名功能(Kimi API 接入)
- 添加用户收藏功能(MySQL 数据库)
- 实现海报生成与分享
- 添加音效和触觉反馈
- 配置生产环境部署(WAR 包 + Nginx)
- 支持多种起名模式(经典、诗词、自然、现代)
- 实现分批加载优化体验
2026-04-17 15:34:51 +08:00

107 lines
2.4 KiB
JavaScript

Page({
data: {
favorites: [],
showDetail: false,
selectedItem: {},
selectedIndex: -1,
openid: 'test_openid' // 实际应从登录获取
},
onLoad() {
this.loadFavorites();
},
onShow() {
// 每次显示页面时刷新列表
this.loadFavorites();
},
// 加载收藏列表
loadFavorites() {
const apiBaseUrl = getApp().globalData.apiBaseUrl;
wx.request({
url: `${apiBaseUrl}/api/favorites/list`,
data: { openid: this.data.openid },
success: (res) => {
if (res.data && res.data.success) {
this.setData({ favorites: res.data.data || [] });
}
},
fail: () => {
wx.showToast({ title: '加载失败', icon: 'none' });
}
});
},
// 返回上一页
onBack() {
wx.navigateBack();
},
// 点击收藏项
onItemTap(e) {
const index = e.currentTarget.dataset.index;
const item = this.data.favorites[index];
this.setData({
selectedItem: item,
selectedIndex: index,
showDetail: true
});
wx.vibrateShort({ type: 'light' });
},
// 关闭详情弹窗
closeDetail() {
this.setData({ showDetail: false });
},
// 阻止冒泡
preventBubble() {
// 什么都不做,只是阻止事件冒泡
},
// 分享
onShare() {
const item = this.data.selectedItem;
wx.showShareImageMenu({
path: '/images/share.png' // 实际应生成海报图片
});
},
// 移除收藏
onRemove() {
const item = this.data.selectedItem;
wx.showModal({
title: '确认移除',
content: `确定要从心动名单中移除「${item.name}」吗?`,
confirmColor: '#B22222',
success: (res) => {
if (res.confirm) {
const apiBaseUrl = getApp().globalData.apiBaseUrl;
wx.request({
url: `${apiBaseUrl}/api/favorites/remove`,
method: 'POST',
data: {
openid: this.data.openid,
name: item.name
},
success: (res) => {
if (res.data && res.data.success) {
wx.showToast({ title: '已移除', icon: 'success' });
this.closeDetail();
this.loadFavorites();
}
}
});
}
}
});
},
// 下拉刷新
onPullDownRefresh() {
this.loadFavorites();
wx.stopPullDownRefresh();
}
});