This commit is contained in:
2025-08-14 14:24:36 +08:00
parent 4d3a62d185
commit f071de4ead
18 changed files with 774 additions and 3774 deletions
+70 -1
View File
@@ -162,7 +162,76 @@
</template>
<script>
import adoptionManager from '@/utils/adoptionManager.js'
// 简化的领养管理器 - 从 utils/adoptionManager.js 移入
const adoptionManager = {
storageKey: 'adoption_pets',
getAdoptionPets() {
try {
return uni.getStorageSync(this.storageKey) || []
} catch (error) {
console.error('获取领养宠物数据失败:', error)
return []
}
},
getPetById(id) {
const pets = this.getAdoptionPets()
return pets.find(pet => pet.id == id)
},
getPetTypeName(type) {
const types = {
cat: '猫咪',
dog: '狗狗',
rabbit: '兔子',
other: '其他'
}
return types[type] || '未知类型'
},
getPetBreedName(type, breed) {
const breeds = {
cat: {
'british-shorthair': '英国短毛猫',
'american-shorthair': '美国短毛猫',
'persian': '波斯猫',
'ragdoll': '布偶猫',
'siamese': '暹罗猫',
'mixed': '混血猫'
},
dog: {
'golden-retriever': '金毛寻回犬',
'labrador': '拉布拉多',
'husky': '哈士奇',
'corgi': '柯基',
'shiba-inu': '柴犬',
'mixed': '混血犬'
}
}
return breeds[type]?.[breed] || '未知品种'
},
getLocationName(province, city, district) {
const regions = {
'beijing': '北京市',
'shanghai': '上海市',
'guangdong': '广东省',
'jiangsu': '江苏省'
}
return regions[province] || province
},
getStatusInfo(status) {
const statusMap = {
available: { name: '可领养', color: '#4CAF50', icon: '✅' },
reserved: { name: '已预约', color: '#FF9800', icon: '⏰' },
adopted: { name: '已领养', color: '#9E9E9E', icon: '❤️' },
pending: { name: '审核中', color: '#2196F3', icon: '📋' }
}
return statusMap[status] || { name: '未知状态', color: '#999999', icon: '❓' }
}
}
export default {
data() {
+340 -1
View File
@@ -285,7 +285,346 @@
</template>
<script>
import adoptionManager from '@/utils/adoptionManager.js'
// 宠物领养数据管理工具类 - 从 utils/adoptionManager.js 移入
class AdoptionManager {
constructor() {
this.storageKey = 'adoption_pets'
// 宠物类型配置
this.petTypes = {
cat: {
name: '猫咪',
icon: '🐱',
breeds: {
'british-shorthair': '英国短毛猫',
'american-shorthair': '美国短毛猫',
'persian': '波斯猫',
'ragdoll': '布偶猫',
'siamese': '暹罗猫',
'maine-coon': '缅因猫',
'scottish-fold': '苏格兰折耳猫',
'russian-blue': '俄罗斯蓝猫',
'bengal': '孟加拉猫',
'mixed': '混血猫',
'unknown': '品种不明'
}
},
dog: {
name: '狗狗',
icon: '🐶',
breeds: {
'golden-retriever': '金毛寻回犬',
'labrador': '拉布拉多',
'husky': '哈士奇',
'german-shepherd': '德国牧羊犬',
'poodle': '贵宾犬',
'chihuahua': '吉娃娃',
'bulldog': '斗牛犬',
'shiba-inu': '柴犬',
'corgi': '柯基',
'border-collie': '边境牧羊犬',
'mixed': '混血犬',
'unknown': '品种不明'
}
},
rabbit: {
name: '兔子',
icon: '🐰',
breeds: {
'holland-lop': '荷兰垂耳兔',
'mini-lop': '迷你垂耳兔',
'lionhead': '狮子头兔',
'dutch': '荷兰兔',
'angora': '安哥拉兔',
'mixed': '混血兔',
'unknown': '品种不明'
}
},
other: {
name: '其他',
icon: '🐾',
breeds: {
'hamster': '仓鼠',
'guinea-pig': '豚鼠',
'bird': '鸟类',
'turtle': '乌龟',
'fish': '鱼类',
'other': '其他'
}
}
}
// 地区数据(简化版三级联动)
this.regions = {
'beijing': {
name: '北京市',
cities: {
'beijing': {
name: '北京市',
districts: {
'chaoyang': '朝阳区',
'haidian': '海淀区',
'dongcheng': '东城区',
'xicheng': '西城区',
'fengtai': '丰台区',
'shijingshan': '石景山区'
}
}
}
},
'shanghai': {
name: '上海市',
cities: {
'shanghai': {
name: '上海市',
districts: {
'huangpu': '黄浦区',
'xuhui': '徐汇区',
'changning': '长宁区',
'jingan': '静安区',
'putuo': '普陀区',
'hongkou': '虹口区'
}
}
}
},
'guangdong': {
name: '广东省',
cities: {
'guangzhou': {
name: '广州市',
districts: {
'tianhe': '天河区',
'yuexiu': '越秀区',
'liwan': '荔湾区',
'haizhu': '海珠区',
'baiyun': '白云区',
'panyu': '番禺区'
}
},
'shenzhen': {
name: '深圳市',
districts: {
'futian': '福田区',
'luohu': '罗湖区',
'nanshan': '南山区',
'yantian': '盐田区',
'baoan': '宝安区',
'longgang': '龙岗区'
}
}
}
},
'jiangsu': {
name: '江苏省',
cities: {
'nanjing': {
name: '南京市',
districts: {
'xuanwu': '玄武区',
'qinhuai': '秦淮区',
'jianye': '建邺区',
'gulou': '鼓楼区',
'pukou': '浦口区',
'qixia': '栖霞区'
}
},
'suzhou': {
name: '苏州市',
districts: {
'gusu': '姑苏区',
'wuzhong': '吴中区',
'xiangcheng': '相城区',
'kunshan': '昆山市',
'changshu': '常熟市',
'zhangjiagang': '张家港市'
}
}
}
}
}
// 领养状态
this.adoptionStatus = {
available: { name: '可领养', color: '#4CAF50', icon: '✅' },
reserved: { name: '已预约', color: '#FF9800', icon: '⏰' },
adopted: { name: '已领养', color: '#9E9E9E', icon: '❤️' },
pending: { name: '审核中', color: '#2196F3', icon: '📋' }
}
}
// 获取所有领养宠物数据
getAdoptionPets() {
try {
let pets = uni.getStorageSync(this.storageKey) || []
// 如果没有数据,初始化一些测试数据
if (pets.length === 0) {
pets = this.initializeTestData()
uni.setStorageSync(this.storageKey, pets)
}
return pets
} catch (error) {
console.error('获取领养宠物数据失败:', error)
return this.initializeTestData()
}
}
// 初始化测试数据
initializeTestData() {
const testData = []
// 猫咪数据
testData.push({
id: Date.now() + 1,
name: '小橘',
type: 'cat',
breed: 'british-shorthair',
age: 2,
gender: 'male',
photos: ['https://images.unsplash.com/photo-1574158622682-e40e69881006?w=400&h=300&fit=crop', 'https://images.unsplash.com/photo-1592194996308-7b43878e84a6?w=400&h=300&fit=crop'],
description: '小橘是一只非常温顺的英国短毛猫,性格亲人,喜欢和人互动。已经完成绝育手术和疫苗接种,身体健康。适合有爱心的家庭领养,希望能给它一个温暖的家。',
personality: ['温顺', '亲人', '安静', '乖巧'],
health: '健康良好,已绝育,疫苗齐全',
location: {
province: 'beijing',
city: 'beijing',
district: 'chaoyang',
address: '朝阳区宠物救助中心'
},
status: 'available',
requirements: [
'有稳定收入',
'有养猫经验',
'家中无其他宠物',
'同意定期回访'
],
contact: {
name: '北京爱心救助站',
phone: '138****1234',
wechat: 'rescue_station_bj',
type: 'organization'
},
publishTime: new Date(Date.now() - 2 * 24 * 60 * 60 * 1000).toISOString()
})
// 更多测试数据...
return testData
}
// 搜索宠物
searchPets(keyword, pets = null) {
if (!pets) {
pets = this.getAdoptionPets()
}
if (!keyword) return pets
const lowerKeyword = keyword.toLowerCase()
return pets.filter(pet => {
return pet.name.toLowerCase().includes(lowerKeyword) ||
pet.description.toLowerCase().includes(lowerKeyword) ||
this.getPetTypeName(pet.type).includes(keyword) ||
this.getPetBreedName(pet.type, pet.breed).includes(keyword) ||
pet.personality.some(trait => trait.includes(keyword))
})
}
// 筛选宠物
filterPets(filters, pets = null) {
if (!pets) {
pets = this.getAdoptionPets()
}
return pets.filter(pet => {
// 宠物类型筛选
if (filters.type && pet.type !== filters.type) {
return false
}
// 品种筛选
if (filters.breed && pet.breed !== filters.breed) {
return false
}
// 地区筛选
if (filters.province && pet.location.province !== filters.province) {
return false
}
if (filters.city && pet.location.city !== filters.city) {
return false
}
if (filters.district && pet.location.district !== filters.district) {
return false
}
// 状态筛选
if (filters.status && pet.status !== filters.status) {
return false
}
// 性别筛选
if (filters.gender && pet.gender !== filters.gender) {
return false
}
// 年龄筛选
if (filters.ageRange) {
const [minAge, maxAge] = filters.ageRange
if (pet.age < minAge || pet.age > maxAge) {
return false
}
}
return true
})
}
// 获取宠物类型名称
getPetTypeName(type) {
return this.petTypes[type]?.name || '未知类型'
}
// 获取宠物品种名称
getPetBreedName(type, breed) {
return this.petTypes[type]?.breeds[breed] || '未知品种'
}
// 获取地区名称
getLocationName(province, city = null, district = null) {
let locationName = this.regions[province]?.name || province
if (city) {
const cityName = this.regions[province]?.cities[city]?.name
if (cityName) {
locationName += ' ' + cityName
}
}
if (district) {
const districtName = this.regions[province]?.cities[city]?.districts[district]
if (districtName) {
locationName += ' ' + districtName
}
}
return locationName
}
// 获取状态信息
getStatusInfo(status) {
return this.adoptionStatus[status] || {
name: '未知状态',
color: '#999999',
icon: '❓'
}
}
}
const adoptionManager = new AdoptionManager()
export default {
data() {