app.vue 13 KB

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