Skip to content

Commit

Permalink
docs: update router config
Browse files Browse the repository at this point in the history
  • Loading branch information
eiinu committed Dec 13, 2023
1 parent 70b0636 commit 6c46d95
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 147 deletions.
93 changes: 72 additions & 21 deletions src/sites/doc/components/DocHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,94 @@
<div class="header-logo">
<a class="logo-link" href="#" @click="toHome"></a>
</div>
<div class="tabs">
<div class="tab-item" @click="switchTo('h5')">h5</div>
<div class="tab-item" @click="switchTo('taro')">taro</div>
</div>
</div>
</template>
<script setup lang="ts">
import { RefData } from '@/sites/assets/util/ref';
const toHome = () => {
RefData.getInstance().currentRoute.value = '/';
};
const switchTo = (type: 'h5' | 'taro') => {
if (type === 'h5') {
location.href = location.href.replace('taro', 'h5');
} else {
location.href = location.href.replace('h5', 'taro');
}
};
</script>

<style lang="scss">
<style lang="scss" scoped>
.doc-header {
height: $doc-header-height;
line-height: $doc-header-height;
padding: 0 50px;
width: 100%;
font-size: 20px;
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
}
.header {
&-logo {
position: relative;
display: inline-block;
width: 240px;
height: 64px;
.logo-link {
width: 120px;
height: 46px;
vertical-align: middle;
position: absolute;
top: 50%;
margin-top: -23px;
.header-logo {
position: relative;
display: inline-block;
width: 240px;
height: 64px;
.logo-link {
width: 120px;
height: 46px;
vertical-align: middle;
position: absolute;
top: 50%;
margin-top: -23px;
}
.logo-border {
width: 1px;
height: 26px;
position: absolute;
right: 0;
top: 50%;
margin-top: -13px;
}
}
.tabs {
display: flex;
height: 40px;
align-items: center;
justify-content: space-between;
z-index: 1;
padding: 2px;
box-sizing: border-box;
border-radius: 2px;
background: #eee;
box-shadow: rgb(0 0 0 / 15%) 0px 2px 4px;
&.single {
padding: 0;
.tab-item {
line-height: 40px;
cursor: auto;
}
.logo-border {
width: 1px;
height: 26px;
position: absolute;
right: 0;
top: 50%;
margin-top: -13px;
}
.tab-item {
position: relative;
padding: 0 10px;
line-height: 36px;
cursor: pointer;
font-size: 16px;
color: #323232;
text-align: center;
border-radius: 2px;
background: #eee;
&.cur {
font-weight: bold;
color: #323232;
background: #fff;
}
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/sites/doc/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const modulesPage = import.meta.glob('/src/packages/__VUE/**/doc.md');
for (const path in modulesPage) {
const name = (/packages\/__VUE\/(.*)\/doc.md/.exec(path) as any[])[1];
pagesRouter.push({
path: '/zh-CN/component/' + name,
path: '/h5/zh-CN/' + name,
component: modulesPage[path]
});
}
Expand All @@ -18,7 +18,7 @@ const modulesEnPage = import.meta.glob('/src/packages/__VUE/**/doc.en-US.md');
for (const path in modulesEnPage) {
const name = (/packages\/__VUE\/(.*)\/doc.en-US.md/.exec(path) as any[])[1];
pagesEnRouter.push({
path: '/en-US/component/' + name,
path: '/h5/en-US/' + name,
component: modulesEnPage[path]
});
}
Expand All @@ -28,25 +28,25 @@ const modulesPageTaro = import.meta.glob('/src/packages/__VUE/**/*.taro.md');
for (const path in modulesPageTaro) {
const name = (/packages\/__VUE\/(.*)\/doc.taro.md/.exec(path) as any[])[1];
pagesRouter.push({
path: `/zh-CN/component/${name}-taro`,
path: '/taro/zh-CN/' + name,
component: modulesPageTaro[path]
});
pagesEnRouter.push({
path: `/en-US/component/${name}-taro`,
path: '/taro/en-US/' + name,
component: modulesPageTaro[path]
});
}

const routes: Array<RouteRecordRaw> = [
{
path: '/zh-CN',
name: '/zh-CN',
path: '/h5/zh-CN',
name: '/h5/zh-CN',
component: Index,
children: pagesRouter
},
{
path: '/en-US',
name: '/en-US',
path: '/h5/en-US',
name: '/h5/en-US',
component: Index,
children: pagesEnRouter
}
Expand All @@ -55,7 +55,7 @@ routes.push({
name: 'notFound',
path: '/:path(.*)+',
redirect: {
path: '/zh-CN/component/button'
path: '/h5/zh-CN/button'
}
});
const router = createRouter({
Expand Down
114 changes: 14 additions & 100 deletions src/sites/doc/views/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,14 @@
</div>
</div>
<div class="doc-content-document isComponent">
<div class="doc-content-tabs">
<div
v-for="item in data.tabs"
:key="item.key"
class="tab-item"
:class="{ cur: data.curKey === item.key }"
@click="handleTabs(item.key)"
>{{ item.text }}</div
>
</div>
<router-view />
</div>
<DocDemoPreview :url="data.demoUrl"></DocDemoPreview>
</div>
</div>
</template>
<script setup lang="ts">
import { onMounted, reactive } from 'vue';
import { onMounted, reactive, watch } from 'vue';
import { nav } from '@/config.json';
import { onBeforeRouteUpdate, RouteLocationNormalized, useRoute, useRouter } from 'vue-router';
import DocHeader from '@/sites/doc/components/DocHeader.vue';
Expand All @@ -35,15 +25,15 @@ import DocDemoPreview from '@/sites/doc/components/DemoPreview.vue';
import { RefData } from '@/sites/assets/util/ref';
import { initSiteLang } from '@/sites/assets/util/useTranslate';
const route = useRoute();
const router = useRouter();
initSiteLang();
const state = reactive({
fixed: false, // 是否吸顶
hidden: false, // 是否隐藏
// 组件名称
componentName: {
name: '',
cName: ''
cName: '',
type: ''
}
});
const data = reactive({
Expand All @@ -66,27 +56,20 @@ const isTaro = (router: RouteLocationNormalized) => {
};
const watchDemoUrl = (router: RouteLocationNormalized) => {
const { origin, pathname } = window.location;
RefData.getInstance().currentRoute.value = router.path as string;
let url = `${origin}${pathname.replace('index.html', '')}demo.html#${router.path}`;
data.demoUrl = url.replace('/component', '');
};
const watchDocMd = (curKey: string) => {
const path = route.path;
// router.replace(isTaro(route) ? path.substr(0, path.length - 5) : `${path}-taro`);
if (curKey.includes('taro')) {
router.replace(isTaro(route) ? path : `${path}-taro`);
if (isTaro(router)) {
data.demoUrl = `http://localhost:10086/#/${
state.componentName.type
}/pages/${state.componentName.name.toLowerCase()}/index`;
} else {
router.replace(isTaro(route) ? path.substr(0, path.length - 5) : path);
if (router.path.includes('zh-CN')) {
data.demoUrl = `/demo.html#/zh-CN/${state.componentName.name.toLowerCase()}`;
} else {
data.demoUrl = `/demo.html#/en-US/${state.componentName.name.toLowerCase()}`;
}
}
};
const handleTabs = (curKey: string) => {
data.curKey = curKey;
watchDocMd(curKey);
};
onMounted(() => {
componentTitle();
watchDemoUrl(route);
Expand All @@ -96,7 +79,6 @@ onMounted(() => {
const scrollTitle = () => {
let top = document.documentElement.scrollTop;
// console.log('state.hidden', state.hidden)
if (top > 127) {
state.fixed = true;
if (top < 142) {
Expand All @@ -118,16 +100,17 @@ const componentTitle = (to?: any) => {
if (sItem.name.toLowerCase() == state.componentName.name) {
state.componentName.name = sItem.name;
state.componentName.cName = sItem.cName;
state.componentName.type = item.enName;
return;
}
});
});
};
onBeforeRouteUpdate((to) => {
componentTitle(to);
watchDemoUrl(to);
data.curKey = isTaro(to) ? 'taro' : 'vue';
componentTitle(to);
});
</script>

Expand All @@ -146,75 +129,6 @@ $doc-title-height: 137px;
min-height: 600px;
}
}
&-tabs {
position: absolute;
right: 475px;
top: 48px;
display: flex;
height: 40px;
align-items: center;
justify-content: space-between;
z-index: 1;
padding: 2px;
box-sizing: border-box;
border-radius: 2px;
background: #eee;
box-shadow: rgb(0 0 0 / 15%) 0px 2px 4px;
&.single {
padding: 0;
.tab-item {
line-height: 40px;
cursor: auto;
}
}
.tab-item {
position: relative;
padding: 0 10px;
line-height: 36px;
cursor: pointer;
font-size: 16px;
color: #323232;
text-align: center;
border-radius: 2px;
background: #eee;
&.cur {
font-weight: bold;
color: #323232;
background: #fff;
}
}
}
&-contributors {
margin: 50px 0;
a {
position: relative;
}
img {
height: 26px;
height: 26px;
border-radius: 50%;
margin-left: 8px;
}
.contributors-hover {
display: none;
padding: 5px 10px;
color: #fff;
font-size: 12px;
background-color: #000;
border-radius: 5px;
position: absolute;
/* min-width:150px; */
white-space: nowrap;
top: -200%;
transform: translateX(-55%);
}
a:hover {
.contributors-hover {
display: inline-block;
}
}
}
}
&-title {
width: 100%;
Expand Down
18 changes: 1 addition & 17 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,7 @@ import { markdown } from '@nutui/vite-plugins';
const resolve = path.resolve;
// https://vitejs.dev/config/
export default defineConfig({
base: '/h5/vue/4x/',
server: {
port: 2023,
host: '0.0.0.0',
proxy: {
'/devServer': {
target: 'https://nutui.jd.com',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/devServer/, '')
},
'/devTheme': {
target: 'https://nutui.jd.com/theme/source',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/devTheme/, '')
}
}
},
base: '/',
resolve: {
alias: [{ find: '@', replacement: resolve(__dirname, './src') }]
},
Expand Down

0 comments on commit 6c46d95

Please sign in to comment.