app.vue 12 KB

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