Skip to content

Commit

Permalink
perf: Add demo code docs
Browse files Browse the repository at this point in the history
  • Loading branch information
w940853815 committed Feb 11, 2025
1 parent c932fbb commit ee67828
Showing 1 changed file with 35 additions and 9 deletions.
44 changes: 35 additions & 9 deletions src/views/pam/Integration/SDKList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
<div class="code-container">
<el-tabs v-model="currentLanguage" @tab-click="handleInput">
<el-tab-pane v-for="language in languages" :key="language.value" :label="language.label" :name="language.value">
<template>
<vue-markdown v-if="readme" class="code-markdown" :source="readme" />
<span v-else>{{ $tc('NoData') }}</span>
</template>
<two-col>
<template>
<vue-markdown class="code-markdown" :source="readme" />
</template>
<template #right>
<vue-markdown class="code-demo" :source="code" />
</template>
</two-col>
</el-tab-pane>
</el-tabs>
<div class="copy-btn">
Expand All @@ -25,18 +29,20 @@
import { IBox } from '@/components'
import VueMarkdown from 'vue-markdown'
import { highlightBlock } from 'highlight.js'
import 'highlight.js/styles/github.css'
import TwoCol from '@/layout/components/Page/TwoColPage.vue'
export default {
name: 'SDKList',
components: {
TwoCol,
IBox,
VueMarkdown
},
data() {
return {
currentLanguage: 'python',
readme: '',
code: '',
languages: [
{ label: 'Python', value: 'python' },
{ label: 'Go', value: 'go' }
Expand All @@ -49,10 +55,10 @@ export default {
methods: {
async copyContent() {
try {
await navigator.clipboard.writeText(this.readme)
this.$message.success('复制成功')
await navigator.clipboard.writeText(this.code)
this.$message.success(this.$tc('CopySuccess'))
} catch (err) {
this.$message.error('复制失败')
this.$message.error(this.$tc('CopyFailed'))
}
},
highlightCode() {
Expand All @@ -67,6 +73,7 @@ export default {
const url = `/api/v1/accounts/integration-applications/sdks/?language=${this.currentLanguage}`
this.$axios.get(url).then(res => {
this.readme = res.readme
this.code = `\`\`\`${this.currentLanguage}\n${res.code}\n\`\`\``
this.$nextTick(() => {
this.highlightCode()
})
Expand All @@ -84,9 +91,28 @@ export default {
}
.code-markdown {
min-height: 210px;
padding: 10px 20px;
border: 1px solid #DCDFE6;
::v-deep .table {
border-collapse: collapse;
border-spacing: 0;
width: 100%;
th, td {
border: 1px solid #ebeef5;
padding: 10px;
text-align: left;
}
th {
background-color: #f5f7fa;
}
}
}
.code-demo{
@import "~highlight.js/styles/atom-one-light.css";
min-height: 210px;
padding: 10px 20px;
border: 1px solid #DCDFE6;
}
.copy-btn {
font-size: 20px;
position: absolute;
Expand Down

0 comments on commit ee67828

Please sign in to comment.