Header.vue 13.1 KB
Newer Older
richard_1015's avatar
richard_1015 已提交
1
<template>
A
ailululu 已提交
2 3
  <!-- <div class="doc-header" :style="{ background: themeColor === 'red' ? headerBg : themeColor }" :class="`doc-header-${data.theme}`"> -->
  <div class="doc-header" :class="themeName()">
A
ailululu 已提交
4
    <div class="header-logo">
A
ailululu 已提交
5
      <a class="logo-link" href="#"></a>
A
ailululu 已提交
6 7 8
      <span class="logo-border"></span>
    </div>
    <div class="header-nav">
A
ailululu 已提交
9
      <Search />
A
ailululu 已提交
10 11
      <div class="nav-box">
        <ul class="nav-list">
A
ailululu 已提交
12
          <li class="nav-item" :class="{ active: isActive(header[0].name) }">
A
ailululu 已提交
13 14 15
            <router-link :to="header[0].name">
              {{ header[0].cName }}
            </router-link>
A
ailululu 已提交
16
          </li>
A
ailululu 已提交
17
          <li class="nav-item" :class="{ active: isActive(header[1].name) }">
A
ailululu 已提交
18 19 20 21 22
            <router-link :to="header[1].name">
              {{ header[1].cName }}
            </router-link>
          </li>
          <li class="nav-item" :class="{ active: isActive(header[2].name) }">
richard_1015's avatar
richard_1015 已提交
23
            <a href="demo.html#/">
A
ailululu 已提交
24 25
              {{ header[2].cName }}
            </a>
A
ailululu 已提交
26
          </li>
A
ailululu 已提交
27
          <li class="nav-item" :class="{ active: isActive(header[3].name) }">
A
ailululu 已提交
28 29 30
            <router-link :to="header[3].name">
              {{ header[3].cName }}
            </router-link>
A
ailululu 已提交
31
          </li>
A
ailululu 已提交
32
          <li class="nav-item">
A
ailululu 已提交
33
            <div
D
Drjingfubo 已提交
34 35 36
              @focus="handleFocus"
              @focusout="handleFocusOut"
              tabindex="0"
A
ailululu 已提交
37 38 39 40 41 42 43
              class="header-select-box"
              @click.stop="data.isShowSelect = !data.isShowSelect"
              :class="[data.isShowSelect == true ? 'select-up' : 'select-down']"
            >
              <div class="header-select-hd"
                >{{ data.verson }}<i class=""></i
              ></div>
D
Drjingfubo 已提交
44 45 46 47 48 49 50 51 52 53 54
              <transition name="fade">
                <div class="header-select-bd" v-show="data.isShowSelect">
                  <div
                    class="header-select-item"
                    v-for="(item, index) in data.versonList"
                    :key="index"
                    @click.stop="checkTheme(item.name, index)"
                    :class="{ active: data.activeIndex === index }"
                  >
                    {{ item.name }}
                  </div>
A
ailululu 已提交
55
                </div>
D
Drjingfubo 已提交
56
              </transition>
A
ailululu 已提交
57
            </div>
A
ailululu 已提交
58 59
          </li>
          <li class="nav-item">
A
ailululu 已提交
60
            <a class="user-link" href="#"></a>
A
ailululu 已提交
61 62 63 64
          </li>
        </ul>
      </div>
    </div>
richard_1015's avatar
richard_1015 已提交
65 66 67
  </div>
