index.vue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <template>
  2. <div class="remark">
  3. <div
  4. class="resize-handler"
  5. @mousedown="$event => resize($event)"
  6. ></div>
  7. <Editor
  8. :value="remark"
  9. ref="editorRef"
  10. @update="value => handleInput(value)"
  11. />
  12. </div>
  13. </template>
  14. <script lang="ts" setup>
  15. import { computed, nextTick, useTemplateRef, watch } from 'vue'
  16. import { storeToRefs } from 'pinia'
  17. import { useSlidesStore } from '@/store'
  18. import Editor from './Editor.vue'
  19. const props = defineProps<{
  20. height: number
  21. }>()
  22. const emit = defineEmits<{
  23. (event: 'update:height', payload: number): void
  24. }>()
  25. const slidesStore = useSlidesStore()
  26. const { currentSlide } = storeToRefs(slidesStore)
  27. const editorRef = useTemplateRef<InstanceType<typeof Editor>>('editorRef')
  28. watch(() => currentSlide.value.id, () => {
  29. nextTick(() => {
  30. editorRef.value!.updateTextContent()
  31. })
  32. }, {
  33. immediate: true,
  34. })
  35. const remark = computed(() => currentSlide.value?.remark || '')
  36. const handleInput = (content: string) => {
  37. slidesStore.updateSlide({ remark: content })
  38. }
  39. const resize = (e: MouseEvent) => {
  40. let isMouseDown = true
  41. const startPageY = e.pageY
  42. const originHeight = props.height
  43. document.onmousemove = e => {
  44. if (!isMouseDown) return
  45. const currentPageY = e.pageY
  46. const moveY = currentPageY - startPageY
  47. let newHeight = -moveY + originHeight
  48. if (newHeight < 40) newHeight = 40
  49. if (newHeight > 360) newHeight = 360
  50. emit('update:height', newHeight)
  51. }
  52. document.onmouseup = () => {
  53. isMouseDown = false
  54. document.onmousemove = null
  55. document.onmouseup = null
  56. }
  57. }
  58. </script>
  59. <style lang="scss" scoped>
  60. .remark {
  61. position: relative;
  62. border-top: 1px solid $borderColor;
  63. }
  64. .resize-handler {
  65. height: 7px;
  66. position: absolute;
  67. top: -3px;
  68. left: 0;
  69. right: 0;
  70. cursor: n-resize;
  71. z-index: 2;
  72. }
  73. </style>