hookehuyr

✨ feat: 产品介绍页面新增头部banner显示

1 <!-- 1 <!--
2 * @Date: 2024-09-27 16:53:09 2 * @Date: 2024-09-27 16:53:09
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2024-11-07 14:51:28 4 + * @LastEditTime: 2024-11-11 09:28:03
5 * @FilePath: /hager/src/views/product/index.vue 5 * @FilePath: /hager/src/views/product/index.vue
6 * @Description: 文件描述 6 * @Description: 文件描述
7 --> 7 -->
8 <template> 8 <template>
9 <div class="product-index"> 9 <div class="product-index">
10 - <hager-box> 10 + <hager-box v-if="!is_search">
11 - <div v-if="!is_search" style="margin-top: 1.5rem;"> 11 + <div style="margin-top: 1.5rem;">
12 <el-breadcrumb v-if="!is_all_cate" separator="/"> 12 <el-breadcrumb v-if="!is_all_cate" separator="/">
13 <el-breadcrumb-item :to="{ path: allPath }">所有产品</el-breadcrumb-item> 13 <el-breadcrumb-item :to="{ path: allPath }">所有产品</el-breadcrumb-item>
14 <el-breadcrumb-item v-if="parent_name" :to="{ path: productPath }">{{ parent_name }}</el-breadcrumb-item> 14 <el-breadcrumb-item v-if="parent_name" :to="{ path: productPath }">{{ parent_name }}</el-breadcrumb-item>
...@@ -18,8 +18,28 @@ ...@@ -18,8 +18,28 @@
18 <el-breadcrumb-item>所有产品</el-breadcrumb-item> 18 <el-breadcrumb-item>所有产品</el-breadcrumb-item>
19 </el-breadcrumb> 19 </el-breadcrumb>
20 </div> 20 </div>
21 - <hager-h1 v-if="!is_search" :title="category_name" :sub="category_name_en" style="margin: 2rem 0;"></hager-h1> 21 + </hager-box>
22 - <hager-h1 v-else :title="'与“' + keyword + '”相关的搜索结果'" :sub="''" style="margin: 2rem 0;"></hager-h1> 22 + <hager-box v-if="!is_xs && !is_search" :class="['top-img', is_xs ? 'xs' : '']" :style="{ backgroundImage: `url('https://cdn.ipadbiz.cn/hager/img/product/banner-l@2x.png'), url(${banner})`, marginTop: '1rem' }">
23 + <div class="banner-text-wrapper" style="margin-top: 5%;">
24 + <div class="text">
25 + <p class="title" style="margin-bottom: 0; color: white; font-size: 2.2vw;">{{ category_name }}</p>
26 + <p class="sub" style="color: white; font-size: 2.2vw;">{{ category_name_en }}</p>
27 + <div style="margin-top: 1rem; font-weight: normal; font-size: 1.15vw; color: white; width: 50%;">
28 + <p v-html="category_description"></p>
29 + </div>
30 + </div>
31 + </div>
32 + </hager-box>
33 + <hager-box>
34 + <div v-if="!is_xs">
35 + <hager-h1 v-if="is_search" :title="'与“' + keyword + '”相关的搜索结果'" :sub="''" style="margin: 2rem 0;"></hager-h1>
36 + </div>
37 + <div v-else>
38 + <hager-h1 v-if="!is_search" :title="category_name" :sub="category_name_en" style="margin: 2rem 0;"></hager-h1>
39 + <hager-h1 v-else :title="'与“' + keyword + '”相关的搜索结果'" :sub="''" style="margin: 2rem 0;"></hager-h1>
40 + </div>
41 + </hager-box>
42 + <hager-box>
23 <el-row v-if="!is_xs" :gutter="0" style="margin: 1rem 0;"> 43 <el-row v-if="!is_xs" :gutter="0" style="margin: 1rem 0;">
24 <el-col :span="6"> 44 <el-col :span="6">
25 <div class="product-nav-wrapper"> 45 <div class="product-nav-wrapper">
...@@ -79,6 +99,8 @@ export default { ...@@ -79,6 +99,8 @@ export default {
79 parent_name: '', 99 parent_name: '',
80 category_name: '所有产品', 100 category_name: '所有产品',
81 category_name_en: 'All Products', 101 category_name_en: 'All Products',
102 + category_description: '',
103 + banner: '',
82 cate_list: [], 104 cate_list: [],
83 product_list: [], 105 product_list: [],
84 no_product_img: 'https://cdn.ipadbiz.cn/hager/img/no-product-img.png', 106 no_product_img: 'https://cdn.ipadbiz.cn/hager/img/no-product-img.png',
...@@ -137,7 +159,9 @@ export default { ...@@ -137,7 +159,9 @@ export default {
137 this.$nextTick(() => { 159 this.$nextTick(() => {
138 // 动态计算图片高度 160 // 动态计算图片高度
139 let img_width = $('.product-item-img img').outerWidth(); 161 let img_width = $('.product-item-img img').outerWidth();
140 - $('.product-item-img img').css('height', img_width * 1 + 'px') 162 + $('.product-item-img img').css('height', img_width * 1 + 'px');
163 + let banner_width = $('.top-img').outerWidth();
164 + $('.top-img').css('height', banner_width * 0.21 + 'px');
141 }) 165 })
142 }, 166 },
143 handleChange(val) { 167 handleChange(val) {
...@@ -158,6 +182,8 @@ export default { ...@@ -158,6 +182,8 @@ export default {
158 let info = data[0]; 182 let info = data[0];
159 this.category_name = '所有产品'; 183 this.category_name = '所有产品';
160 this.category_name_en = 'All Products'; 184 this.category_name_en = 'All Products';
185 + this.category_description = '';
186 + this.banner = 'https://cdn.ipadbiz.cn/hager/img/product/banner-r@2x.png';
161 this.product_list = info.list; 187 this.product_list = info.list;
162 188
163 this.search_keyword = ''; 189 this.search_keyword = '';
...@@ -174,6 +200,8 @@ export default { ...@@ -174,6 +200,8 @@ export default {
174 this.parent_name = info.parent_name; 200 this.parent_name = info.parent_name;
175 this.category_name = info.category_name; 201 this.category_name = info.category_name;
176 this.category_name_en = info.category_name_en; 202 this.category_name_en = info.category_name_en;
203 + this.category_description = info.category_description;
204 + this.banner = info.banner;
177 this.product_list = info.list; 205 this.product_list = info.list;
178 206
179 this.search_keyword = ''; 207 this.search_keyword = '';
...@@ -257,6 +285,21 @@ export default { ...@@ -257,6 +285,21 @@ export default {
257 } 285 }
258 } 286 }
259 287
288 + .top-img {
289 + background-size: 50% 100%; /* 每张背景图各占 50% 的宽度,100% 的高度 */
290 + background-position: left, right; /* 第一张图在左侧,第二张图在右侧 */
291 + background-repeat: no-repeat; /* 避免背景图重复 */
292 + position: relative;
293 + width: 100%;
294 + height: 25rem; /* 或根据需要指定高度 */
295 + &.xs {
296 + height: 12rem;
297 + }
298 + .top-center {
299 + position: absolute;
300 + transform: translateY(50%); /* 垂直与水平居中 */
301 + }
302 + }
260 303
261 .product-list { 304 .product-list {
262 display: flex; 305 display: flex;
......