index.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import type { Theme, Router } from 'vitepress'
  2. import DefaultTheme from 'vitepress/theme'
  3. import Layout from './Layout.vue'
  4. import './index.css';
  5. // about Naive UI
  6. import { App, defineComponent, h, inject, onMounted, watch, nextTick } from 'vue'
  7. import { setup } from '@css-render/vue3-ssr'
  8. import { NConfigProvider } from 'naive-ui'
  9. import { useRoute } from 'vitepress'
  10. // SDK
  11. // import CasdoorPlugin, { SdkConfig } from './sdk/casdoor'
  12. import casdoor from 'casdoor-vue-sdk'
  13. import {
  14. ServerUrl,
  15. ClientId,
  16. AppName,
  17. OrganizationName,
  18. RedirectPath
  19. } from '../plugins/casdoor/config'
  20. // Component
  21. import SseListener from './components/SseListener.vue'
  22. import Waline from './components/Waline.vue'
  23. import CasdoorCallback from './components/CasdoorCallback.vue'
  24. import ParameterTable from './components/ParameterTable.vue'
  25. import SimpleTable from './components/SimpleTable.vue'
  26. import NormalTable from './components/NormalTable.vue'
  27. import PdfViewer from './components/PdfViewer.vue'
  28. import SecurePdfViewer from './components/SecurePdfViewer.vue'
  29. import FilterComponent from './components/FilterComponent.vue'
  30. import ExcalidrawView from './components/ExcalidrawView.vue';
  31. const CssRenderStyle = defineComponent({
  32. setup() {
  33. const collect = inject<() => string>('css-render-collect')
  34. return {
  35. style: collect ? collect() : ''
  36. }
  37. },
  38. render() {
  39. return h('css-render-style', {
  40. innerHTML: this.style
  41. })
  42. }
  43. })
  44. const VitepressPath = defineComponent({
  45. setup() {
  46. const route = useRoute()
  47. return () => {
  48. return h('vitepress-path', null, [route.path])
  49. }
  50. }
  51. })
  52. const NaiveUIProvider = defineComponent({
  53. render() {
  54. return h(
  55. NConfigProvider,
  56. { abstract: true, inlineThemeDisabled: true },
  57. {
  58. default: () => [
  59. h(SseListener), // <-- SSE 监听组件
  60. h(Layout, null, { default: this.$slots.default?.() }),
  61. import.meta.env.SSR ? [h(CssRenderStyle), h(VitepressPath)] : null
  62. ]
  63. }
  64. )
  65. }
  66. })
  67. import mediumZoom from 'medium-zoom'
  68. // import type { Zoom } from 'medium-zoom'
  69. // let zoomInstance : Zoom | undefined = undefined
  70. function pictureZoom() {
  71. const route = useRoute();
  72. const initZoom = () => {
  73. // mediumZoom('[data-zoomable]', { background: 'var(--vp-c-bg)' }); // 默认
  74. // mediumZoom('.main img', { background: 'var(--vp-c-bg)' }); // 不显式添加{data-zoomable}的情况下为所有图像启用此功能
  75. // 除a标签以下的所有图像都进行缩放
  76. // mediumZoom(':not(a) > img:not(.VPImage)', { background: 'var(--vp-c-bg)' }); // 不显式添加{data-zoomable}的情况下为所有图像启用此功能
  77. mediumZoom('.VPDoc img', { background: 'var(--vp-c-bg)' });
  78. };
  79. onMounted(() => {
  80. initZoom();
  81. });
  82. watch(
  83. () => route.path,
  84. () => nextTick(() => initZoom())
  85. );
  86. }
  87. /** @type {import('vitepress').Theme} */
  88. export default {
  89. Layout: NaiveUIProvider,
  90. enhanceApp({ app }: { app: App }) {
  91. if (import.meta.env.SSR) {
  92. const { collect } = setup(app)
  93. app.provide('css-render-collect', collect)
  94. }
  95. app.use(casdoor, {
  96. serverUrl: ServerUrl,
  97. clientId: ClientId,
  98. appName: AppName,
  99. organizationName: OrganizationName,
  100. redirectPath: RedirectPath
  101. })
  102. // 注册自定义全局组件
  103. // app.component('...', ...)
  104. app.component('SseListener', SseListener) // 全局监听SSE
  105. app.component('Waline', Waline) // 评率组件
  106. app.component('CasdoorCallback', CasdoorCallback)
  107. app.component('ParameterTable', ParameterTable)
  108. app.component('SimpleTable', SimpleTable)
  109. app.component('NormalTable', NormalTable)
  110. app.component('PdfViewer', PdfViewer)
  111. app.component('SecurePdfViewer', SecurePdfViewer)
  112. app.component('FilterComponent', FilterComponent)
  113. app.component('ExcalidrawView', ExcalidrawView)
  114. },
  115. setup() {
  116. pictureZoom()
  117. },
  118. extends: DefaultTheme
  119. } satisfies Theme