think.vue 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <template>
  2. <div v-if="content" class="think-process">
  3. <details class="think-details">
  4. <summary class="think-summary">深度思考</summary>
  5. <div class="think-content" v-html="parsedContent"></div>
  6. </details>
  7. </div>
  8. </template>
  9. <script setup lang="ts">
  10. import {computed, getCurrentInstance, onMounted, reactive, watch} from "vue";
  11. import { marked } from 'marked';
  12. import DOMPurify from 'dompurify';
  13. const props = defineProps({
  14. content: String
  15. });
  16. const state: any = reactive({
  17. })
  18. const parsedContent = computed(() => {
  19. if (!props.content) return '';
  20. return DOMPurify.sanitize(marked.parse(props.content));
  21. });
  22. </script>
  23. <style lang="scss" scoped>
  24. .think-process {
  25. margin: 1rem 0;
  26. border-left: 3px solid #e5e7eb;
  27. padding-left: 1rem;
  28. .think-details {
  29. background-color: #f9fafb;
  30. border-radius: 0.5rem;
  31. padding: 0.5rem 1rem;
  32. .think-summary {
  33. cursor: pointer;
  34. font-weight: 500;
  35. color: #4b5563;
  36. outline: none;
  37. }
  38. .think-content {
  39. margin-top: 0.5rem;
  40. padding: 0.5rem;
  41. color: #374151;
  42. white-space: pre-wrap;
  43. font-family: 'Menlo', 'Monaco', 'Consolas', monospace;
  44. font-size: 0.875rem;
  45. line-height: 1.5;
  46. }
  47. }
  48. }
  49. </style>