app.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  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">{{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" 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. input {
  266. width: 100%;
  267. }
  268. }
  269. .search {
  270. height: 22px;
  271. font-size: 14px;
  272. color: #666;
  273. border: none;
  274. background: url(./asset/css/i/sreach.png) no-repeat left center;
  275. padding-left: 45px;
  276. &:focus {
  277. outline: none;
  278. }
  279. }
  280. .search-list {
  281. background: #fff;
  282. position: absolute;
  283. width: 300px;
  284. list-style: none;
  285. border: 1px solid #f2f2f2;
  286. z-index: 99;
  287. top: 27px;
  288. padding: 0;
  289. li {
  290. height: 40px;
  291. line-height: 40px;
  292. font-size: 14px;
  293. a {
  294. display: inline-block;
  295. box-sizing: border-box;
  296. width: 100%;
  297. padding-left: 40px;
  298. text-decoration: none;
  299. color: #666;
  300. }
  301. &:hover {
  302. background: #6096ff;
  303. color: #fff;
  304. a {
  305. color: #fff;
  306. }
  307. }
  308. }
  309. .cur {
  310. background: #6096ff;
  311. color: #fff;
  312. a {
  313. color: #fff;
  314. }
  315. }
  316. }
  317. }
  318. .list {
  319. display: flex;
  320. list-style: none;
  321. margin-left: auto;
  322. li {
  323. padding: 0 10px;
  324. height: 63px;
  325. line-height: 63px;
  326. text-align: center;
  327. }
  328. .cur {
  329. border-bottom: 2px solid #5396ff;
  330. a {
  331. color: #5396ff;
  332. }
  333. }
  334. a {
  335. text-decoration: none;
  336. font-size: 14px;
  337. color: #333333;
  338. cursor: pointer;
  339. }
  340. .github {
  341. a {
  342. display: inline-block;
  343. width: 26px;
  344. height: 26px;
  345. vertical-align: middle;
  346. 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")
  347. no-repeat;
  348. //background: url(./asset/css/i/Shape.png) center no-repeat;
  349. border-radius: 20px;
  350. &:hover,
  351. &:active {
  352. opacity: 0.7;
  353. }
  354. }
  355. }
  356. }
  357. }
  358. .demo-wrapper {
  359. display: flex;
  360. width: 100%;
  361. //padding: 0 20px 0 0;
  362. .demo-nav {
  363. width: 200px;
  364. flex-shrink: 0;
  365. }
  366. .showPhone {
  367. padding-right: 25px;
  368. //margin-left: 20px;
  369. width: 360px;
  370. flex-shrink: 0;
  371. position: relative;
  372. .ph {
  373. height: 611px;
  374. width: 360px;
  375. position: fixed;
  376. border-radius: 55px;
  377. top: 100px;
  378. border-radius: 4px;
  379. overflow: hidden;
  380. z-index: 10;
  381. box-shadow: 0px 0px 9px 5px #eee;
  382. iframe {
  383. border: none;
  384. width: 360px;
  385. height: 542px;
  386. padding: 0;
  387. box-sizing: border-box;
  388. }
  389. }
  390. .bg {
  391. width: 360px;
  392. height: 64px;
  393. padding-top: 5px;
  394. background: linear-gradient(rgba(55, 55, 55, 0.98), #545456);
  395. text-align: center;
  396. img {
  397. width: 90%;
  398. }
  399. input {
  400. width: 90%;
  401. height: 28px;
  402. line-height: 28px;
  403. color: #fff;
  404. background-color: #a2a2a2;
  405. margin: 0 auto;
  406. border-radius: 4px;
  407. white-space: nowrap;
  408. overflow-x: scroll;
  409. border: none;
  410. margin-top: 5px;
  411. padding: 0 5px;
  412. &:focus {
  413. outline: none;
  414. }
  415. }
  416. }
  417. }
  418. }
  419. .foot {
  420. height: 120px;
  421. background: #0a0a0a;
  422. font-size: 16px;
  423. color: #ffffff;
  424. line-height: 120px;
  425. text-align: center;
  426. margin-top: 80px;
  427. position: absolute;
  428. bottom: 0;
  429. width: 100%;
  430. a {
  431. color: #fff;
  432. text-decoration: none;
  433. &:hover {
  434. text-decoration: underline;
  435. }
  436. }
  437. }
  438. [v-cloak] {
  439. display: none;
  440. }
  441. body {
  442. font-size: 16px;
  443. //background:#F8F8F8;
  444. margin: 0;
  445. }
  446. .demo-wrapper {
  447. background-color: #fff;
  448. // min-height:100%;
  449. }
  450. .doc-cont {
  451. padding: 8px 40px 8px 0;
  452. margin-left: 50px;
  453. box-sizing: border-box;
  454. flex: 1;
  455. min-width: 500px;
  456. }
  457. // .button-primary {
  458. // display: block;
  459. // margin: 50px 0;
  460. // height: 38px;
  461. // padding: 0 24px;
  462. // color: #555;
  463. // text-align: center;
  464. // font-size: 12px;
  465. // font-weight: 600;
  466. // line-height: 38px;
  467. // letter-spacing: 10px;
  468. // text-transform: uppercase;
  469. // text-decoration: none;
  470. // white-space: nowrap;
  471. // background-color: transparent;
  472. // border-radius: 4px;
  473. // border: 1px solid #bbb;
  474. // cursor: pointer;
  475. // box-sizing: border-box;
  476. // color: #fff;
  477. // background-color: #33c3f0;
  478. // border-color: #33c3f0;
  479. // }
  480. .demoLink {
  481. background: #fff;
  482. position: relative;
  483. z-index: 99999;
  484. width: auto;
  485. height: auto;
  486. a {
  487. z-index: 9999;
  488. }
  489. &.qrcode {
  490. span {
  491. line-height: 64px;
  492. }
  493. img {
  494. width: 150px;
  495. height: 150px;
  496. }
  497. }
  498. }
  499. @media screen and (max-width: 1500px) {
  500. .demo-wrapper {
  501. .showPhone {
  502. width: 320px;
  503. .ph {
  504. width: 320px;
  505. height: 581px;
  506. & > div,
  507. iframe {
  508. width: 320px;
  509. }
  510. iframe {
  511. height: 512px;
  512. }
  513. }
  514. }
  515. }
  516. }
  517. </style>