Browse Source

保存关系bug修复v1

fuyou 7 months ago
parent
commit
d3e94e6807
1 changed files with 63 additions and 41 deletions
  1. 63 41
      autoremark-ui/src/views/index.vue

+ 63 - 41
autoremark-ui/src/views/index.vue

@@ -173,7 +173,8 @@ export default {
       ColorEntityPair: [],//颜色和实体名形成一个新数组
       colorIds: [],
       isColorsLoaded: false, // 标识数据是否加载完成
-      flag: 0, //标志位,标志为0表示当前用户没有选择实体,无法提交确认,为1则说明已经选择实体可以提交
+      entity_flag: 0, //标志位,标志为0表示当前用户没有选择实体,无法提交确认,为1则说明已经选择实体可以提交
+      relation_flag: 0, //标志位,标志为0表示当前用户没有保存实体,无法构建关系,为1则说明实体已经保存,可以构建关系
       historyLogs: [] ,// 历史记录
       currentColorId:"",//记录当前选中颜色的id
       highlightHistory: [], // 用来保存高亮的历史记录,进行撤销最近
@@ -288,7 +289,7 @@ export default {
         // 替换原文中的选中文本
         this.highlightedText = this.highlightedText.replace(selectedText, highlightedText);
         // 选中实体完毕可以进行提交
-        this.flag = 1;
+        this.entity_flag = 1;
         // 保存高亮历史记录
         this.highlightHistory.push({
           text: selectedText,
@@ -344,6 +345,14 @@ export default {
       this.highlightedText = highlightedText;
     },
     saveRelation() {
+      if (this.relation_flag != 1) {
+        this.$message({
+          message: '请先保存实体!',
+          type: 'warning'
+        });
+        return;
+      }
+
       if (this.headEntityId && this.tailEntityId && this.currentRelationType) {
         // 检查头实体和尾实体是否已经保存到实体表中
         const headEntity = this.entities.find(entity => entity.id === this.headEntityId);
@@ -359,38 +368,45 @@ export default {
 
         // 创建关系对象
         const relation = {
-          headEntityId: this.headEntityId,
-          tailEntityId: this.tailEntityId,
-          type: this.currentRelationType
+          startId: headEntity.id,
+          endId: tailEntity.id,
+          type: '人工标注'
         };
 
         // 调用 addRelation 接口保存关系
         addRelation(relation).then(response => {
-          // if (response.code === 200) {
-            // 保存成功,将关系添加到前端的关系列表中
-            // this.relations.push({
-            //   id: response.data.id,
-            //   ...relation
-            // });
-
-            this.$message({
-              message: '关系保存成功!',
-              type: 'success'
-            });
-
-            // 添加历史记录:保存关系
-            const headEntityText = this.getEntityText(relation.headEntityId);
-            const tailEntityText = this.getEntityText(relation.tailEntityId);
-            this.historyLogs.push(`保存关系:${headEntityText} -> ${tailEntityText}(${relation.type})`);
-
-            // 获取关系的详细信息
-            // this.fetchRelationEntities(response.data.id);
-          // } else {
-          //   this.$message({
-          //     message: '关系保存失败!',
-          //     type: 'error'
-          //   });
-          // }
+           if (response.code === 200) {
+             // 保存成功,将关系添加到前端的关系列表中
+             // this.relations.push({
+             //   id: response.data.id,
+             //   ...relation
+             // });
+
+             this.$message({
+               message: '关系保存成功!',
+               type: 'success'
+             });
+
+             this.historyLogs.push(`保存关系:${headEntity.text} -> ${tailEntity.text}($relation.type})`);
+             // 添加历史记录:保存关系
+             // const headEntityText = this.getEntityText(relation.headEntityId);
+             // const tailEntityText = this.getEntityText(relation.tailEntityId);
+             // this.historyLogs.push(`保存关系:${headEntityText} -> ${tailEntityText}(${relation.type})`);
+
+             // 获取关系的详细信息
+             // this.fetchRelationEntities(response.data.id);
+             // } else {
+             //   this.$message({
+             //     message: '关系保存失败!',
+             //     type: 'error'
+             //   });
+             // }
+           }else {
+             this.$message({
+               message: '关系保存失败!',
+               type: 'error'
+             });
+           }
         }).catch(error => {
           console.error('保存关系失败:', error);
           this.$message({
@@ -410,29 +426,35 @@ export default {
       return entity ? entity.text : '未知实体';
     },
     submit() {
-      if (this.flag === 1) {
+      if (this.entity_flag === 1) {
         this.entityForm.typeId = this.currentColorId;
         this.entityForm.startOffset = this.startOffset;
         this.entityForm.endOffset = this.endOffset;
         this.entityForm.text = this.selectedText;
 
+        console.log("提交实体数据:", this.entityForm);
+
         addEntity(this.entityForm).then(response => {
+          console.log("实体保存响应:",response);
           if (response.code === 200) {
-            // 实体保存成功后,更新 entities 数组
-            const entity = {
-              id: response.data.id, // 假设后端返回保存后的实体ID
-              text: this.selectedText,
-              startOffset: this.startOffset,
-              endOffset: this.endOffset,
-              label: this.selectedLabel,
-              color: this.currentHighlightColor
-            };
-            this.entities.push(entity);
+            // // 实体保存成功后,更新 entities 数组
+            // const entity = {
+            //   id: response.data.id,
+            //   text: this.selectedText,
+            //   startOffset: this.startOffset,
+            //   endOffset: this.endOffset,
+            //   label: this.selectedLabel,
+            //   color: this.currentHighlightColor
+            // };
+            // this.entities.push(entity);
 
             this.$message({
               message: '成功提交',
               type: 'success'
             });
+
+            //设置relation_flag为1,表示实体已保存
+            this.relation_flag = 1;
           } else {
             this.$message({
               message: '提交失败',