Ver código fonte

1. 优化组件拖拽移动,移动前同步富文本内容并暂存组件数据,新实例从缓存初始化,不再使用组件内容保存接口
2. 编辑模式下显示重做、判断对错和查看答案按钮,但禁用点击,并显示不可操作光标。
3. 隐藏语音矩阵判断对错按钮
4. 语音矩阵仅当矩阵中有内容,且存在解析或参考答案时显示查看答案按钮。
5. 修复组件拖拽重建后设置面板仍指向旧数据

dsy 1 semana atrás
pai
commit
cc9d9036b1

+ 1 - 1
.env

@@ -11,4 +11,4 @@ VUE_APP_BookWebSI = '/GCLSBookWebSI/ServiceInterface'
 VUE_APP_EepServer = '/EEPServer/SI'
 
 #version
-VUE_APP_VERSION = '2026.11.19'
+VUE_APP_VERSION = '2026.11.20'

+ 122 - 34
src/views/book/courseware/create/components/CreateCanvas.vue

@@ -155,6 +155,7 @@ export default {
       getBookUnifiedAttr: () => this.book_unified_attrib,
       getTitleList: () => this.title_list,
       getProjectResourcePopedom: () => this.projectResourcePopedom,
+      getMovedComponentContent: (id) => this.movedComponentContent[id],
       moveComponentDragStart: this.dragStart,
       getCoursewareId: () => this.courseware_id,
     };
@@ -178,6 +179,8 @@ export default {
         unified_attrib,
       },
       componentLoadingState: {},
+      movedComponentContent: {},
+      movedComponentIds: {},
       canvasContentVersion: 0,
       visibleBackground: false, // 背景设置弹窗
       rowCheckList: {}, // 行复选框列表
@@ -767,6 +770,7 @@ export default {
           throw new Error('课件框架保存失败');
         }
 
+        this.resetMovedComponentState();
         this.clearGridSource();
         this.$message.success('保存成功');
         if (type === 'quit') {
@@ -1081,6 +1085,10 @@ export default {
           cancelButtonText: '取消',
           type: 'warning',
         });
