fix(site): fix single mode, click name and demo not jump (#1030)

This commit is contained in:
申君健 2023-12-05 15:26:16 +08:00 committed by GitHub
parent e1d3c542b3
commit 6cc3f35777
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 15 deletions

View File

@ -43,6 +43,7 @@ module.exports = {
'@typescript-eslint/brace-style': 'off',
'@typescript-eslint/restrict-plus-operands': 'off',
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/restrict-template-expressions': 'off'
'@typescript-eslint/restrict-template-expressions': 'off',
'@typescript-eslint/no-invalid-this': 'off'
}
}

View File

@ -142,7 +142,7 @@ import { defineComponent, reactive, computed, toRefs, watch, onMounted, ref } fr
import { marked } from 'marked'
import { Loading, Anchor, ButtonGroup } from '@opentiny/vue'
import debounce from '@opentiny/vue-renderless/common/deps/debounce'
import { $t, $t2, $clone, $split, fetchDemosFile, useApiMode, useTemplateMode } from '@/tools'
import { $t, $t2, $clone, fetchDemosFile, useApiMode, useTemplateMode } from '@/tools'
import demo from '@/views/components/demo'
import { router } from '@/router.js'
import { Collapse, CollapseItem } from '@opentiny/vue'
@ -334,30 +334,23 @@ export default defineComponent({
copyText: (text) => {
navigator.clipboard.writeText(text)
},
// api name
jumpToDemo: (demoId) => {
if (demoId.startsWith('chart') || demoId.startsWith('grid')) {
router.push(demoId)
} else {
router.push(`#${demoId}`)
}
},
handleApiClick: (ev) => {
if (ev.target.tagName === 'A') {
ev.preventDefault()
const href = ev.target.getAttribute('href')
const hash = $split(href, '#', -1)
router.push(href)
state.singleDemo = state.currJson.demos.find((d) => d.demoId === hash)
scrollByHash(hash)
}
if (apiModeState.demoMode === 'single') {
state.singleDemo = state.currJson.demos.find((d) => d.demoId === demoId)
}
}
},
// api type
handleTypeClick: (ev) => {
changeActiveNames(ev.target.hash, true)
},
//
handleAnchorClick: (e, data) => {
if (apiModeState.demoMode === 'single' && data.link.startsWith('#')) {
e.preventDefault()