app.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  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="#/doc">指南</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="http://img13.360buyimg.com/uba/jfs/t1/14144/37/3433/5890/5c26d976E7cd98b80/94583409233081cc.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="'http://nutui.jd.com/demo.html#/'+routerName+'?ver='+version">
  55. </div>
  56. </div>
  57. <iframe :src="'/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 = " http://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. "http://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. padding: 115px 0 200px 0;
  208. box-sizing: border-box;
  209. display: flex;
  210. }
  211. .hder {
  212. position: absolute;
  213. top: 0;
  214. width: 100%;
  215. background: #ffffff;
  216. border-bottom: 1px solid #f2f2f2;
  217. height: 64px;
  218. display: flex;
  219. align-items: center;
  220. margin-bottom: 50px;
  221. z-index: 42;
  222. .logo {
  223. width: 295px;
  224. height: 65px;
  225. border-right: 1px solid #d8d8d8;
  226. display: flex;
  227. align-items: center;
  228. flex-shrink: 0;
  229. .logo-link {
  230. display: inline-block;
  231. }
  232. img {
  233. display: block;
  234. width: 120px;
  235. height: 46px;
  236. flex-grow: 0;
  237. flex-shrink: 0;
  238. margin: 0 10px 0 30px;
  239. }
  240. color: #999;
  241. font-size: 12px;
  242. }
  243. .version {
  244. display: inline-block;
  245. margin-top: 7px;
  246. vertical-align: bottom;
  247. }
  248. .h-nav {
  249. display: flex;
  250. padding-left: 42px;
  251. align-items: center;
  252. width: 100%;
  253. select {
  254. width: 74px;
  255. height: 28px;
  256. margin-top: 18px;
  257. margin-left: 20px;
  258. font-size: 12px;
  259. }
  260. .search-box {
  261. height: 22px;
  262. min-width: 300px;
  263. position: relative;
  264. input {
  265. width: 100%;
  266. }
  267. }
  268. .search {
  269. height: 22px;
  270. font-size: 14px;
  271. color: #666;
  272. border: none;
  273. background: url(./asset/css/i/sreach.png) no-repeat left center;
  274. padding-left: 45px;
  275. &:focus {
  276. outline: none;
  277. }
  278. }
  279. .search-list {
  280. background: #fff;
  281. position: absolute;
  282. width: 300px;
  283. list-style: none;
  284. border: 1px solid #f2f2f2;
  285. z-index: 99;
  286. top: 27px;
  287. padding: 0;
  288. li {
  289. height: 40px;
  290. line-height: 40px;
  291. font-size: 14px;
  292. a {
  293. display: inline-block;
  294. box-sizing: border-box;
  295. width: 100%;
  296. padding-left: 40px;
  297. text-decoration: none;
  298. color: #666;
  299. }
  300. &:hover {
  301. background: #6096ff;
  302. color: #fff;
  303. a {
  304. color: #fff;
  305. }
  306. }
  307. }
  308. .cur {
  309. background: #6096ff;
  310. color: #fff;
  311. a {
  312. color: #fff;
  313. }
  314. }
  315. }
  316. }
  317. .list {
  318. display: flex;
  319. list-style: none;
  320. margin-left: auto;
  321. li {
  322. padding: 0 10px;
  323. height: 63px;
  324. line-height: 63px;
  325. text-align: center;
  326. }
  327. .cur {
  328. border-bottom: 2px solid #5396ff;
  329. a {
  330. color: #5396ff;
  331. }
  332. }
  333. a {
  334. text-decoration: none;
  335. font-size: 14px;
  336. color: #333333;
  337. cursor: pointer;
  338. }
  339. .github {
  340. a {
  341. display: inline-block;
  342. width: 26px;
  343. height: 26px;
  344. vertical-align: middle;
  345. background: url(./asset/css/i/Shape.png) center no-repeat;
  346. border-radius: 20px;
  347. }
  348. }
  349. }
  350. }
  351. .demo-wrapper {
  352. display: flex;
  353. width: 100%;
  354. //padding: 0 20px 0 0;
  355. .demo-nav {
  356. width: 200px;
  357. flex-shrink: 0;
  358. }
  359. .showPhone {
  360. padding-right: 25px;
  361. //margin-left: 20px;
  362. width: 375px;
  363. flex-shrink: 0;
  364. position: relative;
  365. .ph {
  366. height: 681px;
  367. width: 389px;
  368. position: fixed;
  369. border-radius: 55px;
  370. top: 100px;
  371. border-radius: 4px;
  372. overflow: hidden;
  373. z-index: 10;
  374. box-shadow: 0px 0px 9px 5px #eee;
  375. iframe {
  376. border: none;
  377. width: 389px;
  378. height: 612px;
  379. padding: 5px 5px 5px 5px;
  380. box-sizing: border-box;
  381. }
  382. }
  383. .bg {
  384. width: 389px;
  385. height: 64px;
  386. padding-top: 5px;
  387. background: linear-gradient(rgba(55, 55, 55, 0.98), #545456);
  388. text-align: center;
  389. img {
  390. width: 350px;
  391. }
  392. input {
  393. width: 350px;
  394. height: 28px;
  395. line-height: 28px;
  396. color: #fff;
  397. background-color: #a2a2a2;
  398. margin: 0 auto;
  399. border-radius: 4px;
  400. white-space: nowrap;
  401. overflow-x: scroll;
  402. border: none;
  403. margin-top: 5px;
  404. padding: 0 5px;
  405. &:focus {
  406. outline: none;
  407. }
  408. }
  409. }
  410. }
  411. }
  412. .foot {
  413. height: 120px;
  414. background: #0a0a0a;
  415. font-size: 16px;
  416. color: #ffffff;
  417. line-height: 120px;
  418. text-align: center;
  419. margin-top: 80px;
  420. position: absolute;
  421. bottom: 0;
  422. width: 100%;
  423. a {
  424. color: #fff;
  425. text-decoration: none;
  426. &:hover {
  427. text-decoration: underline;
  428. }
  429. }
  430. }
  431. [v-cloak] {
  432. display: none;
  433. }
  434. body {
  435. font-size: 16px;
  436. //background:#F8F8F8;
  437. margin: 0;
  438. }
  439. .demo-wrapper {
  440. background-color: #fff;
  441. // min-height:100%;
  442. }
  443. .doc-cont {
  444. padding: 8px 40px 8px 0;
  445. margin-left: 50px;
  446. box-sizing: border-box;
  447. flex: 1;
  448. min-width: 500px;
  449. }
  450. // .button-primary {
  451. // display: block;
  452. // margin: 50px 0;
  453. // height: 38px;
  454. // padding: 0 24px;
  455. // color: #555;
  456. // text-align: center;
  457. // font-size: 12px;
  458. // font-weight: 600;
  459. // line-height: 38px;
  460. // letter-spacing: 10px;
  461. // text-transform: uppercase;
  462. // text-decoration: none;
  463. // white-space: nowrap;
  464. // background-color: transparent;
  465. // border-radius: 4px;
  466. // border: 1px solid #bbb;
  467. // cursor: pointer;
  468. // box-sizing: border-box;
  469. // color: #fff;
  470. // background-color: #33c3f0;
  471. // border-color: #33c3f0;
  472. // }
  473. .demoLink {
  474. background: #fff;
  475. position: relative;
  476. z-index: 99999;
  477. width: auto;
  478. height: auto;
  479. a {
  480. z-index: 9999;
  481. }
  482. &.qrcode {
  483. span {
  484. line-height: 64px;
  485. }
  486. img {
  487. width: 150px;
  488. height: 150px;
  489. }
  490. }
  491. }
  492. </style>