index.ts 1.28 KB
import '@/views/operation/notification/module/user-card';
import '@/views/operation/notification/module/project-card';
import '@/views/operation/notification/module/activity-card';
import '@wangeditor/editor/dist/css/style.css';
import { Boot } from '@wangeditor/editor';
import useOss from '@/hooks/oss';

type InsertImageFnType = (url: string, alt: string, href: string) => void;
type InsertVideoFnType = (url: string, poster: string) => void;

Boot.setToolbarConfig({
  excludeKeys: ['fullScreen', 'codeBlock', 'undo', 'redo'],
  insertKeys: { index: 30, keys: ['user-card', 'activity-card', 'project-card'] },
});

Boot.setEditorConfig({
  MENU_CONF: {
    uploadImage: {
      allowedFileTypes: ['image/*'],
      async customUpload(file: File, insertFn: InsertImageFnType) {
        return useOss()
          .upload(file, 'image')
          .then(({ name, url }) => insertFn(url, name, url));
      },
    },
    uploadVideo: {
      allowedFileTypes: ['video/*'],
      maxNumberOfFiles: 1,
      maxFileSize: 1024 * 1024 * 1024,
      timeout: 60 * 1000,
      async customUpload(file: File, insertFn: InsertVideoFnType) {
        return useOss()
          .upload(file, 'video')
          .then(({ url }) => insertFn(url, `${url}?x-oss-process=video/snapshot,t_1000,f_png`));
      },
    },
  },
});