Commit aadd2d82898958a8a262dc225131583bcb6eb039

Authored by 王强
1 parent b3f9a9bc

1、关键字标红

2、细节优化
src/common/helper.class.js
@@ -173,4 +173,27 @@ export default class Helper { @@ -173,4 +173,27 @@ export default class Helper {
173 173
174 /* 数字格式化 结束 */ 174 /* 数字格式化 结束 */
175 175
  176 + /* 数据格式处理 开始 */
  177 +
  178 + /**
  179 + * 对象内指定字符串内容替换
  180 + * @param {Object} o [目标对象]
  181 + * @param {String} key [目标字段名]
  182 + * @param {String} oldString [原始字符串]
  183 + * @param {String} newString [新字符串]
  184 + */
  185 + objectStringReplaceAll(o, key, oldString, newString) {
  186 +
  187 + // 判断对象是否为数组
  188 + if (typeof o === "object" && o !== null && o.length) {
  189 +
  190 + // 遍历数组,替换内容
  191 + for (let i = 0; i < o.length; i++) {
  192 + o[i][key] = o[i][key].replace(new RegExp(oldString, "gm"), newString);
  193 + }
  194 + }
  195 + }
  196 +
  197 + /* 数据格式处理 结束 */
  198 +
176 } 199 }
177 \ No newline at end of file 200 \ No newline at end of file
src/components/darenList/darenList.less
@@ -9,6 +9,8 @@ @@ -9,6 +9,8 @@
9 display: flex; 9 display: flex;
10 justify-content: flex-start; 10 justify-content: flex-start;
11 align-items: center; 11 align-items: center;
  12 + width: 570px;
  13 + height: auto;
12 .avatar-box { 14 .avatar-box {
13 width: 80px; 15 width: 80px;
14 height: 80px; 16 height: 80px;
@@ -22,19 +24,28 @@ @@ -22,19 +24,28 @@
22 } 24 }
23 .user-info { 25 .user-info {
24 margin-left: 30px; 26 margin-left: 30px;
  27 + width: 460px;
25 .name { 28 .name {
26 color: #4A4A4A; 29 color: #4A4A4A;
27 font-size: 28px; 30 font-size: 28px;
28 font-weight: 400; 31 font-weight: 400;
  32 + width: 100%;
29 white-space: nowrap; 33 white-space: nowrap;
30 text-overflow: ellipsis; 34 text-overflow: ellipsis;
31 overflow: hidden; 35 overflow: hidden;
  36 + /deep/ .k {
  37 + color: #FC1541;
  38 + }
32 } 39 }
33 .desc { 40 .desc {
34 margin-top: 10px; 41 margin-top: 10px;
35 color: #B4B4B4; 42 color: #B4B4B4;
36 font-size: 22px; 43 font-size: 22px;
37 font-weight:400; 44 font-weight:400;
  45 + width: 100%;
  46 + white-space: nowrap;
  47 + text-overflow: ellipsis;
  48 + overflow: hidden;
38 } 49 }
39 } 50 }
40 } 51 }
src/components/darenList/darenList.vue
@@ -7,9 +7,7 @@ @@ -7,9 +7,7 @@
7 <img v-lazy="item.user_img || item.logo" class="avatar-img" /> 7 <img v-lazy="item.user_img || item.logo" class="avatar-img" />
8 </div> 8 </div>
9 <div class="user-info"> 9 <div class="user-info">
10 - <div class="name">  
11 - {{item.title}}  
12 - </div> 10 + <div class="name" v-html="item.title"></div>
13 <div class="desc"> 11 <div class="desc">
14 {{item.fans_count}}粉丝 12 {{item.fans_count}}粉丝
15 </div> 13 </div>
src/components/goodsItem_4/goodsItem_4.less
@@ -42,6 +42,9 @@ @@ -42,6 +42,9 @@
42 white-space: nowrap; 42 white-space: nowrap;
43 text-overflow: ellipsis; 43 text-overflow: ellipsis;
44 overflow: hidden; 44 overflow: hidden;
  45 + /deep/ .k {
  46 + color: #FC1541;
  47 + }
