Forráskód Böngészése

编辑混入增加type、content

dsy 18 órája
szülő
commit
4a874c2950

+ 37 - 18
src/views/book/courseware/create/components/common/ModuleMixin.js

@@ -37,6 +37,14 @@ const mixin = {
       type: String,
       required: true,
     },
+    content: {
+      type: String,
+      default: '{}',
+    },
+    type: {
+      type: String,
+      default: '',
+    },
   },
   components: {
     ModuleBase,
@@ -57,26 +65,19 @@ const mixin = {
     borderColor(newVal) {
       this.borderColorObj.value = newVal;
     },
+    content: {
+      handler(newVal) {
+        if (this.type !== 'interaction') return;
+        this.data = JSON.parse(newVal);
+      },
+      immediate: true,
+    },
   },
   inject: ['courseware_id', 'project_id'],
   created() {
-    ContentGetCoursewareComponentContent({ courseware_id: this.courseware_id, component_id: this.id }).then(
-      ({ content }) => {
-        if (content) {
-          this.data = JSON.parse(content);
-        }
-        this.property.isGetContent = true;
-
-        this.$watch(
-          'data',
-          () => {
-            this.$emit('changeData');
-          },
-          { deep: true },
-        );
-      },
-    );
-
+    if (this.type !== 'interaction') {
+      this.GetCoursewareComponentContent();
+    }
     // 初始化 mind_map.node_list[0].id
     if (!this.data?.mind_map?.node_list?.[0]?.id) {
       this.data.mind_map = this.data.mind_map ?? {};
@@ -87,6 +88,24 @@ const mixin = {
     }
   },
   methods: {
+    GetCoursewareComponentContent() {
+      ContentGetCoursewareComponentContent({ courseware_id: this.courseware_id, component_id: this.id }).then(
+        ({ content }) => {
+          if (content) {
+            this.data = JSON.parse(content);
+          }
+          this.property.isGetContent = true;
+
+          this.$watch(
+            'data',
+            () => {
+              this.$emit('changeData');
+            },
+            { deep: true },
+          );
+        },
+      );
+    },
     /**
      * @description 显示设置
      */
@@ -126,7 +145,7 @@ const mixin = {
       this.componentMove({ ...data, id: this.id });
     },
     /**
-     * 保课节组件内容
+     * 保课节组件内容
      * @returns {Promise} 返回 Promise,便于父组件 await
      */
     saveCoursewareComponentContent() {

+ 1 - 1
src/views/book/courseware/preview/components/common/PreviewMixin.js

@@ -56,7 +56,7 @@ const mixin = {
     PinyinText,
   },
   created() {
-    // 这里分为 预览 和 编辑调整位置种情况
+    // 这里分为 预览 和 编辑调整位置、视频互动组件 三种情况
     // 预览时,content 直接传入
     // 编辑调整位置时,content 需要通过接口获取
     if (this.type === 'edit') {