answerPoint.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { getAnswerPointImg } from "../utils";
  2. /**
  3. * 和clipboard.js部分内容相同,注意同步修改
  4. *
  5. * @this {Object} VEditor 因为VEditor会带很多选项,所以绑定this传过来
  6. */
  7. export async function answerPointHandle() {
  8. this.$refs.editor.focus();
  9. // let sel, range;
  10. // if (window.getSelection) {
  11. // sel = window.getSelection();
  12. // }
  13. const node = document.createElement("img");
  14. node.src = getAnswerPointImg("X");
  15. node.dataset.isAnswerPoint = true;
  16. node.dataset.isAnswerPointX = true;
  17. node.dataset.order = 0;
  18. document.execCommand("insertHTML", false, node.outerHTML);
  19. }
  20. /**
  21. * 答题点拖动后更新,通过判断是否有 [data-is-answer-point-x] 来判断是否是拖动
  22. * 因为drag会触发两次input,第一次事件是删除,要忽略第一次事件
  23. *
  24. * @this {Object} VEditor 因为VEditor会带很多选项,所以绑定this传过来
  25. */
  26. export async function answerPointRebuild() {
  27. const answerPoints = this.$refs.editor.querySelectorAll(
  28. "[data-is-answer-point]"
  29. );
  30. [...answerPoints].forEach((answerPoint, index) => {
  31. answerPoint.dataset.order = index + 1;
  32. answerPoint.src = getAnswerPointImg(index + 1);
  33. });
  34. }