From 354b9f38a8ba430e082e2ae282c09167a853b702 Mon Sep 17 00:00:00 2001 From: liuyufang <359485409@qq.com> Date: Sun, 7 Apr 2019 00:47:36 +0800 Subject: [PATCH] =?UTF-8?q?1.=E5=A2=9E=E5=8A=A0=E6=90=9C=E7=B4=A2=E5=85=B3?= =?UTF-8?q?=E9=94=AE=E5=AD=97=E9=AB=98=E4=BA=AE2.=E8=AF=97=E5=8F=A5?= =?UTF-8?q?=E8=AF=A6=E6=83=85=E9=A1=B5tab=E5=88=87=E6=8D=A2=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=8A=A8=E7=94=BB=E6=95=88=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/index/index.js | 69 +++++++++++++++++++++++--------- pages/index/index.wxml | 16 +++++++- pages/index/index.wxss | 3 ++ pages/poemDetail/poemDetail.js | 13 +++++- pages/poemDetail/poemDetail.wxml | 1 + pages/poemDetail/poemDetail.wxss | 10 ++++- 6 files changed, 88 insertions(+), 24 deletions(-) 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;