Header.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. <template>
  2. <!-- <div class="doc-header" :style="{ background: themeColor === 'red' ? headerBg : themeColor }" :class="`doc-header-${data.theme}`"> -->
  3. <div class="doc-header" :class="themeName()">
  4. <div class="header-logo">
  5. <a class="logo-link" href="#"></a>
  6. <span class="logo-border"></span>
  7. </div>
  8. <div class="header-nav">
  9. <Search />
  10. <div class="nav-box">
  11. <ul class="nav-list">
  12. <li class="nav-item" :class="{ active: isActive(header[0].name) }">
  13. <router-link :to="header[0].name">
  14. {{ header[0].cName }}
  15. </router-link>
  16. </li>
  17. <li class="nav-item" :class="{ active: isActive(header[1].name) }">
  18. <router-link :to="header[1].name">
  19. {{ header[1].cName }}
  20. </router-link>
  21. </li>
  22. <li class="nav-item" :class="{ active: isActive(header[2].name) }">
  23. <a href="demo.html#/">
  24. {{ header[2].cName }}
  25. </a>
  26. </li>
  27. <li class="nav-item" :class="{ active: isActive(header[3].name) }">
  28. <router-link :to="header[3].name">
  29. {{ header[3].cName }}
  30. </router-link>
  31. </li>
  32. <li class="nav-item">
  33. <div
  34. @focus="handleFocus"
  35. @focusout="handleFocusOut"
  36. tabindex="0"
  37. class="header-select-box"
  38. @click.stop="data.isShowSelect = !data.isShowSelect"
  39. :class="[data.isShowSelect == true ? 'select-up' : 'select-down']"
  40. >
  41. <div class="header-select-hd"
  42. >{{ data.verson }}<i class=""></i
  43. ></div>
  44. <transition name="fade">
  45. <div class="header-select-bd" v-show="data.isShowSelect">
  46. <div
  47. class="header-select-item"
  48. v-for="(item, index) in data.versonList"
  49. :key="index"
  50. @click.stop="checkTheme(item.name, index)"
  51. :class="{ active: data.activeIndex === index }"
  52. >
  53. {{ item.name }}
  54. </div>
  55. </div>
  56. </transition>
  57. </div>
  58. </li>
  59. <li class="nav-item">
  60. <a class="user-link" href="#"></a>
  61. </li>
  62. </ul>
  63. </div>
  64. </div>
  65. </div>
  66. </template>
  67. <script lang="ts">
  68. import { defineComponent, reactive, computed, onMounted } from 'vue';
  69. import Search from './Search.vue';
  70. import { header } from '@/config.json';
  71. import { currentRoute, themeColor } from '@/sites/assets/util/ref';
  72. export default defineComponent({
  73. name: 'doc-header',
  74. components: {
  75. Search
  76. },
  77. setup() {
  78. const data = reactive({
  79. theme: 'black',
  80. // headerBg: 'url(' + require('../../assets/images/header-bg.png') + ')',
  81. versonList: [
  82. {
  83. name: '1.x'
  84. },
  85. {
  86. name: '2.x'
  87. },
  88. {
  89. name: '3.x'
  90. }
  91. ],
  92. verson: '3.x',
  93. navIndex: 0,
  94. activeIndex: 0,
  95. isShowSelect: false
  96. });
  97. const handleFocus = () => {
  98. console.log(1);
  99. };
  100. const handleFocusOut = () => {
  101. data.isShowSelect = false;
  102. };
  103. const isActive = computed(() => {
  104. return function(name: string) {
  105. // console.log(name, currentRoute.value);
  106. // console.log('name1', currentRoute.value == name.toLowerCase());
  107. return currentRoute.value == name.toLowerCase();
  108. };
  109. });
  110. const themeName = computed(() => {
  111. return function() {
  112. return `doc-header-${themeColor.value}`;
  113. };
  114. });
  115. const checkTheme = (item: string, index: number) => {
  116. data.isShowSelect = false;
  117. data.activeIndex = index;
  118. data.verson = item;
  119. if (index === 0) {
  120. window.location.href = '//nutui.jd.com/1x/';
  121. } else if (index === 1) {
  122. window.location.href = 'https://nutui.jd.com/#/index';
  123. } else {
  124. // window.location.href = ""
  125. }
  126. };
  127. return {
  128. header,
  129. data,
  130. isActive,
  131. checkTheme,
  132. themeName,
  133. handleFocus,
  134. handleFocusOut
  135. };
  136. }
  137. });
  138. </script>
  139. <style lang="scss">
  140. .doc {
  141. &-header {
  142. position: fixed;
  143. z-index: 2;
  144. top: 0;
  145. left: 0;
  146. right: 0;
  147. min-width: 1300px;
  148. background-size: cover;
  149. background-position: center;
  150. background-repeat: no-repeat;
  151. height: $doc-header-height;
  152. line-height: $doc-header-height;
  153. text-align: left;
  154. padding: 0 50px;
  155. font-size: 20px;
  156. }
  157. }
  158. .header {
  159. &-logo {
  160. position: relative;
  161. display: inline-block;
  162. width: 240px;
  163. height: 64px;
  164. .logo-link {
  165. display: inline-block;
  166. width: 120px;
  167. height: 46px;
  168. vertical-align: middle;
  169. position: absolute;
  170. top: 50%;
  171. margin-top: -23px;
  172. }
  173. .logo-border {
  174. display: inline-block;
  175. width: 1px;
  176. height: 26px;
  177. position: absolute;
  178. right: 0;
  179. top: 50%;
  180. margin-top: -13px;
  181. }
  182. }
  183. &-nav {
  184. display: flex;
  185. justify-content: space-between;
  186. align-items: center;
  187. float: right;
  188. width: calc(100% - 240px);
  189. min-width: 900px;
  190. padding: 0 40px;
  191. .nav-box {
  192. margin-right: 140px;
  193. .nav-list {
  194. min-width: 445px;
  195. display: flex;
  196. list-style: none;
  197. align-items: center;
  198. justify-content: space-around;
  199. }
  200. .nav-item {
  201. position: relative;
  202. margin-right: 30px;
  203. font-size: 14px;
  204. height: 63px;
  205. line-height: 63px;
  206. text-align: center;
  207. cursor: pointer;
  208. a {
  209. display: inline-block;
  210. line-height: 64px;
  211. }
  212. // overflow: hidden;
  213. &.active {
  214. font-weight: bold;
  215. &:after {
  216. content: '';
  217. display: inline-block;
  218. width: 35px;
  219. height: 13px;
  220. position: absolute;
  221. bottom: 3px;
  222. left: 50%;
  223. margin-left: -17.5px;
  224. background: url('../../assets/images/item-active.png');
  225. }
  226. }
  227. &:last-of-type {
  228. margin-right: 0;
  229. }
  230. }
  231. .user-link {
  232. display: inline-block;
  233. width: 26px;
  234. height: 26px;
  235. vertical-align: middle;
  236. background: url('../../assets/images/icon-user.png') no-repeat;
  237. background-size: 26px;
  238. }
  239. }
  240. }
  241. }
  242. .header-select {
  243. &-box {
  244. position: relative;
  245. display: inline-block;
  246. vertical-align: middle;
  247. outline: 0;
  248. }
  249. &-hd {
  250. min-width: 77px;
  251. height: 28px;
  252. padding: 0 30px 0 15px;
  253. line-height: 26px;
  254. font-size: 14px;
  255. color: $theme-red-word;
  256. background-position: right 15px top 12px;
  257. background-size: 8px 5px;
  258. background-repeat: no-repeat;
  259. border-radius: 14px;
  260. }
  261. &-bd {
  262. position: absolute;
  263. top: 30px;
  264. border-radius: 3px;
  265. overflow: hidden;
  266. }
  267. &-item {
  268. width: 77px;
  269. height: 28px;
  270. padding: 0 12px;
  271. line-height: 26px;
  272. font-size: 14px;
  273. border-width: 0px 1px 1px;
  274. border-style: solid;
  275. cursor: pointer;
  276. &:first-of-type {
  277. border-top-width: 1px;
  278. }
  279. }
  280. }
  281. // 颜色
  282. .doc-header {
  283. // 红色
  284. &-red {
  285. background-image: $theme-red-header-bg;
  286. color: $theme-red-word;
  287. .header {
  288. &-logo {
  289. .logo-link {
  290. background: url('../../assets/images/logo-header-white.png') no-repeat
  291. center/100%;
  292. }
  293. .logo-border {
  294. background: $theme-red-border;
  295. }
  296. }
  297. &-nav {
  298. .search-box {
  299. .search-input {
  300. color: $theme-red-word;
  301. background-position: 0 0;
  302. &::-webkit-input-placeholder {
  303. color: $theme-red-input;
  304. }
  305. }
  306. }
  307. .nav-box {
  308. .nav-item {
  309. color: $theme-red-word;
  310. a {
  311. color: $theme-red-word;
  312. }
  313. &.active {
  314. color: $theme-red-actice;
  315. &:after {
  316. background-position: 0 0;
  317. }
  318. a {
  319. color: $theme-red-actice;
  320. }
  321. }
  322. }
  323. .user-link {
  324. background-position: 0 0;
  325. // &:hover {
  326. // background-position: -26px 0;
  327. // }
  328. }
  329. }
  330. }
  331. }
  332. .header-select {
  333. &-box {
  334. &.select-down {
  335. .header-select-hd {
  336. background-image: url('../../assets/images/icon-select-white-down.png');
  337. }
  338. }
  339. &.select-up {
  340. .header-select-hd {
  341. background-image: url('../../assets/images/icon-select-white-up.png');
  342. }
  343. }
  344. }
  345. &-hd {
  346. color: $theme-red-word;
  347. border: 1px solid $theme-white-select-border;
  348. }
  349. &-bd {
  350. color: $theme-white-select-word;
  351. }
  352. &-item {
  353. border-color: $theme-red-select-border;
  354. background-color: $theme-red-select-bg;
  355. &:hover {
  356. color: $theme-red;
  357. }
  358. }
  359. }
  360. }
  361. // 白色
  362. &-white {
  363. background: $white;
  364. color: $theme-white-word;
  365. border-bottom: 1px solid $theme-white-box-border;
  366. .header {
  367. &-logo {
  368. .logo-link {
  369. background: url('../../assets/images/logo-header-red.png') no-repeat
  370. center/100%;
  371. }
  372. .logo-border {
  373. background: $theme-white-border;
  374. }
  375. }
  376. &-nav {
  377. .search-box {
  378. .search-input {
  379. color: $theme-white-word;
  380. background-position: 0 -22px;
  381. &::-webkit-input-placeholder {
  382. color: $theme-white-input;
  383. }
  384. }
  385. }
  386. .nav-box {
  387. .nav-item {
  388. color: $theme-white-word;
  389. a {
  390. color: $theme-white-word;
  391. }
  392. &.active {
  393. color: $theme-white-actice;
  394. &:after {
  395. background-position: 0 -13px;
  396. }
  397. a {
  398. color: $theme-white-actice;
  399. }
  400. }
  401. }
  402. .user-link {
  403. background-position: 0 -25px;
  404. // &:hover {
  405. // background-position: -26px -25px;
  406. // }
  407. }
  408. }
  409. }
  410. }
  411. .header-select {
  412. &-box {
  413. &.select-down {
  414. .header-select-hd {
  415. background-image: url('../../assets/images/icon-select-gray-down.png');
  416. }
  417. }
  418. &.select-up {
  419. .header-select-hd {
  420. background-image: url('../../assets/images/icon-select-gray-up.png');
  421. }
  422. }
  423. }
  424. &-hd {
  425. color: $theme-white-select-word;
  426. border: 1px solid $theme-white-select-border;
  427. }
  428. &-bd {
  429. color: $theme-white-select-word;
  430. }
  431. &-item {
  432. border-color: $theme-white-select-border;
  433. background-color: $theme-white-select-bg;
  434. &:hover {
  435. color: $theme-white-actice;
  436. }
  437. }
  438. }
  439. }
  440. // 黑色
  441. &-black {
  442. background: $black;
  443. color: $theme-black-word;
  444. border-bottom: 1px solid $theme-black-box-border;
  445. .header {
  446. &-logo {
  447. .logo-link {
  448. background: url('../../assets/images/logo-header-red.png') no-repeat
  449. center/100%;
  450. }
  451. .logo-border {
  452. background: $theme-black-border;
  453. }
  454. }
  455. &-nav {
  456. .search-box {
  457. .search-input {
  458. color: $theme-black-word;
  459. background-position: 0 -44px;
  460. &::-webkit-input-placeholder {
  461. color: $theme-black-input;
  462. }
  463. }
  464. }
  465. .nav-box {
  466. .nav-item {
  467. color: $theme-black-word;
  468. a {
  469. color: $theme-black-word;
  470. }
  471. &.active {
  472. color: $theme-black-actice;
  473. &:after {
  474. background-position: 0 -13px;
  475. }
  476. a {
  477. color: $theme-black-actice;
  478. }
  479. }
  480. }
  481. .user-link {
  482. background-position: 0 -51px;
  483. // &:hover {
  484. // background-position: -26px -51px;
  485. // }
  486. }
  487. }
  488. }
  489. }
  490. .header-select {
  491. &-box {
  492. &.select-down {
  493. .header-select-hd {
  494. background-image: url('../../assets/images/icon-select-white-down.png');
  495. }
  496. }
  497. &.select-up {
  498. .header-select-hd {
  499. background-image: url('../../assets/images/icon-select-white-up.png');
  500. }
  501. }
  502. }
  503. &-hd {
  504. color: $theme-black-select-word;
  505. background-color: $theme-black-select-bg;
  506. border: 1px solid $theme-black-select-border;
  507. }
  508. &-bd {
  509. color: $theme-black-select-word;
  510. }
  511. &-item {
  512. background-color: $theme-black-select-bg;
  513. border-color: $theme-black-select-bg;
  514. &:hover {
  515. background-color: $theme-black-select-hover;
  516. border-color: $theme-black-select-hover;
  517. }
  518. }
  519. }
  520. }
  521. }
  522. // 下拉列表选择动画效果
  523. .fade-enter-active,
  524. .fade-leave-active {
  525. transition: opacity 0.5s;
  526. }
  527. .fade-enter, .fade-leave-to /* .fade-leave-active below version 2.1.8 */ {
  528. opacity: 0;
  529. }
  530. </style>