hagerHeader.vue 12.6 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 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411
<!--
 * @Date: 2024-09-26 13:42:11
 * @LastEditors: hookehuyr hookehuyr@gmail.com
 * @LastEditTime: 2024-09-30 11:34:14
 * @FilePath: /hager/src/components/common/hagerHeader.vue
 * @Description: 文件描述
-->
<template>
  <div class="hager-header">
    <el-row class="hidden-xs-only" style="background-color: #fff;">
      <el-col :sm="2" :md="2" :lg="3" :xl="4">&nbsp;</el-col>
      <el-col :sm="20" :md="20" :lg="18" :xl="16" style="position: relative;height: 5rem;">
        <el-row style="">
          <el-col :sm="16" :md="16" :lg="16" :xl="16">
            <div class="nav-wrapper">
              <div>图标</div>
              <div :class="[is_active === 'product' ? 'active' : '', 'item']" @click="onClickProduct">产品中心</div>
              <div :class="[is_active === 'solution' ? 'active' : '', 'item']" @click="goTo('/solution/index')">解决方案</div>
              <div :class="[is_active === '新闻中心' ? 'active' : '', 'item']">新闻中心</div>
              <div :class="[is_active === '招聘信息' ? 'active' : '', 'item']">招聘信息</div>
              <div :class="[is_active === '关于海格' ? 'active' : '', 'item']">关于海格</div>
              <div :class="[is_active === '联系我们' ? 'active' : '', 'item']">联系我们</div>
              <div :class="[is_active === 'index' ? 'active' : '', 'item']" @click="goTo('/')">首页</div>
            </div>
          </el-col>
          <el-col :sm="8" :md="8" :lg="8" :xl="8">
            <div style="display: flex; height: 5rem; align-items: center;justify-content: right;">
              <div style="display: flex; align-items: center; border-radius: 1rem; border: 1px solid #f5f5f5;  background-color: #e3f1f7; padding: 0.5rem 1rem;">
                <i class=el-icon-zoom-out></i>&nbsp;
                <input style="border: 0;background-color: #e3f1f7;" placeholder="搜索" />
              </div>
              <div style="margin: 0 1rem;"><i class=el-icon-eleme></i></div>
              <div><i class=el-icon-eleme></i></div>
            </div>
          </el-col>
        </el-row>
        <el-collapse-transition>
          <div v-show="show" class="product-center">
            <div style="display: flex; width: 100%;">
              <div class="product-left-wrapper">
                <div :class="['product-left-item', p_index === index ? 'active' : '']" v-for="(item, index) in product_menu" :key="index" @click="onClick(item, index)">
                  <div style="display: flex; align-items: center;">
                    <el-image style="width: 2rem; height: 2rem" src="https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg" fit="fit"></el-image>
                    &nbsp;
                    {{ item.name }}
                  </div>
                  <div>
                    <i class="el-icon-right"></i>
                  </div>
                </div>
              </div>
              <div class="product-right-wrapper">
                <div class="product-right-title">
                  <div class="text">{{ product_info.name }}</div>
                  <div @click="closeMenu"><i class="el-icon-close" style="font-size: 1.25rem;"></i></div>
                </div>
                <div class="product-right-desc">{{ product_info.desc }}</div>
                <div class="product-right-center">
                  <div v-for="(item, index) in product_info.product" :key="index" class="product-right-center-item">
                    <div @click="goToC(item)" class="header-text">{{ item.name }}&nbsp;</div>
                    <div>
                      <div class="item-text" @click="goToP(item)" v-for="(p, idx) in item.list" :key="idx">{{ p.name }}</div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </el-collapse-transition>
      </el-col>
      <el-col :sm="2" :md="2" :lg="3" :xl="4">&nbsp;</el-col>
    </el-row>
  </div>
</template>

<script>
import mixin from 'common/mixin';
import { parseQueryString } from '@/utils/tools';

