search.vue
9.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
<!--
* @Date: 2024-10-20 16:57:48
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2024-10-25 15:39:59
* @FilePath: /hager/src/views/search.vue
* @Description: 文件描述
-->
<template>
<div class="hager-search-page">
<hager-box>
<div class="search-title">与“{{ keyword }}”相关的搜索结果</div>
<el-tabs v-model="activeName" @tab-click="handleClick">
<el-tab-pane name="product">
<div slot="label" class="customer-label">产品 <span>2</span></div>
<div class="search-product-list">
<div :class="['search-product-item', is_xs ? 'xs' : '']" v-for="(item, index) in product_list" :key="index">
<div :class="['search-product-item-img', is_xs ? 'xs' : '']" :style="{ 'background-image': 'url('+ item.img +')' }"></div>
<p @click="goToDetail(item)" class="search-product-item-title">{{ item.title }}</p>
</div>
</div>
<div style="height: 5rem;"></div>
</el-tab-pane>
<el-tab-pane name="solution">
<div slot="label" class="customer-label">解决方案 <span>3</span></div>
<div style="margin-top: 1rem;" v-for="(item, index) in news_list" :key="index">
<div :class="['search-news-wrapper', is_xs ? 'xs' : '']">
<div class="search-news-title" v-html="highlightKeyword(keyword, item.title)"></div>
<div class="search-news-content" v-html="highlightKeyword(keyword, item.content)"></div>
<div class="search-news-more">
<div class="search-news-more-btn" @click="goTo(item.id)">MORE</div>
</div>
</div>
</div>
</el-tab-pane>
<el-tab-pane name="success">
<div slot="label" class="customer-label">成功案例 <span>3</span></div>
<div style="margin-top: 1rem;" v-for="(item, index) in news_list" :key="index">
<div :class="['search-news-wrapper', is_xs ? 'xs' : '']">
<div class="search-news-title" v-html="highlightKeyword(keyword, item.title)"></div>
<div class="search-news-content" v-html="highlightKeyword(keyword, item.content)"></div>
<div class="search-news-more">
<div class="search-news-more-btn" @click="goTo(item.id)">MORE</div>
</div>
</div>
</div>
</el-tab-pane>
<el-tab-pane name="news">
<div slot="label" class="customer-label">新闻 <span>3</span></div>
<div style="margin-top: 1rem;" v-for="(item, index) in news_list" :key="index">
<!-- <el-breadcrumb separator="/">
<el-breadcrumb-item>首页</el-breadcrumb-item>
<el-breadcrumb-item>新闻中心</el-breadcrumb-item>
</el-breadcrumb> -->
<div :class="['search-news-wrapper', is_xs ? 'xs' : '']">
<div class="search-news-title" v-html="highlightKeyword(keyword, item.title)"></div>
<div class="search-news-content" v-html="highlightKeyword(keyword, item.content)"></div>
<div class="search-news-more">
<div class="search-news-more-btn" @click="goTo(item.id)">MORE</div>
</div>
</div>
</div>
</el-tab-pane>
</el-tabs>
</hager-box>
</div>
</template>
<script>
import mixin from 'common/mixin';
import hagerBox from '@/components/common/hagerBox';
import $ from 'jquery';
import objectFitImages from 'object-fit-images';
export default {
components: { hagerBox },
mixins: [mixin.init],
data () {
return {
activeName: 'product',
keyword: this.$route.query.keyword,
news_list: [{
id: '123',
title: '海格电气全新智能型hw+空气断路器重磅上市',
content: '11 月 24 日,海格电气在惠州举办了 2023 海格匠心之旅暨 hw+ 全系列新品发布会,面向中国市场正式推出了全新一代智能型 hw+ 空气断路器。海格电气管理层及员工代表,行业客户及合作伙伴等齐聚惠州工厂,共同见证海格电气新一代',
}, {
id: '456',
title: '里程碑时刻!海格电气首台全新一代HW+空气断路器',
content: '全新一代HW+空气断路器的整机下线,标志着海格电气在低压配电领域的进一步技术升级。作为海格电气在中国市场重磅推出的里程碑式产品,全新一代HW+空气断路器为大型建筑复杂、高负荷的用电需求提供高质量解决方案。',
}],
product_list: [{
id: '',
img: 'https://cdn.ipadbiz.cn/hager/img/product/t01.jpg',
title: 'acb hw 空气断路器'
}, {
id: '',
img: 'https://cdn.ipadbiz.cn/hager/img/product/t01.jpg',
title: 'acb hw 空气断路器'
}, {
id: '',
img: 'https://cdn.ipadbiz.cn/hager/img/product/t01.jpg',
title: 'acb hw 空气断路器'
}],
is_end: false
}
},
watch: {
'$route.query.keyword': function(newKeyword) {
this.keyword = newKeyword || '';
},
},
mounted () {
objectFitImages(this.$el); // 对当前组件的 DOM 元素应用
if (this.is_xs) { // 自适应模式下,左右箭头的颜色修改
this.modifyTabColor();
}
// 监听窗口的 resize 事件
window.addEventListener('resize', this.modifyTabColor);
},
beforeDestroy() {
// 在组件销毁前移除监听器,防止内存泄漏
window.removeEventListener('resize', this.modifyTabColor);
},
methods: {
modifyTabColor () {
this.$nextTick(() => {
setTimeout(() => {
// next按钮修改颜色
$('.el-tabs__nav-wrap').children('span.el-tabs__nav-next').css('color', '#F56400');
$('.el-tabs__nav-wrap').children('span.el-tabs__nav-next').on('click', (e) => {
$('.el-tabs__nav-wrap').children('span.el-tabs__nav-next').css('color', '#333')
$('.el-tabs__nav-wrap').children('span.el-tabs__nav-prev').css('color', '#F56400')
})
$('.el-tabs__nav-wrap').children('span.el-tabs__nav-prev').on('click', (e) => {
$('.el-tabs__nav-wrap').children('span.el-tabs__nav-next').css('color', '#F56400')
$('.el-tabs__nav-wrap').children('span.el-tabs__nav-prev').css('color', '#333')
})
}, 100);
})
},
handleClick(tab, event) {
console.log(tab, event);
},
highlightKeyword (keyword, text) {
// 创建一个正则表达式来查找关键词
var regex = new RegExp(`(${keyword})`, 'gi');
// 用 <span> 标签替换匹配到的关键词并加上高亮类
var highlightedText = text.replace(regex, '<span style="color: #00ABE5;">$1</span>');
return highlightedText;
},
goTo (id) {
this.$router.push({
path: '/news/detail',
query: {
id: id
}
});
},
goToDetail (v) { // 跳转产品详情
this.$router.push({
path: '/product/detail',
query: {
id: v.id
}
});
}
}
}
</script>
<style lang="less" scoped>
.hager-search-page {
.search-title {
font-size: 1.25rem;
color: @secondary-color;
margin: 2rem 0;
font-weight: bold;
}
.search-product-list {
display: flex;
flex-wrap: wrap;
gap: 1rem;
margin-top: 1rem;
}
.search-product-item {
width: calc(33.54% - 1rem);
&.xs {
width: calc(50% - 1rem);
}
}
.search-product-item-img {
background-color: #FFF;
display: flex;
align-items: center;
justify-content: center;
height: 18rem;
padding: 3rem;
box-sizing: border-box;
border-radius: 5px;
border: 1px solid #ECECEC;
background-position: center;
background-size: 70%;
background-repeat: no-repeat;
&.xs {
padding: 3rem 1rem;
background-size: 100%;
img {
width: 100%;
}
}
}
.search-product-item-title {
text-align: left;
margin-top: 0.75rem;
color: @text-color;
padding-left: 0.5rem;
font-weight: bold;
&:hover {
cursor: pointer;
text-decoration: underline;
}
}
.search-news-wrapper {
margin: 1.5rem 0;
&.xs {
border-bottom: 1px solid #ECECEC;
}
.search-news-title {
font-size: 1.15rem;
font-weight: bold;
margin-bottom: 1rem;
}
.search-news-content {
line-height: 2rem;
}
.search-news-more {
display: flex;
justify-content: flex-end;
.search-news-more-btn {
color: #F56400;
padding: 0.5rem 2rem;
border: 1px solid #F56400;
margin: 1rem 0;
&:hover {
cursor: pointer;
}
}
}
}
}
:deep(.el-tabs__item.is-active, ) {
color: @secondary-color;
}
:deep(.el-tabs__active-bar) {
background-color: @secondary-color;
}
:deep(.el-tabs__item:hover) {
color: @secondary-color;
}
:deep(.el-tabs__item) {
color: @text-color;
}
.customer-label {
font-size: 0.95rem;
padding: 0 0.5rem;
span {
color: #F56400;
}
}
:deep(.el-tabs__nav-prev) {
font-size: 1rem;
}
:deep(.el-tabs__nav-next) {
font-size: 1rem;
}
</style>