Header.vue 14 KB

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