mirror of
https://github.com/youzan/vant.git
synced 2025-10-20 02:31:21 +00:00
[Doc] add demo pages (#237)
* [bugfix] Checkbox border render error in weixin browser * [bugfix] TreeSelect dependency path error * [bugfix] Swipe should clear autoplay timer when destroyed * [bugfix] Optimize component dependency analyze when build style entry * merge * update yarn.lock * update README.md * update README.md * update README.md * update README.md * update README.md * [Doc] add more badges in README.md * update README.md * [bugfix] Address & Contact list style * fix: contact test cases * [bugfix] popup style missing when build style entry * [bugfix] Search: onSearch event arguments missing * [Doc] add demo pages * update zan-doc@0.3.7 * fix: build entry error
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<div class="app">
|
||||
<zan-doc :simulator="simulator" :config="config" :base="base">
|
||||
<router-view></router-view>
|
||||
<zan-doc :simulators="simulators" :currentSimulator="currentSimulator" :config="config" :base="base">
|
||||
<router-view @changeDemoURL="onChangeDemoURL"></router-view>
|
||||
</zan-doc>
|
||||
</div>
|
||||
</template>
|
||||
@@ -17,10 +17,9 @@ export default {
|
||||
group.list = group.list.filter(item => item.title !== '业务组件');
|
||||
}
|
||||
|
||||
const hash = window.location.hash;
|
||||
|
||||
return {
|
||||
simulator: `/zanui/vue/examples${hash}`,
|
||||
simulators: [`/zanui/vue/examples${location.hash}`],
|
||||
demoURL: '',
|
||||
lang: getLang()
|
||||
};
|
||||
},
|
||||
@@ -32,6 +31,10 @@ export default {
|
||||
|
||||
config() {
|
||||
return docConfig[this.lang];
|
||||
},
|
||||
|
||||
currentSimulator() {
|
||||
return this.$route.name === 'zh-CN/demo' ? 1 : 0;
|
||||
}
|
||||
},
|
||||
|
||||
@@ -39,6 +42,12 @@ export default {
|
||||
'$route'(to) {
|
||||
this.lang = to.meta.lang;
|
||||
}
|
||||
},
|
||||
|
||||
methods: {
|
||||
onChangeDemoURL(url) {
|
||||
this.simulators = [this.simulators[0], url];
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
94
docs/src/components/demo.vue
Normal file
94
docs/src/components/demo.vue
Normal file
@@ -0,0 +1,94 @@
|
||||
<template>
|
||||
<section class="zan-doc-demos">
|
||||
<h2>示例</h2>
|
||||
<p>下面是一些使用 Vant 搭建的示例页面,点击图片切换至对应示例。</p>
|
||||
<div class="zan-doc-demos__gallery">
|
||||
<div
|
||||
:class="['zan-doc-demos__item', { 'zan-doc-demos__item--active': index === currentDemo }]"
|
||||
v-for="(demo, index) in demos"
|
||||
>
|
||||
<h4>{{ demo.title }}</h4>
|
||||
<a :href="demo.source" target="_blank">源代码</a>
|
||||
<img :src="demo.preview" @click="onChangeDemo(demo, index)" />
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
currentDemo: 0,
|
||||
demos: [{
|
||||
title: '会员中心',
|
||||
preview: 'https://img.yzcdn.cn/public_files/2017/10/23/e1d70757e3ab88d39a360b704be8f43f.png',
|
||||
url: 'https://chenjiahan.github.io/vant-demo/#/user',
|
||||
source: 'https://github.com/chenjiahan/vant-demo/tree/master/src/view/user'
|
||||
}, {
|
||||
title: '购物车',
|
||||
preview: 'https://img.yzcdn.cn/public_files/2017/10/24/06b8b5ed3692314d434db7f6854dcdbe.png',
|
||||
url: 'https://chenjiahan.github.io/vant-demo/#/cart',
|
||||
source: 'https://github.com/chenjiahan/vant-demo/tree/master/src/view/cart'
|
||||
}]
|
||||
};
|
||||
},
|
||||
|
||||
beforeMount() {
|
||||
this.$emit('changeDemoURL', this.demos[0].url);
|
||||
},
|
||||
|
||||
methods: {
|
||||
onChangeDemo(demo, index) {
|
||||
this.currentDemo = index;
|
||||
this.$emit('changeDemoURL', demo.url);
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.zan-doc-demos {
|
||||
&__gallery {
|
||||
margin-top: 30px;
|
||||
}
|
||||
|
||||
&__item {
|
||||
width: 28%;
|
||||
text-align: center;
|
||||
margin-bottom: 40px;
|
||||
display: inline-block;
|
||||
|
||||
&:nth-child(3n+1),
|
||||
&:nth-child(3n+2) {
|
||||
margin-right: 4%;
|
||||
}
|
||||
|
||||
h4 {
|
||||
font-size: 14px;
|
||||
line-height: 20px;
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
img {
|
||||
width: 100%;
|
||||
cursor: pointer;
|
||||
border-radius: 3px;
|
||||
background-color: #f8f8f8;
|
||||
box-shadow: 0 2px 3px rgba(10, 10, 10, 0.1), 0 0 0 1px rgba(10, 10, 10, 0.1);
|
||||
}
|
||||
|
||||
a {
|
||||
display: block;
|
||||
font-size: 12px;
|
||||
margin: 4px 0 7px;
|
||||
}
|
||||
|
||||
&--active {
|
||||
img {
|
||||
box-shadow: 0 1px 4px rgba(51, 136, 255, .4), 0 0 0 1px rgba(51, 136, 255, .4);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
@@ -28,12 +28,18 @@ module.exports = {
|
||||
},
|
||||
{
|
||||
title: '业务组件',
|
||||
link: '/zanui/captain/component/quickstart'
|
||||
link: '/zanui/captain'
|
||||
},
|
||||
{
|
||||
path: '/changelog',
|
||||
title: '更新日志',
|
||||
noExample: true
|
||||
},
|
||||
{
|
||||
path: '/demo',
|
||||
title: '示例页面',
|
||||
noDocument: true,
|
||||
noExample: true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import Vue from 'vue';
|
||||
import VueRouter from 'vue-router';
|
||||
import App from './ExamplesApp';
|
||||
import App from './WapApp';
|
||||
import routes from './router.config';
|
||||
import { setLang } from './utils/lang';
|
||||
import Vant, { Lazyload } from 'packages';
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import Vue from 'vue';
|
||||
import VueRouter from 'vue-router';
|
||||
import App from './ExamplesDocsApp';
|
||||
import App from './DocsApp';
|
||||
import routes from './router.config';
|
||||
import ZanDoc from 'zan-doc';
|
||||
import isMobile from './utils/is-mobile';
|
||||
|
@@ -3,19 +3,16 @@ import { getLang } from './utils/lang';
|
||||
import DemoList from './components/demo-list';
|
||||
import componentDocs from '../examples-dist/entry-docs';
|
||||
import componentDemos from '../examples-dist/entry-demos';
|
||||
import Demo from './components/demo';
|
||||
import './utils/iframe-router';
|
||||
|
||||
const registerRoute = (isExample) => {
|
||||
const route = [{
|
||||
path: '/',
|
||||
redirect: to => {
|
||||
return `/${getLang()}/`;
|
||||
}
|
||||
redirect: to => `/${getLang()}/`
|
||||
}, {
|
||||
path: '*',
|
||||
redirect: to => {
|
||||
return `/${getLang()}/`;
|
||||
}
|
||||
redirect: to => `/${getLang()}/`
|
||||
}];
|
||||
|
||||
Object.keys(docConfig).forEach((lang, index) => {
|
||||
@@ -53,9 +50,18 @@ const registerRoute = (isExample) => {
|
||||
const { path } = page;
|
||||
if (path) {
|
||||
const name = lang + '/' + path.replace('/', '');
|
||||
let component;
|
||||
|
||||
if (path === '/demo') {
|
||||
component = Demo;
|
||||
} else {
|
||||
component = isExample ? componentDemos[name] : componentDocs[name];
|
||||
}
|
||||
|
||||
route.push({
|
||||
name,
|
||||
component,
|
||||
path: `/${lang}/component${path}`,
|
||||
component: isExample ? componentDemos[name] : componentDocs[name],
|
||||
meta: { lang }
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user