</template>
<script lang="ts">
D
Drjingfubo 已提交
68
import { defineComponent, reactive, computed, onMounted } from 'vue';
A
ailululu 已提交
69
import Search from './Search.vue';
richard_1015's avatar
richard_1015 已提交
70
import { header } from '@/config.json';
A
ailululu 已提交
71
import { currentRoute, themeColor } from '@/sites/assets/util/ref';
richard_1015's avatar
richard_1015 已提交
72
export default defineComponent({
A
ailululu 已提交
73
  name: 'doc-header',
A
ailululu 已提交
74 75 76
  components: {
    Search
  },
A
ailululu 已提交
77 78
  setup() {
    const data = reactive({
A
ailululu 已提交
79
      theme: 'black',
A
ailululu 已提交
80
      // headerBg: 'url(' + require('../../assets/images/header-bg.png') + ')',
A
ailululu 已提交
81 82 83 84 85 86 87 88 89 90 91 92
      versonList: [
        {
          name: '1.x'
        },
        {
          name: '2.x'
        },
        {
          name: '3.x'
        }
      ],
      verson: '3.x',
A
ailululu 已提交
93
      navIndex: 0,
A
ailululu 已提交
94 95
      activeIndex: 0,
      isShowSelect: false
A
ailululu 已提交
96
    });
D
Drjingfubo 已提交
97 98 99 100 101 102
    const handleFocus = () => {
      console.log(1);
    };
    const handleFocusOut = () => {
      data.isShowSelect = false;
    };
A
ailululu 已提交
103 104
    const isActive = computed(() => {
      return function(name: string) {
richard_1015's avatar
richard_1015 已提交
105
        // console.log(name, currentRoute.value);
A
ailululu 已提交
106
        // console.log('name1', currentRoute.value == name.toLowerCase());
A
ailululu 已提交
107 108 109
        return currentRoute.value == name.toLowerCase();
      };
    });
A
ailululu 已提交
110 111 112 113 114 115
    const themeName = computed(() => {
      return function() {
        return `doc-header-${themeColor.value}`;
      };
    });
    const checkTheme = (item: string, index: number) => {
A
ailululu 已提交
116 117
      data.isShowSelect = false;
      data.activeIndex = index;
A
ailululu 已提交
118
      data.verson = item;
A
ailululu 已提交
119 120 121 122 123 124 125
      if (index === 0) {
        window.location.href = '//nutui.jd.com/1x/';
      } else if (index === 1) {
        window.location.href = 'https://nutui.jd.com/#/index';
      } else {
        // window.location.href = ""
      }
A
ailululu 已提交
126 127
    };
    return {
A
ailululu 已提交
128
      header,
A
ailululu 已提交
129
      data,
A
ailululu 已提交
130
      isActive,
A
ailululu 已提交
131
      checkTheme,
D
Drjingfubo 已提交
132 133 134
      themeName,
      handleFocus,
      handleFocusOut
A
ailululu 已提交
135
    };
A
ailululu 已提交
136
  }
richard_1015's avatar
richard_1015 已提交
137 138 139 140 141 142
});
</script>

