Bladeren bron

特征库v1.1

李志伟 3 jaren geleden
bovenliggende
commit
582295945a

+ 77
- 20
src/components/CharacterResult/edit.vue Bestand weergeven

@@ -1,9 +1,14 @@
1 1
 <template>
2 2
   <div class="body_edit">
3
-    <h2 style="text-align: center">特征实例编辑</h2>
3
+    <h2 style="text-align: center">
4
+      特征实例{{ this.resultId ? "编辑" : "添加" }}
5
+    </h2>
4 6
     <el-form ref="form" :model="form" label-width="150px" size="mini">
5 7
       <el-form-item label="实例名称:">
6
-        <el-input v-model="form.name"></el-input>
8
+        <el-input
9
+          v-model="form.name"
10
+          placeholder="请输入实例名(必填)"
11
+        ></el-input>
7 12
       </el-form-item>
8 13
       <el-form-item label="特征库图标:">
9 14
         <UploadImage />
@@ -13,20 +18,46 @@
13 18
       </el-form-item>
14 19
 
15 20
       <el-form-item label="特征词:">
21
+        <el-select
22
+          v-model="nowList"
23
+          multiple
24
+          filterable
25
+          default-first-option
26
+          placeholder="请选择"
27
+          @change="handleChange"
28
+        >
29
+          <el-option
30
+            v-for="item in wordList"
31
+            :key="item.wordId"
32
+            :label="item.word"
33
+            :value="item.wordId"
34
+          >
35
+          </el-option>
36
+        </el-select>
16 37
       </el-form-item>
17 38
       <el-form-item>
18 39
         <el-button type="primary" @click="onSubmit">确定</el-button>
19 40
         <el-button @click="onReset">重置</el-button>
41
+        <el-button @click="handleClose">关闭</el-button>
20 42
       </el-form-item>
21 43
     </el-form>
22 44
   </div>
23 45
 </template>
24 46
 <script>
25
-import { saveCharacterResult } from "@/api/characterLib";
47
+import {
48
+  saveCharacterResult,
49
+  UpdateCharacterResult,
50
+  getCharacterResultDetail,
51
+} from "@/api/characterLib";
26 52
 import UploadImage from "@/components/UploadImage/index.vue";
