hookehuyr

首页最新资讯模块显示兼容性优化

1 /* 1 /*
2 * @Date: 2024-08-26 10:12:56 2 * @Date: 2024-08-26 10:12:56
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2024-10-11 13:20:49 4 + * @LastEditTime: 2024-10-15 18:40:00
5 * @FilePath: /hager/src/main.js 5 * @FilePath: /hager/src/main.js
6 * @Description: 文件描述 6 * @Description: 文件描述
7 */ 7 */
...@@ -28,6 +28,47 @@ Vue.component(CollapseTransition.name, CollapseTransition) ...@@ -28,6 +28,47 @@ Vue.component(CollapseTransition.name, CollapseTransition)
28 28
29 Vue.use(VueAwesomeSwiper); 29 Vue.use(VueAwesomeSwiper);
30 30
31 +Vue.directive('clamp', {
32 + inserted(el, binding) {
33 + // 保存原始的完整文本
34 + el.__fullText__ = el.innerText;
35 +
36 + // 初始调用文本截断函数
37 + clampText(el, binding.value);
38 +
39 + // 添加 resize 监听器
40 + el.__resizeHandler__ = () => {
41 + clampText(el, binding.value);
42 + };
43 + window.addEventListener('resize', el.__resizeHandler__);
44 + },
45 +
46 + componentUpdated(el, binding) {
47 + // 组件更新时重新截断文本
48 + clampText(el, binding.value);
49 + },
50 +
51 + unbind(el) {
52 + // 移除监听器以避免内存泄漏
53 + window.removeEventListener('resize', el.__resizeHandler__);
54 + delete el.__resizeHandler__;
55 + }
56 +});
57 +
58 +function clampText(element, lineCount) {
59 + const lineHeight = parseFloat(getComputedStyle(element).lineHeight); // 获取行高
60 + const maxHeight = lineHeight * lineCount; // 根据行数计算最大高度
61 + let fullText = element.__fullText__; // 使用原始的完整文本进行截断
62 + element.innerText = fullText; // 每次截断前恢复完整文本
63 + element.style.maxHeight = `${maxHeight}px`; // 设置最大高度
64 +
65 + // 处理文本截断
66 + while (element.scrollHeight > element.offsetHeight) { // 如果内容溢出
67 + fullText = fullText.slice(0, -1); // 每次减少一个字符
68 + element.innerText = fullText + '...'; // 重新设置文本并加省略号
69 + }
70 +}
71 +
31 new Vue({ 72 new Vue({
32 router, 73 router,
33 render: (h) => h(App), 74 render: (h) => h(App),
......
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-10-15 17:18:48 4 + * @LastEditTime: 2024-10-15 18:40:38
5 * @FilePath: /hager/src/views/index.vue 5 * @FilePath: /hager/src/views/index.vue
6 * @Description: 文件描述 6 * @Description: 文件描述
7 --> 7 -->
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
47 <p class="text">22 production sites</p> 47 <p class="text">22 production sites</p>
48 </div> 48 </div>
49 </div> 49 </div>
50 - <div style="display: flex; justify-content: center; margin-top: 1rem;"> 50 + <div class="more-box" style="margin-top: 1rem;">
51 <hager-more></hager-more> 51 <hager-more></hager-more>
52 </div> 52 </div>
53 </div> 53 </div>
...@@ -55,14 +55,14 @@ ...@@ -55,14 +55,14 @@
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"> 58 + <el-row :gutter="15" v-for="(item, index) in splitListIntoChunks(solution_list)" :key="index">
59 - <el-col :span="6" v-for="(item, index) in solution_list" :key="index"> 59 + <el-col :span="6" v-for="(x, idx) in item" :key="idx">
60 <div 60 <div
61 - @click="goToSolution(item)" 61 + @click="goToSolution(x)"
62 - class="solution-item" 62 + :class="['solution-item', x.id === 'other' ? 'other' : '']"
63 - :style="{ backgroundImage: 'url('+item.src+')' }" 63 + :style="{ backgroundImage: 'url('+x.src+')' }"
64 > 64 >
65 - <p>{{ item.title }}</p> 65 + <p>{{ x.title }}</p>
66 </div> 66 </div>
67 </el-col> 67 </el-col>
68 </el-row> 68 </el-row>
...@@ -114,32 +114,35 @@ ...@@ -114,32 +114,35 @@
114 </div> 114 </div>
115 </div> 115 </div>
116 </div> 116 </div>
117 + <div class="more-box" style="margin-top: 2rem;">
118 + <hager-more></hager-more>
119 + </div>
117 </hager-box> 120 </hager-box>
118 <hager-box v-if="!is_xs" class="box-2n"> 121 <hager-box v-if="!is_xs" class="box-2n">
119 <hager-h1 title="最新资讯" sub="News"></hager-h1> 122 <hager-h1 title="最新资讯" sub="News"></hager-h1>
120 <div class="news-container"> 123 <div class="news-container">
121 <el-row :gutter="0" v-for="(item, index) in news_list" :key="index"> 124 <el-row :gutter="0" v-for="(item, index) in news_list" :key="index">
122 - <el-col :span="12" style="height: 25rem;"> 125 + <el-col :span="12" style="background-color: #FFF; height: 25rem;">
123 <img class="news-item-img" v-if="index % 2 === 0" :src="item.src" alt="News Image 1"> 126 <img class="news-item-img" v-if="index % 2 === 0" :src="item.src" alt="News Image 1">
124 <div v-else @click="goToNew(item)" class="news-item"> 127 <div v-else @click="goToNew(item)" class="news-item">
125 <div class="news-item-title">{{ item.title }}</div> 128 <div class="news-item-title">{{ item.title }}</div>
126 - <p class="news-item-sub">{{ item.sub }}</p> 129 + <p class="news-item-sub" v-clamp="2">{{ item.sub }}</p>
127 - <p class="news-item-content">{{ item.content }}</p> 130 + <p class="news-item-content" v-clamp="3">{{ item.content }}</p>
128 - <i class="el-icon-right"></i> 131 + <div class="news-item-more" style="margin-top: 3rem;">MORE</div>
129 </div> 132 </div>
130 </el-col> 133 </el-col>
131 <el-col :span="12" style="background-color: #FFF; height: 25rem;"> 134 <el-col :span="12" style="background-color: #FFF; height: 25rem;">
132 <div v-if="index % 2 === 0" @click="goToNew(item)" class="news-item"> 135 <div v-if="index % 2 === 0" @click="goToNew(item)" class="news-item">
133 <div class="news-item-title">{{ item.title }}</div> 136 <div class="news-item-title">{{ item.title }}</div>
134 - <p class="news-item-sub">{{ item.sub }}</p> 137 + <p class="news-item-sub" v-clamp="2">{{ item.sub }}</p>
135 - <p class="news-item-content">{{ item.content }}</p> 138 + <p class="news-item-content" v-clamp="3">{{ item.content }}</p>
136 - <i class="el-icon-right"></i> 139 + <div class="news-item-more" style="margin-top: 3rem;">MORE</div>
137 </div> 140 </div>
138 <img class="news-item-img" v-else :src="item.src" alt="News Image 1"> 141 <img class="news-item-img" v-else :src="item.src" alt="News Image 1">
139 </el-col> 142 </el-col>
140 </el-row> 143 </el-row>
141 </div> 144 </div>
142 - <div style="display: flex; justify-content: center; margin-top: 2rem;"> 145 + <div class="more-box" style="margin-top: 3rem;">
143 <hager-more></hager-more> 146 <hager-more></hager-more>
144 </div> 147 </div>
145 </hager-box> 148 </hager-box>
...@@ -151,21 +154,21 @@ ...@@ -151,21 +154,21 @@
151 <img class="news-item-img xs" :src="item.src" alt="News Image 1"> 154 <img class="news-item-img xs" :src="item.src" alt="News Image 1">
152 <div @click="goToNew(item)" class="news-item xs"> 155 <div @click="goToNew(item)" class="news-item xs">
153 <div class="news-item-title">{{ item.title }}</div> 156 <div class="news-item-title">{{ item.title }}</div>
154 - <p class="news-item-sub">{{ item.sub }}</p> 157 + <p class="news-item-sub" v-clamp="2">{{ item.sub }}</p>
155 - <p class="news-item-content">{{ item.content }}</p> 158 + <p class="news-item-content" v-clamp="3">{{ item.content }}</p>
156 - <i class="el-icon-right"></i> 159 + <div class="news-item-more">MORE</div>
157 </div> 160 </div>
158 </el-col> 161 </el-col>
159 </el-row> 162 </el-row>
160 </div> 163 </div>
161 - <div style="display: flex; justify-content: center; margin-top: 2rem;"> 164 + <div class="more-box" style="margin-top: 3rem;">
162 <hager-more></hager-more> 165 <hager-more></hager-more>
163 </div> 166 </div>
164 </div> 167 </div>
165 <hager-box class="box-n"> 168 <hager-box class="box-n">
166 <hager-h1 title="招聘信息" sub="Recruit"></hager-h1> 169 <hager-h1 title="招聘信息" sub="Recruit"></hager-h1>
167 <p style="margin: 2rem 0;">心国近心,支注万你。海恰人囫指员光工,然于則行!我们哦这音齐稱央那八我们附行列,共同书与成功的扁草。用你的才罕,刨道九限可能!</p> 170 <p style="margin: 2rem 0;">心国近心,支注万你。海恰人囫指员光工,然于則行!我们哦这音齐稱央那八我们附行列,共同书与成功的扁草。用你的才罕,刨道九限可能!</p>
168 - <div style="display: flex; justify-content: center; margin-top: 2rem;"> 171 + <div class="more-box" style="margin-top: 2rem;">
169 <hager-more></hager-more> 172 <hager-more></hager-more>
170 </div> 173 </div>
171 </hager-box> 174 </hager-box>
...@@ -188,7 +191,7 @@ export default { ...@@ -188,7 +191,7 @@ export default {
188 src: 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg', 191 src: 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg',
189 title: '获奖+1!海格电气荣获2023酒店文旅优秀国际标1!海格电气荣获2023酒店文旅优秀国际标1!海格电气荣获2023酒店文旅优秀国际标1!海格电气荣获2023酒店文旅优秀国际标1!海格电气荣获2023酒店文旅优秀国际标1!海格电气荣获2023酒店文旅优秀国际标1!海格电气荣获2023酒店文旅优秀国际标1!海格电气荣获2023酒店文旅优秀国际标1!海格电气荣获2023酒店文旅优秀', 192 title: '获奖+1!海格电气荣获2023酒店文旅优秀国际标1!海格电气荣获2023酒店文旅优秀国际标1!海格电气荣获2023酒店文旅优秀国际标1!海格电气荣获2023酒店文旅优秀国际标1!海格电气荣获2023酒店文旅优秀国际标1!海格电气荣获2023酒店文旅优秀国际标1!海格电气荣获2023酒店文旅优秀国际标1!海格电气荣获2023酒店文旅优秀国际标1!海格电气荣获2023酒店文旅优秀',
190 content: '11月28-29日,2023汤点文旅住宿节在苏州国际会议酒店隆重开幕,作为酒店整11月28-29日,2023汤点文旅住宿节在苏州国际会议酒店隆重开幕,作为酒店整11月28-29日,2023汤点文旅住宿节在苏州国际会议酒店隆重开幕,作为酒店整11月28-29日,2023汤点文旅住宿节在苏州国际会议酒店隆重开幕,作为酒店整', 193 content: '11月28-29日,2023汤点文旅住宿节在苏州国际会议酒店隆重开幕,作为酒店整11月28-29日,2023汤点文旅住宿节在苏州国际会议酒店隆重开幕,作为酒店整11月28-29日,2023汤点文旅住宿节在苏州国际会议酒店隆重开幕,作为酒店整11月28-29日,2023汤点文旅住宿节在苏州国际会议酒店隆重开幕,作为酒店整',
191 - sub: 'o Ehe gy aha oid asto Ehe gy aha oid asto Ehe gy aha oid ast' 194 + sub: 'o Ehe gy aha oid asto Ehe gy aha oid asto Ehe gy aha oid ast o Ehe gy aha oid asto Ehe gy aha oid asto Ehe gy aha oid astgy aha oid asto Ehe gy aha oid asto Ehe gy aha oid ast'
192 }, { 195 }, {
193 src: 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg', 196 src: 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg',
194 title: '获奖+1!海格电气荣获2023酒店文旅优秀国际标1!海格电气荣获2023酒店文旅优秀国际标1!海格电气荣获2023酒店文旅优秀国际标1!海格电气荣获2023酒店文旅优秀国际标1!海格电气荣获2023酒店文旅优秀国际标1!海格电气荣获2023酒店文旅优秀国际标1!海格电气荣获2023酒店文旅优秀国际标1!海格电气荣获2023酒店文旅优秀国际标1!海格电气荣获2023酒店文旅优秀', 197 title: '获奖+1!海格电气荣获2023酒店文旅优秀国际标1!海格电气荣获2023酒店文旅优秀国际标1!海格电气荣获2023酒店文旅优秀国际标1!海格电气荣获2023酒店文旅优秀国际标1!海格电气荣获2023酒店文旅优秀国际标1!海格电气荣获2023酒店文旅优秀国际标1!海格电气荣获2023酒店文旅优秀国际标1!海格电气荣获2023酒店文旅优秀国际标1!海格电气荣获2023酒店文旅优秀',
...@@ -214,6 +217,12 @@ export default { ...@@ -214,6 +217,12 @@ export default {
214 }, { 217 }, {
215 src: 'https://fastly.jsdelivr.net/npm/@vant/assets/cat.jpeg', 218 src: 'https://fastly.jsdelivr.net/npm/@vant/assets/cat.jpeg',
216 title: '4住宅解决方案' 219 title: '4住宅解决方案'
220 + }, {
221 + src: 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg',
222 + title: '3住宅解决方案'
223 + }, {
224 + src: 'https://fastly.jsdelivr.net/npm/@vant/assets/cat.jpeg',
225 + title: '4住宅解决方案'
217 }], 226 }],
218 product_list: [{ 227 product_list: [{
219 src: 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg', 228 src: 'https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg',
...@@ -288,6 +297,21 @@ export default { ...@@ -288,6 +297,21 @@ export default {
288 } 297 }
289 }, 298 },
290 methods: { 299 methods: {
300 + splitListIntoChunks (list) {
301 + const chunkSize = 4; // 每组4个项目
302 + const result = [];
303 +
304 + // 按每4个为一组进行分割
305 + for (let i = 0; i < list.length; i += chunkSize) {
306 + const chunk = list.slice(i, i + chunkSize);
307 + result.push(chunk);
308 + }
309 +
310 + // 在最后一组添加 {src:'', title:'other'}
311 + result[result.length - 1].push({ id: 'other', src: '', title: 'Other解决方案' });
312 +
313 + return result;
314 + },
291 toggleFold (v) { 315 toggleFold (v) {
292 this.is_fold = !this.is_fold; 316 this.is_fold = !this.is_fold;
293 }, 317 },
...@@ -422,21 +446,26 @@ export default { ...@@ -422,21 +446,26 @@ export default {
422 background-size: cover; 446 background-size: cover;
423 background-position: center; 447 background-position: center;
424 transition: transform 0.3s ease-in-out; 448 transition: transform 0.3s ease-in-out;
449 + margin-bottom: 1rem;
425 &:hover { 450 &:hover {
426 - // transform: scale(1.05); 451 + transform: scale(1.05);
427 - // box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); 452 + box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
428 cursor: pointer; 453 cursor: pointer;
429 } 454 }
430 &.other { 455 &.other {
431 display: flex; 456 display: flex;
432 background-color: #e0f7ff; /* 特殊的样式 */ 457 background-color: #e0f7ff; /* 特殊的样式 */
433 color: @secondary-color; 458 color: @secondary-color;
434 - font-weight: bold; 459 + // font-weight: bold;
435 // line-height: 8rem; 460 // line-height: 8rem;
436 background-image: none; 461 background-image: none;
437 align-items: center; 462 align-items: center;
438 justify-content: center; 463 justify-content: center;
439 - font-size: 1.5rem; 464 + font-size: 1.25rem;
465 + p {
466 + position: relative;
467 + background-color: #e0f7ff;
468 + }
440 } 469 }
441 p { 470 p {
442 position: absolute; 471 position: absolute;
...@@ -502,14 +531,29 @@ export default { ...@@ -502,14 +531,29 @@ export default {
502 .news-item-sub { 531 .news-item-sub {
503 color: @primary-color; 532 color: @primary-color;
504 margin-top: 0.25rem; 533 margin-top: 0.25rem;
534 + line-height: 1.5em;
535 + overflow: hidden;
536 + word-break: break-word;
505 } 537 }
506 .news-item-content { 538 .news-item-content {
507 margin: 2rem 0; 539 margin: 2rem 0;
540 + color: @text-color;
541 + line-height: 1.5em;
542 + overflow: hidden;
543 + word-break: break-word;
508 } 544 }
509 - i { 545 + .news-item-more {
510 - color: @primary-color; 546 + border: 0.08rem solid #F56400;
511 - font-size: 1.5rem; 547 + color: #F56400;
548 + padding: 0.5rem 1rem;
549 + width: 5rem;
550 + text-align: center;
551 + font-size: 0.8rem;
512 } 552 }
553 + // i {
554 + // color: @primary-color;
555 + // font-size: 1.5rem;
556 + // }
513 } 557 }
514 } 558 }
515 559
...@@ -563,5 +607,10 @@ export default { ...@@ -563,5 +607,10 @@ export default {
563 padding-left: 20%; 607 padding-left: 20%;
564 } 608 }
565 } 609 }
610 +
611 + .more-box {
612 + display: flex;
613 + justify-content: center;
614 + }
566 } 615 }
567 </style> 616 </style>
......