Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mac下粘贴部分类型文件导致报错 #48

Closed
YuhuiM opened this issue Nov 10, 2020 · 2 comments
Closed

Mac下粘贴部分类型文件导致报错 #48

YuhuiM opened this issue Nov 10, 2020 · 2 comments

Comments

@YuhuiM
Copy link

YuhuiM commented Nov 10, 2020

目前发现svg、csv会导致报错

https://github.com/code-farmer-i/vue-markdown-editor/blob/dev/src/utils/file.js

// Modified from https://github.com/ElemeFE/element/blob/dev/packages/upload/src/upload-dragger.vue
export function filesFilter(files, config) {
  const { accept } = config;

  const filesKeys = Object.keys(files).filter((key) => {
    const file = files[key]; 
    const { type, name } = file; // 这边file是null,导致解构报错
    const extension = name.indexOf('.') > -1 ? `.${name.split('.').pop()}` : '';
    const baseType = type.replace(/\/.*$/, '');

    return accept
      .split(',')
      .map((type) => type.trim())
      .filter((type) => type)
      .some((acceptedType) => {
        if (/\..+$/.test(acceptedType)) {
          return extension === acceptedType;
        }

        if (/\/\*$/.test(acceptedType)) {
          return baseType === acceptedType.replace(/\/\*$/, '');
        }

        // eslint-disable-next-line no-useless-escape
        // eslint-disable-next-line no-useless-escape
        if (/^[^\/]+\/[^\/]+$/.test(acceptedType)) {
          return type === acceptedType;
        }

        return false;
      });
  });

  return filesKeys.map((key) => files[key]);
}

export function getFilesFromClipboardData(clipboardData) {
  return Object.keys(clipboardData.items)
    .filter((key) => clipboardData.items[key].kind === 'file')
    .map((key) => clipboardData.items[key].getAsFile()); // 这里getAsFile()返回null,导致上面报错
}
@YuhuiM
Copy link
Author

YuhuiM commented Nov 10, 2020

测试了一下Windows Chrome,Windows好像不能粘贴

@code-farmer-i
Copy link
Owner

不支持粘贴svg和一部分类型,报错已在1.5.3 & 2.1.5 版本中优化。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants