修改小程序

This commit is contained in:
2025-10-17 17:29:11 +08:00
parent 434fa135d1
commit 212dffd0da
227 changed files with 12887 additions and 45341 deletions

View File

@@ -0,0 +1,125 @@
// pages/farmers/farmers.js
Page({
data: {
farmers: [],
loading: false,
searchKeyword: '',
currentPage: 1,
pageSize: 10,
total: 0
},
onLoad: function (options) {
this.checkLoginStatus();
this.loadFarmers();
},
onShow: function () {
this.loadFarmers();
},
checkLoginStatus: function() {
const token = wx.getStorageSync('token');
if (!token) {
wx.reLaunch({
url: '/pages/login/login'
});
return false;
}
return true;
},
loadFarmers: function() {
if (!this.checkLoginStatus()) return;
this.setData({
loading: true
});
// 模拟数据
const mockFarmers = [
{
id: 1,
name: '张三',
phone: '13800138001',
address: '宁夏银川市兴庆区',
farmName: '张三养殖场',
animalCount: 120,
status: 'active'
},
{
id: 2,
name: '李四',
phone: '13800138002',
address: '宁夏银川市金凤区',
farmName: '李四牧场',
animalCount: 85,
status: 'active'
},
{
id: 3,
name: '王五',
phone: '13800138003',
address: '宁夏银川市西夏区',
farmName: '王五养殖合作社',
animalCount: 200,
status: 'inactive'
}
];
setTimeout(() => {
this.setData({
farmers: mockFarmers,
loading: false,
total: mockFarmers.length
});
}, 500);
},
onSearchInput: function(e) {
this.setData({
searchKeyword: e.detail.value
});
},
onSearch: function() {
this.loadFarmers();
},
onFarmerTap: function(e) {
const farmerId = e.currentTarget.dataset.id;
wx.navigateTo({
url: `/pages/farmer/detail/detail?id=${farmerId}`
});
},
onAddFarmer: function() {
wx.navigateTo({
url: '/pages/farmer/add/add'
});
},
onPullDownRefresh: function() {
this.loadFarmers();
wx.stopPullDownRefresh();
},
onReachBottom: function() {
// 加载更多数据
if (this.data.farmers.length < this.data.total) {
this.loadMoreFarmers();
}
},
loadMoreFarmers: function() {
// 实现分页加载
console.log('加载更多养殖户数据');
},
onShareAppMessage: function() {
return {
title: '养殖户管理',
path: '/pages/farmers/farmers'
};
}
});

View File

@@ -0,0 +1,8 @@
{
"navigationBarTitleText": "养殖户管理",
"navigationBarBackgroundColor": "#7CB342",
"navigationBarTextStyle": "white",
"backgroundColor": "#f5f5f5",
"enablePullDownRefresh": true,
"onReachBottomDistance": 50
}

View File

@@ -0,0 +1,80 @@
<!--pages/farmers/farmers.wxml-->
<view class="container">
<!-- 顶部搜索栏 -->
<view class="search-bar">
<view class="search-input-wrapper">
<input
class="search-input"
placeholder="搜索养殖户姓名或农场名称"
value="{{searchKeyword}}"
bindinput="onSearchInput"
bindconfirm="onSearch"
/>
<view class="search-btn" bindtap="onSearch">
<text class="search-icon">🔍</text>
</view>
</view>
<view class="add-btn" bindtap="onAddFarmer">
<text class="add-icon">+</text>
<text class="add-text">新增</text>
</view>
</view>
<!-- 养殖户列表 -->
<view class="farmers-list">
<view
class="farmer-item"
wx:for="{{farmers}}"
wx:key="id"
data-id="{{item.id}}"
bindtap="onFarmerTap"
>
<view class="farmer-avatar">
<text class="avatar-text">{{item.name.charAt(0)}}</text>
</view>
<view class="farmer-info">
<view class="farmer-header">
<text class="farmer-name">{{item.name}}</text>
<view class="farmer-status {{item.status}}">
<text class="status-text">{{item.status === 'active' ? '正常' : '停用'}}</text>
</view>
</view>
<view class="farmer-details">
<view class="detail-item">
<text class="detail-label">农场:</text>
<text class="detail-value">{{item.farmName}}</text>
</view>
<view class="detail-item">
<text class="detail-label">电话:</text>
<text class="detail-value">{{item.phone}}</text>
</view>
<view class="detail-item">
<text class="detail-label">地址:</text>
<text class="detail-value">{{item.address}}</text>
</view>
<view class="detail-item">
<text class="detail-label">牲畜数量:</text>
<text class="detail-value animal-count">{{item.animalCount}}头</text>
</view>
</view>
</view>
<view class="farmer-arrow">
<text class="arrow-icon">></text>
</view>
</view>
</view>
<!-- 加载状态 -->
<view class="loading" wx:if="{{loading}}">
<text class="loading-text">加载中...</text>
</view>
<!-- 空状态 -->
<view class="empty-state" wx:if="{{!loading && farmers.length === 0}}">
<text class="empty-icon">📋</text>
<text class="empty-text">暂无养殖户数据</text>
<view class="empty-btn" bindtap="onAddFarmer">
<text>添加养殖户</text>
</view>
</view>
</view>