45 } 48 }
46 } 49 }
47 .bottom-box { 50 .bottom-box {
src/components/goodsItem_4/goodsItem_4.vue
@@ -6,7 +6,7 @@ @@ -6,7 +6,7 @@
6 </div> 6 </div>
7 <div class="content-box"> 7 <div class="content-box">
8 <div class="top-box"> 8 <div class="top-box">
9 - <div class="title">{{item.title}}</div> 9 + <div class="title" v-html="item.title"></div>
10 </div> 10 </div>
11 <div class="bottom-box"> 11 <div class="bottom-box">
12 <div class="price-box"> 12 <div class="price-box">
src/components/goodsItem_5/goodsItem_5.less
@@ -47,6 +47,9 @@ @@ -47,6 +47,9 @@
47 white-space: nowrap; 47 white-space: nowrap;
48 text-overflow: ellipsis; 48 text-overflow: ellipsis;
49 overflow: hidden; 49 overflow: hidden;
  50 + /deep/ .k {
  51 + color: #FC1541;
  52 + }
50 } 53 }
51 .desc-box { 54 .desc-box {
52 display: flex; 55 display: flex;
src/components/goodsItem_5/goodsItem_5.vue
@@ -7,7 +7,7 @@ @@ -7,7 +7,7 @@
7 </div> 7 </div>
8 <div class="content-box"> 8 <div class="content-box">
9 <div class="top-box"> 9 <div class="top-box">
10 - <div class="title">{{item.title}}</div> 10 + <div class="title" v-html="item.title"></div>
11 <div class="desc-box"> 11 <div class="desc-box">
12 <div class="desc">评价:{{item.grade}}</div> 12 <div class="desc">评价:{{item.grade}}</div>
13 <div class="desc">月销:{{item.sale_count}}</div> 13 <div class="desc">月销:{{item.sale_count}}</div>
src/pages/search/search.vue
@@ -234,6 +234,11 @@ @@ -234,6 +234,11 @@
234 234
235 // 设置商品数据 235 // 设置商品数据
236 if (datas.goods.length) { 236 if (datas.goods.length) {
  237 +
  238 + // 替换标题中的keyword
  239 + this.keywordHigh(datas.goods, ext.keyword);
  240 +
  241 + // 设置数据
237 this.$set(this.goodsLists, "list", datas.goods); 242 this.$set(this.goodsLists, "list", datas.goods);
238 this.$set(this.titles.goods, "title", ext.keyword + "-商品"); 243 this.$set(this.titles.goods, "title", ext.keyword + "-商品");
239 this.$set(this.titles.goods, "more", this.displayPage.status.GOODS); 244 this.$set(this.titles.goods, "more", this.displayPage.status.GOODS);
@@ -241,6 +246,11 @@ @@ -241,6 +246,11 @@
241 246
242 // 设置达人数据 247 // 设置达人数据
243 if (datas.shop.length) { 248 if (datas.shop.length) {
  249 +
  250 + // 替换标题中的keyword
  251 + this.keywordHigh(datas.shop, ext.keyword);
  252 +
  253 + // 设置数据
244 this.$set(this.darenLists, "list", datas.shop); 254 this.$set(this.darenLists, "list", datas.shop);
245 this.$set(this.titles.daren, "title", ext.keyword + "-达人"); 255 this.$set(this.titles.daren, "title", ext.keyword + "-达人");
246 this.$set(this.titles.daren, "more", this.displayPage.status.DAREN); 256 this.$set(this.titles.daren, "more", this.displayPage.status.DAREN);
@@ -248,6 +258,11 @@ @@ -248,6 +258,11 @@
248 258
249 // 设置美食数据 259 // 设置美食数据
250 if (datas.foodsShop.length) { 260 if (datas.foodsShop.length) {
  261 +
  262 + // 替换标题中的keyword
  263 + this.keywordHigh(datas.foodsShop, ext.keyword);
  264 +
  265 + // 设置数据
251 this.$set(this.foodLists, "list", datas.foodsShop); 266 this.$set(this.foodLists, "list", datas.foodsShop);
252 this.$set(this.foodLists, "coordinate", ext.coordinate); 267 this.$set(this.foodLists, "coordinate", ext.coordinate);
253 this.$set(this.titles.food, "title", ext.keyword + "-美食"); 268 this.$set(this.titles.food, "title", ext.keyword + "-美食");
@@ -369,6 +384,9 @@ @@ -369,6 +384,9 @@
369 // 设置商品数据 384 // 设置商品数据
370 if (datas.goods.length) { 385 if (datas.goods.length) {
371 386
  387 + // 替换标题中的keyword
  388 + this.keywordHigh(datas.goods, ext.keyword);
  389 +
372 // 判断数据处理方式 390 // 判断数据处理方式
373 if (this.paging.page > 1) { // 追加数据 391 if (this.paging.page > 1) { // 追加数据
374 this.$set(this.goodsLists, "list", [...this.goodsLists.list, ...datas.goods]); 392 this.$set(this.goodsLists, "list", [...this.goodsLists.list, ...datas.goods]);
@@ -390,6 +408,9 @@ @@ -390,6 +408,9 @@
390 // 设置达人数据 408 // 设置达人数据
391 if (datas.shop.length) { 409 if (datas.shop.length) {
392 410
  411 + // 替换标题中的keyword
  412 + this.keywordHigh(datas.shop, ext.keyword);
  413 +
393 // 判断数据处理方式 414 // 判断数据处理方式
394 if (this.paging.page > 1) { 415 if (this.paging.page > 1) {
395 this.$set(this.darenLists, "list", [...this.darenLists.list, ...datas.shop]); 416 this.$set(this.darenLists, "list", [...this.darenLists.list, ...datas.shop]);
@@ -411,6 +432,9 @@ @@ -411,6 +432,9 @@
411 // 设置美食数据 432 // 设置美食数据
412 if (datas.foodsShop.length) { 433 if (datas.foodsShop.length) {
413 434
  435 + // 替换标题中的keyword
  436 + this.keywordHigh(datas.foodsShop, ext.keyword);
  437 +
414 // 判断数据处理方式 438 // 判断数据处理方式
415 if (this.paging.page > 1) { 439 if (this.paging.page > 1) {
416 this.$set(this.foodLists, "list", [...this.foodLists.list, ...datas.foodsShop]); 440 this.$set(this.foodLists, "list", [...this.foodLists.list, ...datas.foodsShop]);
@@ -669,6 +693,19 @@ @@ -669,6 +693,19 @@
669 }, 693 },
670 694
671 /** 695 /**
  696 + * 搜索结果关键字title高亮
  697 + * @param {Object} o [目标对象]
  698 + * @param {String} keyword [关键字]
  699 + */
  700 + keywordHigh(o, keyword) {
  701 +
  702 + // 判断是否有字符串替换工具函数
  703 + if (typeof this.$parent.helper === "object" && typeof this.$parent.helper.objectStringReplaceAll === "function") {
  704 + this.$parent.helper.objectStringReplaceAll(o, "title", keyword, "<span class='k'>" + keyword + "</span>");
  705 + }
  706 + },
  707 +
  708 + /**
672 * 获取历史搜索结果Storage 709 * 获取历史搜索结果Storage
673 */ 710 */
674 getSearchHistoryArr() { 711 getSearchHistoryArr() {