/** * @description video 菜单 panel tab 配置 * @author tonghan,darin_l */ import editor from '../../editor/index' import { PanelConf, PanelTabConf } from '../menu-constructors/Panel' import { getRandom } from '../../utils/util' import $ from '../../utils/dom-core' import UploadVideo from './upload-video' import { videoRegex } from '../../utils/const' export default function (editor: editor, video: string): PanelConf { const config = editor.config const uploadVideo = new UploadVideo(editor) // panel 中需要用到的id const upVideoTriggerId = getRandom('up-video-trigger-id') const upVideoId = getRandom('up-video-id') const inputVideoLinkId = getRandom('input-video-link') const videoLinkBtnId = getRandom('video-link-btn') const i18nPrefix = 'menus.panelMenus.video.' const t = (text: string, prefix: string = i18nPrefix): string => { return editor.i18next.t(prefix + text) } /** * 提示信息 * @param alertInfo alert info * @param debugInfo debug info */ function alert(alertInfo: string, debugInfo?: string): void { const customAlert = editor.config.customAlert if (customAlert) { customAlert(alertInfo) } else { window.alert(alertInfo) } if (debugInfo) { console.error('wangEditor: ' + debugInfo) } } /** * 校验网络视频链接是否合法 * @param src 网络视频链接 */ function checkLinkVideo(src: string): boolean { //编辑器进行正常校验,视频合规则使指针为true,不合规为false let flag = true if (!videoRegex.test(src)) { flag = false } //查看开发者自定义配置的返回值 const check = config.linkVideoCheck(src) if (check === undefined) { //用户未能通过开发者的校验,且开发者不希望编辑器提示用户 if (flag === false) console.log(t('您刚才插入的视频链接未通过编辑器校验', 'validate.')) } else if (check === true) { //用户通过了开发者的校验 if (flag === false) { alert( `${t('您插入的网络视频无法识别', 'validate.')},${t( '请替换为支持的视频类型', 'validate.' )}:mp4 | rmvb | wma | avi | mov` ) } else return true } else { //用户未能通过开发者的校验,开发者希望我们提示这一字符串 alert(check) } return false } // tabs 配置 ----------------------------------------- const fileMultipleAttr = config.uploadVideoMaxLength === 1 ? '' : 'multiple="multiple"' const tabsConf: PanelTabConf[] = [ { // table 的标题 title: t('上传视频'), // 模板 tpl: `