refactor(app): 移除分类和详情模块,新增云开发测试页

- 从项目中删除分类页及相关代码和样式文件
- 从项目中删除详情页及相关代码和样式文件
- 首页简化为欢迎界面并添加跳转云开发测试页入口
- 更新自定义底部栏移除分类入口
- 更新app.js初始化云开发环境
- 修改app.json移除分类页面配置
- 调整首页样式和交互,提高简洁度
- 配置云函数目录路径cloudfunctionRoot为cloudfunctions/
This commit is contained in:
2025-12-05 15:58:08 +08:00
parent 854c4f5449
commit 8fc4630bb5
22 changed files with 514 additions and 950 deletions

View File

@@ -1,22 +1,9 @@
// pages/index/index.js
const { get } = require('../../utils/request');
const { formatRelativeTime } = require('../../utils/util');
Page({
data: {
searchValue: '',
bannerList: [],
categoryList: [],
infoList: [],
loading: false,
page: 1,
pageSize: 10,
hasMore: true
},
data: {},
onLoad() {
this.initData();
},
onLoad() {},
onShow() {
// 初始化 TabBar 选中状态
@@ -25,114 +12,10 @@ Page({
}
},
onPullDownRefresh() {
this.initData().then(() => {
wx.stopPullDownRefresh();
});
},
onReachBottom() {
if (this.data.hasMore && !this.data.loading) {
this.loadMoreInfo();
}
},
// 初始化数据
async initData() {
this.setData({ page: 1, hasMore: true });
// 模拟数据 - 实际项目中替换为API调用
this.setData({
bannerList: [
{ id: 1, image: '/assets/images/banner1.png', title: '热门资讯' },
{ id: 2, image: '/assets/images/banner2.png', title: '最新动态' }
],
categoryList: [
{ id: 1, name: '科技', icon: 'technology' },
{ id: 2, name: '财经', icon: 'finance' },
{ id: 3, name: '教育', icon: 'education' },
{ id: 4, name: '健康', icon: 'health' },
{ id: 5, name: '生活', icon: 'life' },
{ id: 6, name: '娱乐', icon: 'entertainment' },
{ id: 7, name: '体育', icon: 'sports' },
{ id: 8, name: '更多', icon: 'more' }
],
infoList: [
{
id: 1,
title: '这是一条测试信息标题,展示信息服务的基本样式',
summary: '这是信息摘要内容,用于展示信息的简要描述...',
image: '/assets/images/info1.png',
category: '科技',
time: new Date().getTime() - 3600000,
views: 1234
},
{
id: 2,
title: '第二条信息标题,这里是标题内容展示',
summary: '这是第二条信息的摘要内容...',
image: '/assets/images/info2.png',
category: '财经',
time: new Date().getTime() - 7200000,
views: 856
}
]
});
},
// 加载更多信息
async loadMoreInfo() {
if (this.data.loading) return;
this.setData({ loading: true });
// 模拟加载更多
setTimeout(() => {
const newPage = this.data.page + 1;
// 模拟无更多数据
if (newPage > 3) {
this.setData({ hasMore: false, loading: false });
return;
}
this.setData({
page: newPage,
loading: false
});
}, 1000);
},
// 搜索
onSearch(e) {
const value = e.detail;
// 跳转到云开发测试页
goCloudTest() {
wx.navigateTo({
url: `/pages/search/search?keyword=${value}`
url: '/pages/cloud-test/cloud-test'
});
},
// 搜索值变化
onSearchChange(e) {
this.setData({ searchValue: e.detail });
},
// 点击分类
onCategoryTap(e) {
const { id, name } = e.currentTarget.dataset;
wx.navigateTo({
url: `/pages/category/category?id=${id}&name=${name}`
});
},
// 点击信息
onInfoTap(e) {
const { id } = e.currentTarget.dataset;
wx.navigateTo({
url: `/pages/detail/detail?id=${id}`
});
},
// 格式化时间
formatTime(time) {
return formatRelativeTime(time);
}
});

View File

@@ -1,5 +1,4 @@
{
"navigationBarTitleText": "首页",
"enablePullDownRefresh": true,
"usingComponents": {}
}

View File

@@ -1,98 +1,20 @@
<!--pages/index/index.wxml-->
<view class="container">
<!-- 搜索栏 -->
<view class="search-bar">
<van-search
value="{{ searchValue }}"
placeholder="搜索信息"
shape="round"
bind:search="onSearch"
bind:change="onSearchChange"
/>
<view class="welcome-section">
<text class="welcome-title">信息服务小程序</text>
<text class="welcome-subtitle">基于微信云开发</text>
</view>
<!-- 轮播图 -->
<view class="banner-section" wx:if="{{ bannerList.length > 0 }}">
<swiper
class="banner-swiper"
indicator-dots
autoplay
circular
interval="3000"
>
<swiper-item wx:for="{{ bannerList }}" wx:key="id">
<image class="banner-image" src="{{ item.image }}" mode="aspectFill" />
</swiper-item>
</swiper>
</view>
<!-- 分类入口 -->
<view class="category-section card">
<view class="category-grid">
<view
class="category-item"
wx:for="{{ categoryList }}"
wx:key="id"
data-id="{{ item.id }}"
data-name="{{ item.name }}"
bindtap="onCategoryTap"
<view class="menu-section">
<van-cell-group>
<van-cell
title="云开发测试"
label="测试云函数、云数据库、云存储"
is-link
bindtap="goCloudTest"
>
<view class="category-icon">
<van-icon name="apps-o" size="48rpx" color="#1890ff" />
</view>
<text class="category-name">{{ item.name }}</text>
</view>
</view>
</view>
<!-- 信息列表 -->
<view class="info-section">
<view class="section-header">
<text class="section-title">最新资讯</text>
</view>
<view class="info-list">
<view
class="info-item card"
wx:for="{{ infoList }}"
wx:key="id"
data-id="{{ item.id }}"
bindtap="onInfoTap"
>
<view class="info-content">
<view class="info-text">
<text class="info-title ellipsis-2">{{ item.title }}</text>
<text class="info-summary ellipsis-2">{{ item.summary }}</text>
<view class="info-meta">
<van-tag plain type="primary" size="medium">{{ item.category }}</van-tag>
<text class="info-time">{{ item.timeText }}</text>
<text class="info-views">{{ item.views }}阅读</text>
</view>
</view>
<van-image
wx:if="{{ item.image }}"
class="info-image"
width="180rpx"
height="120rpx"
fit="cover"
radius="8rpx"
src="{{ item.image }}"
/>
</view>
</view>
</view>
<!-- 加载状态 -->
<view class="loading-section" wx:if="{{ loading }}">
<van-loading size="24px">加载中...</van-loading>
</view>
<!-- 没有更多 -->
<view class="no-more" wx:if="{{ !hasMore && infoList.length > 0 }}">
<text>— 没有更多了 —</text>
</view>
<!-- 空状态 -->
<van-empty wx:if="{{ !loading && infoList.length === 0 }}" description="暂无信息" />
<van-icon slot="icon" name="code-o" size="40rpx" color="#1890ff" style="margin-right: 20rpx;" />
</van-cell>
</van-cell-group>
</view>
</view>

View File

@@ -1,145 +1,33 @@
/* pages/index/index.wxss */
.container {
padding-bottom: 120rpx;
min-height: 100vh;
background-color: #f5f5f5;
padding: 30rpx;
box-sizing: border-box;
}
/* 搜索栏 */
.search-bar {
position: sticky;
top: 0;
z-index: 100;
background-color: #fff;
.welcome-section {
text-align: center;
padding: 60rpx 0;
}
/* 轮播图 */
.banner-section {
padding: 20rpx;
}
.banner-swiper {
height: 300rpx;
border-radius: 16rpx;
overflow: hidden;
}
.banner-image {
width: 100%;
height: 100%;
}
/* 分类 */
.category-section {
margin-top: 0;
}
.category-grid {
display: flex;
flex-wrap: wrap;
}
.category-item {
width: 25%;
display: flex;
flex-direction: column;
align-items: center;
padding: 20rpx 0;
}
.category-icon {
width: 80rpx;
height: 80rpx;
border-radius: 50%;
background-color: #e6f7ff;
display: flex;
align-items: center;
justify-content: center;
margin-bottom: 12rpx;
}
.category-name {
font-size: 24rpx;
color: #333;
}
/* 信息列表 */
.info-section {
margin-top: 20rpx;
}
.section-header {
padding: 20rpx 30rpx;
display: flex;
justify-content: space-between;
align-items: center;
}
.section-title {
font-size: 32rpx;
.welcome-title {
display: block;
font-size: 44rpx;
font-weight: bold;
color: #333;
}
.info-item {
margin-top: 0;
margin-bottom: 20rpx;
}
.info-content {
display: flex;
justify-content: space-between;
}
.info-text {
flex: 1;
margin-right: 20rpx;
display: flex;
flex-direction: column;
}
.info-title {
font-size: 30rpx;
font-weight: 500;
color: #333;
line-height: 1.5;
margin-bottom: 12rpx;
}
.info-summary {
font-size: 26rpx;
color: #666;
line-height: 1.5;
margin-bottom: 16rpx;
}
.info-meta {
display: flex;
align-items: center;
margin-top: auto;
}
.info-time {
font-size: 22rpx;
.welcome-subtitle {
display: block;
font-size: 28rpx;
color: #999;
margin-left: 16rpx;
}
.info-views {
font-size: 22rpx;
color: #999;
margin-left: 16rpx;
}
/* 加载状态 */
.loading-section {
display: flex;
justify-content: center;
padding: 40rpx;
}
.no-more {
text-align: center;
padding: 40rpx;
color: #999;
font-size: 24rpx;
.menu-section {
margin-top: 40rpx;
border-radius: 16rpx;
overflow: hidden;
}