Browse Source

fix: checkVideo 增加 poster 参数

pull/4819/head
wangfupeng 3 years ago
parent
commit
c0402e1554
  1. 4
      packages/editor/examples/check.html
  2. 4
      packages/video-module/__tests__/helpler.test.ts
  3. 2
      packages/video-module/src/module/helper/insert-video.ts
  4. 3
      packages/video-module/src/module/menu/config.ts

4
packages/editor/examples/check.html

@ -174,7 +174,9 @@
console.log('inserted video', videoNode)
},
checkVideo(src) {
checkVideo(src, poster) {
console.log('video src', src)
console.log('video poster', poster)
if (src.indexOf('http') !== 0) {
return '视频地址必须以 http/https 开头'
}

4
packages/video-module/__tests__/helpler.test.ts

@ -22,7 +22,7 @@ describe('Video module helper', () => {
config: {
MENU_CONF: {
insertVideo: {
checkVideo: (_src: string) => 'check result',
checkVideo: (_src: string, _poster: string) => 'check result',
},
},
},
@ -40,7 +40,7 @@ describe('Video module helper', () => {
config: {
MENU_CONF: {
insertVideo: {
checkVideo: (_src: string) => null,
checkVideo: (_src: string, _poster: string) => null,
},
},
},

2
packages/video-module/src/module/helper/insert-video.ts

@ -22,7 +22,7 @@ export default async function (editor: IDomEditor, src: string, poster = '') {
// 校验
const { onInsertedVideo, checkVideo, parseVideoSrc } = editor.getMenuConfig('insertVideo')
const checkRes = await checkVideo(src)
const checkRes = await checkVideo(src, poster)
if (typeof checkRes === 'string') {
// 校验失败,给出提示
editor.alert(checkRes, 'error')

3
packages/video-module/src/module/menu/config.ts

@ -77,8 +77,9 @@ export function genInsertVideoMenuConfig() {
/**
* video async
* @param src src
* @param poster poster
*/
checkVideo(src: string): boolean | string | undefined {
checkVideo(src: string, poster: string): boolean | string | undefined {
// 1. 返回 true ,说明检查通过
// 2. 返回一个字符串,说明检查未通过,编辑器会阻止插入。会 alert 出错误信息(即返回的字符串)
// 3. 返回 undefined(即没有任何返回),说明检查未通过,编辑器会阻止插入

Loading…
Cancel
Save