+        if (this.movingComponent || this.savingCourseware) {
+          this.$message.warning('组件正在移动或课件正在保存,请稍后操作');
+          return;
+        }
         this.deleteComponent(id);
       } catch (err) {
         if (err === 'cancel') {
@@ -1414,18 +1422,14 @@ export default {
           return;
         }
 
-        try {
-          component.background = background;
-          const result = await component.saveCoursewareComponentContent();
-          if (result?.status !== 1) throw new Error('组件内容保存失败');
-        } catch (error) {
-          console.error('移动组件前保存内容失败', error);
-          this.$message.error('组件内容保存失败,已取消移动');
-          this.resetMoveData();
-          return;
-        }
+        component.syncRichTextContent();
+        component.background = background;
+        this.$set(this.movedComponentContent, oldID, {
+          data: _.cloneDeep(component.data),
+          background,
+        });
+        this.$set(this.movedComponentIds, oldID, true);
 
-        // 保存成功后再调整原组件 id,避免保存失败时留下不完整的页面结构
         const deleteID = this.replaceGridIdByOldId(oldID);
 
         if (this.curRow >= -1 && this.curCol <= -1) {
@@ -1442,8 +1446,19 @@ export default {
 
         await this.$nextTick();
         this.deleteComponent(deleteID);
+        await this.$nextTick();
         const movedComponent = this.findChildComponentByKey(`grid-${oldID}`);
-        if (movedComponent) movedComponent.background = background;
+        if (movedComponent && movedComponent.property?.isGetContent) {
+          movedComponent.background = background;
+          this.$delete(this.movedComponentContent, oldID);
+          if (this.getCurSettingId() === oldID) movedComponent.showSetting();
+        } else {
+          if (this.getCurSettingId() === oldID) {
+            this.curComponentId = '';
+            this.$emit('showSettingEmpty');
+          }
+          this.$message.error('组件移动后未能正常加载,请检查组件内容,确认无误后再保存。');
+        }
       } finally {
         this.movingComponent = false;
       }
@@ -1914,6 +1929,7 @@ export default {
       this.$emit('showSettingEmpty');
       this.curComponentId = '';
       this.componentLoadingState = {};
+      this.resetMovedComponentState();
       this.canvasContentVersion += 1;
       this.clearGridSource(templateData.row_list);
       templateData.row_list.forEach((row) => {
@@ -2046,6 +2062,10 @@ export default {
      * @param {String} position 放入位置类型
      */
     pasteComponent(componentData, position) {
+      if (this.movingComponent || this.savingCourseware) {
+        this.$message.warning('组件正在移动或课件正在保存,请稍后操作');
+        return;
+      }
       if (!componentData) return;
       // 兼容只传组件内容的复制数据
       const isClipboardData =
@@ -2137,30 +2157,78 @@ export default {
       });
     },
     // 交换组件位置
-    switchComponent() {
-      let checkedNum = 0;
-      let components = [];
-      this.$refs.component.forEach((child) => {
-        if (child.$refs.base.checked) {
-          checkedNum += 1;
-          components.push(child.id);
-        }
-      });
-      if (checkedNum !== 2) {
+    async switchComponent() {
+      if (this.movingComponent || this.savingCourseware) {
+        this.$message.warning('组件正在移动或课件正在保存,请稍后操作');
+        return;
+      }
+      const selected = (this.$refs.component || []).filter((child) => child.$refs.base.checked);
+      if (selected.length !== 2) {
         this.$message.error('请选择两个组件进行交换');
         return;
       }
-      this.$confirm('组件未保存的改动将丢失。确定要交换这两个组件的位置吗?', '提示', {
-        confirmButtonText: '确定',
-        cancelButtonText: '取消',
-        type: 'warning',
-      })
-        .then(() => {
-          this.switchComponentData(components);
-        })
-        .catch(() => {
-          // 取消交换
+      try {
+        await this.$confirm('组件未保存的改动将丢失。确定要交换这两个组件的位置吗?', '提示', {
+          confirmButtonText: '确定',
+          cancelButtonText: '取消',
+          type: 'warning',
         });
+      } catch (error) {
+        if (error === 'cancel' || error === 'close') return;
+        throw error;
+      }
+      if (this.movingComponent || this.savingCourseware) {
+        this.$message.warning('组件正在移动或课件正在保存,请稍后操作');
+        return;
+      }
+      const components = selected.map(({ id }) => id);
+      if (
+        selected.some(
+          (child) => !child.property?.isGetContent || this.findChildComponentByKey(`grid-${child.id}`) !== child,
+        )
+      ) {
+        this.$message.warning('组件内容尚未加载完成或已发生变化,请重新选择');
+        return;
+      }
+
+      this.movingComponent = true;
+      try {
+        const movedComponents = selected.filter((child) => this.movedComponentIds[child.id]);
+        const backgrounds = await Promise.all(movedComponents.map((child) => child.getComponentBackground()));
+        const snapshots = movedComponents.map((child, index) => {
+          child.syncRichTextContent();
+          return { data: _.cloneDeep(child.data), background: backgrounds[index] };
+        });
+        const previousSnapshots = movedComponents.map((child) => this.movedComponentContent[child.id]);
+        movedComponents.forEach((child, index) => {
+          child.background = backgrounds[index];
+          this.$set(this.movedComponentContent, child.id, snapshots[index]);
+        });
+        if (!this.switchComponentData(components)) {
+          movedComponents.forEach(({ id }, index) => {
+            if (previousSnapshots[index]) {
+              this.$set(this.movedComponentContent, id, previousSnapshots[index]);
+            } else {
+              this.$delete(this.movedComponentContent, id);
+            }
+          });
+          throw new Error('未找到需要交换的组件');
+        }
+        await this.$nextTick();
+        movedComponents.forEach(({ id }) => {
+          const component = this.findChildComponentByKey(`grid-${id}`);
+          if (component?.property?.isGetContent) {
+            this.$delete(this.movedComponentContent, id);
+          } else {
+            this.$message.error('交换后的组件尚未加载完成,请检查后再保存');
+          }
+        });
+      } catch (error) {
+        console.error('交换组件失败', error);
+        this.$message.error('交换组件失败,请重试');
+      } finally {
+        this.movingComponent = false;
+      }
     },
     /**
      * 合并遍历 data.row_list,找到两个网格对象并直接交换它们的属性
@@ -2183,20 +2251,40 @@ export default {
         if (g1 && g2) break;
       }
 
-      if (!g1 || !g2) return;
+      if (!g1 || !g2) return false;
 
-      const tmp = { grid_area: g1.grid_area, id: g1.id, type: g1.type }; // 临时存储 g1 的属性
+      const tmp = {
+        grid_area: g1.grid_area,
+        id: g1.id,
+        type: g1.type,
+        oldId: g1.oldId,
+        sourceCoursewareId: g1.sourceCoursewareId,
+      };
       g1.grid_area = g2.grid_area;
       g1.type = g2.type;
       g1.id = g2.id;
+      this.$set(g1, 'oldId', g2.oldId);
+      this.$set(g1, 'sourceCoursewareId', g2.sourceCoursewareId);
 
       g2.grid_area = tmp.grid_area;
       g2.type = tmp.type;
       g2.id = tmp.id;
+      this.$set(g2, 'oldId', tmp.oldId);
+      this.$set(g2, 'sourceCoursewareId', tmp.sourceCoursewareId);
+      return true;
+    },
+    resetMovedComponentState() {
+      this.movedComponentContent = {};
+      this.movedComponentIds = {};
     },
     clearContent() {
+      if (this.movingComponent || this.savingCourseware) {
+        this.$message.warning('组件正在移动或课件正在保存,请稍后操作');
+        return;
+      }
       this.data.row_list = [];
       this.content_group_row_list = [];
+      this.resetMovedComponentState();
     },
     showSetComponentBackground() {
       this.$refs.previewEdit.showSetComponentBackground();

+ 1 - 0
src/views/book/courseware/create/components/PreviewEdit.vue

@@ -70,6 +70,7 @@ export default {
       getDragStatus: () => this.drag.dragging,
       bookInfo: this.bookInfo,
       getPermissionControl: () => this.permissionControl,
+      isPositionAdjustment: true, // 是否允许位置调整
     };
   },
   props: {

+ 30 - 1
src/views/book/courseware/create/components/common/ModuleMixin.js

@@ -141,7 +141,15 @@ const mixin = {
       immediate: true,
     },
   },
-  inject: ['courseware_id', 'project_id', 'getBookUnifiedAttr'],
+  inject: {
+    courseware_id: 'courseware_id',
+    project_id: 'project_id',
+    getBookUnifiedAttr: 'getBookUnifiedAttr',
+    getMovedComponentContent: {
+      from: 'getMovedComponentContent',
+      default: () => () => null,
+    },
+  },
   created() {
     if (this.type === 'interaction') {
       this.$emit('contentLoading', !this.property.isGetContent);
@@ -165,6 +173,26 @@ const mixin = {
       const coursewareID = this.sourceCoursewareId || this.courseware_id;
       const component_id = this.sourceCoursewareId ? this.oldId || this.id : this.id;
 
+      // 拖拽移动组件时,使用保存的组件内容,避免接口返回的初始内容覆盖组件内容
+      const movedContent = this.getMovedComponentContent?.(this.id);
+      if (movedContent) {
+        this.data = mergeComponentData(this.data, movedContent.data);
+        this.background = movedContent.background;
+        this.property.isGetContent = true;
+        this.$emit('contentLoading', false);
+        this.$watch(
+          'data',
+          () => {
+            this.$emit('changeData');
+          },
+          { deep: true },
+        );
+        this.$nextTick(() => {
+          this.property.isSilentPropertyWatch = false;
+        });
+        return;
+      }
+
       ContentGetCoursewareComponentContent({ courseware_id: coursewareID, component_id })
         .then(({ content }) => {
           // 粘贴组件时内容已由源组件预设,接口返回的初始内容(通常为空)不能覆盖粘贴过来的设置
@@ -228,6 +256,7 @@ const mixin = {
         .catch((error) => {
           // 请求失败时保持未加载状态(避免用空内容覆盖已保存内容),但把错误暴露出来便于排查
           console.error('组件内容获取失败', component_id, error);
+          this.$message.error(`组件内容获取失败:${error}`);
         })
         .finally(() => {
           this.$nextTick(() => {

+ 24 - 8
src/views/book/courseware/preview/common/PreviewOperation.vue

@@ -1,18 +1,26 @@
 <template>
-  <div ref="operation" class="operation" :class="{ 'is-wrapped': isWrapped }">
+  <div
+    ref="operation"
+    class="operation"
+    :class="{ 'is-wrapped': isWrapped, 'is-position-adjustment': isPositionAdjustment }"
+  >
     <!-- 重做 -->
-    <div v-show="permissionControl.can_answer && isShowRetry" class="button retry" @click="retry()"></div>
+    <div
+      v-show="(isPositionAdjustment || permissionControl.can_answer) && isShowRetry"
+      class="button retry"
+      @click="!isPositionAdjustment && retry()"
+    ></div>
     <!-- 判断对错 -->
     <div
-      v-show="permissionControl.can_judge_correct && isShowAnswer && isShowJudgeCorrect"
+      v-show="(isPositionAdjustment || permissionControl.can_judge_correct) && isShowAnswer && isShowJudgeCorrect"
       class="button correct"
-      @click="judgeCorrect"
+      @click="!isPositionAdjustment && judgeCorrect()"
     ></div>
     <!-- 查看答案 -->
     <div
-      v-show="permissionControl.can_show_answer && isShowAnswer"
+      v-show="(isPositionAdjustment || permissionControl.can_show_answer) && isShowAnswer"
       class="button answer"
-      @click="showAnswerAnalysis()"
+      @click="!isPositionAdjustment && showAnswerAnalysis()"
     ></div>
     <!-- 批改 -->
     <div v-show="permissionControl.can_correct" class="button remark" @click="openAnswerCorrect(false)"></div>
@@ -24,9 +32,13 @@
 <script>
 export default {
   name: 'PreviewOperation',
-  inject: ['getPermissionControl', 'openAnswerCorrect'],
+  inject: {
+    getPermissionControl: 'getPermissionControl',
+    openAnswerCorrect: 'openAnswerCorrect',
+    isPositionAdjustment: { default: false },
+  },
   props: {
-    // 是否显示答案按钮
+    // 是否显示查看答案按钮
     isShowAnswer: {
       type: Boolean,
       default: true,
@@ -118,6 +130,10 @@ export default {
     justify-content: flex-start;
   }
 
+  &.is-position-adjustment .button {
+    cursor: not-allowed;
+  }
+
   .button {
     width: 90px;
     height: 40px;

+ 17 - 1
src/views/book/courseware/preview/components/voice_matrix/VoiceMatrixPreview.vue

@@ -246,7 +246,13 @@
           </template>
         </MatrixRecord>
       </div>
-      <PreviewOperation @showAnswerAnalysis="showAnswerAnalysis" @judgeCorrect="judgeCorrect" @retry="retry" />
+      <PreviewOperation
+        :is-show-judge-correct="false"
+        :is-show-answer="isShowAnswer"
+        @showAnswerAnalysis="showAnswerAnalysis"
+        @judgeCorrect="judgeCorrect"
+        @retry="retry"
+      />
     </div>
 
     <AnswerCorrect
@@ -378,6 +384,16 @@ export default {
         return word.row === row && word.column === column;
       });
     },
+    hasOptionContent() {
+      return this.data.option_list.some((row) => row.some((item) => item.content.length > 0));
+    },
+    // 是否显示查看答案按钮:有录入内容且解析(analysis_list)或参考答案(answer_list)有数据时显示
+    isShowAnswer() {
+      return (
+        this.hasOptionContent &&
+        ((this.data.analysis_list || []).length > 0 || (this.data.answer_list || []).length > 0)
+      );
+    },
   },
   watch: {
     // 切换题目时语音测评默认关闭