优化,完善代码

This commit is contained in:
2026-05-14 14:42:51 +08:00
parent 79a21ff0a5
commit 16c91facac
26 changed files with 1792 additions and 1322 deletions

View File

@@ -54,6 +54,9 @@
<u-icon name="arrow-right" size="32" color="#ccc"></u-icon>
</view>
</view>
<!-- 加载更多组件 -->
<u-loadmore :status="loadStatus" />
</view>
<view v-else class="empty">
@@ -70,8 +73,8 @@
pageNo: 1,
pageSize:10,
flowList: [],
loadStatus: 'loadmore',
activeTab: '收', // 默认显示“收”
loadStatus: 'more', // ✅ 修复为官方正确值
activeTab: '收',
tabs: [{
label: '收入',
value: '支'
@@ -81,7 +84,6 @@
value: '收'
},
],
// 年份筛选相关
currentYear: null,
years: [],
showYearPicker: false
@@ -99,6 +101,7 @@
onShow() {
this.$checkToken(this.$getToken())
},
// ✅ 删除和 scroll-view 冲突的 onReachBottom
watch: {
activeTab(newVal, oldVal) {
if (newVal !== oldVal) {
@@ -106,16 +109,16 @@
}
}
},
computed: {
},
methods: {
onTabClick(val) {
this.activeTab = val
this.resetAndLoad()
},
fetchPayRecord() {
if (this.loadStatus !== 'loadmore') return;
this.loadStatus = 'loading';
// ✅ 正确判断加载状态
if (this.loadStatus !== 'more') return;
this.loadStatus = 'loading';
let url = '/bill/pageQueryPayRecord'
this.$u.post(url, {
pageNo: this.pageNo,
@@ -128,22 +131,21 @@
const rows = res.data.result || [];
if (this.pageNo === 1) this.flowList = [];
this.flowList = this.flowList.concat(rows);
if (rows.length < this.pageSize) {
this.loadStatus = 'nomore';
} else {
this.pageNo++;
this.loadStatus = 'loadmore';
this.loadStatus = 'more';
}
}).catch(err => {
console.log("获取账单记录失败:", err)
this.loadStatus = 'loadmore';
this.loadStatus = 'more'; // ✅ 异常恢复
})
},
// 切换年份选择器显示
toggleYearPicker() {
this.showYearPicker = !this.showYearPicker;
},
// 选择年份
selectYear(year) {
this.currentYear = year;
this.showYearPicker = false;
@@ -154,21 +156,19 @@
return '¥' + Number(val).toFixed(2);
},
resetAndLoad(){
// 重新加载数据
this.loadStatus = 'loadmore';
this.loadStatus = 'more';
this.pageNo = 1;
this.flowList = [];
this.fetchPayRecord();
},
loadMore() {
// 只有在 loadStatus 为 'loadmore' 时才触发
if (this.loadStatus !== 'loadmore') return;
// 调用接口获取下一页
if (this.loadStatus !== 'more') return;
this.fetchPayRecord();
},
goDetail(item) {
},
},
}
};
</script>
@@ -177,159 +177,167 @@
background: #f8f8f8;
min-height: 100vh;
padding-top: 175rpx;
.filter-bar {
box-sizing: border-box;
}
.filter-bar {
display: flex;
justify-content: space-between;
align-items: center;
background: #fff;
padding: 24rpx 30rpx;
margin: 20rpx;
margin-bottom: 0;
border-radius: 12rpx;
box-shadow: 0 2rpx 6rpx rgba(0, 0, 0, 0.05);
}
/* 年份筛选 */
.year-filter {
display: flex;
align-items: center;
gap: 8rpx;
font-size: 32rpx;
color: #333;
cursor: pointer;
}
/* 支出/收入切换 */
.tab-bar {
display: flex;
gap: 20rpx;
}
.tab-item {
padding: 12rpx 32rpx;
font-size: 28rpx;
border-radius: 24rpx;
color: #333;
background-color: #f5f5f5;
transition: all 0.2s ease;
&.active {
color: #fff;
background: #ff3b30;
}
}
/* 自定义年份选择器样式 */
.year-picker-popup {
background: #fff;
padding: 30rpx 0;
}
.popup-header {
text-align: center;
padding: 20rpx 0;
border-bottom: 1rpx solid #f0f0f0;
}
.popup-title {
font-size: 34rpx;
font-weight: 600;
color: #333;
}
.year-list {
padding: 20rpx;
}
.year-item {
font-size: 32rpx;
color: #666;
text-align: center;
padding: 24rpx;
border-radius: 12rpx;
margin-bottom: 16rpx;
background: #f5f5f5;
transition: all 0.2s ease;
&:last-child {
margin-bottom: 0;
}
&.active {
background: #ff3b30;
color: #fff;
}
&:hover {
background: #ff5252;
color: #fff;
}
}
/* ✅ 正确的滚动高度 */
.scroll-content {
height: calc(100vh - 175rpx - 120rpx);
box-sizing: border-box;
}
.record-list {
padding: 20rpx;
.record-item {
display: flex;
justify-content: space-between;
align-items: center;
background: #fff;
padding: 24rpx 30rpx;
margin: 20rpx;
margin-bottom: 0;
border-radius: 12rpx;
box-shadow: 0 2rpx 6rpx rgba(0, 0, 0, 0.05);
}
/* 年份筛选 */
.year-filter {
display: flex;
align-items: center;
gap: 8rpx;
font-size: 32rpx;
color: #333;
cursor: pointer;
}
/* 支出/收入切换 */
.tab-bar {
display: flex;
gap: 20rpx;
}
.tab-item {
padding: 12rpx 32rpx;
font-size: 28rpx;
border-radius: 24rpx;
color: #333;
background-color: #f5f5f5;
transition: all 0.2s ease;
&.active {
color: #fff;
background: #ff3b30;
}
}
/* 自定义年份选择器样式 */
.year-picker-popup {
background: #fff;
padding: 30rpx 0;
}
.popup-header {
text-align: center;
padding: 20rpx 0;
border-bottom: 1rpx solid #f0f0f0;
}
.popup-title {
font-size: 34rpx;
font-weight: 600;
color: #333;
}
.year-list {
border-radius: 16rpx;
margin-bottom: 20rpx;
padding: 20rpx;
}
.year-item {
font-size: 32rpx;
color: #666;
text-align: center;
padding: 24rpx;
border-radius: 12rpx;
margin-bottom: 16rpx;
background: #f5f5f5;
transition: all 0.2s ease;
&:last-child {
margin-bottom: 0;
}
&.active {
background: #ff3b30;
color: #fff;
}
&:hover {
background: #ff5252;
color: #fff;
}
}
box-shadow: 0 2rpx 6rpx rgba(0, 0, 0, 0.03);
.record-list {
padding: 20rpx;
.left {
flex: 1;
.record-item {
.title {
font-size: 28rpx;
font-weight:5600;
color: #2D2B2C;
}
.sub {
font-size: 24rpx;
color: #86868C;
margin-top: 18rpx;
}
.status {
font-size: 28rpx;
&.paid {
color: #73B936;
}
&.unpaid {
color: #F34038;
}
}
}
.right {
display: flex;
justify-content: space-between;
align-items: center;
background: #fff;
border-radius: 16rpx;
margin-bottom: 20rpx;
padding: 20rpx;
box-shadow: 0 2rpx 6rpx rgba(0, 0, 0, 0.03);
.left {
flex: 1;
.amount {
font-size: 28rpx;
font-weight: 500;
margin-right: 10rpx;
.title {
font-size: 28rpx;
font-weight:5600;
color: #2D2B2C;
&.income {
color: #73B936;
}
.sub {
font-size: 24rpx;
color: #86868C;
margin-top: 18rpx;
}
.status {
font-size: 28rpx;
&.paid {
color: #73B936;
}
&.unpaid {
color: #F34038;
}
}
}
.right {
display: flex;
align-items: center;
.amount {
font-size: 28rpx;
font-weight: 500;
margin-right: 10rpx;
&.income {
color: #73B936;
}
&.expense {
color: #F34038;
}
&.expense {
color: #F34038;
}
}
}
}
.empty {
margin-top: 100rpx;
}
}
.empty {
margin-top: 100rpx;
}
</style>