hookehuyr

修复图片高度显示问题

1 <!-- 1 <!--
2 * @Date: 2024-08-27 10:06:30 2 * @Date: 2024-08-27 10:06:30
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2024-11-07 10:50:53 4 + * @LastEditTime: 2024-11-07 14:39:51
5 * @FilePath: /hager/src/views/index.vue 5 * @FilePath: /hager/src/views/index.vue
6 * @Description: 首页 6 * @Description: 首页
7 --> 7 -->
...@@ -55,7 +55,7 @@ ...@@ -55,7 +55,7 @@
55 <hager-box class="box-2n" @screen-width="handleScreenWidth"> 55 <hager-box class="box-2n" @screen-width="handleScreenWidth">
56 <hager-h1 title="解决方案" sub="Solution"></hager-h1> 56 <hager-h1 title="解决方案" sub="Solution"></hager-h1>
57 <div v-if="!is_xs" class="hager-solution"> 57 <div v-if="!is_xs" class="hager-solution">
58 - <el-row :gutter="15" v-for="(item, index) in splitListIntoChunks(solution_list)" :key="index"> 58 + <el-row :gutter="20" v-for="(item, index) in splitListIntoChunks(solution_list)" :key="index">
59 <el-col :span="6" v-for="(x, idx) in item" :key="idx"> 59 <el-col :span="6" v-for="(x, idx) in item" :key="idx">
60 <div 60 <div
61 @click="goToSolution(x)" 61 @click="goToSolution(x)"
...@@ -253,10 +253,11 @@ export default { ...@@ -253,10 +253,11 @@ export default {
253 // breakpoint时 显示的条数 253 // breakpoint时 显示的条数
254 this.productSlidesPerView = swiper.slidesPerView; 254 this.productSlidesPerView = swiper.slidesPerView;
255 }); 255 });
256 - }); 256 + // 高度监听
257 - // 高度监听
258 - this.$nextTick(() => {
259 this.product_box_height = $('.product-item').outerWidth() - $('.product-title').outerHeight() + 'px'; 257 this.product_box_height = $('.product-item').outerWidth() - $('.product-title').outerHeight() + 'px';
258 + // 动态计算解决方案图片高度
259 + let img_box_width = $('.solution-item').outerWidth();
260 + $('.solution-item').css('height', img_box_width * 0.56 + 'px');
260 }); 261 });
261 window.addEventListener('resize', this.handleHeightResize); 262 window.addEventListener('resize', this.handleHeightResize);
262 }, 263 },
...@@ -274,6 +275,9 @@ export default { ...@@ -274,6 +275,9 @@ export default {
274 handleHeightResize () { 275 handleHeightResize () {
275 // 高度监听 276 // 高度监听
276 this.product_box_height = $('.product-item').outerWidth() - $('.product-title').outerHeight() + 'px'; 277 this.product_box_height = $('.product-item').outerWidth() - $('.product-title').outerHeight() + 'px';
278 + // 动态计算解决方案图片高度
279 + let img_box_width = $('.solution-item').outerWidth();
280 + $('.solution-item').css('height', img_box_width * 0.56 + 'px');
277 }, 281 },
278 getToGroup () { 282 getToGroup () {
279 this.$router.push({ 283 this.$router.push({
......
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 10:56:07 4 + * @LastEditTime: 2024-11-07 14:51:28
5 * @FilePath: /hager/src/views/product/index.vue 5 * @FilePath: /hager/src/views/product/index.vue
6 * @Description: 文件描述 6 * @Description: 文件描述
7 --> 7 -->
...@@ -65,6 +65,7 @@ import hagerBox from '@/components/common/hagerBox'; ...@@ -65,6 +65,7 @@ import hagerBox from '@/components/common/hagerBox';
65 import hagerH1 from '@/components/common/hagerH1.vue'; 65 import hagerH1 from '@/components/common/hagerH1.vue';
66 import Accordion from '@/components/accordion/Accordion.vue'; 66 import Accordion from '@/components/accordion/Accordion.vue';
67 import { getProductCateAPI, getProductSearchAPI } from "@/api/hager.js"; 67 import { getProductCateAPI, getProductSearchAPI } from "@/api/hager.js";
68 +import $ from 'jquery';
68 69
69 export default { 70 export default {
70 components: { hagerBox, hagerH1, Accordion }, 71 components: { hagerBox, hagerH1, Accordion },
...@@ -91,6 +92,11 @@ export default { ...@@ -91,6 +92,11 @@ export default {
91 } else { // 没有ID显示所有产品 92 } else { // 没有ID显示所有产品
92 this.getAllMain(); 93 this.getAllMain();
93 } 94 }
95 + window.addEventListener('resize', this.changeImgHeight);
96 + },
97 + beforeDestroy() {
98 + // 在组件销毁前移除监听器,防止内存泄漏
99 + window.removeEventListener('resize', this.handleHeightResize);
94 }, 100 },
95 computed: { 101 computed: {
96 allPath () { 102 allPath () {
...@@ -127,6 +133,13 @@ export default { ...@@ -127,6 +133,13 @@ export default {
127 }, 133 },
128 }, 134 },
129 methods: { 135 methods: {
136 + changeImgHeight () {
137 + this.$nextTick(() => {
138 + // 动态计算图片高度
139 + let img_width = $('.product-item-img img').outerWidth();
140 + $('.product-item-img img').css('height', img_width * 1 + 'px')
141 + })
142 + },
130 handleChange(val) { 143 handleChange(val) {
131 }, 144 },
132 goToDetail (v) { // 跳转产品详情 145 goToDetail (v) { // 跳转产品详情
...@@ -150,6 +163,8 @@ export default { ...@@ -150,6 +163,8 @@ export default {
150 this.search_keyword = ''; 163 this.search_keyword = '';
151 // 设置页面标题 164 // 设置页面标题
152 document.title = '所有产品 | Hager China'; 165 document.title = '所有产品 | Hager China';
166 + // 动态计算图片高度
167 + this.changeImgHeight();
153 } 168 }
154 }, 169 },
155 async getMain () { 170 async getMain () {
...@@ -167,6 +182,8 @@ export default { ...@@ -167,6 +182,8 @@ export default {
167 this.getCurrentCate(this.cate_id); 182 this.getCurrentCate(this.cate_id);
168 // 设置页面标题 183 // 设置页面标题
169 document.title = this.category_name + ' | Hager China'; 184 document.title = this.category_name + ' | Hager China';
185 + // 动态计算图片高度
186 + this.changeImgHeight();
170 } 187 }
171 }, 188 },
172 async getCurrentCate (cate_id) { 189 async getCurrentCate (cate_id) {
...@@ -263,6 +280,7 @@ export default { ...@@ -263,6 +280,7 @@ export default {
263 box-sizing: border-box; 280 box-sizing: border-box;
264 border-radius: 8px; 281 border-radius: 8px;
265 border: 1px solid #eee; 282 border: 1px solid #eee;
283 + overflow: hidden;
266 &:hover { 284 &:hover {
267 cursor: pointer; 285 cursor: pointer;
268 } 286 }
......
1 <!-- 1 <!--
2 * @Date: 2024-10-18 13:45:53 2 * @Date: 2024-10-18 13:45:53
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2024-11-04 16:32:38 4 + * @LastEditTime: 2024-11-07 14:58:09
5 * @FilePath: /hager/src/views/recruit.vue 5 * @FilePath: /hager/src/views/recruit.vue
6 * @Description: 招聘信息 6 * @Description: 招聘信息
7 --> 7 -->
...@@ -117,7 +117,7 @@ ...@@ -117,7 +117,7 @@
117 </div> 117 </div>
118 <div v-if="active_idx === 2"> 118 <div v-if="active_idx === 2">
119 <hager-box v-if="!is_xs"> 119 <hager-box v-if="!is_xs">
120 - <el-row v-for="(item, index) in culture_list" :key="index" style="box-shadow: 0rem 0rem 1.33rem 0.08rem rgba(0,0,0,0.09); border-radius: 5px; margin-bottom: 3rem;"> 120 + <el-row v-for="(item, index) in culture_list" :key="index" style="box-shadow: 0rem 0rem 1.33rem 0.08rem rgba(0,0,0,0.09); border-radius: 10px; margin-bottom: 3rem;">
121 <el-col :span="12"> 121 <el-col :span="12">
122 <div v-if="index % 2 === 0" class="corporate-culture-img" :style="{ 'background-image': 'url('+ item.img +')' }"></div> 122 <div v-if="index % 2 === 0" class="corporate-culture-img" :style="{ 'background-image': 'url('+ item.img +')' }"></div>
123 <div v-else class="corporate-culture-box"> 123 <div v-else class="corporate-culture-box">
...@@ -297,7 +297,10 @@ export default { ...@@ -297,7 +297,10 @@ export default {
297 this.designSlidesPerView = swiper.slidesPerView 297 this.designSlidesPerView = swiper.slidesPerView
298 }); 298 });
299 // 高度监听 299 // 高度监听
300 - this.recruit_box_height = $('.job-img-wrapper').outerWidth() * 0.09 + 'px'; 300 + this.recruit_box_height = $('.job-img-wrapper').outerWidth() * 0.1 + 'px';
301 + // 动态计算图片高度
302 + let img_box_width = $('.img-box').outerWidth();
303 + $('.img-box').css('height', img_box_width * 0.56 + 'px');
301 }); 304 });
302 window.addEventListener('resize', this.handleHeightResize); 305 window.addEventListener('resize', this.handleHeightResize);
303 }, 306 },
...@@ -308,7 +311,10 @@ export default { ...@@ -308,7 +311,10 @@ export default {
308 methods: { 311 methods: {
309 handleHeightResize () { 312 handleHeightResize () {
310 // 高度监听 313 // 高度监听
311 - this.recruit_box_height = $('.job-img-wrapper').outerWidth() * 0.09 + 'px'; 314 + this.recruit_box_height = $('.job-img-wrapper').outerWidth() * 0.1 + 'px';
315 + // 动态计算图片高度
316 + let img_box_width = $('.img-box').outerWidth();
317 + $('.img-box').css('height', img_box_width * 0.56 + 'px')
312 }, 318 },
313 onClickBtn (idx) { 319 onClickBtn (idx) {
314 this.active_idx = idx; 320 this.active_idx = idx;
...@@ -499,6 +505,7 @@ export default { ...@@ -499,6 +505,7 @@ export default {
499 background-repeat: no-repeat; 505 background-repeat: no-repeat;
500 background-size: cover; 506 background-size: cover;
501 // background-position: center; 507 // background-position: center;
508 + border-radius: 8px;
502 &.xs { 509 &.xs {
503 height: 15rem; 510 height: 15rem;
504 border-top-left-radius: 5px; 511 border-top-left-radius: 5px;
...@@ -511,6 +518,7 @@ export default { ...@@ -511,6 +518,7 @@ export default {
511 padding: 2rem; 518 padding: 2rem;
512 height: 22rem; /* 让 .about-box 撑满父容器 */ 519 height: 22rem; /* 让 .about-box 撑满父容器 */
513 box-sizing: border-box; 520 box-sizing: border-box;
521 + border-radius: 10px;
514 &.xs { 522 &.xs {
515 background-color: #F7F7F7; 523 background-color: #F7F7F7;
516 } 524 }
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
24 <hager-h1 title="行业解决方案" sub="Industry Solutions" style="margin: 2rem 0 1rem;"></hager-h1> 24 <hager-h1 title="行业解决方案" sub="Industry Solutions" style="margin: 2rem 0 1rem;"></hager-h1>
25 <div>海格电气为建筑,能源,工业,基础设施等行业提供安全、稳定、可靠、智能的低压配电解决方案及KNX智能楼宇解决方案。</div> 25 <div>海格电气为建筑,能源,工业,基础设施等行业提供安全、稳定、可靠、智能的低压配电解决方案及KNX智能楼宇解决方案。</div>
26 <div v-if="!is_xs" class="hager-industry-solutions"> 26 <div v-if="!is_xs" class="hager-industry-solutions">
27 - <el-row :gutter="15" v-for="(item, index) in splitListIntoChunks(solution_list)" :key="index"> 27 + <el-row :gutter="20" v-for="(item, index) in splitListIntoChunks(solution_list)" :key="index">
28 <el-col :span="6" v-for="(x, idx) in item" :key="idx"> 28 <el-col :span="6" v-for="(x, idx) in item" :key="idx">
29 <div @click="goToSolution(x)" class="card"> 29 <div @click="goToSolution(x)" class="card">
30 <img :src="x.cover" class="card-image"> 30 <img :src="x.cover" class="card-image">
...@@ -128,6 +128,9 @@ export default { ...@@ -128,6 +128,9 @@ export default {
128 // 高度监听 128 // 高度监听
129 this.solution_box_height = $('.hager-solution-top').outerWidth() * 0.4 + 'px'; 129 this.solution_box_height = $('.hager-solution-top').outerWidth() * 0.4 + 'px';
130 this.solution_mini_height = $('.hager-solution-top').outerWidth() * 0.6 + 'px'; 130 this.solution_mini_height = $('.hager-solution-top').outerWidth() * 0.6 + 'px';
131 + // 动态计算图片高度
132 + let img_width = $('.card-image').outerWidth();
133 + $('.card-image').css('height', img_width * 0.7 + 'px');
131 }); 134 });
132 window.addEventListener('resize', this.handleHeightResize); 135 window.addEventListener('resize', this.handleHeightResize);
133 }, 136 },
...@@ -140,6 +143,9 @@ export default { ...@@ -140,6 +143,9 @@ export default {
140 // 高度监听 143 // 高度监听
141 this.solution_box_height = $('.hager-solution-top').outerWidth() * 0.4 + 'px'; 144 this.solution_box_height = $('.hager-solution-top').outerWidth() * 0.4 + 'px';
142 this.solution_mini_height = $('.hager-solution-top').outerWidth() * 0.6 + 'px'; 145 this.solution_mini_height = $('.hager-solution-top').outerWidth() * 0.6 + 'px';
146 + // 动态计算图片高度
147 + let img_width = $('.card-image').outerWidth();
148 + $('.card-image').css('height', img_width * 0.7 + 'px');
143 }, 149 },
144 splitListIntoChunks (list) { 150 splitListIntoChunks (list) {
145 const chunkSize = 4; // 每组4个项目 151 const chunkSize = 4; // 每组4个项目
......