-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add route link bar above the canvas * feat: route bar support switch route * add TODO * change css variables * fix: fix switch page error after create one * feat: support select router page on RouterLink * feat: RouterLink support navigate by right-click menu operation in canvas * feat: navigation operation place to first * feat: support setting default page * fix: hide route bar in block canvas * fix: hide route bar in block canvas * feat: add confirm modal before switch page * fix: remove TODO comment * fix: Modified based on review comments * fix some issues * fix wrong type of route id
- Loading branch information
Showing
13 changed files
with
488 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default as CanvasRouteBar } from './src/CanvasRouteBar.vue' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
<template> | ||
<div id="canvas-route-bar" :style="sizeStyle"> | ||
<div class="address-bar"> | ||
<template v-for="route in routes" :key="route.id"> | ||
<span class="slash">/</span> | ||
<span :class="[{ route: route.isPage && route.id !== pageId }]" @click="handleClickRoute(route)">{{ | ||
route.route | ||
}}</span> | ||
</template> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script setup> | ||
import { getMetaApi, META_SERVICE, useLayout, useMessage, usePage } from '@opentiny/tiny-engine-meta-register' | ||
import { computed, onMounted, onUnmounted, ref, watch } from 'vue' | ||
const sizeStyle = computed(() => { | ||
const { width } = useLayout().getDimension() | ||
return { width } | ||
}) | ||
const { pageSettingState, getAncestors, switchPageWithConfirm } = usePage() | ||
const pageId = ref(getMetaApi(META_SERVICE.GlobalService).getBaseInfo().pageId) | ||
const { subscribe, unsubscribe } = useMessage() | ||
let subscriber = null | ||
onMounted(() => { | ||
subscriber = subscribe({ | ||
topic: 'locationHistoryChanged', | ||
callback: (data) => { | ||
if (data.pageId) { | ||
pageId.value = data.pageId | ||
} | ||
}, | ||
subscriber: 'routeBar' | ||
}) | ||
}) | ||
onUnmounted(() => { | ||
if (subscriber) { | ||
unsubscribe(subscriber) | ||
} | ||
}) | ||
/** | ||
* @typedef {Object} Route | ||
* @property {string | number} id | ||
* @property {string} route | ||
* @property {boolean} isPage | ||
*/ | ||
/** @type {import('vue').Ref<Route[]>} */ | ||
const routes = ref([]) | ||
watch( | ||
pageId, | ||
async (value) => { | ||
if (!value) { | ||
routes.value = [] | ||
return | ||
} | ||
const ancestors = await getAncestors(value, true) | ||
routes.value = ancestors.concat(value).map((id) => { | ||
const { route, isPage } = pageSettingState.treeDataMapping[id] | ||
return { | ||
id, | ||
route: route | ||
.replace(/\/+/g, '/') // 替换连续的 '/' 为单个 '/' | ||
.replace(/^\/|\/$/g, ''), // 去掉开头和结尾的 '/' | ||
isPage | ||
} | ||
}) | ||
}, | ||
{ immediate: true } | ||
) | ||
/** | ||
* @param route {Route} | ||
*/ | ||
const handleClickRoute = (route) => { | ||
switchPageWithConfirm(route.id) | ||
} | ||
</script> | ||
|
||
<style lang="less" scoped> | ||
#canvas-route-bar { | ||
position: absolute; | ||
top: 18px; | ||
height: 32px; | ||
max-width: 100%; | ||
background-color: var(--te-common-bg-prompt); | ||
border-top-left-radius: 4px; | ||
border-top-right-radius: 4px; | ||
display: flex; | ||
align-items: center; | ||
padding: 0 8px; | ||
} | ||
.address-bar { | ||
display: flex; | ||
align-items: center; | ||
gap: 2px; | ||
background-color: var(--te-common-bg-container); | ||
height: 20px; | ||
width: 100%; | ||
border-radius: 999px; | ||
padding: 0 10px; | ||
cursor: default; | ||
} | ||
.route { | ||
cursor: pointer; | ||
&:hover { | ||
text-decoration: underline; | ||
color: var(--te-common-text-link); | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.