美化了样式
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
import { baseUrl, globalImgUrl } from "../../../request";
|
||||
const { notLogin } = require('../../../utils/util')
|
||||
|
||||
// pages/course/courseList/courseList.js
|
||||
Page({
|
||||
@ -10,6 +11,8 @@ Page({
|
||||
courseList:[], // 课程列表
|
||||
courseType: '', // 课程类别
|
||||
globalImgUrl,
|
||||
tempCourseList: [],
|
||||
searchKeyword: ''
|
||||
},
|
||||
|
||||
// 跳转课程详情页面
|
||||
@ -22,6 +25,23 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
onSearchInput(e) {
|
||||
const keyword = (e.detail.value || '').trim();
|
||||
this.setData({ searchKeyword: keyword });
|
||||
},
|
||||
// 键盘“搜索/回车”触发:立即搜索
|
||||
onSearch() {
|
||||
const { tempCourseList } = this.data
|
||||
const keyword = (this.data.searchKeyword || '').trim();
|
||||
if (!keyword) {
|
||||
this.setData({courseList: tempCourseList})
|
||||
return;
|
||||
}
|
||||
// 模糊匹配 name
|
||||
const filtered = this.data.courseList.filter(item => item.name.includes(keyword)
|
||||
);
|
||||
this.setData({ courseList: filtered });
|
||||
},
|
||||
/**
|
||||
* 生命周期函数--监听页面加载
|
||||
*/
|
||||
@ -48,13 +68,11 @@ Page({
|
||||
console.log('课程列表',res.data.data);
|
||||
if (res.data.code === 1) {
|
||||
this.setData({
|
||||
courseList: res.data.data
|
||||
courseList: res.data.data,
|
||||
tempCourseList: res.data.data
|
||||
});
|
||||
} else {
|
||||
wx.showToast({
|
||||
icon: 'none',
|
||||
title: res.data.message || '获取课程失败',
|
||||
});
|
||||
notLogin(res.data.message)
|
||||
}
|
||||
},
|
||||
fail: err => {
|
||||
|
@ -1,39 +1,38 @@
|
||||
<view class="flex-col page">
|
||||
<text class="self-center text">{{ courseType }}</text>
|
||||
<image class="shrink-0 self-start image image_2" src="./image/line.png" />
|
||||
<image class="shrink-0 self-end image image_3" src="./image/line.png" />
|
||||
<!-- pages/course/searchCourses/searchCourses.wxml -->
|
||||
<view class="page">
|
||||
|
||||
<view class="flex-col self-stretch list">
|
||||
<!-- 遍历接口返回的 items 数组 -->
|
||||
<view
|
||||
class="flex-col list-item"
|
||||
wx:for="{{courseList}}"
|
||||
wx:for-item="item"
|
||||
wx:for-index="index"
|
||||
wx:key="id"
|
||||
>
|
||||
<view
|
||||
class="flex-row items-center relative group"
|
||||
bindtap="gotoCourseDetail"
|
||||
data-id="{{item.id}}"
|
||||
>
|
||||
<!-- 课程封面 -->
|
||||
<image
|
||||
class="shrink-0 image_4"
|
||||
src="{{ globalImgUrl + item.image}}"
|
||||
mode="aspectFill"
|
||||
/>
|
||||
<view class="flex-col flex-1 ml-12">
|
||||
<!-- 课程名称 -->
|
||||
<text class="font">{{item.name}}</text>
|
||||
<view class="flex-row justify-between items-baseline mt-17">
|
||||
<!-- 卷后价格 -->
|
||||
<text class="font_2">券后{{item.discountPrice}}元起</text>
|
||||
<!-- 已有下单人数 -->
|
||||
<text class="font_3">{{item.orderCount}}人学习</text>
|
||||
</view>
|
||||
<!-- 顶部搜索条(固定) -->
|
||||
<view class="search-bar" hover-class="hover">
|
||||
<image class="search-icon" src="./image/sousuo.png" mode="aspectFit"/>
|
||||
<input
|
||||
class="search-input"
|
||||
placeholder="搜索更多好课"
|
||||
placeholder-class="search-ph"
|
||||
bindinput="onSearchInput"
|
||||
confirm-type="search"
|
||||
bindconfirm="onSearch"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<!-- 搜索结果(独立滚动 & 隐藏滚动条) -->
|
||||
<scroll-view scroll-y class="list no-scrollbar">
|
||||
<block wx:for="{{courseList}}" wx:for-item="item" wx:key="item.id">
|
||||
<view class="course-card" bindtap="gotoCourseDetail" data-id="{{item.id}}" hover-class="hover">
|
||||
<image class="cover" src="{{ globalImgUrl + item.image }}" mode="aspectFill" lazy-load="true"/>
|
||||
<view class="info">
|
||||
<text class="title">{{item.name}}</text>
|
||||
<view class="meta">
|
||||
<text class="price-pill">券后{{item.discountPrice}}元起</text>
|
||||
<text class="people">{{item.orderCount}}人学习</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</block>
|
||||
|
||||
<!-- 空状态(可选) -->
|
||||
<view wx:if="{{!courseList || courseList.length === 0}}" class="empty">
|
||||
<image class="empty-icon" src="./image/empty.png" mode="aspectFit"/>
|
||||
<text class="empty-text">没找到相关课程,换个关键词试试~</text>
|
||||
</view>
|
||||
</scroll-view>
|
||||
</view>
|
||||
|
@ -1,63 +1,131 @@
|
||||
/* pages/course/courseList/courseList.wxss */
|
||||
.mt-17 {
|
||||
margin-top: 31.88rpx;
|
||||
}
|
||||
/* pages/course/searchCourses/searchCourses.wxss */
|
||||
|
||||
/* ===== 页面骨架:整页固定,列表单独滚动 ===== */
|
||||
.page {
|
||||
/* padding: 38.53rpx 0 ; */
|
||||
background-color: #ffffff;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
overflow-y: auto;
|
||||
overflow-x: hidden;
|
||||
height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background: #ffffff;
|
||||
overflow: hidden; /* 禁止整页滚动 */
|
||||
box-sizing: border-box;
|
||||
font-family: SourceHanSansCN, PingFang SC, Microsoft YaHei, system-ui, -apple-system, sans-serif;
|
||||
}
|
||||
.text {
|
||||
color: #000000;
|
||||
font-size: 30rpx;
|
||||
font-family: SourceHanSansCN;
|
||||
line-height: 27.64rpx;
|
||||
|
||||
::-webkit-scrollbar {
|
||||
width: 0;
|
||||
height: 0;
|
||||
background: transparent;
|
||||
}
|
||||
.image {
|
||||
width: 255rpx;
|
||||
height: 1.88rpx;
|
||||
|
||||
|
||||
/* 轻触反馈 */
|
||||
.hover { opacity: .86; transition: opacity .18s ease; }
|
||||
|
||||
/* ===== 顶部搜索条(固定) ===== */
|
||||
.search-bar {
|
||||
padding: 24rpx 28rpx;
|
||||
box-sizing: border-box;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16rpx;
|
||||
background: #fff;
|
||||
}
|
||||
.image_2 {
|
||||
margin-left: 40.78rpx;
|
||||
margin-top: -14.7rpx;
|
||||
}
|
||||
.image_3 {
|
||||
margin-right: 37.97rpx;
|
||||
.search-icon { width: 36rpx; height: 36rpx; opacity: .9; }
|
||||
|
||||
/* 胶囊输入框 */
|
||||
.search-input {
|
||||
flex: 1;
|
||||
height: 72rpx;
|
||||
padding: 0 26rpx;
|
||||
border-radius: 9999rpx;
|
||||
background: #f5f6f7;
|
||||
font-size: 26rpx;
|
||||
color: #111;
|
||||
line-height: 72rpx;
|
||||
box-shadow: inset 0 0 0 1rpx rgba(0,0,0,.04);
|
||||
}
|
||||
.search-ph { color: #a8a8a8; font-size: 26rpx; }
|
||||
|
||||
/* ===== 列表:占满剩余高度,单独滚动,隐藏滚动条 ===== */
|
||||
.list {
|
||||
padding-top: 20.21rpx;
|
||||
flex: 1;
|
||||
padding: 0 24rpx 28rpx;
|
||||
box-sizing: border-box;
|
||||
-webkit-overflow-scrolling: touch;
|
||||
background: #fff;
|
||||
}
|
||||
.list-item {
|
||||
height: 178.13rpx;
|
||||
.no-scrollbar::-webkit-scrollbar { display: none; width: 0; height: 0; background: transparent; }
|
||||
.no-scrollbar { scrollbar-width: none; }
|
||||
|
||||
/* ===== 课程卡片(左图右文) ===== */
|
||||
.course-card {
|
||||
display: flex;
|
||||
gap: 22rpx;
|
||||
padding: 20rpx;
|
||||
margin-top: 20rpx;
|
||||
background: #ffffff;
|
||||
border-radius: 20rpx;
|
||||
border: 1rpx solid #f1f1f1;
|
||||
box-shadow: 0 8rpx 24rpx rgba(0,0,0,.05);
|
||||
}
|
||||
.group {
|
||||
margin: -18.24rpx 29.46rpx 0 35.63rpx;
|
||||
padding: 57.19rpx 0 26.27rpx;
|
||||
border-bottom: solid 1.88rpx #d6d6d6;
|
||||
.cover {
|
||||
width: 280rpx; /* 3:2 比例更舒服 */
|
||||
height: 186rpx;
|
||||
flex: 0 0 280rpx;
|
||||
border-radius: 14rpx;
|
||||
object-fit: cover;
|
||||
}
|
||||
.image_4 {
|
||||
border-radius: 9.38rpx;
|
||||
width: 208.13rpx;
|
||||
height: 133.13rpx;
|
||||
.info {
|
||||
flex: 1;
|
||||
min-width: 0; /* 防文字溢出 */
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: space-between;
|
||||
}
|
||||
.font {
|
||||
font-size: 26.25rpx;
|
||||
font-family: SourceHanSansCN;
|
||||
line-height: 31.88rpx;
|
||||
color: #000000;
|
||||
.title {
|
||||
font-size: 28rpx;
|
||||
line-height: 40rpx;
|
||||
color: #111;
|
||||
font-weight: 600;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2; /* 两行省略 */
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
word-break: break-word;
|
||||
}
|
||||
.font_2 {
|
||||
font-size: 26.25rpx;
|
||||
font-family: AlibabaPuHuiTi;
|
||||
line-height: 24.15rpx;
|
||||
color: #ff5733;
|
||||
.meta {
|
||||
margin-top: 12rpx;
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
justify-content: space-between;
|
||||
}
|
||||
.font_3 {
|
||||
font-size: 22.5rpx;
|
||||
font-family: AlibabaPuHuiTi;
|
||||
line-height: 20.34rpx;
|
||||
color: #a6a6a6;
|
||||
}
|
||||
.price-pill {
|
||||
padding: 6rpx 14rpx;
|
||||
font-size: 24rpx;
|
||||
color: #fff;
|
||||
border-radius: 9999rpx;
|
||||
background: linear-gradient(90deg, #ff6a00, #ff8a2a);
|
||||
box-shadow: 0 6rpx 16rpx rgba(255,106,0,.22);
|
||||
white-space: nowrap;
|
||||
}
|
||||
.people {
|
||||
font-size: 22rpx;
|
||||
color: #9aa0a6;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
/* ===== 空状态 ===== */
|
||||
.empty {
|
||||
padding: 120rpx 0 80rpx;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 18rpx;
|
||||
color: #9aa0a6;
|
||||
}
|
||||
.empty-icon { width: 240rpx; height: 240rpx; opacity: .7; }
|
||||
.empty-text { font-size: 24rpx; line-height: 34rpx; }
|
||||
|
||||
/* ===== 兼容你项目里可能已有的工具类(可留可删) ===== */
|
||||
.ml-3 { margin-left: 6rpx; }
|
||||
.mt-17 { margin-top: 12rpx; }
|
||||
|
BIN
pages/course/courseList/image/empty.png
Normal file
BIN
pages/course/courseList/image/empty.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.1 KiB |
BIN
pages/course/courseList/image/sousuo.png
Normal file
BIN
pages/course/courseList/image/sousuo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 812 B |
Reference in New Issue
Block a user