mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
feat(cli): support custom simulator (#8499)
This commit is contained in:
parent
3ddfe3bbb4
commit
16ff1ba9a7
@ -15,6 +15,7 @@
|
||||
- [site.baiduAnalytics](#sitebaiduanalytics)
|
||||
- [site.searchConfig](#sitesearchconfig)
|
||||
- [site.hideSimulator](#sitehidesimulator)
|
||||
- [site.simulator.url](#sitesimulatorurl)
|
||||
- [Webpack](#webpack)
|
||||
- [Babel](#babel)
|
||||
- [默认配置](#-1)
|
||||
@ -245,6 +246,13 @@ module.exports = {
|
||||
|
||||
是否隐藏所有页面右侧的手机模拟器,默认不隐藏
|
||||
|
||||
### site.simulator.url
|
||||
|
||||
- Type: `string`
|
||||
- Default: -
|
||||
|
||||
自定义手机模拟器的 iframe URL 地址。
|
||||
|
||||
### site.htmlPluginOptions
|
||||
|
||||
- Type: `object`
|
||||
|
@ -2,6 +2,8 @@
|
||||
* 同步父窗口和 iframe 的 vue-router 状态
|
||||
*/
|
||||
|
||||
import { config } from 'site-desktop-shared';
|
||||
|
||||
let queue = [];
|
||||
let isIframeReady = false;
|
||||
|
||||
@ -27,7 +29,12 @@ if (window.top === window) {
|
||||
|
||||
function getCurrentDir() {
|
||||
const router = window.vueRouter;
|
||||
return router.currentRoute.value.path;
|
||||
const { path } = router.currentRoute.value;
|
||||
|
||||
if (config.site.simulator?.routeMapper) {
|
||||
return config.site.simulator?.routeMapper(path);
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
export function syncPathToParent() {
|
||||
|
@ -25,15 +25,20 @@ export default {
|
||||
},
|
||||
|
||||
data() {
|
||||
const path = location.pathname.replace(/\/index(\.html)?/, '/');
|
||||
|
||||
return {
|
||||
simulator: `${path}mobile.html${location.hash}`,
|
||||
hasSimulator: true,
|
||||
};
|
||||
},
|
||||
|
||||
computed: {
|
||||
simulator() {
|
||||
if (config.site.simulator?.url) {
|
||||
return config.site.simulator?.url;
|
||||
}
|
||||
const path = location.pathname.replace(/\/index(\.html)?/, '/');
|
||||
return `${path}mobile.html${location.hash}`;
|
||||
},
|
||||
|
||||
lang() {
|
||||
const { lang } = this.$route.meta;
|
||||
return lang || '';
|
||||
|
@ -214,7 +214,7 @@ export default {
|
||||
position: absolute;
|
||||
top: 34px;
|
||||
left: 0;
|
||||
width: 100px;
|
||||
width: 100%;
|
||||
z-index: 99;
|
||||
color: #333;
|
||||
line-height: 36px;
|
||||
|
@ -120,6 +120,8 @@ router.afterEach(() => {
|
||||
nextTick(syncPathToChild);
|
||||
});
|
||||
|
||||
listenToSyncPath(router);
|
||||
if (config.site.simulator?.syncPathFromSimulator !== false) {
|
||||
listenToSyncPath(router);
|
||||
}
|
||||
|
||||
window.vueRouter = router;
|
||||
|
@ -16,9 +16,8 @@ module.exports = {
|
||||
site: {
|
||||
defaultLang: 'en-US',
|
||||
versions: [
|
||||
{ label: 'Vant v1', link: '/vant/v1/' },
|
||||
{ label: 'Vant v2', link: '/vant/' },
|
||||
{ label: 'Vant Weapp', link: '/vant-weapp/' },
|
||||
{ label: 'v1', link: '/vant/v1/' },
|
||||
{ label: 'v2', link: '/vant/' },
|
||||
],
|
||||
baiduAnalytics: {
|
||||
seed: 'ad6b5732c36321f2dafed737ac2da92f',
|
||||
@ -31,10 +30,14 @@ module.exports = {
|
||||
locales: {
|
||||
'zh-CN': {
|
||||
title: 'Vant',
|
||||
description: '轻量、可靠的移动端 Vue 组件库',
|
||||
description: '轻量、可靠的移动端组件库',
|
||||
logo: 'https://img.yzcdn.cn/vant/logo.png',
|
||||
langLabel: '中',
|
||||
links: [
|
||||
{
|
||||
logo: 'https://b.yzcdn.cn/vant/logo/weapp.svg',
|
||||
url: 'https://vant-contrib.gitee.io/vant-weapp/',
|
||||
},
|
||||
{
|
||||
logo: 'https://b.yzcdn.cn/vant/logo/github.svg',
|
||||
url: 'https://github.com/youzan/vant',
|
||||
|
Loading…
x
Reference in New Issue
Block a user