Header.vue 13 KB

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