audio.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. // import { saveBlobToDisk } from "@/utils/fileUtils";
  2. import { audioToImageNode } from "../utils";
  3. /**
  4. * 对粘贴事件进行处理:
  5. * 1. text类型直接粘贴
  6. * 2. 文件类型,判断图片
  7. *
  8. * @this {Object} VEditor 因为VEditor会带很多选项,所以绑定this传过来
  9. * @param {Event} event
  10. */
  11. export async function audioHandle(event) {
  12. this.$refs.editor.focus();
  13. /** @type {File} */
  14. const file = event.target.files[0];
  15. event.target.value = "";
  16. if (file.size > this.maxAudioSize) {
  17. this.$message(
  18. `音频大小超过限制!最大不超过 ${
  19. this.$parent.maxAudioSize / 1024 / 1024
  20. } MB.`
  21. );
  22. return;
  23. }
  24. // console.log(this.$parent.folder, this.$parent.$refs.editor);
  25. // TODO:上传音频文件
  26. // const relativeFilePath = await saveBlobToDisk(this.folder, file, "mp3");
  27. const relativeFilePath = "";
  28. const imageNode = await audioToImageNode(relativeFilePath);
  29. // console.log({ relativeFilePath, imageNode });
  30. // console.log(imageNode.outerHTML);
  31. document.execCommand("insertHTML", false, imageNode.outerHTML);
  32. this.$emit("audio-added");
  33. }