129 lines
3.5 KiB
JavaScript
129 lines
3.5 KiB
JavaScript
/**
|
|
* Search utility functions
|
|
* Requirements: 11.1, 11.2, 11.3, 11.4
|
|
*/
|
|
|
|
/**
|
|
* Determines the display state for search results based on member status
|
|
* Property 20: Search Results Display
|
|
* *For any* search result display, non-member users SHALL see results with blur overlay,
|
|
* while member users SHALL see full results.
|
|
* **Validates: Requirements 11.3, 11.4**
|
|
*
|
|
* @param {boolean} isMember - Whether the current user is a member
|
|
* @param {Array} results - The search results array
|
|
* @returns {Object} Display state object
|
|
*/
|
|
export function getSearchResultsDisplayState(isMember, results) {
|
|
const hasResults = Array.isArray(results) && results.length > 0
|
|
|
|
return {
|
|
// Whether to show the blur overlay on results
|
|
showBlurOverlay: !isMember && hasResults,
|
|
// Whether to show full results without blur
|
|
showFullResults: isMember && hasResults,
|
|
// Whether results can be clicked/interacted with
|
|
canInteract: isMember,
|
|
// Whether to show the member prompt
|
|
showMemberPrompt: !isMember && hasResults,
|
|
// Whether there are results to display
|
|
hasResults: hasResults
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Determines if a user can view a search result detail
|
|
* Property 20: Search Results Display
|
|
* **Validates: Requirements 11.3, 11.4**
|
|
*
|
|
* @param {boolean} isMember - Whether the current user is a member
|
|
* @returns {Object} Access state object
|
|
*/
|
|
export function getSearchResultAccessState(isMember) {
|
|
return {
|
|
// Whether the user can view profile details
|
|
canViewDetail: isMember,
|
|
// Whether the user can contact the result user
|
|
canContact: isMember,
|
|
// Message to show if access is denied
|
|
accessDeniedMessage: isMember ? null : '开通会员查看完整信息'
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Builds search parameters from filter state
|
|
* Property 19: Search Parameters
|
|
* **Validates: Requirements 11.2**
|
|
*
|
|
* @param {Object} filters - The filter state object
|
|
* @param {number} pageIndex - Current page index
|
|
* @param {number} pageSize - Page size
|
|
* @returns {Object} Search parameters for API call
|
|
*/
|
|
export function buildSearchParams(filters, pageIndex = 1, pageSize = 10) {
|
|
const params = {
|
|
pageIndex,
|
|
pageSize
|
|
}
|
|
|
|
// Age range
|
|
if (filters.ageMin > 0) {
|
|
params.ageMin = filters.ageMin
|
|
}
|
|
if (filters.ageMax > 0) {
|
|
params.ageMax = filters.ageMax
|
|
}
|
|
|
|
// Height range
|
|
if (filters.heightMin > 0) {
|
|
params.heightMin = filters.heightMin
|
|
}
|
|
if (filters.heightMax > 0) {
|
|
params.heightMax = filters.heightMax
|
|
}
|
|
|
|
// Education
|
|
if (Array.isArray(filters.education) && filters.education.length > 0) {
|
|
params.education = filters.education
|
|
}
|
|
|
|
// Location
|
|
if (filters.province) {
|
|
params.province = filters.province
|
|
}
|
|
if (filters.city) {
|
|
params.city = filters.city
|
|
}
|
|
|
|
// Monthly income
|
|
if (filters.monthlyIncomeMin > 0) {
|
|
params.monthlyIncomeMin = filters.monthlyIncomeMin
|
|
}
|
|
if (filters.monthlyIncomeMax > 0) {
|
|
params.monthlyIncomeMax = filters.monthlyIncomeMax
|
|
}
|
|
|
|
// House status
|
|
if (Array.isArray(filters.houseStatus) && filters.houseStatus.length > 0) {
|
|
params.houseStatus = filters.houseStatus
|
|
}
|
|
|
|
// Car status
|
|
if (Array.isArray(filters.carStatus) && filters.carStatus.length > 0) {
|
|
params.carStatus = filters.carStatus
|
|
}
|
|
|
|
// Marriage status
|
|
if (Array.isArray(filters.marriageStatus) && filters.marriageStatus.length > 0) {
|
|
params.marriageStatus = filters.marriageStatus
|
|
}
|
|
|
|
return params
|
|
}
|
|
|
|
export default {
|
|
getSearchResultsDisplayState,
|
|
getSearchResultAccessState,
|
|
buildSearchParams
|
|
}
|