-
Notifications
You must be signed in to change notification settings - Fork 354
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: add canvas route bar #967
Merged
Merged
Changes from 17 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
891f807
feat: add route link bar above the canvas
gene9831 27e52ea
Merge branch 'feat/router-page' of github.com:opentiny/tiny-engine in…
gene9831 3f0af99
Merge branch 'feat/router-page' of github.com:opentiny/tiny-engine in…
gene9831 fcfbec9
feat: route bar support switch route
gene9831 7d64ee4
add TODO
gene9831 0364b46
change css variables
gene9831 0724c6e
fix: fix switch page error after create one
gene9831 9d9795c
feat: support select router page on RouterLink
gene9831 84548b5
feat: RouterLink support navigate by right-click menu operation in ca…
gene9831 4e11a87
feat: navigation operation place to first
gene9831 2576766
feat: support setting default page
gene9831 af19037
fix: hide route bar in block canvas
gene9831 854bb0a
fix: hide route bar in block canvas
gene9831 44e8245
feat: add confirm modal before switch page
gene9831 7d721e7
fix: remove TODO comment
gene9831 577ea7d
Merge branch 'feat/router-page' of github.com:opentiny/tiny-engine in…
gene9831 9561922
fix: Modified based on review comments
gene9831 4a4e25e
Merge branch 'feat/router-page' of github.com:opentiny/tiny-engine in…
gene9831 ff9937d
fix some issues
gene9831 d7d1c4f
fix wrong type of route id
gene9831 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,120 @@ | ||
<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) { | ||
return | ||
gene9831 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个会一直调用嘛? isBlock是个普通函数?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里
isBlock
是值,不是函数。修改成const isBlock = useCanvas().isBlock
,保存函数引用,避免computed