27 53
 export default {
28
-  props:{
29
-    libId:String
54
+  props: {
55
+    libId: String,
56
+    resultId: String,
57
+    wordList: {
58
+      type: Array,
59
+      required: true,
60
+    },
30 61
   },
31 62
   data() {
32 63
     return {
@@ -34,35 +65,61 @@ export default {
34 65
         name: undefined,
35 66
         thumb: undefined,
36 67
         desc: undefined,
37
-        libId:undefined,
38
-        wordList:[]
68
+        libId: undefined,
69
+        wordList: [],
39 70
       },
71
+      nowList:[]
40 72
     };
41 73
   },
42 74
 
43 75
   methods: {
44 76
     onReset() {
45
-      this.form={
77
+      this.form = {
46 78
         name: undefined,
47 79
         thumb: undefined,
48 80
         desc: undefined,
49
-        libId:undefined,
50
-        wordList:[]
51
-      }
81
+        libId: undefined,
82
+        wordList: [],
83
+      };
52 84
     },
85
+    handleChange(val) {},
53 86
     onSubmit() {
54
-      this.form.libId=this.libId
55
-      console.log(this.form)
56
-      
57
-      saveCharacterResult(this.form).then((res) => {
58
-        this.$message('添加实例成功')
59
-        console.log(res);
60
-      });
61
-    }
87
+      this.form.wordList = this.wordList.filter((item) =>
88
+        this.nowList.some((v) => v == item.wordId)
89
+      );
90
+      this.form.libId = this.libId;
91
+      if (this.form.name) {
92
+        if (this.resultId) {
93
+          UpdateCharacterResult(this.form,this.resultId).then((res) => {
94
+            this.$message("修改实例成功");
95
+            //告诉父页面实例表需要刷新并且关闭当前组件
96
+            this.$emit("handleRefresh", true);
97
+          });
98
+        } else {
99
+          saveCharacterResult(this.form).then((res) => {
100
+            this.$message("添加实例成功");
101
+            //告诉父页面实例表需要刷新并且关闭当前组件
102
+            this.$emit("handleRefresh", true);
103
+          });
104
+        }
105
+      } else {
106
+        this.$message("请输入实例名");
107
+      }
108
+    },
109
+    handleClose() {
110
+      this.$emit("handleClose", true);
111
+    },
62 112
   },
63 113
   //进入页面执行的方法
64 114
   mounted: function () {
65
-    if (this.$route?.query.row) {
115
+    if (this.resultId) {
116
+      getCharacterResultDetail(this.resultId).then((res) => {
117
+        this.form = res.data;
118
+        let list=res.data.wordList
119
+        list.map((item)=>{
120
+          this.nowList.push(item.wordId)
121
+        })
122
+      });
66 123
     }
67 124
   },
68 125
   components: {

+ 7
- 3
src/components/CharacterResult/index.vue Bestand weergeven

@@ -44,11 +44,15 @@ export default {
44 44
   methods: {
45 45
     handleEdit(row) {
46 46
       // 向外传送数据row.resultId
47
+      this.$emit("handleEdit", row.resultId);
47 48
     },
48 49
     handleDelete(row) {
49
-      // deleteCharacterResult(row.resultId).then(() => {
50
-      //   this.onRefresh();
51
-      // });
50
+      deleteCharacterResult(row.resultId).then(() => {
51
+        this.onRefresh();
52
+        this.$message("删除实例成功");
53
+        //关闭编辑实例页面防止编辑页面还没关闭就删除当前实例了
54
+        this.$emit("handleClose", true);
55
+      });
52 56
     },
53 57
     onSearch() {
54 58
       getCharacterResultList({ name: this.name }).then((res) => {

+ 35
- 3
src/views/characterLibManage/edit.vue Bestand weergeven

@@ -21,7 +21,9 @@
21 21
           <el-form-item>
22 22
             <el-button type="primary" @click="onEdit">修改</el-button>
23 23
             <el-button @click="onCancel">取消</el-button>
24
-            <el-button type="primary" @click="onCancel">添加实例</el-button>
24
+            <el-button type="primary" @click="handleAddRusult"
25
+              >添加实例</el-button
26
+            >
25 27
           </el-form-item>
26 28
         </el-form>
27 29
       </el-col>
@@ -36,11 +38,18 @@
36 38
     </el-row>
37 39
     <el-row :gutter="20">
38 40
       <el-col :span="10">
39
-        <CharacterResult />
41
+        <CharacterResult ref="CharacterResult" @handleEdit="handleEdit" @handleClose="handleClose"/>
40 42
       </el-col>
41 43
       <el-col :span="10">
42 44
         实例详情
43
-        <CharacterResultEdit :libId="characterLib.libId" />
45
+        <CharacterResultEdit
46
+          v-if="isDisplay"
47
+          :libId="characterLib.libId"
48
+          :resultId="resultId"
49
+          :wordList="this.characterLib.wordList"
50
+          @handleRefresh="handleRefresh"
51
+          @handleClose="handleClose"
52
+        />
44 53
       </el-col>
45 54
     </el-row>
46 55
   </div>
@@ -56,6 +65,7 @@ import TagComponents from "@/components/TagComponents/index.vue";
56 65
 export default {
57 66
   data() {
58 67
     return {
68
+      isDisplay: false,
59 69
       characterLib: {
60 70
         libId: undefined,
61 71
         name: undefined,
@@ -63,10 +73,12 @@ export default {
63 73
         remark: undefined,
64 74
         wordList: [],
65 75
       },
76
+      resultId: undefined,
66 77
     };
67 78
   },
68 79
 
69 80
   methods: {
81
+    //上方实例库的方法
70 82
     onCancel() {
71 83
       this.$router.go(-1);
72 84
     },
@@ -77,6 +89,12 @@ export default {
77 89
         }
78 90
       );
79 91
     },
92
+    //添加实例
93
+    handleAddRusult() {
94
+      this.isDisplay = true;
95
+    },
96
+
97
+    //实例列表的方法
80 98
     handleDelete(val) {
81 99
       if (this.characterLib.libId) {
82 100
         let nowWordId = undefined;
@@ -125,6 +143,20 @@ export default {
125 143
         });
126 144
       }
127 145
     },
146
+    handleEdit(val) {
147
+      this.isDisplay = true;
148
+      this.resultId = val;
149
+    },
150
+
151
+    //实例编辑页面调用实例列表的刷新方法 兄弟组件调用方法
152
+    handleRefresh() {
153
+      this.handleClose();
154
+      this.$refs.CharacterResult.onRefresh();
155
+    },
156
+    handleClose() {
157
+      this.isDisplay = false;
158
+      this.resultId=undefined
159
+    },
128 160
   },
129 161
   //进入页面执行的方法
130 162
   mounted: function () {