<style lang="scss">
.doc {
  &-header {
richard_1015's avatar
richard_1015 已提交
143 144 145 146 147
    position: fixed;
    z-index: 2;
    top: 0;
    left: 0;
    right: 0;
A
ailululu 已提交
148
    min-width: 1300px;
richard_1015's avatar
richard_1015 已提交
149 150
    background-size: cover;
    background-position: center;
A
ailululu 已提交
151
    background-repeat: no-repeat;
richard_1015's avatar
richard_1015 已提交
152 153 154 155 156
    height: $doc-header-height;
    line-height: $doc-header-height;
    text-align: left;
    padding: 0 50px;
    font-size: 20px;
A
ailululu 已提交
157 158 159 160 161 162 163 164 165
  }
}
.header {
  &-logo {
    position: relative;
    display: inline-block;
    width: 240px;
    height: 64px;
    .logo-link {
A
ailululu 已提交
166 167 168
      display: inline-block;
      width: 120px;
      height: 46px;
A
ailululu 已提交
169
      vertical-align: middle;
A
ailululu 已提交
170 171 172
      position: absolute;
      top: 50%;
      margin-top: -23px;
A
ailululu 已提交
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
    }
    .logo-border {
      display: inline-block;
      width: 1px;
      height: 26px;
      position: absolute;
      right: 0;
      top: 50%;
      margin-top: -13px;
    }
  }
  &-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    float: right;
    width: calc(100% - 240px);
A
ailululu 已提交
190
    min-width: 900px;
A
ailululu 已提交
191 192 193 194
    padding: 0 40px;
    .nav-box {
      margin-right: 140px;
      .nav-list {
A
ailululu 已提交
195
        min-width: 445px;
A
ailululu 已提交
196 197 198
        display: flex;
        list-style: none;
        align-items: center;
D
Drjingfubo 已提交
199
        justify-content: space-around;
A
ailululu 已提交
200 201 202 203 204 205 206 207 208
      }
      .nav-item {
        position: relative;
        margin-right: 30px;
        font-size: 14px;
        height: 63px;
        line-height: 63px;
        text-align: center;
        cursor: pointer;
A
ailululu 已提交
209 210 211 212
        a {
          display: inline-block;
          line-height: 64px;
        }
A
ailululu 已提交
213
        // overflow: hidden;
A
ailululu 已提交
214
        &.active {
A
ailululu 已提交
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
          font-weight: bold;
          &:after {
            content: '';
            display: inline-block;
            width: 35px;
            height: 13px;
            position: absolute;
            bottom: 3px;
            left: 50%;
            margin-left: -17.5px;
            background: url('../../assets/images/item-active.png');
          }
        }
        &:last-of-type {
          margin-right: 0;
        }
      }
      .user-link {
        display: inline-block;
        width: 26px;
        height: 26px;
        vertical-align: middle;
A
ailululu 已提交
237 238
        background: url('../../assets/images/icon-user.png') no-repeat;
        background-size: 26px;
A
ailululu 已提交
239 240 241 242
      }
    }
  }
}
A
ailululu 已提交
243 244 245 246 247
.header-select {
  &-box {
    position: relative;
    display: inline-block;
    vertical-align: middle;
D
Drjingfubo 已提交
248
    outline: 0;
A
ailululu 已提交
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
  }
  &-hd {
    min-width: 77px;
    height: 28px;
    padding: 0 30px 0 15px;
    line-height: 26px;
    font-size: 14px;
    color: $theme-red-word;
    background-position: right 15px top 12px;
    background-size: 8px 5px;
    background-repeat: no-repeat;
    border-radius: 14px;
  }
  &-bd {
    position: absolute;
    top: 30px;
    border-radius: 3px;
    overflow: hidden;
  }
  &-item {
    width: 77px;
    height: 28px;
    padding: 0 12px;
    line-height: 26px;
    font-size: 14px;
    border-width: 0px 1px 1px;
    border-style: solid;
    cursor: pointer;
    &:first-of-type {
      border-top-width: 1px;
    }
  }
}
A
ailululu 已提交
282 283 284 285
// 颜色
.doc-header {
  // 红色
  &-red {
A
ailululu 已提交
286
    background-image: $theme-red-header-bg;
A
ailululu 已提交
287 288 289
    color: $theme-red-word;
    .header {
      &-logo {
A
ailululu 已提交
290
        .logo-link {
A
ailululu 已提交
291 292
          background: url('../../assets/images/logo-header-white.png') no-repeat
            center/100%;
A
ailululu 已提交
293
        }
A
ailululu 已提交
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310
        .logo-border {
          background: $theme-red-border;
        }
      }
      &-nav {
        .search-box {
          .search-input {
            color: $theme-red-word;
            background-position: 0 0;
            &::-webkit-input-placeholder {
              color: $theme-red-input;
            }
          }
        }
        .nav-box {
          .nav-item {
            color: $theme-red-word;
A
ailululu 已提交
311 312 313
            a {
              color: $theme-red-word;
            }
A
ailululu 已提交
314
            &.active {
A
ailululu 已提交
315 316 317 318
              color: $theme-red-actice;
              &:after {
                background-position: 0 0;
              }
A
ailululu 已提交
319 320 321
              a {
                color: $theme-red-actice;
              }
A
ailululu 已提交
322 323 324 325
            }
          }
          .user-link {
            background-position: 0 0;
A
ailululu 已提交
326 327 328
            // &:hover {
            //   background-position: -26px 0;
            // }
A
ailululu 已提交
329 330 331 332
          }
        }
      }
    }
A
ailululu 已提交
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
    .header-select {
      &-box {
        &.select-down {
          .header-select-hd {
            background-image: url('../../assets/images/icon-select-white-down.png');
          }
        }
        &.select-up {
          .header-select-hd {
            background-image: url('../../assets/images/icon-select-white-up.png');
          }
        }
      }
      &-hd {
        color: $theme-red-word;
        border: 1px solid $theme-white-select-border;
      }
      &-bd {
        color: $theme-white-select-word;
      }
      &-item {
        border-color: $theme-red-select-border;
        background-color: $theme-red-select-bg;
        &:hover {
          color: $theme-red;
        }
      }
    }
A
ailululu 已提交
361 362 363 364 365 366 367 368
  }
  // 白色
  &-white {
    background: $white;
    color: $theme-white-word;
    border-bottom: 1px solid $theme-white-box-border;
    .header {
      &-logo {
A
ailululu 已提交
369
        .logo-link {
A
ailululu 已提交
370 371
          background: url('../../assets/images/logo-header-red.png') no-repeat
            center/100%;
A
ailululu 已提交
372
        }
A
ailululu 已提交
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389
        .logo-border {
          background: $theme-white-border;
        }
      }
      &-nav {
        .search-box {
          .search-input {
            color: $theme-white-word;
            background-position: 0 -22px;
            &::-webkit-input-placeholder {
              color: $theme-white-input;
            }
          }
        }
        .nav-box {
          .nav-item {
            color: $theme-white-word;
A
ailululu 已提交
390 391 392
            a {
              color: $theme-white-word;
            }
A
ailululu 已提交
393
            &.active {
A
ailululu 已提交
394 395 396 397
              color: $theme-white-actice;
              &:after {
                background-position: 0 -13px;
              }
A
ailululu 已提交
398 399 400
              a {
                color: $theme-white-actice;
              }
A
ailululu 已提交
401 402 403
            }
          }
          .user-link {
A
ailululu 已提交
404
            background-position: 0 -25px;
A
ailululu 已提交
405 406 407
            // &:hover {
            //   background-position: -26px -25px;
            // }
A
ailululu 已提交
408 409 410 411
          }
        }
      }
    }
A
ailululu 已提交
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439
    .header-select {
      &-box {
        &.select-down {
          .header-select-hd {
            background-image: url('../../assets/images/icon-select-gray-down.png');
          }
        }
        &.select-up {
          .header-select-hd {
            background-image: url('../../assets/images/icon-select-gray-up.png');
          }
        }
      }
      &-hd {
        color: $theme-white-select-word;
        border: 1px solid $theme-white-select-border;
      }
      &-bd {
        color: $theme-white-select-word;
      }
      &-item {
        border-color: $theme-white-select-border;
        background-color: $theme-white-select-bg;
        &:hover {
          color: $theme-white-actice;
        }
      }
    }
A
ailululu 已提交
440 441 442 443 444 445 446 447
  }
  // 黑色
  &-black {
    background: $black;
    color: $theme-black-word;
    border-bottom: 1px solid $theme-black-box-border;
    .header {
      &-logo {
A
ailululu 已提交
448
        .logo-link {
A
ailululu 已提交
449 450
          background: url('../../assets/images/logo-header-red.png') no-repeat
            center/100%;
A
ailululu 已提交
451
        }
A
ailululu 已提交
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468
        .logo-border {
          background: $theme-black-border;
        }
      }
      &-nav {
        .search-box {
          .search-input {
            color: $theme-black-word;
            background-position: 0 -44px;
            &::-webkit-input-placeholder {
              color: $theme-black-input;
            }
          }
        }
        .nav-box {
          .nav-item {
            color: $theme-black-word;
A
ailululu 已提交
469 470 471
            a {
              color: $theme-black-word;
            }
A
ailululu 已提交
472
            &.active {
A
ailululu 已提交
473 474 475 476
              color: $theme-black-actice;
              &:after {
                background-position: 0 -13px;
              }
A
ailululu 已提交
477 478 479
              a {
                color: $theme-black-actice;
              }
A
ailululu 已提交
480 481 482
            }
          }
          .user-link {
A
ailululu 已提交
483
            background-position: 0 -51px;
A
ailululu 已提交
484 485 486
            // &:hover {
            //   background-position: -26px -51px;
            // }
A
ailululu 已提交
487 488 489 490
          }
        }
      }
    }
A
ailululu 已提交
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506
    .header-select {
      &-box {
        &.select-down {
          .header-select-hd {
            background-image: url('../../assets/images/icon-select-white-down.png');
          }
        }
        &.select-up {
          .header-select-hd {
            background-image: url('../../assets/images/icon-select-white-up.png');
          }
        }
      }
      &-hd {
        color: $theme-black-select-word;
        background-color: $theme-black-select-bg;
A
ailululu 已提交
507
        border: 1px solid $theme-black-select-border;
A
ailululu 已提交
508 509 510 511 512 513
      }
      &-bd {
        color: $theme-black-select-word;
      }
      &-item {
        background-color: $theme-black-select-bg;
A
ailululu 已提交
514
        border-color: $theme-black-select-bg;
A
ailululu 已提交
515
        &:hover {
A
ailululu 已提交
516 517
          background-color: $theme-black-select-hover;
          border-color: $theme-black-select-hover;
A
ailululu 已提交
518 519 520
        }
      }
    }
richard_1015's avatar
richard_1015 已提交
521 522
  }
}
D
Drjingfubo 已提交
523 524 525 526 527 528 529 530
// 下拉列表选择动画效果
.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.5s;
}
.fade-enter, .fade-leave-to /* .fade-leave-active below version 2.1.8 */ {
  opacity: 0;
}
richard_1015's avatar
richard_1015 已提交
531
</style>