Header.vue 11.6 KB
Newer Older
richard_1015's avatar
richard_1015 已提交
1
<template>
A
ailululu 已提交
2
  <div class="doc-header" :class="themeName()">
A
ailululu 已提交
3
    <div class="header-logo">
Y
yangxiaolu3 已提交
4
      <a class="logo-link" href="https://nutui.jd.com/#/"></a>
A
ailululu 已提交
5
      <span class="logo-border"></span>
richard_1015's avatar
richard_1015 已提交
6
      <span class="version">{{ version }}</span>
A
ailululu 已提交
7 8
    </div>
    <div class="header-nav">
richard_1015's avatar
richard_1015 已提交
9 10 11
      <a href="https://www.bilibili.com/video/BV1fi4y1D7qb" target="_blank"
        >🌈 &nbsp;&nbsp;视频教程 「一分钟快速实现主题定制」 https://www.bilibili.com/video/BV1fi4y1D7qb</a
      >
A
ailululu 已提交
12
    </div>
richard_1015's avatar
richard_1015 已提交
13 14 15
  </div>
</template>
<script lang="ts">
D
Drjingfubo 已提交
16
import { defineComponent, reactive, computed, onMounted } from 'vue';
richard_1015's avatar
richard_1015 已提交
17
import { nav } from '@/config.json';
richard_1015's avatar
richard_1015 已提交
18
import { version } from '/package.json';
richard_1015's avatar
richard_1015 已提交
19
import { RefData } from '@/sites/assets/util/ref';
richard_1015's avatar
richard_1015 已提交
20
export default defineComponent({
A
ailululu 已提交
21
  name: 'doc-header',
richard_1015's avatar
richard_1015 已提交
22
  components: {},
A
ailululu 已提交
23
  setup() {
S
suzigang 已提交
24
    let packages = [] as any[];
S
suzigang 已提交
25 26 27
    nav.forEach((item) => {
      packages.push(...item.packages);
    });
A
ailululu 已提交
28
    const data = reactive({
A
ailululu 已提交
29
      theme: 'black',
A
ailululu 已提交
30
      // headerBg: 'url(' + require('../../assets/images/header-bg.png') + ')',
A
ailululu 已提交
31
      verson: '3.x',
A
ailululu 已提交
32
      navIndex: 0,
A
ailululu 已提交
33 34
      activeIndex: 0,
      isShowSelect: false
A
ailululu 已提交
35
    });
D
Drjingfubo 已提交
36 37 38 39 40 41
    const handleFocus = () => {
      console.log(1);
    };
    const handleFocusOut = () => {
      data.isShowSelect = false;
    };
richard_1015's avatar
richard_1015 已提交
42 43 44 45 46

    const toHome = () => {
      RefData.getInstance().currentRoute.value = '/';
    };

A
ailululu 已提交
47
    const isActive = computed(() => {
S
suzigang 已提交
48 49 50 51 52 53 54
      let value = RefData.getInstance().currentRoute.value;
      return function (name: string) {
        const lName = name.toLowerCase();
        if (lName === 'component') {
          if (value.indexOf('-taro') > -1) {
            value = value.split('-taro')[0];
          }
55
          return packages.findIndex((item) => item.name.toLowerCase() === value) > -1;
S
suzigang 已提交
56 57 58
        } else {
          return value === lName || lName.includes(value);
        }
A
ailululu 已提交
59 60
      };
    });
A
ailululu 已提交
61
    const themeName = computed(() => {
S
suzigang 已提交
62
      return function () {
richard_1015's avatar
richard_1015 已提交
63
        return `doc-header-${RefData.getInstance().themeColor.value}`;
A
ailululu 已提交
64 65
      };
    });
richard_1015's avatar
richard_1015 已提交
66
    const checkTheme = (item: any, index: number) => {
A
ailululu 已提交
67 68
      data.isShowSelect = false;
      data.activeIndex = index;
richard_1015's avatar
richard_1015 已提交
69 70
      data.verson = item.name;
      window.location.href = item.link;
A
ailululu 已提交
71 72
    };
    return {
richard_1015's avatar
richard_1015 已提交
73
      version,
A
ailululu 已提交
74
      data,
richard_1015's avatar
richard_1015 已提交
75
      toHome,
A
ailululu 已提交
76
      isActive,
A
ailululu 已提交
77
      checkTheme,
D
Drjingfubo 已提交
78 79 80
      themeName,
      handleFocus,
      handleFocusOut
A
ailululu 已提交
81
    };
A
ailululu 已提交
82
  }
richard_1015's avatar
richard_1015 已提交
83 84 85 86 87 88
});
</script>

