Header.vue 13 KB

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