-
Notifications
You must be signed in to change notification settings - Fork 272
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(docs): the official website adds API anchor function #2366
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,7 +130,7 @@ | |
</template> | ||
</div> | ||
</tiny-tab-item> | ||
<tiny-tab-item v-if="showApiTab && !isRunningTest" title="API" name="api"> | ||
<tiny-tab-item v-if="showApiTab && !isRunningTest && currJson.apis?.length" title="API" name="api"> | ||
<!-- api文档 --> | ||
<div id="API" class="all-api-container"> | ||
<div class="ti-f-c ti-f-wrap api-list"> | ||
|
@@ -248,6 +248,7 @@ | |
|
||
<script lang="jsx"> | ||
import { defineComponent, reactive, computed, toRefs, watch, onMounted, ref, onUnmounted, nextTick } from 'vue' | ||
import { useRoute } from 'vue-router' | ||
import { marked } from 'marked' | ||
import hljs from 'highlight.js' | ||
import { Anchor, ButtonGroup, Grid, GridColumn, Tabs, TabItem, Tooltip } from '@opentiny/vue' | ||
|
@@ -279,6 +280,8 @@ export default defineComponent({ | |
const isRunningTest = localStorage.getItem('tiny-e2e-test') === 'true' | ||
const anchorRefreshKey = ref(0) | ||
const apiTableRef = ref() | ||
const route = useRoute() | ||
|
||
const state = reactive({ | ||
webDocPath: computed(() => ''), | ||
langKey: getWord('zh-CN', 'en-US'), | ||
|
@@ -310,7 +313,7 @@ export default defineComponent({ | |
currAnchorLinks: computed(() => (state.activeTab === 'demos' ? state.demoAnchorLinks : state.apiAnchorLinks)), | ||
// 单demo显示时 | ||
singleDemo: null, | ||
activeTab: 'demos', | ||
activeTab: route.hash === '#api' ? 'api' : 'demos', | ||
tableData: {}, | ||
currApiTypes: [], | ||
showApiTab: computed(() => state.currApiTypes.length), | ||
|
@@ -616,7 +619,8 @@ export default defineComponent({ | |
copyText: (text) => { | ||
navigator.clipboard.writeText(text) | ||
}, | ||
onTabsClick: () => { | ||
onTabsClick: (data) => { | ||
router.push(`#${data.name}`) | ||
scrollToLayoutTop() | ||
}, | ||
// 点击 api区域的 name列时 | ||
|
@@ -676,6 +680,8 @@ export default defineComponent({ | |
state.currJson = {} | ||
} else { | ||
loadPage() | ||
// 切换组件时tabs激活页变成demos | ||
state.activeTab = 'demos' | ||
Comment on lines
+683
to
+684
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider preserving the active tab based on URL hash. When switching components, the code always resets to the 'demos' tab. This might not be the desired behavior when users navigate via API anchor links or switch components while viewing API documentation. Consider this implementation: -state.activeTab = 'demos'
+state.activeTab = route.hash === '#api' ? 'api' : 'demos'
|
||
// 每次切换组件都需要让锚点组件重新刷新 | ||
anchorRefreshKey.value++ | ||
} | ||
|
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.
🛠️ Refactor suggestion
Consider conditional scroll behavior for tab switching.
The current implementation always scrolls to the top when switching tabs. This might not be the desired behavior when switching to the API tab, as users might want to maintain their scroll position.
Consider updating the implementation to only scroll when necessary:
📝 Committable suggestion