Header.vue 13 KB

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