app.vue 11 KB

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