index.ts 4.3 KB

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