2019-09-17 19:24:39 +08:00
|
|
|
<template>
|
2019-12-22 23:19:08 +08:00
|
|
|
<n-card
|
2020-03-04 03:01:15 +08:00
|
|
|
v-if="isShow"
|
2019-12-22 23:19:08 +08:00
|
|
|
class="demo-card"
|
|
|
|
:segmented="{
|
|
|
|
footer: true
|
2019-09-17 19:24:39 +08:00
|
|
|
}"
|
2019-12-22 23:19:08 +08:00
|
|
|
:content-style="contentStyle"
|
2019-09-17 19:24:39 +08:00
|
|
|
>
|
2019-12-22 23:19:08 +08:00
|
|
|
<template v-slot:header>
|
2019-11-17 00:57:30 +08:00
|
|
|
<slot name="title" />
|
2019-12-22 23:19:08 +08:00
|
|
|
</template>
|
2020-03-09 17:18:01 +08:00
|
|
|
|
2019-12-22 23:19:08 +08:00
|
|
|
<template v-slot:header-extra>
|
2020-05-31 11:56:00 +08:00
|
|
|
<n-tooltip
|
2020-09-19 16:48:23 +08:00
|
|
|
trigger="hover"
|
2020-05-31 11:56:00 +08:00
|
|
|
:placement="'top'"
|
|
|
|
:show-arrow="true"
|
|
|
|
>
|
|
|
|
<template v-slot:activator>
|
|
|
|
<edit-on-github-button
|
|
|
|
style="padding: 0; margin-right: 6px;"
|
|
|
|
size="tiny"
|
2020-09-04 01:06:39 +08:00
|
|
|
:relative-url="relativeUrl"
|
2020-05-31 11:56:00 +08:00
|
|
|
/>
|
|
|
|
</template>
|
2020-10-08 04:14:14 +08:00
|
|
|
{{ t('editOnGithub') }}
|
2020-05-31 11:56:00 +08:00
|
|
|
</n-tooltip>
|
|
|
|
<n-tooltip
|
2020-09-10 15:55:31 +08:00
|
|
|
ref="expandCodeButton"
|
2020-09-19 16:48:23 +08:00
|
|
|
trigger="hover"
|
2020-05-31 11:56:00 +08:00
|
|
|
:placement="'top'"
|
|
|
|
:show-arrow="true"
|
|
|
|
>
|
|
|
|
<template v-slot:activator>
|
|
|
|
<n-button
|
|
|
|
style="padding: 0;"
|
|
|
|
size="tiny"
|
|
|
|
text
|
|
|
|
icon-depth="tertiary"
|
|
|
|
@click="toggleCodeDisplay"
|
|
|
|
>
|
|
|
|
<template v-slot:icon>
|
|
|
|
<code-outline />
|
|
|
|
</template>
|
|
|
|
</n-button>
|
|
|
|
</template>
|
2020-10-08 04:14:14 +08:00
|
|
|
{{ !showCode ? t('show') : t('hide') }}
|
2020-05-31 11:56:00 +08:00
|
|
|
</n-tooltip>
|
2019-12-22 23:19:08 +08:00
|
|
|
</template>
|
|
|
|
<slot name="content" />
|
2020-01-05 15:20:35 +08:00
|
|
|
<slot name="demo" />
|
2019-12-23 22:18:04 +08:00
|
|
|
<template v-if="showCode" v-slot:footer>
|
2019-09-27 15:56:33 +08:00
|
|
|
<n-scrollbar>
|
|
|
|
<slot name="code" />
|
|
|
|
</n-scrollbar>
|
2019-12-22 23:19:08 +08:00
|
|
|
</template>
|
|
|
|
</n-card>
|
2019-09-17 19:24:39 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2020-09-10 15:55:31 +08:00
|
|
|
import { nextTick } from 'vue'
|
2020-10-26 15:03:02 +08:00
|
|
|
import codeOutline from 'naive-ui/lib/icons/code-outline.vue'
|
2020-10-08 04:14:14 +08:00
|
|
|
import { displayModeRef, i18n } from '../util-compositions'
|
2019-09-17 19:24:39 +08:00
|
|
|
|
|
|
|
export default {
|
2019-10-24 18:04:31 +08:00
|
|
|
components: {
|
2020-03-19 13:26:06 +08:00
|
|
|
codeOutline
|
2019-10-24 18:04:31 +08:00
|
|
|
},
|
2020-09-03 23:02:40 +08:00
|
|
|
props: {
|
|
|
|
title: {
|
|
|
|
type: String,
|
|
|
|
required: true
|
|
|
|
},
|
|
|
|
demoFileName: {
|
|
|
|
type: String,
|
|
|
|
required: true
|
2020-09-03 23:40:38 +08:00
|
|
|
},
|
2020-09-04 01:06:39 +08:00
|
|
|
relativeUrl: {
|
2020-09-03 23:40:38 +08:00
|
|
|
type: String,
|
|
|
|
required: true
|
2020-09-03 23:02:40 +08:00
|
|
|
}
|
|
|
|
},
|
2019-10-14 17:49:23 +08:00
|
|
|
inject: {
|
|
|
|
NDocumentation: {
|
|
|
|
default: null
|
|
|
|
}
|
|
|
|
},
|
2020-09-27 22:27:25 +08:00
|
|
|
setup () {
|
|
|
|
return {
|
2020-10-08 04:14:14 +08:00
|
|
|
displayMode: displayModeRef,
|
|
|
|
...(i18n({
|
|
|
|
'zh-CN': {
|
|
|
|
'show': '显示代码',
|
|
|
|
'hide': '收起代码',
|
|
|
|
'editOnGithub': '在 Github 上编辑'
|
|
|
|
},
|
|
|
|
'en-US': {
|
|
|
|
'show': 'Show Code',
|
|
|
|
'hide': 'Hide Code',
|
|
|
|
'editOnGithub': 'Edit on Github'
|
|
|
|
}
|
|
|
|
}))
|
2020-09-27 22:27:25 +08:00
|
|
|
}
|
|
|
|
},
|
2019-09-17 19:24:39 +08:00
|
|
|
data () {
|
|
|
|
return {
|
2019-09-20 00:22:55 +08:00
|
|
|
showCode: false,
|
2019-12-22 23:19:08 +08:00
|
|
|
contentStyle: null,
|
2020-03-04 03:01:15 +08:00
|
|
|
isShow: true,
|
2020-09-27 22:27:25 +08:00
|
|
|
isDebugDemo: false
|
2019-09-17 19:24:39 +08:00
|
|
|
}
|
|
|
|
},
|
2019-09-20 00:22:55 +08:00
|
|
|
watch: {
|
2019-09-29 19:07:16 +08:00
|
|
|
showCode () {
|
2019-12-22 23:19:08 +08:00
|
|
|
this.contentStyle = {
|
|
|
|
transition: 'none'
|
|
|
|
}
|
2020-09-10 15:55:31 +08:00
|
|
|
nextTick(() => {
|
|
|
|
this.$refs.expandCodeButton.syncPosition()
|
2019-12-22 23:19:08 +08:00
|
|
|
this.contentStyle = null
|
2019-09-29 19:07:16 +08:00
|
|
|
})
|
2020-03-04 03:01:15 +08:00
|
|
|
},
|
2020-09-27 22:27:25 +08:00
|
|
|
displayMode () {
|
2020-03-04 03:01:15 +08:00
|
|
|
this.init()
|
2019-09-20 00:22:55 +08:00
|
|
|
}
|
|
|
|
},
|
2020-09-03 23:02:40 +08:00
|
|
|
created () {
|
2020-03-04 03:01:15 +08:00
|
|
|
this.init()
|
2019-09-20 00:22:55 +08:00
|
|
|
},
|
2019-09-17 19:24:39 +08:00
|
|
|
methods: {
|
2019-09-20 00:22:55 +08:00
|
|
|
toggleCodeDisplay () {
|
2019-09-17 19:24:39 +08:00
|
|
|
this.showCode = !this.showCode
|
2020-03-04 03:01:15 +08:00
|
|
|
},
|
|
|
|
init () {
|
|
|
|
const map = this.NDocumentation.anchorLinkMap
|
2020-09-03 23:02:40 +08:00
|
|
|
this.isDebugDemo = this.demoFileName && (~this.demoFileName.indexOf('debug') || ~this.demoFileName.indexOf('Debug'))
|
2020-09-03 17:02:31 +08:00
|
|
|
if (this.isDebugDemo) {
|
2020-09-27 22:27:25 +08:00
|
|
|
if (this.displayMode === 'debug') {
|
2020-03-04 03:01:15 +08:00
|
|
|
this.isShow = true
|
2020-09-03 23:02:40 +08:00
|
|
|
map.set(this.demoFileName, this.title)
|
2020-03-04 03:01:15 +08:00
|
|
|
} else {
|
|
|
|
this.isShow = false
|
2020-09-03 23:02:40 +08:00
|
|
|
map.delete(this.demoFileName)
|
2020-03-04 03:01:15 +08:00
|
|
|
}
|
|
|
|
} else {
|
2020-09-03 23:02:40 +08:00
|
|
|
map.set(this.demoFileName, this.title)
|
2020-03-04 03:01:15 +08:00
|
|
|
}
|
2020-09-03 23:02:40 +08:00
|
|
|
this.NDocumentation.anchorLinkMap = new Map(map)
|
2019-09-17 19:24:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|