241 lines
7.4 KiB
JavaScript
241 lines
7.4 KiB
JavaScript
Page({
|
||
data: {
|
||
currentVisibility: '',
|
||
selectedTags: [], // 选中的标签列表
|
||
selectedTagsFriendsCount: 0, // 标签里的好友数量
|
||
selectedTagsDisplayText: '', // 标签显示文本
|
||
selectedFriends: [], // 选中的好友列表
|
||
selectedFriendsCount: 0, // 选中的好友数量
|
||
selectedFriendsDisplayText: '', // 选中的好友显示文本
|
||
excludeTags: [], // 排除的标签列表
|
||
excludeTagsFriendsCount: 0, // 排除标签里的好友数量
|
||
excludeTagsDisplayText: '', // 排除标签显示文本
|
||
excludeFriends: [], // 排除的好友列表
|
||
excludeFriendsCount: 0, // 排除的好友数量
|
||
excludeFriendsDisplayText: '' // 排除的好友显示文本
|
||
},
|
||
|
||
onLoad(options) {
|
||
let visibility = options.currentVisibility || '';
|
||
|
||
// 如果当前选中的是隐藏的选项,重置为公开
|
||
if (visibility === 'friends_only' || visibility === 'partial_visible' || visibility === 'exclude_friends') {
|
||
visibility = 'public';
|
||
}
|
||
|
||
if (visibility) {
|
||
this.setData({
|
||
currentVisibility: visibility
|
||
});
|
||
}
|
||
},
|
||
|
||
onShow() {
|
||
// 从标签或好友选择页面返回时,更新数据
|
||
// 这里可以通过全局变量或事件总线来获取更新的数据
|
||
// TODO: 实现从选择页面返回时的数据同步
|
||
},
|
||
|
||
// 加载部分可见的数据
|
||
loadPartialVisibleData() {
|
||
// TODO: 从上一页获取已选中的标签和好友
|
||
// 暂时使用空数据
|
||
this.setData({
|
||
selectedTags: [],
|
||
selectedTagsFriendsCount: 0,
|
||
selectedFriends: [],
|
||
selectedFriendsCount: 0
|
||
});
|
||
},
|
||
|
||
// 选择标签
|
||
selectTags() {
|
||
const selectedTagsStr = encodeURIComponent(JSON.stringify(this.data.selectedTags || []));
|
||
wx.navigateTo({
|
||
url: `/subpackages/social/tag-friends/tag-friends?selectedTags=${selectedTagsStr}&mode=partial_visible`,
|
||
success: (res) => {
|
||
console.log('跳转到标签选择页面成功');
|
||
},
|
||
fail: (err) => {
|
||
console.error('跳转失败:', err);
|
||
wx.showToast({
|
||
title: '跳转失败',
|
||
icon: 'none'
|
||
});
|
||
}
|
||
});
|
||
},
|
||
|
||
// 选择好友
|
||
selectFriends() {
|
||
const selectedFriendsStr = encodeURIComponent(JSON.stringify(this.data.selectedFriends || []));
|
||
wx.navigateTo({
|
||
url: `/subpackages/social/friend-selector/friend-selector?selectedFriends=${selectedFriendsStr}&mode=partial_visible`,
|
||
success: (res) => {
|
||
console.log('跳转到好友选择页面成功');
|
||
},
|
||
fail: (err) => {
|
||
console.error('跳转失败:', err);
|
||
wx.showToast({
|
||
title: '跳转失败',
|
||
icon: 'none'
|
||
});
|
||
}
|
||
});
|
||
},
|
||
|
||
// 更新标签数据(从标签选择页面返回时调用)
|
||
updateSelectedTags(tags, friendsCount, displayText) {
|
||
this.setData({
|
||
selectedTags: tags,
|
||
selectedTagsFriendsCount: friendsCount,
|
||
selectedTagsDisplayText: displayText || ''
|
||
});
|
||
},
|
||
|
||
// 更新好友数据(从好友选择页面返回时调用)
|
||
updateSelectedFriends(friends, friendsCount, displayText) {
|
||
this.setData({
|
||
selectedFriends: friends,
|
||
selectedFriendsCount: friendsCount,
|
||
selectedFriendsDisplayText: displayText || ''
|
||
});
|
||
},
|
||
|
||
// 加载不给谁看的数据
|
||
loadExcludeFriendsData() {
|
||
// TODO: 从上一页获取已选中的排除标签和好友
|
||
// 暂时使用空数据
|
||
this.setData({
|
||
excludeTags: [],
|
||
excludeTagsFriendsCount: 0,
|
||
excludeFriends: [],
|
||
excludeFriendsCount: 0
|
||
});
|
||
},
|
||
|
||
// 选择排除标签
|
||
selectExcludeTags() {
|
||
const excludeTagsStr = encodeURIComponent(JSON.stringify(this.data.excludeTags || []));
|
||
wx.navigateTo({
|
||
url: `/subpackages/social/tag-friends/tag-friends?selectedTags=${excludeTagsStr}&mode=exclude_friends`,
|
||
success: (res) => {
|
||
console.log('跳转到排除标签选择页面成功');
|
||
},
|
||
fail: (err) => {
|
||
console.error('跳转失败:', err);
|
||
wx.showToast({
|
||
title: '跳转失败',
|
||
icon: 'none'
|
||
});
|
||
}
|
||
});
|
||
},
|
||
|
||
// 选择排除好友
|
||
selectExcludeFriends() {
|
||
const excludeFriendsStr = encodeURIComponent(JSON.stringify(this.data.excludeFriends || []));
|
||
wx.navigateTo({
|
||
url: `/subpackages/social/friend-selector/friend-selector?selectedFriends=${excludeFriendsStr}&mode=exclude_friends`,
|
||
success: (res) => {
|
||
console.log('跳转到排除好友选择页面成功');
|
||
},
|
||
fail: (err) => {
|
||
console.error('跳转失败:', err);
|
||
wx.showToast({
|
||
title: '跳转失败',
|
||
icon: 'none'
|
||
});
|
||
}
|
||
});
|
||
},
|
||
|
||
// 更新排除标签数据(从标签选择页面返回时调用)
|
||
updateExcludeTags(tags, friendsCount, displayText) {
|
||
this.setData({
|
||
excludeTags: tags,
|
||
excludeTagsFriendsCount: friendsCount,
|
||
excludeTagsDisplayText: displayText || ''
|
||
});
|
||
},
|
||
|
||
// 更新排除好友数据(从好友选择页面返回时调用)
|
||
updateExcludeFriends(friends, friendsCount, displayText) {
|
||
this.setData({
|
||
excludeFriends: friends,
|
||
excludeFriendsCount: friendsCount,
|
||
excludeFriendsDisplayText: displayText || ''
|
||
});
|
||
},
|
||
|
||
// 选择可见性选项
|
||
selectVisibility(e) {
|
||
const type = e.currentTarget.dataset.type;
|
||
|
||
// 禁止选择隐藏的选项
|
||
if (type === 'friends_only' || type === 'partial_visible' || type === 'exclude_friends') {
|
||
return;
|
||
}
|
||
|
||
this.setData({
|
||
currentVisibility: type
|
||
});
|
||
},
|
||
|
||
// 完成选择
|
||
completeSelection() {
|
||
// 获取当前选择的可见性状态
|
||
const { currentVisibility, selectedTags, selectedFriends, excludeTags, excludeFriends } = this.data;
|
||
|
||
console.log('completeSelection 被调用,currentVisibility:', currentVisibility);
|
||
|
||
// 检查是否选择了可见性
|
||
if (!currentVisibility || currentVisibility.trim() === '') {
|
||
wx.showToast({
|
||
title: '请选择可见性',
|
||
icon: 'none'
|
||
});
|
||
return;
|
||
}
|
||
|
||
const pages = getCurrentPages();
|
||
const prevPage = pages[pages.length - 2];
|
||
|
||
console.log('上一页是否存在:', !!prevPage);
|
||
console.log('updateVisibility 方法是否存在:', prevPage && typeof prevPage.updateVisibility === 'function');
|
||
|
||
if (prevPage && typeof prevPage.updateVisibility === 'function') {
|
||
// 如果是部分可见,传递标签和好友数据
|
||
if (currentVisibility === 'partial_visible') {
|
||
console.log('传递部分可见数据');
|
||
prevPage.updateVisibility(currentVisibility, {
|
||
selectedTags: selectedTags,
|
||
selectedFriends: selectedFriends
|
||
});
|
||
} else if (currentVisibility === 'exclude_friends') {
|
||
// 如果是不给谁看,传递排除标签和好友数据
|
||
console.log('传递排除好友数据');
|
||
prevPage.updateVisibility(currentVisibility, {
|
||
excludeTags: excludeTags,
|
||
excludeFriends: excludeFriends
|
||
});
|
||
} else {
|
||
console.log('传递普通可见性:', currentVisibility);
|
||
prevPage.updateVisibility(currentVisibility);
|
||
}
|
||
|
||
// 延迟返回,确保 updateVisibility 执行完成
|
||
setTimeout(() => {
|
||
console.log('准备返回上一页');
|
||
wx.navigateBack();
|
||
}, 100);
|
||
} else {
|
||
console.error('无法获取上一页或 updateVisibility 方法不存在');
|
||
// 如果无法获取上一页,直接返回
|
||
wx.navigateBack();
|
||
}
|
||
},
|
||
navigateBack() {
|
||
wx.navigateBack();
|
||
}
|
||
});
|