{"size": 1102, "ext": "js", "max_stars_repo_path": "src/components/contextMenu.js", "max_stars_repo_name": "rktccn/RoPlay-music-vue3", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/components/contextMenu.js", "max_issues_repo_name": "rktccn/RoPlay-music-vue3", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/components/contextMenu.js", "max_forks_repo_name": "rktccn/RoPlay-music-vue3", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 21.6078431373, "max_line_length": 66, "alphanum_fraction": 0.6506352087}
import contextMenu from "./contextMenu.vue";
import { createApp } from "vue";
import { usePlayer } from "../store/player";

const init = () => {
  // 阻止页面右击事件
  document.oncontextmenu = function () {
    return false;
  };

  // 禁用滚动事件
  let element = document.getElementsByClassName("el-main")[0];

  let top = element.scrollTop;
  element.onscroll = function (e) {
    element.scrollTop = top;
    e.preventDefault();
  };
};

const createContextMenu = (mousePosition, id) => {
  init();

  // 创建一个挂载容器
  const parentNode = document.createElement("div");

  // 卸载组件
  const unmount = () => {
    document.oncontextmenu = function () {
      return true;
    };
    contextMenuInstance.unmount();
    document.body.removeChild(parentNode);
    document.getElementsByClassName("el-main")[0].onscroll = null;
  };

  const contextMenuInstance = createApp(contextMenu, {
    mousePosition,
    id,
    player: usePlayer(),
    onClose: () => {
      unmount();
    },
  });
  // 挂载组件
  document.body.appendChild(parentNode);
  contextMenuInstance.mount(parentNode);
};

export default createContextMenu;
