From a7380c6b52b94fcb7ef7d55774d745d79f500eab Mon Sep 17 00:00:00 2001 From: Sendya <18x@loacg.com> Date: Wed, 16 Dec 2020 18:51:06 +0800 Subject: [PATCH] refactor: route context --- examples/demoBox.less | 14 +++++ examples/demoBox.tsx | 64 +++++++++++++++++++ examples/index.tsx | 27 +++++---- examples/route-context.tsx | 23 +++---- examples/side-menu.tsx | 118 +++++++++++++++++++++--------------- src/RouteContext.tsx | 14 +++-- src/SiderMenu/BaseMenu.tsx | 7 +-- src/SiderMenu/SiderMenu.tsx | 4 +- src/hooks/context/index.ts | 29 +++++---- 9 files changed, 201 insertions(+), 99 deletions(-) create mode 100644 examples/demoBox.less create mode 100644 examples/demoBox.tsx diff --git a/examples/demoBox.less b/examples/demoBox.less new file mode 100644 index 00000000..4d4809df --- /dev/null +++ b/examples/demoBox.less @@ -0,0 +1,14 @@ +.browser-nav { + padding: 2px 6px; + background-color: #ebedf1; + + &::before { + content: ''; + display: inline-block; + width: 12px; + height: 12px; + border-radius: 50%; + background-color: #fd6458; + box-shadow: 20px 0 0 #ffbf2b, 40px 0 0 #24cc3d; + } +} diff --git a/examples/demoBox.tsx b/examples/demoBox.tsx new file mode 100644 index 00000000..80b75660 --- /dev/null +++ b/examples/demoBox.tsx @@ -0,0 +1,64 @@ +import { createApp, defineComponent, ref, h, onMounted } from 'vue'; +import { RouterLink } from './mock-router'; +import * as Icon from '@ant-design/icons-vue'; +import './demoBox.less'; + +export const DemoBox = defineComponent({ + setup(_, { slots }) { + const instance = ref(); + const frameRef = ref(); + + const content = (): void => { + const children = slots?.default(); + console.log('frameRef.value', frameRef.value); + const body = frameRef.value.contentDocument.body; + const head = frameRef.value.contentDocument.head; + const el = document.createElement('div'); + el.className = 'demoBox' + body.appendChild(el); + + // const styleLink = document.createElement('link'); + // styleLink.rel = 'stylesheet'; + // styleLink.type = 'text/css'; + // styleLink.href = './index.css'; + head.innerHTML = ` + + + ` + + const box = createApp({ + render() { + return children; + }, + }).use(RouterLink); + + const filterIcons = ['default', 'createFromIconfontCN', 'getTwoToneColor', 'setTwoToneColor']; + Object.keys(Icon) + .filter(k => !filterIcons.includes(k)) + .forEach(k => { + box.component(Icon[k].displayName, Icon[k]); + }); + + box.mount(el); + + instance.value = box; + } + + onMounted(() => { + content(); + }) + return { + frameRef, + content, + } + }, + render () { + return ( +
+
+
+