app.vue 11 KB

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