element/examples/app.vue

185 lines
3.7 KiB
Vue
Raw Normal View History

2016-07-27 14:15:02 +08:00
<style lang="css">
2016-11-01 18:28:20 +08:00
@import 'highlight.js/styles/color-brewer.css';
2016-07-27 14:15:02 +08:00
@import 'assets/styles/common.css';
2016-08-18 15:53:54 +08:00
@import 'assets/styles/fonts/style.css';
2016-07-27 14:15:02 +08:00
html, body {
margin: 0;
padding: 0;
2016-08-23 19:15:15 +08:00
height: 100%;
2016-07-27 14:15:02 +08:00
}
2016-08-23 19:15:15 +08:00
#app {
height: 100%;
2016-08-23 16:57:58 +08:00
}
2016-08-23 19:15:15 +08:00
body {
2016-07-27 14:15:02 +08:00
font-family: 'Helvetica Neue',Helvetica,'PingFang SC','Hiragino Sans GB','Microsoft YaHei',SimSun,sans-serif;
2016-08-23 19:15:15 +08:00
overflow: auto;
2016-09-20 17:09:18 +08:00
font-weight: 400;
-webkit-font-smoothing: antialiased;
2016-07-27 14:15:02 +08:00
}
2016-08-30 19:30:58 +08:00
a {
color: #4078c0;
text-decoration: none;
}
2016-09-28 12:35:24 +08:00
button, input, select, textarea {
font-family: inherit;
font-size: inherit;
line-height: inherit;
color: inherit;
}
2016-08-30 19:30:58 +08:00
.hljs {
2016-09-18 22:01:26 +08:00
line-height: 1.8;
font-family: Menlo, Monaco, Consolas, Courier, monospace;
font-size: 12px;
padding: 18px 24px;
2016-08-30 19:30:58 +08:00
background-color: #f9fafc;
2016-09-18 22:01:26 +08:00
border: solid 1px #eaeefb;
2016-08-30 19:30:58 +08:00
margin-bottom: 25px;
border-radius: 4px;
2016-09-20 17:09:18 +08:00
-webkit-font-smoothing: auto;
2016-08-30 19:30:58 +08:00
}
2016-08-23 19:15:15 +08:00
.main-cnt {
margin-top: -80px;
padding: 80px 0 120px;
2016-07-27 14:15:02 +08:00
box-sizing: border-box;
2016-08-23 19:15:15 +08:00
min-height: 100%;
2016-07-27 14:15:02 +08:00
}
2016-08-25 15:54:45 +08:00
.container,
.page-container {
2016-09-13 20:02:33 +08:00
width: 1140px;
2016-08-25 15:54:45 +08:00
margin: 0 auto;
}
.page-container {
padding-top: 55px;
h2 {
font-size: 28px;
color: #1f2d3d;
margin: 0;
}
h3 {
font-size: 22px;
}
h2, h3, h4, h5 {
font-weight: normal;
color: #1f2f3d;
2016-11-04 16:59:59 +08:00
&:hover a {
opacity: .4;
}
a {
float: left;
margin-left: -20px;
opacity: 0;
cursor: pointer;
&:hover {
opacity: .4;
}
}
2016-08-25 15:54:45 +08:00
}
p {
font-size: 14px;
color: #5e6d82;
}
2016-07-27 14:15:02 +08:00
}
.demo {
margin: 20px 0;
}
2016-09-14 18:38:38 +08:00
@media (max-width: 1140px) {
.container,
.page-container {
width: 100%;
}
}
2016-07-27 14:15:02 +08:00
</style>
<template>
2016-07-27 17:05:28 +08:00
<div id="app">
2016-11-13 02:34:39 +08:00
<main-header v-if="lang !== 'play'"></main-header>
2016-08-23 19:15:15 +08:00
<div class="main-cnt">
<router-view></router-view>
</div>
2016-11-13 02:34:39 +08:00
<main-footer v-if="lang !== 'play'"></main-footer>
2016-07-27 17:05:28 +08:00
</div>
2016-07-27 14:15:02 +08:00
</template>
<script>
import { use } from 'main/locale';
import zhLocale from 'main/locale/lang/zh-CN';
import enLocale from 'main/locale/lang/en';
use(location.href.indexOf('zh-CN') > -1 ? zhLocale : enLocale);
2016-07-27 14:15:02 +08:00
export default {
2016-09-08 18:11:18 +08:00
name: 'app',
computed: {
lang() {
return this.$route.path.split('/')[1] || 'zh-CN';
}
},
watch: {
lang() {
this.localize();
}
},
2016-11-04 16:59:59 +08:00
methods: {
localize() {
use(this.lang === 'zh-CN' ? zhLocale : enLocale);
},
2016-11-04 16:59:59 +08:00
renderAnchorHref() {
2016-11-06 15:56:41 +08:00
if (/changelog/g.test(location.href)) return;
2016-11-04 16:59:59 +08:00
const anchors = document.querySelectorAll('h2 a,h3 a');
const basePath = location.href.split('#').splice(0, 2).join('#');
[].slice.call(anchors).forEach(a => {
const href = a.getAttribute('href');
a.href = basePath + href;
});
},
goAnchor() {
if (location.href.match(/#/g).length > 1) {
const auchor = location.href.match(/#[^#]+$/g);
if (!auchor || auchor.length !== 1) return;
const elm = document.querySelector(auchor[0]);
if (!elm) return;
setTimeout(_ => {
document.documentElement.scrollTop = document.body.scrollTop = elm.offsetTop;
}, 50);
}
}
},
mounted() {
this.localize();
2016-11-04 16:59:59 +08:00
this.renderAnchorHref();
this.goAnchor();
},
2016-09-08 18:11:18 +08:00
created() {
window.addEventListener('hashchange', () => {
2016-11-04 16:59:59 +08:00
if (location.href.match(/#/g).length < 2) {
document.documentElement.scrollTop = document.body.scrollTop = 0;
this.renderAnchorHref();
} else {
this.goAnchor();
}
2016-09-08 18:11:18 +08:00
});
}
2016-07-27 14:15:02 +08:00
};
</script>