<style lang="scss">
.doc {
  &-header {
Y
yangxiaolu3 已提交
89
    position: fixed;
richard_1015's avatar
richard_1015 已提交
90
    z-index: 2;
richard_1015's avatar
richard_1015 已提交
91
    top: 0;
richard_1015's avatar
richard_1015 已提交
92 93
    left: 0;
    right: 0;
A
ailululu 已提交
94
    min-width: 1300px;
richard_1015's avatar
richard_1015 已提交
95 96
    background-size: cover;
    background-position: center;
A
ailululu 已提交
97
    background-repeat: no-repeat;
richard_1015's avatar
richard_1015 已提交
98 99 100 101 102
    height: $doc-header-height;
    line-height: $doc-header-height;
    text-align: left;
    padding: 0 50px;
    font-size: 20px;
A
ailululu 已提交
103 104 105 106 107 108 109 110 111
  }
}
.header {
  &-logo {
    position: relative;
    display: inline-block;
    width: 240px;
    height: 64px;
    .logo-link {
A
ailululu 已提交
112 113
      width: 120px;
      height: 46px;
A
ailululu 已提交
114
      vertical-align: middle;
A
ailululu 已提交
115 116 117
      position: absolute;
      top: 50%;
      margin-top: -23px;
A
ailululu 已提交
118 119 120 121 122 123 124 125 126
    }
    .logo-border {
      width: 1px;
      height: 26px;
      position: absolute;
      right: 0;
      top: 50%;
      margin-top: -13px;
    }
richard_1015's avatar
richard_1015 已提交
127 128
    .version {
      position: absolute;
129
      right: 70px;
richard_1015's avatar
richard_1015 已提交
130 131
      font-size: 14px;
    }
A
ailululu 已提交
132 133 134 135 136 137 138
  }
  &-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    float: right;
    width: calc(100% - 240px);
A
ailululu 已提交
139
    min-width: 900px;
A
ailululu 已提交
140
    padding: 0 40px;
richard_1015's avatar
richard_1015 已提交
141 142 143
    > a {
      color: #fff;
    }
A
ailululu 已提交
144 145 146
    .nav-box {
      margin-right: 140px;
      .nav-list {
147
        min-width: 490px;
A
ailululu 已提交
148 149 150
        display: flex;
        list-style: none;
        align-items: center;
D
Drjingfubo 已提交
151
        justify-content: space-around;
A
ailululu 已提交
152 153 154 155 156 157 158 159 160
      }
      .nav-item {
        position: relative;
        margin-right: 30px;
        font-size: 14px;
        height: 63px;
        line-height: 63px;
        text-align: center;
        cursor: pointer;
161
        flex-shrink: 0;
A
ailululu 已提交
162 163 164 165
        a {
          display: inline-block;
          line-height: 64px;
        }
A
ailululu 已提交
166
        // overflow: hidden;
A
ailululu 已提交
167
        &.active {
A
ailululu 已提交
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
          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;
richard_1015's avatar
richard_1015 已提交
190 191
        background-repeat: no-repeat;
        background-image: url('../../assets/images/icon-user.png');
A
ailululu 已提交
192
        background-size: 26px;
richard_1015's avatar
richard_1015 已提交
193 194

        &.gitee {
195
          margin-left: 8px;
richard_1015's avatar
richard_1015 已提交
196
          background-image: url('../../assets/images/icon-gitee.png');
richard_1015's avatar
richard_1015 已提交
197 198
        }
      }
A
ailululu 已提交
199 200 201
    }
  }
}
A
ailululu 已提交
202 203 204 205 206
.header-select {
  &-box {
    position: relative;
    display: inline-block;
    vertical-align: middle;
D
Drjingfubo 已提交
207
    outline: 0;
A
ailululu 已提交
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
  }
  &-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;
richard_1015's avatar
richard_1015 已提交
224
    left: 50%;
richard_1015's avatar
richard_1015 已提交
225
    margin-left: -60px;
A
ailululu 已提交
226 227 228 229
    border-radius: 3px;
    overflow: hidden;
  }
  &-item {
richard_1015's avatar
richard_1015 已提交
230
    width: 120px;
A
ailululu 已提交
231 232 233 234 235 236 237 238 239 240 241 242
    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 已提交
243 244 245 246
// 颜色
.doc-header {
  // 红色
  &-red {
A
ailululu 已提交
247
    background-image: $theme-red-header-bg;
A
ailululu 已提交
248 249 250
    color: $theme-red-word;
    .header {
      &-logo {
A
ailululu 已提交
251
        .logo-link {
252
          background: url('../../assets/images/logo-header-white.png') no-repeat center/100%;
A
ailululu 已提交
253
        }
A
ailululu 已提交
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
        .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 已提交
271 272 273
            a {
              color: $theme-red-word;
            }
A
ailululu 已提交
274
            &.active {
A
ailululu 已提交
275 276 277 278
              color: $theme-red-actice;
              &:after {
                background-position: 0 0;
              }
A
ailululu 已提交
279 280 281
              a {
                color: $theme-red-actice;
              }
A
ailululu 已提交
282 283 284 285
            }
          }
          .user-link {
            background-position: 0 0;
A
ailululu 已提交
286 287 288
            // &:hover {
            //   background-position: -26px 0;
            // }
A
ailululu 已提交
289 290 291 292
          }
        }
      }
    }
A
ailululu 已提交
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
    .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 已提交
321 322 323 324 325 326 327 328
  }
  // 白色
  &-white {
    background: $white;
    color: $theme-white-word;
    border-bottom: 1px solid $theme-white-box-border;
    .header {
      &-logo {
A
ailululu 已提交
329
        .logo-link {
330
          background: url('../../assets/images/logo-header-red.png') no-repeat center/100%;
A
ailululu 已提交
331
        }
A
ailululu 已提交
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348
        .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 已提交
349 350 351
            a {
              color: $theme-white-word;
            }
A
ailululu 已提交
352
            &.active {
A
ailululu 已提交
353 354 355 356
              color: $theme-white-actice;
              &:after {
                background-position: 0 -13px;
              }
A
ailululu 已提交
357 358 359
              a {
                color: $theme-white-actice;
              }
A
ailululu 已提交
360 361 362
            }
          }
          .user-link {
A
ailululu 已提交
363
            background-position: 0 -25px;
A
ailululu 已提交
364 365 366
            // &:hover {
            //   background-position: -26px -25px;
            // }
A
ailululu 已提交
367 368 369 370
          }
        }
      }
    }
