Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 打开外部页面(内嵌/外链) #226

Merged
merged 1 commit into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions src/pages/frame/doc/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<template>
<div :class="`${prefix}-iframe-page`" :style="getWrapStyle">
<t-loading :loading="loading" size="large" :style="getWrapStyle">
<iframe ref="frameRef" :src="frameSrc" :class="`${prefix}-iframe-page__main`" @load="hideLoading"></iframe>
</t-loading>
</div>
</template>
<script lang="ts">
import { prefix } from '@/config/global';
import STYLE_CONFIG from '@/config/style';

const computedStyle = getComputedStyle(document.documentElement);
const sizeXxxl = computedStyle.getPropertyValue('--td-comp-size-xxxl');
const paddingTBXxl = computedStyle.getPropertyValue('--td-comp-paddingTB-xxl');

export default {
name: 'DetailAdvanced',
data() {
return {
prefix,
loading: true,
frameSrc: 'https://tdesign.tencent.com/starter/docs/vue/get-started',
settingStore: { ...STYLE_CONFIG },
getWrapStyle: `height: ${window.innerHeight}px`,
};
},
mounted() {
window.addEventListener('resize', this.calcHeight, false);
this.$nextTick(() => {
this.calcHeight();
});
},
methods: {
hideLoading() {
this.loading = false;
this.calcHeight();
},

getOuterHeight(dom: Element) {
let height = dom.clientHeight;
const computedStyle = window.getComputedStyle(dom);
height += parseInt(computedStyle.marginTop, 10);
height += parseInt(computedStyle.marginBottom, 10);
height += parseInt(computedStyle.borderTopWidth, 10);
height += parseInt(computedStyle.borderBottomWidth, 10);
return height;
},

calcHeight() {
const iframe = this.$refs.frameRef;
if (!iframe) {
return;
}
let clientHeight = 0;
const { showFooter, isUseTabsRouter, showBreadcrumb } = this.settingStore;
const headerHeight = parseFloat(sizeXxxl);
const navDom = document.querySelector('.t-tabs__nav');
const navHeight = isUseTabsRouter ? this.getOuterHeight(navDom) : 0;
const breadcrumbDom = document.querySelector('.t-breadcrumb');
const breadcrumbHeight = showBreadcrumb ? this.getOuterHeight(breadcrumbDom) : 0;
const contentPadding = parseFloat(paddingTBXxl) * 2;
const footerDom = document.querySelector('.t-layout__footer');
const footerHeight = showFooter ? this.getOuterHeight(footerDom) : 0;
const top = headerHeight + navHeight + breadcrumbHeight + contentPadding + footerHeight + 2;
window.innerHeight -= top;
clientHeight = document.documentElement.clientHeight - top;
iframe.style.height = `${clientHeight}px`;
this.getWrapStyle = `height: ${window.innerHeight}px`;
},
},
};
</script>
<style lang="less" scoped>
@import '@/style/variables';

.@{starter-prefix}-iframe-page {
&__main {
width: 100%;
height: 100%;
overflow: hidden;
background-color: #fff;
border: 0;
box-sizing: border-box;
}
}
</style>
86 changes: 86 additions & 0 deletions src/pages/frame/tdesign/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<template>
<div :class="`${prefix}-iframe-page`" :style="getWrapStyle">
<t-loading :loading="loading" size="large" :style="getWrapStyle">
<iframe ref="frameRef" :src="frameSrc" :class="`${prefix}-iframe-page__main`" @load="hideLoading"></iframe>
</t-loading>
</div>
</template>
<script lang="ts">
import { prefix } from '@/config/global';
import STYLE_CONFIG from '@/config/style';

const computedStyle = getComputedStyle(document.documentElement);
const sizeXxxl = computedStyle.getPropertyValue('--td-comp-size-xxxl');
const paddingTBXxl = computedStyle.getPropertyValue('--td-comp-paddingTB-xxl');

export default {
name: 'DetailAdvanced',
data() {
return {
prefix,
loading: true,
frameSrc: 'https://tdesign.tencent.com/vue-next/getting-started',
settingStore: { ...STYLE_CONFIG },
getWrapStyle: `height: ${window.innerHeight}px`,
};
},
mounted() {
window.addEventListener('resize', this.calcHeight, false);
this.$nextTick(() => {
this.calcHeight();
});
},
methods: {
hideLoading() {
this.loading = false;
this.calcHeight();
},

getOuterHeight(dom: Element) {
let height = dom.clientHeight;
const computedStyle = window.getComputedStyle(dom);
height += parseInt(computedStyle.marginTop, 10);
height += parseInt(computedStyle.marginBottom, 10);
height += parseInt(computedStyle.borderTopWidth, 10);
height += parseInt(computedStyle.borderBottomWidth, 10);
return height;
},

calcHeight() {
const iframe = this.$refs.frameRef;
if (!iframe) {
return;
}
let clientHeight = 0;
const { showFooter, isUseTabsRouter, showBreadcrumb } = this.settingStore;
const headerHeight = parseFloat(sizeXxxl);
const navDom = document.querySelector('.t-tabs__nav');
const navHeight = isUseTabsRouter ? this.getOuterHeight(navDom) : 0;
const breadcrumbDom = document.querySelector('.t-breadcrumb');
const breadcrumbHeight = showBreadcrumb ? this.getOuterHeight(breadcrumbDom) : 0;
const contentPadding = parseFloat(paddingTBXxl) * 2;
const footerDom = document.querySelector('.t-layout__footer');
const footerHeight = showFooter ? this.getOuterHeight(footerDom) : 0;
const top = headerHeight + navHeight + breadcrumbHeight + contentPadding + footerHeight + 2;
window.innerHeight -= top;
clientHeight = document.documentElement.clientHeight - top;
iframe.style.height = `${clientHeight}px`;
this.getWrapStyle = `height: ${window.innerHeight}px`;
},
},
};
</script>
<style lang="less" scoped>
@import '@/style/variables';

.@{starter-prefix}-iframe-page {
&__main {
width: 100%;
height: 100%;
overflow: hidden;
background-color: #fff;
border: 0;
box-sizing: border-box;
}
}
</style>
26 changes: 26 additions & 0 deletions src/router/modules/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,32 @@ export default [
},
],
},
{
path: '/frame',
name: 'frame',
component: Layout,
redirect: '/frame/doc',
meta: { title: '外部页面', icon: 'internet' },
children: [
{
path: 'doc',
name: 'Doc',
component: () => import('@/pages/frame/doc/index.vue'),
meta: { title: '使用文档(内嵌)' },
},
{
path: 'TDesign',
name: 'TDesign',
component: () => import('@/pages/frame/tdesign/index.vue'),
meta: { title: 'TDesign 文档(内嵌)' },
},
{
path: 'https://tdesign.tencent.com/vue-next/getting-started',
name: 'TDesign2',
meta: { title: 'TDesign 文档(外链)' },
},
],
},
{
path: '/result',
name: 'result',
Expand Down