app.vue 11 KB

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