diff --git a/pages/index/index.js b/pages/index/index.js
index 0b3a9b0..68d9e13 100644
--- a/pages/index/index.js
+++ b/pages/index/index.js
@@ -17,15 +17,40 @@ Page({
searchPoem(key){
let _this = this;
let resultList = [];
- let originList = poemList;
+ let originList = JSON.parse(JSON.stringify(poemList));
for (var i = 0; i < originList.length; i++){
let poem = originList[i];
if(_this.poemMatchKey(poem,key)){
- resultList.push(poem);
+ //处理高亮数据
+ let data = _this.handleHighlightKeyword(poem, key);
+ resultList.push(data);
}
}
return resultList;
},
+ //处理高亮数据
+ handleHighlightKeyword(data, key){
+ let _this = this;
+ let titleArr = data.title.split(key);
+ let title = data.title.indexOf(key) != -1?_this.handleHighlightArr(titleArr, key): titleArr;
+ let authorArr = data.author.split(key);
+ let author = data.author.indexOf(key) != -1 ?_this.handleHighlightArr(authorArr, key): authorArr;
+ let summaryArr = data.summary.split(key);
+ let summary = data.summary.indexOf(key) != -1 ?_this.handleHighlightArr(summaryArr, key): summaryArr;
+ data.title = title;
+ data.author = author;
+ data.summary = summary;
+ return data;
+ },
+ handleHighlightArr(list, key){
+ let arr = [];
+ list.forEach((item, index) => {
+ arr.push(item);
+ if(index != list.length-1)
+ arr.push(key)
+ })
+ return arr;
+ },
// 判断一首诗是否命中关键词
poemMatchKey(poem,key){
if(poem.title.indexOf(key) != -1) {
@@ -47,27 +72,31 @@ Page({
_this.goPage(url);
},
getKeyword(e){
- let _this = this, poemData;
- if (e.detail.value){
- poemData = _this.searchPoem(e.detail.value);
- _this.setData({
- keyword: e.detail.value
- })
- }else{
- poemData = poemList
- }
+ let _this = this, poemData,
+ keyword = e.detail.value.trim();
_this.setData({
- listData: poemData
- })
- if(_this.data.listData.length == 0){
- _this.setData({
- noData: true
- })
- }else{
+ keyword
+ },()=>{
+ if (keyword) {
+ poemData = _this.searchPoem(keyword);
+ } else {
+ poemData = poemList
+ }
_this.setData({
- noData: false
+ listData: poemData
+ }, () => {
+ if (_this.data.listData.length == 0) {
+ _this.setData({
+ noData: true
+ })
+ } else {
+ _this.setData({
+ noData: false
+ })
+ }
})
- }
+ })
+
},
goPage(url){
wx.navigateTo({
diff --git a/pages/index/index.wxml b/pages/index/index.wxml
index 0ff1d25..623ea4f 100644
--- a/pages/index/index.wxml
+++ b/pages/index/index.wxml
@@ -8,7 +8,7 @@
-
+
{{item.title}}
{{item.summary}}
@@ -17,6 +17,20 @@
[{{item.dynasty}}]{{item.author}}
+
+
+
+ {{value}}
+
+
+ {{value}}
+
+
+
+ [{{item.dynasty}}]{{value}}
+
+
+
已经到底了哟~
diff --git a/pages/index/index.wxss b/pages/index/index.wxss
index aefc46c..d52a4bd 100644
--- a/pages/index/index.wxss
+++ b/pages/index/index.wxss
@@ -63,6 +63,9 @@
text-overflow:ellipsis;
white-space: nowrap;
}
+.content .list .active{
+ color: #ff4c00!important;
+}
.content .list .left .sub-title{
font-size: 24rpx;
color: #666;
diff --git a/pages/poemDetail/poemDetail.js b/pages/poemDetail/poemDetail.js
index 5c2046a..6110163 100644
--- a/pages/poemDetail/poemDetail.js
+++ b/pages/poemDetail/poemDetail.js
@@ -73,9 +73,18 @@ Page({
*/
selectOption(e){
let _this = this,
- optionid = e.currentTarget.dataset.optionid;
+ optionid = e.currentTarget.dataset.optionid,
+ left = "calc(33.3% * "+optionid+" + 16.6% - 60rpx)",
+ animation = wx.createAnimation({
+ duration: 200,
+ timingFunction: "linear",
+ delay: 0,
+ transformOrigin: "50% 50%"
+ });
+ animation.left(left).step();
_this.setData({
- optionid
+ optionid,
+ animationData: animation.export()
});
},
/**
diff --git a/pages/poemDetail/poemDetail.wxml b/pages/poemDetail/poemDetail.wxml
index 6255c0f..87adb22 100644
--- a/pages/poemDetail/poemDetail.wxml
+++ b/pages/poemDetail/poemDetail.wxml
@@ -17,6 +17,7 @@
赏析
+
{{item.sp}}{{item.def}}
diff --git a/pages/poemDetail/poemDetail.wxss b/pages/poemDetail/poemDetail.wxss
index 654acd9..a911bff 100644
--- a/pages/poemDetail/poemDetail.wxss
+++ b/pages/poemDetail/poemDetail.wxss
@@ -24,6 +24,15 @@
/**注释部分**/
.appreciation {
width: 100%;
+ position: relative;
+}
+.appreciation .option-line{
+ height: 6rpx;
+ width: 120rpx;
+ background: #ff4c00;
+ position: absolute;
+ top: 122rpx;
+ left: calc(16.6% - 60rpx);
}
.appreciation .option-bar{
width: 100%;
@@ -51,7 +60,6 @@
}
.appreciation .option-bar .item .active{
color: #ff4c00;
- border-bottom: 6rpx solid #ff4c00;
}
.appreciation .appreciation-content{
font-size: 30rpx;