app.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  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="default.html#/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. <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="default.html#/doc">指南</a>
  36. </li>
  37. <li>
  38. <a class="qrcode demoLink" href="/demo.html#/index" target="_blank">示例
  39. <a :href="routerName">
  40. <span>请使用手机扫码体验</span><img src="http://img13.360buyimg.com/uba/jfs/t1/14144/37/3433/5890/5c26d976E7cd98b80/94583409233081cc.png" 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://nutui.jd.com/demo.html#/'+routerName">
  71. </div>
  72. </div>
  73. <iframe :src="'/demo.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. import PackageJson from "../../package.json";
  89. export default {
  90. name: "App",
  91. data() {
  92. return {
  93. packages: "",
  94. searchList: [],
  95. searchVal: "",
  96. routerName: "",
  97. showPhone: false,
  98. searchCurName:'',
  99. searchIndex:0,
  100. codeurl:'',
  101. version:''
  102. };
  103. },
  104. watch: {
  105. // '$route':obj =>{
  106. // if(this){
  107. // this.routerName = obj.name
  108. // }
  109. // },
  110. $route: "fetchData"
  111. },
  112. methods: {
  113. openwindow(val){
  114. if(val.target.value==1){
  115. window.location.href=" http://nutui.jd.com/1x/"
  116. }
  117. },
  118. choseList(e){
  119. console.log(e)
  120. let searchIndex = this.searchIndex;
  121. if(e.keyCode==40){
  122. searchIndex++;
  123. }
  124. if(e.keyCode==38){
  125. searchIndex--;
  126. }
  127. if(searchIndex<0){
  128. searchIndex = 0;
  129. }
  130. let searchList = this.searchList;
  131. if(searchList.length>0){
  132. let chnName = searchList[searchIndex].chnName;
  133. if(chnName){
  134. this.searchCurName = chnName;
  135. this.searchIndex = searchIndex;
  136. if(e.keyCode==13){
  137. this.$router.push({
  138. path:'/'+searchList[searchIndex].name
  139. })
  140. this.searchCurName='';
  141. this.searchIndex=0;
  142. this.searchList=[];
  143. this.searchVal='';
  144. }
  145. }
  146. }
  147. },
  148. fetchData(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 = PackageJson.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. .logo-link{
  240. display:inline-block;
  241. }
  242. img{
  243. display: block;
  244. width: 120px;
  245. height: 46px;
  246. flex-grow: 0;
  247. flex-shrink:0;
  248. margin: 0 10px 0 30px;
  249. }
  250. color:#999;
  251. font-size: 12px;
  252. }
  253. .version{
  254. display:inline-block;
  255. margin-top:7px;
  256. vertical-align: bottom;
  257. }
  258. .h-nav {
  259. display: flex;
  260. padding-left: 42px;
  261. align-items: center;
  262. width: 100%;
  263. select{
  264. width:74px;
  265. height:28px;
  266. margin-top:18px;
  267. margin-left:20px;
  268. font-size:12px;
  269. }
  270. .search-box {
  271. height: 22px;
  272. min-width: 300px;
  273. position: relative;
  274. input {
  275. width: 100%;
  276. }
  277. }
  278. .search {
  279. height: 22px;
  280. font-size: 14px;
  281. color: #666;
  282. border: none;
  283. background: url(./asset/css/i/sreach.png) no-repeat left center;
  284. padding-left: 45px;
  285. &:focus {
  286. outline: none;
  287. }
  288. }
  289. .search-list {
  290. background: #fff;
  291. position: absolute;
  292. width: 300px;
  293. list-style: none;
  294. border: 1px solid #f2f2f2;
  295. z-index: 99;
  296. top: 27px;
  297. padding: 0;
  298. li {
  299. height: 40px;
  300. line-height: 40px;
  301. a {
  302. display: inline-block;
  303. box-sizing: border-box;
  304. width: 100%;
  305. padding-left: 40px;
  306. text-decoration: none;
  307. color: #666;
  308. }
  309. &:hover {
  310. background: #6096ff;
  311. color: #fff;
  312. a {
  313. color: #fff;
  314. }
  315. }
  316. }
  317. .cur{
  318. background: #6096ff;
  319. color: #fff;
  320. a {
  321. color: #fff;
  322. }
  323. }
  324. }
  325. }
  326. .list {
  327. display: flex;
  328. list-style: none;
  329. margin-left: auto;
  330. li {
  331. padding:0 10px;
  332. height: 63px;
  333. line-height: 63px;
  334. text-align: center;
  335. }
  336. .cur {
  337. border-bottom: 2px solid #5396ff;
  338. a {
  339. color: #5396ff;
  340. }
  341. }
  342. a {
  343. text-decoration: none;
  344. font-size: 14px;
  345. color: #333333;
  346. cursor: pointer;
  347. }
  348. .github {
  349. a {
  350. display: inline-block;
  351. width: 26px;
  352. height: 26px;
  353. vertical-align: middle;
  354. background: url(./asset/css/i/Shape.png) center no-repeat;
  355. border-radius: 20px;
  356. }
  357. }
  358. }
  359. }
  360. .demo-wrapper {
  361. display: flex;
  362. width:100%;
  363. //padding: 0 20px 0 0;
  364. .demo-nav {
  365. width: 200px;
  366. flex-shrink: 0;
  367. }
  368. .showPhone {
  369. padding-right:25px;
  370. //margin-left: 20px;
  371. width: 375px;
  372. flex-shrink: 0;
  373. position: relative;
  374. .ph {
  375. height: 681px;
  376. width: 389px;
  377. position: fixed;
  378. border-radius: 55px;
  379. top: 100px;
  380. border-radius: 4px;
  381. overflow: hidden;
  382. z-index: 10;
  383. box-shadow: 0px 0px 9px 5px #eee;
  384. iframe {
  385. border: none;
  386. width: 389px;
  387. height: 612px;
  388. padding: 5px 5px 5px 5px;
  389. box-sizing: border-box;
  390. }
  391. }
  392. .bg {
  393. width: 389px;
  394. height: 64px;
  395. padding-top:5px;
  396. background: linear-gradient(rgba(55,55,55,.98),#545456);
  397. text-align: center;
  398. img{
  399. width: 350px;
  400. }
  401. input{
  402. width: 350px;
  403. height: 28px;
  404. line-height: 28px;
  405. color: #fff;
  406. background-color: #a2a2a2;
  407. margin: 0 auto;
  408. border-radius: 4px;
  409. white-space: nowrap;
  410. overflow-x: scroll;
  411. border: none;
  412. margin-top:5px;
  413. padding: 0 5px;
  414. &:focus{
  415. outline: none;
  416. }
  417. }
  418. }
  419. }
  420. }
  421. .foot {
  422. height: 120px;
  423. background: #0a0a0a;
  424. font-size: 16px;
  425. color: #ffffff;
  426. line-height: 120px;
  427. text-align: center;
  428. margin-top: 80px;
  429. position: absolute;
  430. bottom: 0;
  431. width: 100%;
  432. a {
  433. color: #fff;
  434. text-decoration: none;
  435. &:hover {
  436. text-decoration: underline;
  437. }
  438. }
  439. }
  440. [v-cloak] {
  441. display: none;
  442. }
  443. body {
  444. font-size: 16px;
  445. //background:#F8F8F8;
  446. margin: 0;
  447. }
  448. .demo-wrapper {
  449. background-color: #fff;
  450. // min-height:100%;
  451. }
  452. .doc-cont {
  453. padding: 8px 40px 8px 0;
  454. margin-left:50px;
  455. box-sizing: border-box;
  456. flex:1;
  457. min-width: 500px;
  458. }
  459. // .button-primary {
  460. // display: block;
  461. // margin: 50px 0;
  462. // height: 38px;
  463. // padding: 0 24px;
  464. // color: #555;
  465. // text-align: center;
  466. // font-size: 12px;
  467. // font-weight: 600;
  468. // line-height: 38px;
  469. // letter-spacing: 10px;
  470. // text-transform: uppercase;
  471. // text-decoration: none;
  472. // white-space: nowrap;
  473. // background-color: transparent;
  474. // border-radius: 4px;
  475. // border: 1px solid #bbb;
  476. // cursor: pointer;
  477. // box-sizing: border-box;
  478. // color: #fff;
  479. // background-color: #33c3f0;
  480. // border-color: #33c3f0;
  481. // }
  482. .demoLink{
  483. background: #fff;
  484. position: relative;
  485. z-index: 99999;
  486. width: auto;
  487. height: auto;
  488. a{
  489. z-index: 9999;
  490. }
  491. &.qrcode{
  492. span{
  493. line-height: 64px;
  494. }
  495. img{
  496. width:150px;
  497. height:150px;
  498. }
  499. }
  500. }
  501. </style>