Commit 2085c5fa by jscat

nyx: 发现

1. 为小程序的发现添加搜索功能,
2. 搜索功能新增"搜索"tab标签
parent fbf32adf
{
{
{
"pages": [
"pages/key/key",
"pages/key/key",
"pages/discover/note-info/note-info",
"pages/my/my",
"pages/discover/discover",
"pages/discover/note-writer/note-writer",
"pages/discover/searchbar/searchbar",
"pages/map/map",
"pages/key/matchDaily/matchDaily",
"pages/key/matchStudy/matchStudy",
"pages/key/matchDaily/matchDaily",
"pages/key/matchStudy/matchStudy",
"pages/key/matchStudy/matchStudyDetail/matchStudyDetail",
"pages/my/rank/rank",
"pages/my/user/user",
......@@ -30,6 +34,12 @@
"selectedIconPath": "./icon/map1.png"
},
{
"pagePath": "pages/discover/discover",
"text": "发现",
"iconPath": "./icon/discover2.png",
"selectedIconPath": "./icon/discover2.png"
},
{
"pagePath": "pages/key/key",
"text": "知识",
"iconPath": "./icon/key.png",
......
//config.js API全局域名配置
//config.js API全局域名配置
//config.js API全局域名配置
var prod = 0;
var local = 0;
var test = 1;
var local = 1;
var test = 0;
var debug = 0; //是否打印调试信息
var host_key = "https://fun.hisuhong.com";
......
// pages/kinds/kinds.js
// pages/kinds/kinds.js
......@@ -27,30 +27,6 @@ Page({
// writer_name: "无敌花木兰",
// writer_image: "../../icon/icon_avatar3.png"
// },
// {
// note_image: [ "https://img.xiaohongshu.com/items/c1a0056ba9ba17b30446a0e040dc9e30@800w_90Q_1x_2o.jpg",
// ],
// title: "便携香水加香一天",
// like: 10,
// writer_name: "无敌花木兰",
// writer_image: "../../icon/icon_avatar3.png"
// },
// {
// note_image: ["https://img.xiaohongshu.com/items/c1a0056ba9ba17b30446a0e040dc9e30@800w_90Q_1x_2o.jpg",
// ],
// title: "便携香水加香一天",
// like: 10,
// writer_name: "无敌花木兰",
// writer_image: "../../icon/icon_avatar3.png"
// },
// {
// note_image: ["https://img.xiaohongshu.com/items/c1a0056ba9ba17b30446a0e040dc9e30@800w_90Q_1x_2o.jpg",
// ],
// title: "便携香水加香一天",
// like: 10,
// writer_name: "无敌花木兰",
// writer_image: "../../icon/icon_avatar3.png"
// },
],
//分页加载部分
......@@ -64,15 +40,21 @@ Page({
noteTop: 0,
noteHeight: 0,
//搜索模块
inputShowed: false, //初始文本框不显示内容
strSearch : "", //搜索的字串
inputVal : "", //输入字符串,主要用于页面显示
},
switchCategory(e) {
var _this = this;
var curIndex = e.currentTarget.dataset.index ? e.currentTarget.dataset.index : 0
var strCategory = _this.__data__.category[curIndex].name
this.setData({
curIndex: curIndex,
})
_this.getNotes(0, 1, 4, curIndex);
_this.getNotes(0, 1, 4, strCategory);
},
// 搜索点击事件
entrySearch(e) {
......@@ -110,7 +92,8 @@ Page({
{
//getNotes(strCategory)
var curIndex = _this.__data__.curIndex
_this.getNotes(0, 1, 4, curIndex);
var strCategory = _this.__data__.category[curIndex].name
_this.getNotes(0, 1, 4, strCategory);
}
},
......@@ -157,6 +140,7 @@ Page({
console.log('页面上拉触底')
var _this = this;
var curIndex = _this.__data__.curIndex
var strSearch = _this.__data__.category[curIndex].name
var isHideLoadMore = _this.__data__.isHideLoadMore;
var pageIndex = _this.__data__.pageIndex;
......@@ -167,7 +151,7 @@ Page({
console.log('加载更多')
setTimeout(() => {
_this.getNotes(1, pageIndex, 4, curIndex);
_this.getNotes(1, pageIndex, 4, strSearch);
}, 1000)
}
else {
......@@ -188,10 +172,14 @@ Page({
*/
// 获取notes数据
// scrollType: 是否是翻页
getNotes: function (scrollType,pageNum, pageCount, curIndex) {
getNotes: function (scrollType,pageNum, pageCount, strSearch) {
var _this = this;
var strCategory = _this.__data__.category[curIndex].name
var query_url = strCategory == "推荐" ? '&top=1' : '&tag=' + strCategory
//如果是"推荐"和"搜索",需要单独处理
//搜索时候,需要转换为搜索的关键词
strSearch = strSearch == "搜索" ? _this.__data__.strSearch : strSearch
var query_url = strSearch == "推荐" ? '&top=1' : '&tag=' + strSearch + '&title=' + strSearch
var strUrl = config.notes_query_url + "?pageCount=" + pageCount
+ "&pageNum=" + pageNum + query_url
config.debug == 1 ? console.log("===strUrl is: \"" + strUrl + "\"") : ""
......@@ -221,6 +209,8 @@ Page({
result["writer_image"] = res.data.data[i].avatarUrl
list.push(result)
}
//进行翻页设置(加载更多)
if (scrollType == 1) {
var notesList = _this.__data__.notes;
......@@ -235,5 +225,58 @@ Page({
}
})
},
/* 搜索模块 */
// 使文本框进入可编辑状态
showInput: function () {
this.setData({
inputShowed: true //设置文本框可以输入内容
});
},
// 取消搜索
hideInput: function () {
var _this = this;
var cat = _this.__data__.category;
if (cat[cat.length - 1].name == "搜索") {
cat.pop()
}
this.setData({
inputShowed: false,
category:cat,
curIndex: 1,
});
var strCategory = _this.__data__.category[1].name
_this.getNotes(0, 1, 4, strCategory);
},
// * 删除输入字符串
clearInput: function(){
this.setData({
inputVal: "",
});
},
// 开始搜索
startSearch: function (e) {
var _this = this;
var strSearch = e.detail.value
var cat = _this.__data__.category
console.log("===input search text_" + strSearch)
_this.getNotes(0, 1, 4, strSearch);
if(cat[cat.length-1].name != "搜索")
{
cat.push({
name: "搜索",
id: "search",
})
}
_this.setData({
strSearch: strSearch,
category: cat,
curIndex: cat.length-1,
inputVal: strSearch,
})
},
})
<view class="page">
<view class="page">
<view class="page">
<!-- 搜索框 -->
<block style="position: fixed">
<!--refer https://blog.csdn.net/weixin_44022446/article/details/86438015 -->
<view class="weui-search-bar">
<view class="weui-search-bar__form">
<view class="weui-search-bar__box">
<icon class="weui-icon-search_in-box" type="search" size="16"></icon>
<input type="text" class="weui-search-bar__input" placeholder="搜索" value="{{inputVal}}" focus="{{inputShowed}}" bindinput="inputTyping" />
<input type="text" class="weui-search-bar__input" placeholder="搜索" value="{{inputVal}}" focus="{{inputShowed}}" bindconfirm="startSearch" />
<view class="weui-icon-clear" wx:if="{{inputVal.length > 0}}" bindtap="clearInput">
<icon type="clear" size="16"></icon>
</view>
......@@ -18,10 +18,9 @@
<view class="weui-search-bar__cancel-btn" hidden="{{!inputShowed}}" bindtap="hideInput">取消
</view>
</view>
</block>
<!-- 导航栏 -->
<view class="navBar">
<view class="navBar" >
<scroll-view class="navBar-box" scroll-x="true" style="white-space: nowrap; display:flex ">
<view class="cate-list {{curIndex==index?'on':''}}" wx:for="{{category}}"
wx:key="{{item.id}}" data-id="{{item.id}}" data-index="{{index}}"
......@@ -56,6 +55,8 @@
</view>
</scroll-view>
<!-- 加载更多 -->
<view class="weui-loadmore" hidden="{{isHideLoadMore}}">
<view class="weui-loading"></view>
......@@ -65,10 +66,6 @@
<view class="weui-loadmore__tips">没有更多啦 {{'>'}}_{{'<'}} </view>
</view>
</scroll-view>
</view>
/*
/*
......@@ -5,6 +5,9 @@
em: 默认文字大小是16px, font-size: 16px; em是一个相对的大小; 1em=1*16=16px
结构: position -> margin -> ( border -> padding -> input )
position: 定位原则:子绝父相; absolute,绝对;relative,相对;fixed,固定,比如搜索框
display: inline 行内元素 不带空格 block 块级元素 带空格
margin: 上右下左 top right bottom :left
*/
.page{
......@@ -12,6 +15,7 @@
background-color:#f5f8fa;
}
/* narBar -> navBar-box -> cate-list -> cate-list.on */
.navBar{
height: 60rpx;
background: #fff;
......@@ -33,7 +37,7 @@
font-weight: bold;
}
/* */
/* list-block -> note-block -> note-info */
.list-block{
height:100%;
display:flex;
......@@ -44,7 +48,6 @@
}
.notes-block{
width: 46%;
/* height: 20%; */
margin: 6px;
background: #fff;
border-radius: 5px;
......@@ -98,7 +101,80 @@
margin: auto;
}
/* 加载更多 */
/*搜索框 */
.weui-search-bar {
position: relative;
padding: 8px 10px;
display: -webkit-box;
display: -webkit-flex;
display: flex;
box-sizing: border-box;
background-color: #EFEFF4;
border-top: 1rpx solid #D7D6DC;
border-bottom: 1rpx solid #D7D6DC;
}
.weui-icon-search {
margin-right: 4px;
font-size: inherit;
vertical-align: middle;
margin-top:0%;
}
.weui-icon-search_in-box {
position: absolute;
left: 10px;
top: 0px;
vertical-align: middle;
margin-top:0%;
font-size: inherit;
}
.weui-search-bar__text {
display: inline-block;
font-size: 16px;
}
.weui-search-bar__form {
position: relative;
-webkit-box-flex: 1;
-webkit-flex: auto;
flex: auto;
border-radius: 5px;
background: #FFFFFF;
border: 1rpx solid #E6E6EA;
}
.weui-search-bar__box {
position: relative;
padding-left: 30px;
padding-right: 30px;
width: 100%;
box-sizing: border-box;
z-index: 1;
}
.weui-search-bar__input {
height: 28px;
line-height: 28px;
font-size: 16px;
}
.weui-search-bar__label {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
z-index: 2;
border-radius: 3px;
text-align: center;
color: #9B9B9B;
background: #FFFFFF;
line-height: 28px;
}
.weui-search-bar__cancel-btn {
margin-left: 10px;
line-height: 28px;
color: #09BB07;
white-space: nowrap;
}
/* 加载更多 */
.weui-loading {
margin: 0 5px;
width: 20px;
......
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
......@@ -244,10 +244,7 @@ limitations under the License.
SELECT * FROM view_post_info
WHERE 1=1
<if test="tag != null and tag != '' ">
AND tag LIKE CONCAT('%', #{tag} ,'%')
</if>
<if test="title != null and title != '' ">
AND title LIKE CONCAT('%', #{title} ,'%')
AND ( tag LIKE CONCAT('%', #{tag} ,'%') OR title LIKE CONCAT('%', #{title} ,'%') )
</if>
<if test="createDatetime != null">
AND DATE_FORMAT(create_datetime, '%Y-%m-%d') &gt;= DATE_FORMAT(#{createDatetime,jdbcType=DATE}, '%Y-%m-%d')
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论