el-dropdown不能自己在每一项添加方法,控制台会报错

el-dropdown不能自己在每一项添加方法,控制台会报错
在这里插入图片描述

          
            
              
                
              
              新增素材
            
            
          

改成

          
            
              
                
              
              新增素材
            
            
          


方法:
const choiceCourseAdd = (command) => {
  console.log(command, "command");
  if (command == "11") {
   console.log('11')
  } else if (command == "22") {
 console.log('22')
  } else {
   console.log('33')
  }
};

调用视频,文件的案例

        
                    
                      
                        
                      
                      添加素材
                    
                    
                  
                  
                    
                      
                        
                      
                      添加素材
                    
                    
                  


const choiceCourseAdd = (command) => {
  if (command == "视频") {
    filevideoInputRef.value.click();
  }else if(command == "文件"){
    fileInputRef.value.click();
  } else if (command == "考试") {
    dialogExam.value = true;
  getCreatdByTableListFn();
  } else {
    dialogQuestionnaires.value = true;
  questionList();
  }
}
视频的逻辑
const createVideoDuration = (file, name) => {
  const video = document.createElement("video");
  video.preload = "metadata";
  video.onloadedmetadata = () => {
    window.URL.revokeObjectURL(video.src);
    const duration = formatVideoDuration(video.duration);
    let url = URL.createObjectURL(file);
    let videoList = dataList.value.filter((v) => v.typeName == "视频");
    if (videoList?.length >= 1) {
      ElMessage.error("只能上传一个视频");
    } else {
      dataList.value.push({
        name: name,
        count: duration,
        data: file,
        url: url,
        seconds: Math.floor(video.duration),
        typeName: "视频",
        idhaveEdit: route.query.id ? false : true,
      });
    }
  };

  video.src = URL.createObjectURL(file);
};
const formatVideoDuration = (seconds) => {
  const minutes = Math.floor(seconds / 60);
  const formattedSeconds =
    seconds % 60 < 10
      ? "0" + Math.floor(seconds % 60)
      : Math.floor(seconds % 60);
  return minutes + "分" + formattedSeconds + "秒";
};
// 课程内容的视频
const handleVideoChange = (e) => {
  const file = e.target.files[0];
  if (file) {
    const fileSize = file.size; // 获取文件大小
    const maxSize = 400 * 1024 * 1024; // 400MB转换为字节
    if (fileSize > maxSize) {
      ElMessage.error("上传的视频不能超过400MB!");
    } else {
      const name = e.target.files[0].name;
      if (file && file.type.startsWith("video/")) {
        createVideoDuration(file, name);
      }
    }
  }
};
文件的逻辑
//课程内容的文件
const handlefileChange = (e) => {
  let file = e.target.files[0];
  let fileName = file.name;
  var filetypes = [".doc", ".ppt", ".pdf", ".docx"];
  let filextend = fileName.substring(fileName.lastIndexOf("."));
  if (filetypes.indexOf(filextend) < 0) {
    ElMessage({
      message: "上传文件格式只能是pdf/ppt/docx/doc",
      type: "warning",
    });
    return false;
  }
  let url = URL.createObjectURL(e.target.files[0]);

  let isHave = dataList.value.some((v) => v.name == e.target.files[0].name);
  if (isHave) {
    ElMessage({
      message: "文件已存在",
      type: "warning",
    });
    return false;
  } else {
    dataList.value.push({
      name: e.target.files[0].name,
      count: "-",
      data: e.target.files[0],
      url: url,
      idhaveEdit: route.query.id ? false : true,
    });
    //清空input的值
    fileInputRef.value.value = "";
  }
};

你可能感兴趣的:(javascript,前端,开发语言)