View File

@@ -0,0 +1,220 @@
/* pages/farmers/farmers.wxss */
.container {
min-height: 100vh;
background-color: #f5f5f5;
padding: 0;
}
/* 搜索栏样式 */
.search-bar {
display: flex;
align-items: center;
background-color: #ffffff;
padding: 20rpx 30rpx;
box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
gap: 20rpx;
}
.search-input-wrapper {
flex: 1;
display: flex;
align-items: center;
background-color: #f8f8f8;
border-radius: 25rpx;
padding: 0 20rpx;
height: 70rpx;
}
.search-input {
flex: 1;
font-size: 28rpx;
color: #333333;
height: 100%;
}
.search-btn {
width: 60rpx;
height: 60rpx;
display: flex;
align-items: center;
justify-content: center;
background-color: #7CB342;
border-radius: 50%;
margin-left: 10rpx;
}
.search-icon {
color: white;
font-size: 24rpx;
}
.add-btn {
display: flex;
align-items: center;
background-color: #7CB342;
color: white;
padding: 15rpx 25rpx;
border-radius: 35rpx;
gap: 8rpx;
}
.add-icon {
font-size: 28rpx;
font-weight: bold;
}
.add-text {
font-size: 26rpx;
}
/* 养殖户列表样式 */
.farmers-list {
padding: 20rpx;
}
.farmer-item {
display: flex;
align-items: center;
background-color: #ffffff;
border-radius: 12rpx;
padding: 25rpx;
margin-bottom: 20rpx;
box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.1);
gap: 20rpx;
}
.farmer-avatar {
width: 80rpx;
height: 80rpx;
background-color: #7CB342;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
}
.avatar-text {
color: white;
font-size: 32rpx;
font-weight: bold;
}
.farmer-info {
flex: 1;
min-width: 0;
}
.farmer-header {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 15rpx;
}
.farmer-name {
font-size: 32rpx;
font-weight: 500;
color: #333333;
}
.farmer-status {
padding: 6rpx 16rpx;
border-radius: 20rpx;
font-size: 22rpx;
}
.farmer-status.active {
background-color: #e8f5e8;
color: #4CAF50;
}
.farmer-status.inactive {
background-color: #ffeaea;
color: #f44336;
}
.farmer-details {
display: flex;
flex-direction: column;
gap: 8rpx;
}
.detail-item {
display: flex;
align-items: center;
font-size: 24rpx;
}
.detail-label {
color: #666666;
width: 120rpx;
flex-shrink: 0;
}
.detail-value {
color: #333333;
flex: 1;
}
.animal-count {
color: #7CB342;
font-weight: 500;
}
.farmer-arrow {
width: 30rpx;
height: 30rpx;
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
}
.arrow-icon {
color: #cccccc;
font-size: 24rpx;
}
/* 加载状态 */
.loading {
display: flex;
justify-content: center;
align-items: center;
padding: 40rpx;
}
.loading-text {
color: #999999;
font-size: 28rpx;
}
/* 空状态 */
.empty-state {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 100rpx 40rpx;
text-align: center;
}
.empty-icon {
font-size: 120rpx;
margin-bottom: 30rpx;
opacity: 0.5;
}
.empty-text {
color: #999999;
font-size: 28rpx;
margin-bottom: 40rpx;
}
.empty-btn {
background-color: #7CB342;
color: white;
padding: 20rpx 40rpx;
border-radius: 25rpx;
font-size: 28rpx;
}