Header.vue 12 KB

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