app.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. <template>
  2. <div>
  3. <div v-if="routerName == 'frontcover' || routerName == ''">
  4. <router-view></router-view>
  5. </div>
  6. <div class="md-swaper" @click="clearSearch" v-else>
  7. <div class="hder">
  8. <div class="logo">
  9. <a href="#/index" class="logo-link">
  10. <img src="./asset/css/i/nut.png" alt />
  11. </a>
  12. <span class="version">v{{ version }}</span>
  13. </div>
  14. <div class="h-nav">
  15. <search />
  16. <ul class="list">
  17. <li class="joinus">
  18. <a href="#/joinus"></a>
  19. <img src="./asset/css/i/jion_us.gif" alt="" />
  20. </li>
  21. <li class="cur">
  22. <a href="#/intro">指南</a>
  23. </li>
  24. <li>
  25. <a class="qrcode demoLink" href="/demo.html#/index" target="_blank">
  26. 示例
  27. <a :href="routerName">
  28. <span>请使用手机扫码体验</span>
  29. <img src="https://img14.360buyimg.com/uba/jfs/t1/32118/11/559/2782/5c3d81ecEbda0c0f1/5f2b637d11817204.png" alt />
  30. </a>
  31. </a>
  32. </li>
  33. <li>
  34. <select @change="openwindow">
  35. <option value="2">2.X</option>
  36. <option value="1">1.X</option>
  37. </select>
  38. </li>
  39. <li class="github">
  40. <a target="_back" href="https://github.com/jdf2e/nutui"></a>
  41. </li>
  42. </ul>
  43. </div>
  44. </div>
  45. <div class="demo-wrapper">
  46. <router-view class="demo-nav fixed-box"></router-view>
  47. <keep-alive include="index">
  48. <router-view class="doc-cont fl-right" :class="showPhone ? '' : 'docpad'" name="main"></router-view>
  49. </keep-alive>
  50. <div v-if="showPhone" class="showPhone">
  51. <div class="ph">
  52. <div class="bg">
  53. <img src="./asset/css/i/phtitle.png" alt />
  54. <div>
  55. <input type="text" readonly :value="demourl + routerName" />
  56. </div>
  57. </div>
  58. <iframe :src="demourl + routerName + '?ver=' + version"></iframe>
  59. </div>
  60. </div>
  61. </div>
  62. <div class="foot">
  63. Copyright © 2018~2020
  64. <a href="//jdc.jd.com" target="_blank">JDC</a>-
  65. <a target="_blank" href="javascript:;">前端开发部</a>
  66. </div>
  67. </div>
  68. </div>
  69. </template>
  70. <script>
  71. import './asset/css/common.scss';
  72. import './asset/css/style-blue.scss';
  73. import { packages } from '@/config.json';
  74. import search from './search.vue';
  75. import leftNav from './info.vue';
  76. import { version } from '@/../package.json';
  77. export default {
  78. name: 'app',
  79. components: {
  80. search,
  81. leftNav
  82. },
  83. data() {
  84. return {
  85. packages,
  86. version,
  87. searchList: [],
  88. searchVal: '',
  89. routerName: '',
  90. showPhone: false,
  91. searchCurName: '',
  92. searchIndex: 0,
  93. codeurl: '',
  94. demourl: location.origin + '/demo.html#/'
  95. };
  96. },
  97. watch: {
  98. // '$route':obj =>{
  99. // if(this){
  100. // this.routerName = obj.name
  101. // }
  102. // },
  103. $route: 'fetchData'
  104. },
  105. created() {
  106. let that = this;
  107. let name = this.$route.name;
  108. for (let i = 0, item; (item = packages[i]); i++) {
  109. if (name == item.name.toLowerCase()) {
  110. this.showPhone = true;
  111. }
  112. }
  113. },
  114. methods: {
  115. openwindow(val) {
  116. if (val.target.value == 1) {
  117. window.location.href = 'https://nutui.jd.com/1x/';
  118. }
  119. },
  120. choseList(e) {
  121. let searchIndex = this.searchIndex;
  122. if (e.keyCode == 40) {
  123. searchIndex++;
  124. }
  125. if (e.keyCode == 38) {
  126. searchIndex--;
  127. }
  128. if (searchIndex < 0) {
  129. searchIndex = 0;
  130. }
  131. let searchList = this.searchList;
  132. if (searchList.length > 0) {
  133. let chnName = searchList[searchIndex].chnName;
  134. if (chnName) {
  135. this.searchCurName = chnName;
  136. this.searchIndex = searchIndex;
  137. if (e.keyCode == 13) {
  138. this.$router.push({
  139. path: '/' + searchList[searchIndex].name
  140. });
  141. this.searchCurName = '';
  142. this.searchIndex = 0;
  143. this.searchList = [];
  144. this.searchVal = '';
  145. }
  146. }
  147. }
  148. },
  149. fetchData(obj) {
  150. this.routerName = obj.name;
  151. this.showPhone = false;
  152. for (let i = 0, item; (item = packages[i]); i++) {
  153. if (obj.name == item.name) {
  154. this.showPhone = true;
  155. }
  156. }
  157. let that = this;
  158. this.qrcode.toDataURL('https://nutui.jd.com/index.html#/' + that.routerName, { width: 170 }, (err, url) => {
  159. that.codeurl = url;
  160. });
  161. },
  162. onfocus(e) {
  163. e.target.select();
  164. },
  165. clearSearch() {
  166. this.searchList = [];
  167. },
  168. search(e) {
  169. let val = e.target.value.toLowerCase();
  170. if (val) {
  171. let packages = this.packages;
  172. let list = [];
  173. for (let i = 0, item; (item = packages[i]); i++) {
  174. let cn = item.chnName.toLowerCase();
  175. let en = item.name.toLowerCase();
  176. if (cn.indexOf(val) > -1 || en.indexOf(val) > -1) {
  177. list.push(item);
  178. }
  179. }
  180. this.searchList = list;
  181. }
  182. },
  183. checklist(obj) {
  184. this.searchVal = '';
  185. this.searchList = [];
  186. this.searchCurName = '';
  187. this.searchIndex = 0;
  188. }
  189. }
  190. };
  191. </script>
  192. <style lang="scss">
  193. .fixed-box {
  194. position: fixed;
  195. z-index: 9;
  196. height: 100%;
  197. overflow: hidden;
  198. overflow-y: auto;
  199. top: 0;
  200. background: #fff;
  201. box-sizing: border-box;
  202. }
  203. .fade-enter-active,
  204. .fade-leave-active {
  205. transition: opacity 0.5s;
  206. }
  207. .fade-enter, .fade-leave-to /* .fade-leave-active below version 2.1.8 */ {
  208. opacity: 0;
  209. }
  210. * {
  211. -webkit-tap-highlight-color: transparent;
  212. }
  213. .md-swaper {
  214. position: relative;
  215. background: #fff;
  216. min-height: 100vh;
  217. min-width: 1200px;
  218. padding: 85px 0 200px 0;
  219. box-sizing: border-box;
  220. display: flex;
  221. }
  222. .hder {
  223. position: fixed;
  224. top: 0;
  225. width: 100%;
  226. background: #ffffff;
  227. border-bottom: 1px solid #f2f2f2;
  228. height: 64px;
  229. display: flex;
  230. align-items: center;
  231. margin-bottom: 50px;
  232. z-index: 42;
  233. min-width: 1200px;
  234. .logo {
  235. width: 293px;
  236. height: 65px;
  237. display: flex;
  238. align-items: center;
  239. flex-shrink: 0;
  240. border-right: 1px solid #d8d8d8;
  241. .logo-link {
  242. display: inline-block;
  243. }
  244. img {
  245. display: block;
  246. width: 120px;
  247. height: 46px;
  248. flex-grow: 0;
  249. flex-shrink: 0;
  250. margin: 0 10px 0 30px;
  251. }
  252. color: #999;
  253. font-size: 12px;
  254. }
  255. .version {
  256. display: inline-block;
  257. margin-top: 7px;
  258. vertical-align: bottom;
  259. }
  260. .h-nav {
  261. display: flex;
  262. padding-left: 42px;
  263. align-items: center;
  264. width: 100%;
  265. background: #fff;
  266. z-index: 999;
  267. border-bottom: 1px solid #f2f2f2;
  268. select {
  269. width: 74px;
  270. height: 28px;
  271. margin-top: 18px;
  272. margin-left: 20px;
  273. font-size: 12px;
  274. }
  275. .search-box {
  276. height: 22px;
  277. min-width: 300px;
  278. position: relative;
  279. float: left;
  280. input {
  281. width: 100%;
  282. }
  283. }
  284. .search {
  285. height: 22px;
  286. font-size: 14px;
  287. color: #666;
  288. border: none;
  289. background: url(./asset/css/i/sreach.png) no-repeat left center;
  290. padding-left: 45px;
  291. &:focus {
  292. outline: none;
  293. }
  294. }
  295. .search-list {
  296. background: #fff;
  297. position: absolute;
  298. width: 300px;
  299. list-style: none;
  300. border: 1px solid #f2f2f2;
  301. z-index: 99;
  302. top: 27px;
  303. padding: 0;
  304. li {
  305. height: 40px;
  306. line-height: 40px;
  307. font-size: 14px;
  308. a {
  309. display: inline-block;
  310. box-sizing: border-box;
  311. width: 100%;
  312. padding-left: 40px;
  313. text-decoration: none;
  314. color: #666;
  315. }
  316. &:hover {
  317. background: #6096ff;
  318. color: #fff;
  319. a {
  320. color: #fff;
  321. }
  322. }
  323. }
  324. .cur {
  325. background: #6096ff;
  326. color: #fff;
  327. a {
  328. color: #fff;
  329. }
  330. }
  331. }
  332. }
  333. .list {
  334. display: flex;
  335. list-style: none;
  336. margin-left: auto;
  337. align-items: center;
  338. li {
  339. padding: 0 10px;
  340. height: 63px;
  341. line-height: 63px;
  342. text-align: center;
  343. }
  344. .cur {
  345. border-bottom: 2px solid #5396ff;
  346. a {
  347. color: #5396ff;
  348. }
  349. }
  350. a {
  351. text-decoration: none;
  352. font-size: 14px;
  353. color: #333333;
  354. cursor: pointer;
  355. }
  356. .github {
  357. a {
  358. display: inline-block;
  359. width: 26px;
  360. height: 26px;
  361. vertical-align: middle;
  362. background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' height='24' viewBox='0 0 16 16' version='1.1' width='24' aria-hidden='true'%3E%3Cpath fill-rule='evenodd' fill='rgb(102,102,102)' d='M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0 0 16 8c0-4.42-3.58-8-8-8z'%3E%3C/path%3E%3C/svg%3E")
  363. no-repeat;
  364. //background: url(./asset/css/i/Shape.png) center no-repeat;
  365. border-radius: 20px;
  366. &:hover,
  367. &:active {
  368. opacity: 0.7;
  369. }
  370. }
  371. }
  372. .joinus {
  373. position: relative;
  374. height: 40px;
  375. border-radius: 3px;
  376. overflow: hidden;
  377. padding: 0;
  378. margin-right: 20px;
  379. a {
  380. position: absolute;
  381. z-index: 1;
  382. width: 100%;
  383. height: 100%;
  384. top: 0;
  385. left: 0;
  386. }
  387. }
  388. }
  389. }
  390. .demo-wrapper {
  391. display: flex;
  392. width: 100%;
  393. //padding: 0 20px 0 0;
  394. .demo-nav {
  395. width: 294px;
  396. flex-shrink: 0;
  397. }
  398. .showPhone {
  399. padding-right: 25px;
  400. //margin-left: 20px;
  401. width: 360px;
  402. flex-shrink: 0;
  403. position: relative;
  404. .ph {
  405. height: 611px;
  406. width: 360px;
  407. position: fixed;
  408. border-radius: 55px;
  409. top: 100px;
  410. border-radius: 4px;
  411. overflow: hidden;
  412. z-index: 10;
  413. box-shadow: 0px 0px 9px 5px #eee;
  414. iframe {
  415. border: none;
  416. width: 360px;
  417. height: 542px;
  418. padding: 0;
  419. box-sizing: border-box;
  420. }
  421. }
  422. .bg {
  423. width: 360px;
  424. height: 64px;
  425. padding-top: 5px;
  426. background: linear-gradient(rgba(55, 55, 55, 0.98), #545456);
  427. text-align: center;
  428. img {
  429. width: 90%;
  430. }
  431. input {
  432. width: 90%;
  433. height: 28px;
  434. line-height: 28px;
  435. color: #fff;
  436. background-color: #a2a2a2;
  437. margin: 0 auto;
  438. border-radius: 4px;
  439. white-space: nowrap;
  440. overflow-x: scroll;
  441. border: none;
  442. margin-top: 5px;
  443. padding: 0 5px;
  444. &:focus {
  445. outline: none;
  446. }
  447. }
  448. }
  449. }
  450. .fl-right {
  451. margin-left: 320px;
  452. }
  453. }
  454. .foot {
  455. height: 120px;
  456. background: #0a0a0a;
  457. font-size: 16px;
  458. color: #ffffff;
  459. line-height: 120px;
  460. text-align: center;
  461. margin-top: 80px;
  462. position: absolute;
  463. bottom: 0;
  464. width: 100%;
  465. padding-left: 300px;
  466. box-sizing: border-box;
  467. a {
  468. color: #fff;
  469. text-decoration: none;
  470. &:hover {
  471. text-decoration: underline;
  472. }
  473. }
  474. }
  475. [v-cloak] {
  476. display: none;
  477. }
  478. body {
  479. font-size: 16px;
  480. //background:#F8F8F8;
  481. margin: 0;
  482. }
  483. .demo-wrapper {
  484. background-color: #fff;
  485. // min-height:100%;
  486. }
  487. .doc-cont {
  488. padding: 8px 40px 8px 0;
  489. margin-left: 50px;
  490. box-sizing: border-box;
  491. flex: 1;
  492. min-width: 500px;
  493. }
  494. .docpad {
  495. padding: 8px 200px 8px 0;
  496. }
  497. // .button-primary {
  498. // display: block;
  499. // margin: 50px 0;
  500. // height: 38px;
  501. // padding: 0 24px;
  502. // color: #555;
  503. // text-align: center;
  504. // font-size: 12px;
  505. // font-weight: 600;
  506. // line-height: 38px;
  507. // letter-spacing: 10px;
  508. // text-transform: uppercase;
  509. // text-decoration: none;
  510. // white-space: nowrap;
  511. // background-color: transparent;
  512. // border-radius: 4px;
  513. // border: 1px solid #bbb;
  514. // cursor: pointer;
  515. // box-sizing: border-box;
  516. // color: #fff;
  517. // background-color: #33c3f0;
  518. // border-color: #33c3f0;
  519. // }
  520. .demoLink {
  521. background: #fff;
  522. position: relative;
  523. z-index: 99999;
  524. width: auto;
  525. height: auto;
  526. a {
  527. z-index: 9999;
  528. }
  529. &.qrcode {
  530. span {
  531. line-height: 64px;
  532. }
  533. img {
  534. width: 150px;
  535. height: 150px;
  536. }
  537. }
  538. }
  539. @media screen and (max-width: 1500px) {
  540. .demo-wrapper {
  541. .showPhone {
  542. width: 320px;
  543. .ph {
  544. width: 320px;
  545. height: 581px;
  546. & > div,
  547. iframe {
  548. width: 320px;
  549. }
  550. iframe {
  551. height: 512px;
  552. }
  553. }
  554. }
  555. }
  556. }
  557. </style>