| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- <template>
- <view class="pet-list-page">
- <!-- 顶部操作栏 -->
- <view class="action-bar">
- <view class="search-box">
- <uni-icons type="search" size="14" color="#999"></uni-icons>
- <input type="text" placeholder="搜索宠物名/主人" class="search-input" />
- </view>
- <button size="mini" class="add-btn" @click="goToAdd">+ 新增档案</button>
- </view>
- <!-- 宠物档案卡片列表 -->
- <view class="list-container">
- <view class="pet-card" v-for="pet in pets" :key="pet.id" @click="handleCardClick(pet)">
- <image :src="pet.avatar" class="pet-photo" mode="aspectFill"></image>
- <view class="card-info">
- <view class="info-top">
- <text class="pet-name">{{ pet.name }}</text>
- <text class="owner-name">{{ pet.ownerName }}</text>
- </view>
- <text class="pet-meta">{{ pet.breed }} · {{ pet.age }}</text>
- <view class="health-overview">
- <text class="health-badge">{{ pet.health }}</text>
- <text class="vaccine-info">疫苗: {{ pet.vaccine }}</text>
- </view>
- <view class="card-footer">
- <view class="action-btn-group">
- <text class="btn-item detail" @click.stop="goToDetail(pet)">详情</text>
- <text class="btn-item edit" @click.stop="goToEdit(pet)">编辑</text>
- <text class="btn-item delete" @click.stop="onDelete(pet)">删除</text>
- </view>
- </view>
- </view>
- </view>
- </view>
- </view>
- </template>
- <script setup>
- import { ref } from 'vue'
- import petMockData from '@/mock/pet.json'
- const goToAdd = () => uni.navigateTo({ url: '/pages/my/pet/add/index' })
- const goToDetail = (pet) => uni.navigateTo({ url: '/pages/my/pet/detail/index' })
- const goToEdit = (pet) => uni.navigateTo({ url: '/pages/my/pet/edit/index' })
- const handleCardClick = (pet) => {
- goToEdit(pet)
- }
- const onDelete = (pet) => {
- uni.showModal({
- title: '确认删除',
- content: `确定要删除宠物档案 [${pet.name}] 吗?`,
- success: (res) => {
- if (res.confirm) {
- pets.value = pets.value.filter(item => item.id !== pet.id)
- uni.showToast({ title: '删除成功', icon: 'success' })
- }
- }
- })
- }
- const pets = ref(petMockData.map(p => ({
- id: p.id, name: p.name, breed: p.breed, age: p.age,
- ownerName: p.ownerName, health: p.health, vaccine: p.vaccine, avatar: p.avatar
- })))
- </script>
- <style lang="scss" scoped>
- /* 此部分与原文件保持一致 */
- .pet-list-page {
- min-height: 100vh;
- background-color: #f2f2f2;
- padding-bottom: 40rpx;
- }
- .action-bar {
- display: flex;
- align-items: center;
- padding: 20rpx 24rpx;
- background-color: #fff;
- gap: 16rpx;
- }
- .search-box {
- flex: 1;
- display: flex;
- align-items: center;
- background: #f5f5f5;
- border-radius: 32rpx;
- padding: 12rpx 20rpx;
- gap: 12rpx;
- }
- .search-input {
- flex: 1;
- font-size: 26rpx;
- background: transparent;
- }
- .add-btn {
- font-size: 24rpx;
- font-weight: bold;
- background: linear-gradient(90deg, #ffd53f, #ff9500);
- color: #333;
- border: none;
- border-radius: 32rpx;
- padding: 12rpx 28rpx;
- white-space: nowrap;
- }
- .list-container {
- padding: 24rpx;
- }
- .pet-card {
- display: flex;
- background: #fff;
- border-radius: 24rpx;
- overflow: hidden;
- margin-bottom: 24rpx;
- box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.04);
- }
- .pet-photo {
- width: 210rpx;
- height: 280rpx;
- flex-shrink: 0;
- }
- .card-info {
- flex: 1;
- padding: 24rpx;
- display: flex;
- flex-direction: column;
- }
- .info-top {
- display: flex;
- justify-content: space-between;
- align-items: center;
- margin-bottom: 8rpx;
- }
- .pet-name {
- font-size: 34rpx;
- font-weight: 800;
- color: #333;
- }
- .owner-name {
- font-size: 24rpx;
- color: #999;
- }
- .pet-meta {
- font-size: 26rpx;
- color: #666;
- margin-bottom: 16rpx;
- }
- .health-overview {
- display: flex;
- align-items: center;
- gap: 16rpx;
- margin-bottom: 20rpx;
- }
- .health-badge {
- font-size: 22rpx;
- color: #2e7d32;
- background: #e8f5e9;
- padding: 4rpx 16rpx;
- border-radius: 8rpx;
- }
- .vaccine-info {
- font-size: 22rpx;
- color: #795548;
- background: #efebe9;
- padding: 4rpx 16rpx;
- border-radius: 8rpx;
- }
- .card-footer {
- margin-top: auto;
- border-top: 1rpx solid #f8f8f8;
- padding-top: 16rpx;
- }
- .action-btn-group {
- display: flex;
- justify-content: flex-end;
- gap: 16rpx;
- }
- .btn-item {
- font-size: 24rpx;
- padding: 8rpx 20rpx;
- border-radius: 12rpx;
- border: 1rpx solid #eee;
- color: #666;
- }
- .btn-item.detail {
- background: #fdf6ec;
- border-color: #faecd8;
- color: #e6a23c;
- }
- .btn-item.delete {
- color: #f56c6c;
- border-color: #fde2e2;
- background: #fef0f0;
- }
- </style>
|