DialogCode.vue 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <template>
  2. <div :class="container_klass">
  3. <p class="dialog-code-footer-title">{{ cd_title }}:</p>
  4. <div v-html="code" class="dialog-code-content"></div>
  5. </div>
  6. </template>
  7. <script setup>
  8. import { onMounted, computed } from 'vue';
  9. // import { applyHighLight } from '../conversation-dialog/format-code-string';
  10. /**
  11. * 此组件展示对话中的代码
  12. * 例如python代码、SQL代码
  13. */
  14. const props = defineProps({
  15. type: String, // 代码类型:python/sql
  16. code: String, // 代码内容
  17. index: Number // 对应了序号
  18. });
  19. /**
  20. * 容器class
  21. */
  22. const container_klass = computed(() => {
  23. return `code-display-${props.type}-${props.index}`;
  24. });
  25. /**
  26. * 代码类型展示
  27. */
  28. const cd_title = computed(() => {
  29. if (props.type === 'python') {
  30. return 'Python';
  31. }
  32. if (props.type === 'sql') {
  33. return 'SQL';
  34. }
  35. return '';
  36. });
  37. onMounted(() => {
  38. // applyHighLight(`.${container_klass.value}`);
  39. });
  40. </script>
  41. <style scoped>
  42. .dialog-code-footer {
  43. border-radius: 12px;
  44. font-size: 14px;
  45. background-color: #32333c;
  46. color: #bcbdc3;
  47. margin: 16px 0;
  48. margin-left: 50px;
  49. }
  50. .dialog-code-footer-title {
  51. font-size: 16px;
  52. font-weight: 500;
  53. width: 100%;
  54. color: #3d3f3f;
  55. }
  56. .dialog-code-content {
  57. margin-top: 5px;
  58. margin-bottom: 5px;
  59. }
  60. </style>