export default {
  mixins: [mixin.init],
  data () {
    return {
      show: false,
      test1: true,
      product_menu: [{
        name: '配电产品',
        info: {
          name: '配电产品',
          desc: '探索配电新境界,我们的产品引领行业潮流,提供高效、安全的配电解决方案,助您事业更上一层楼!',
          product: [
            {
              name: '空气断路器',
              list: [{
                id: '',
                name: 'HW系列空气断路器'
              }, {
                id: '',
                name: 'HW+系列空气断路器'
              }]
            },
            {
              name: '空气断路器',
              list: [{
                id: '',
                name: 'HW系列空气断路器'
              }, {
                id: '',
                name: 'HW+系列空气断路器'
              }]
            },
            {
              name: '空气断路器',
              list: [{
                id: '',
                name: 'HW系列空气断路器'
              }, {
                id: '',
                name: 'HW+系列空气断路器'
              }]
            },
            {
              name: '空气断路器',
              list: [{
                id: '',
                name: 'HW系列空气断路器'
              }, {
                id: '',
                name: 'HW+系列空气断路器'
              }, {
                id: '',
                name: 'HW系列空气断路器'
              }, {
                id: '',
                name: 'HW+系列空气断路器'
              }, {
                id: '',
                name: 'HW系列空气断路器'
              }]
            },
            {
              name: '空气断路器',
              list: [{
                id: '',
                name: 'HW系列空气断路器'
              }, {
                id: '',
                name: 'HW+系列空气断路器'
              }]
            },
            {
              name: '空气断路器',
              list: [{
                id: '',
                name: 'HW系列空气断路器'
              }, {
                id: '',
                name: 'HW+系列空气断路器'
              }]
            },
            {
              name: '空气断路器',
              list: [{
                id: '',
                name: 'HW系列空气断路器'
              }, {
                id: '',
                name: 'HW+系列空气断路器'
              }, {
                id: '',
                name: 'HW系列空气断路器'
              }, {
                id: '',
                name: 'HW+系列空气断路器'
              }, {
                id: '',
                name: 'HW系列空气断路器'
              }, {
                id: '',
                name: 'HW系列空气断路器'
              }, {
                id: '',
                name: 'HW+系列空气断路器'
              }, {
                id: '',
                name: 'HW系列空气断路器'
              }, {
                id: '',
                name: 'HW+系列空气断路器'
              }, {
                id: '',
                name: 'HW系列空气断路器'
              }]
            },
          ]
        }
      }, {
        name: '成套产品',
        info: {
          name: '成套产品',
          desc: '探索配电新境界,我们的产品引领行业潮流,提供高效、安全的配电解决方案,助您事业更上一层楼!',
          product: []
        }
      }, {
        name: '开关面板',
        info: {
          name: '开关面板',
          desc: '探索配电新境界,我们的产品引领行业潮流,提供高效、安全的配电解决方案,助您事业更上一层楼!',
          product: []
        }
      }, {
        name: '智能控制',
        info: {
          name: '智能控制',
          desc: '探索配电新境界,我们的产品引领行业潮流,提供高效、安全的配电解决方案,助您事业更上一层楼!',
          product: []
        }
      }],
      product_info: {},
      is_active: '',
      p_index: 0,
    }
  },
  mounted () {
    this.product_info = this.product_menu[0]['info'];
    // 修改数据结构显示
    this.product_info.product = this.splitProductList(this.product_info.product)
  },
  watch: {
    '$route' (to, from) {
      this.is_active = to.meta.tag;
    }
  },
  methods: {
    splitProductList (products) {
      const maxLength = 5; // 超过5个需要拆分
      let result = [];

      products.forEach(product => {
        // 如果 list 长度不超过 5,则直接加入 result
        if (product.list.length <= maxLength) {
          result.push(product);
        } else {
          // 如果 list 长度超过 5,则拆分
          let listChunks = [];
          for (let i = 0; i < product.list.length; i += maxLength) {
            listChunks.push(product.list.slice(i, i + maxLength));
          }

          // 第一个块保留原有的 name,后续块 name 设为空
          listChunks.forEach((chunk, index) => {
            if (index === 0) {
              result.push({
                name: product.name,
                list: chunk
              });
            } else {
              result.push({
                name: '',
                list: chunk
              });
            }
          });
        }
      });

      return result;
    },
    onClickProduct() {
      // 当鼠标悬停时
      this.show = true;
    },
    onClick (item, index) {
      this.product_info = item.info;
      this.p_index = index
    },
    closeMenu () {
      this.show = false;
    },
    goTo (path) { // 跳转页面
      if (this.$route.path !== path) { // 不能重复点击当前页面
        this.$router.push({
          path,
        });
      }
    },
    goToC (item) { // 跳转产品二级
      this.$router.push({
        path: '/product/index',
        query: {
          // id: id
        }
      });
      this.closeMenu();
    },
    goToP (item) { // 跳转产品详情
      this.$router.push({
        path: '/product/detail',
        query: {
          // id: id
        }
      });
      this.closeMenu();
    }
  }
}
</script>

<style lang="less" scoped>
  .hager-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 9;
    .product-center {
      position: absolute;
      top: 5rem;
      left: 0;
      width: 100%;
      height: auto;
      background-color: #fff;
      border-bottom-left-radius: 5px;
      border-bottom-right-radius: 5px;
      .product-left-wrapper {
        flex-basis: 33.33%;
        padding: 1rem;
        &:hover {
          cursor: pointer;
        }
        .product-left-item {
          display: flex;
          align-items: center;
          justify-content: space-between;
          padding: 1rem;
          &.active {
            background-color: @background-color;
            border-radius: 5px;
          }
          i {
            color: @primary-color;
          }
        }
      }
      .product-right-wrapper {
        flex-basis: 66.67%;
        background-color: @background-color;
        padding: 1.75rem 1.5rem;
        .product-right-title {
          display: flex;
          justify-content: space-between;
          margin-bottom: 0.25rem;
          .text {
            font-size: 1.25rem;
            color: @text-color;
            font-weight: bold;
          }
          i {
            &:hover {
              cursor: pointer;
            }
          }
        }
        .product-right-desc {
          margin-bottom: 1.5rem;
          color: @secondary-text-color;
        }
        .product-right-center {
          display: flex;
          flex-wrap: wrap;
          // justify-content: space-between;
          .product-right-center-item {
            flex-basis: calc(33.33%);
            margin-bottom: 10px;
            .header-text {
              margin-bottom: 0.25rem;
              color: @text-color;
              &:hover {
                cursor: pointer;
                text-decoration: underline;
              }
            }
            .item-text {
              line-height: 1.75;
              color: @secondary-text-color;
              &:hover {
                cursor: pointer;
                text-decoration: underline;
              }
            }
          }
        }
      }
    }
    .nav-wrapper {
      display: flex;
      height: 5rem;
      align-items: center;
      justify-content: space-around;
      .item {
        color: @secondary-color;
        &:hover {
          cursor: pointer;
        }
      }
      .active {
        color: @primary-color;
      }
    }
  }
</style>