ソースを参照

feat(program): the first media component defaults to full screen

Casper Dai 3 年 前
コミット
3050cd2f2b
2 ファイル変更37 行追加16 行削除
  1. 18 10
      src/views/bigscreen/ast/Designer.vue
  2. 19 6
      src/views/bigscreen/ast/core/utils.js

+ 18 - 10
src/views/bigscreen/ast/Designer.vue

@@ -341,6 +341,7 @@ import {
 } from '@/constant'
 import {
   widgets,
+  isMediaWidget,
   normalize,
   getOptions,
   copy,
@@ -506,18 +507,25 @@ export default {
     widgetOnDrop (evt) {
       const type = evt.dataTransfer.getData('type')
       if (type) {
-        let { offsetX: left, offsetY: top } = evt
         const node = normalize({ type })
-        top -= node.height / 2
-        if (top < 0) {
-          top = 0
-        }
-        left -= node.width / 2
-        if (left < 0) {
-          left = 0
+        if (this.widgets.length || !isMediaWidget(type)) {
+          let { offsetX: left, offsetY: top } = evt
+          top -= node.height / 2
+          if (top < 0) {
+            top = 0
+          }
+          left -= node.width / 2
+          if (left < 0) {
+            left = 0
+          }
+          node.top = top
+          node.left = left
+        } else {
+          node.top = 0
+          node.left = 0
+          node.width = this.node.width
+          node.height = this.node.height
         }
-        node.top = top
-        node.left = left
         this.node.widgets.push(node)
         this.$nextTick(() => {
           this.selectedWidgetIndex = this.widgets.length - 1

+ 19 - 6
src/views/bigscreen/ast/core/utils.js

@@ -5,31 +5,44 @@ import {
 } from '@/constant'
 import { WidgetType } from './constant'
 import widgetCanvas from './config-json/canvas'
-import widgetText from './config-json/text'
-import widgetMarquee from './config-json/marquee'
 import widgetMedia from './config-json/media'
 import widgetImage from './config-json/image'
 import widgetVideo from './config-json/video'
+import widgetLive from './config-json/live'
+import widgetText from './config-json/text'
+import widgetMarquee from './config-json/marquee'
 import widgetTime from './config-json/time'
 import widgetWeather from './config-json/weather'
 import widgetWeb from './config-json/web'
-import widgetLive from './config-json/live'
 
 export const widgets = Object.freeze([
   widgetMedia,
+  widgetLive,
   widgetText,
   widgetMarquee,
   widgetTime,
   __STAGING__ ? widgetWeather : null,
-  widgetWeb,
-  widgetLive
+  widgetWeb
 ].filter(Boolean))
 
+export function isMediaWidget (type) {
+  switch (type) {
+    case WidgetType.MEDIA:
+    case WidgetType.IMAGE:
+    case WidgetType.VIDEO:
+    case WidgetType.LIVE:
+    case WidgetType.WEB:
+      return true
+    default:
+      return false
+  }
+}
+
 const supportWidgets = Object.freeze([
   ...widgets,
   widgetImage,
   widgetVideo
-].filter(Boolean))
+])
 
 let scale = null
 export function create (node) {