美化了样式
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 => {
|
||||
|
Reference in New Issue
Block a user