A
ailululu 已提交
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
    .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 已提交
399 400 401 402 403 404 405 406
  }
  // 黑色
  &-black {
    background: $black;
    color: $theme-black-word;
    border-bottom: 1px solid $theme-black-box-border;
    .header {
      &-logo {
A
ailululu 已提交
407
        .logo-link {
408
          background: url('../../assets/images/logo-header-red.png') no-repeat center/100%;
A
ailululu 已提交
409
        }
A
ailululu 已提交
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426
        .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 已提交
427 428 429
            a {
              color: $theme-black-word;
            }
A
ailululu 已提交
430
            &.active {
A
ailululu 已提交
431 432 433 434
              color: $theme-black-actice;
              &:after {
                background-position: 0 -13px;
              }
A
ailululu 已提交
435 436 437
              a {
                color: $theme-black-actice;
              }
A
ailululu 已提交
438 439 440
            }
          }
          .user-link {
A
ailululu 已提交
441
            background-position: 0 -51px;
A
ailululu 已提交
442 443 444
            // &:hover {
            //   background-position: -26px -51px;
            // }
A
ailululu 已提交
445 446 447 448
          }
        }
      }
    }
A
ailululu 已提交
449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464
    .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 已提交
465
        border: 1px solid $theme-black-select-border;
A
ailululu 已提交
466 467 468 469 470 471
      }
      &-bd {
        color: $theme-black-select-word;
      }
      &-item {
        background-color: $theme-black-select-bg;
A
ailululu 已提交
472
        border-color: $theme-black-select-bg;
A
ailululu 已提交
473
        &:hover {
A
ailululu 已提交
474 475
          background-color: $theme-black-select-hover;
          border-color: $theme-black-select-hover;
A
ailululu 已提交
476 477 478
        }
      }
    }
richard_1015's avatar
richard_1015 已提交
479 480
  }
}
D
Drjingfubo 已提交
481 482 483 484 485 486 487 488
// 下拉列表选择动画效果
.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 已提交
489
</style>