Kaynağa Gözat

feat(program): validity verification

Casper Dai 3 yıl önce
ebeveyn
işleme
98fe995cff

+ 4 - 4
src/views/bigscreen/core/base.js

@@ -8,7 +8,7 @@ import {
 import { getAssetUrl } from '@/api/asset'
 import {
   create,
-  check,
+  inquire,
   toJSON
 } from './utils'
 
@@ -217,10 +217,10 @@ export default {
       })
     },
     check () {
-      const result = check(this.node)
-      if (result.code === 1) {
+      const warning = inquire(this.node)
+      if (warning) {
         return this.$confirm(
-          '视频均未设置音频输出,确定保存?',
+          `${warning},确定保存?`,
           '提示',
           {
             type: 'warning',

+ 44 - 10
src/views/bigscreen/core/utils.js

@@ -34,16 +34,6 @@ export function create (node) {
   return canvas
 }
 
-export function check ({ bgm, widgets }) {
-  if (bgm.length === 0) {
-    const videos = widgets.filter(widget => widget.type === widgetVideo.type)
-    if (videos.length > 0 && !videos.some(video => video.mute === 0)) {
-      return { code: 1 }
-    }
-  }
-  return { code: 0 }
-}
-
 export function toJSON (node) {
   const transformOptions = { color: transformColorToAndroid }
   const canvas = transform({ ...node }, widgetCanvas.transform, transformOptions)
@@ -136,3 +126,47 @@ function transform (data, transformOptions = {}, strat = {}) {
   })
   return data
 }
+
+export function inquire (node) {
+  const { bgm, widgets } = node
+  if (bgm.length === 0) {
+    const videoType = widgetVideo.type
+    const liveType = widgetLive.type
+    const videos = widgets.filter(widget => {
+      const type = widget.type
+      if (type === videoType && widget.sources.length) {
+        return true
+      }
+      if (type === liveType && widget.url) {
+        return true
+      }
+      return false
+    })
+    if (videos.length > 0 && !videos.some(({ mute }) => mute === 0)) {
+      return '视频均未设置音频输出'
+    }
+  }
+}
+
+export function validate (node) {
+  const { widgets } = node
+  if (!widgets.length) {
+    return '未配置组件,请先进行配置'
+  }
+  const sourceTypes = [widgetImage.type, widgetVideo.type]
+  const webType = widgetWeb.type
+  const liveType = widgetLive.type
+  for (let i = 0; i < widgets.length; i++) {
+    const widget = widgets[i]
+    const type = widget.type
+    if (sourceTypes.includes(type) && widget.sources.length === 0) {
+      return `${widget.layerName}未配置数据,请先进行配置`
+    }
+    if (type === webType && !widget.href) {
+      return `${widget.layerName}未配置链接地址,请先进行配置`
+    }
+    if (type === liveType && !widget.url) {
+      return `${widget.layerName}未配置播放地址,请先进行配置`
+    }
+  }
+}

+ 8 - 9
src/views/bigscreen/index.vue

@@ -175,6 +175,7 @@ import {
 } from '@/api/program'
 import { State } from '@/constant'
 import { createListOptions } from '@/utils'
+import { validate } from './core/utils'
 
 export default {
   name: 'BigScreen',
@@ -363,15 +364,13 @@ export default {
           return
         }
         try {
-          const { widgets } = JSON.parse(itemJsonStr)
-          for (let i = 0; i < widgets.length; i++) {
-            if (widgets[i].sources?.length === 0) {
-              this.$message({
-                type: 'warning',
-                message: `${widgets[i].layerName}未配置数据,请先进行配置`
-              })
-              return
-            }
+          const error = validate(JSON.parse(itemJsonStr))
+          if (error) {
+            this.$message({
+              type: 'warning',
+              message: error
+            })
+            return
           }
         } catch (e) {
           this.$message({