app.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  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 fixed-box"></router-view>
  46. <keep-alive include="index">
  47. <router-view class="doc-cont fl-right" :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" href="javascript:;">前端开发部</a>
  65. </div>
  66. </div>
  67. </div>
  68. </template>
  69. <script>
  70. import "./asset/css/common.scss";
  71. import "./asset/css/style-blue.scss";
  72. import { packages } from "../../src/config.json";
  73. import search from "./search.vue";
  74. import leftNav from './info.vue';
  75. import { version } from "../../package.json";
  76. export default {
  77. name: "App",
  78. data() {
  79. return {
  80. packages,
  81. version,
  82. searchList: [],
  83. searchVal: "",
  84. routerName: "",
  85. showPhone: false,
  86. searchCurName: "",
  87. searchIndex: 0,
  88. codeurl: ""
  89. };
  90. },
  91. watch: {
  92. // '$route':obj =>{
  93. // if(this){
  94. // this.routerName = obj.name
  95. // }
  96. // },
  97. $route: "fetchData"
  98. },
  99. components: {
  100. search,
  101. leftNav
  102. },
  103. methods: {
  104. openwindow(val) {
  105. if (val.target.value == 1) {
  106. window.location.href = "https://nutui.jd.com/1x/";
  107. }
  108. },
  109. choseList(e) {
  110. let searchIndex = this.searchIndex;
  111. if (e.keyCode == 40) {
  112. searchIndex++;
  113. }
  114. if (e.keyCode == 38) {
  115. searchIndex--;
  116. }
  117. if (searchIndex < 0) {
  118. searchIndex = 0;
  119. }
  120. let searchList = this.searchList;
  121. if (searchList.length > 0) {
  122. let chnName = searchList[searchIndex].chnName;
  123. if (chnName) {
  124. this.searchCurName = chnName;
  125. this.searchIndex = searchIndex;
  126. if (e.keyCode == 13) {
  127. this.$router.push({
  128. path: "/" + searchList[searchIndex].name
  129. });
  130. this.searchCurName = "";
  131. this.searchIndex = 0;
  132. this.searchList = [];
  133. this.searchVal = "";
  134. }
  135. }
  136. }
  137. },
  138. fetchData(obj) {
  139. this.routerName = obj.name;
  140. this.showPhone = false;
  141. for (let i = 0, item; (item = packages[i]); i++) {
  142. if (obj.name == item.name) {
  143. this.showPhone = true;
  144. }
  145. }
  146. let that = this;
  147. this.qrcode.toDataURL(
  148. "https://nutui.jd.com/index.html#/" + that.routerName,
  149. { width: 170 },
  150. (err, url) => {
  151. that.codeurl = url;
  152. }
  153. );
  154. },
  155. onfocus(e) {
  156. e.target.select();
  157. },
  158. clearSearch() {
  159. this.searchList = [];
  160. },
  161. search(e) {
  162. let val = e.target.value.toLowerCase();
  163. if (val) {
  164. let packages = this.packages;
  165. let list = [];
  166. for (let i = 0, item; (item = packages[i]); i++) {
  167. let cn = item.chnName.toLowerCase();
  168. let en = item.name.toLowerCase();
  169. if (cn.indexOf(val) > -1 || en.indexOf(val) > -1) {
  170. list.push(item);
  171. }
  172. }
  173. this.searchList = list;
  174. }
  175. },
  176. checklist(obj) {
  177. this.searchVal = "";
  178. this.searchList = [];
  179. this.searchCurName = "";
  180. this.searchIndex = 0;
  181. }
  182. },
  183. created() {
  184. let that = this;
  185. let name = this.$route.name;
  186. for (let i = 0, item; (item = packages[i]); i++) {
  187. if (name == item.name) {
  188. this.showPhone = true;
  189. }
  190. }
  191. }
  192. };
  193. </script>
  194. <style lang="scss">
  195. .fixed-box{
  196. position: fixed;
  197. z-index: 9;
  198. height: 100%;
  199. overflow:hidden;
  200. overflow-y: auto;
  201. top:0;
  202. background: #fff;
  203. box-sizing: border-box;
  204. }
  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: 85px 0 200px 0;
  221. box-sizing: border-box;
  222. display: flex;
  223. }
  224. .hder {
  225. position: fixed;
  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: 293px;
  237. height: 65px;
  238. display: flex;
  239. align-items: center;
  240. flex-shrink: 0;
  241. border-right: 1px solid #d8d8d8;
  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. .fl-right{
  432. margin-left: 320px;
  433. }
  434. }
  435. .foot {
  436. height: 120px;
  437. background: #0a0a0a;
  438. font-size: 16px;
  439. color: #ffffff;
  440. line-height: 120px;
  441. text-align: center;
  442. margin-top: 80px;
  443. position: absolute;
  444. bottom: 0;
  445. width: 100%;
  446. padding-left: 300px;
  447. box-sizing: border-box;
  448. a {
  449. color: #fff;
  450. text-decoration: none;
  451. &:hover {
  452. text-decoration: underline;
  453. }
  454. }
  455. }
  456. [v-cloak] {
  457. display: none;
  458. }
  459. body {
  460. font-size: 16px;
  461. //background:#F8F8F8;
  462. margin: 0;
  463. }
  464. .demo-wrapper {
  465. background-color: #fff;
  466. // min-height:100%;
  467. }
  468. .doc-cont {
  469. padding: 8px 40px 8px 0;
  470. margin-left: 50px;
  471. box-sizing: border-box;
  472. flex: 1;
  473. min-width: 500px;
  474. }
  475. .docpad{
  476. padding: 8px 200px 8px 0;
  477. }
  478. // .button-primary {
  479. // display: block;
  480. // margin: 50px 0;
  481. // height: 38px;
  482. // padding: 0 24px;
  483. // color: #555;
  484. // text-align: center;
  485. // font-size: 12px;
  486. // font-weight: 600;
  487. // line-height: 38px;
  488. // letter-spacing: 10px;
  489. // text-transform: uppercase;
  490. // text-decoration: none;
  491. // white-space: nowrap;
  492. // background-color: transparent;
  493. // border-radius: 4px;
  494. // border: 1px solid #bbb;
  495. // cursor: pointer;
  496. // box-sizing: border-box;
  497. // color: #fff;
  498. // background-color: #33c3f0;
  499. // border-color: #33c3f0;
  500. // }
  501. .demoLink {
  502. background: #fff;
  503. position: relative;
  504. z-index: 99999;
  505. width: auto;
  506. height: auto;
  507. a {
  508. z-index: 9999;
  509. }
  510. &.qrcode {
  511. span {
  512. line-height: 64px;
  513. }
  514. img {
  515. width: 150px;
  516. height: 150px;
  517. }
  518. }
  519. }
  520. @media screen and (max-width: 1500px) {
  521. .demo-wrapper {
  522. .showPhone {
  523. width: 320px;
  524. .ph {
  525. width: 320px;
  526. height: 581px;
  527. & > div,
  528. iframe {
  529. width: 320px;
  530. }
  531. iframe {
  532. height: 512px;
  533. }
  534. }
  535. }
  536. }
  537. }
  538. </style>