Kaynağa Gözat

特征库1.0

李志伟 3 yıl önce
ebeveyn
işleme
7d283a4978

+ 46
- 0
src/api/characterWord.js Dosyayı Görüntüle

@@ -0,0 +1,46 @@
1
+import request from '@/utils/request'
2
+
3
+/**
4
+* 保存特征词
5
+* @param {*} data 
6
+* @returns 
7
+*/
8
+export const saveCharacterWord = (data) => request({
9
+  url: '/admin/character-word',
10
+  method: 'post',
11
+  data
12
+})
13
+
14
+/**
15
+ * 特征词列表
16
+ * @param {*} params 
17
+ * @returns 
18
+ */
19
+export const getCharacterWordList = (params) => request({
20
+  url: '/admin/character-word', params
21
+})
22
+
23
+/**
24
+ * 删除特征词
25
+ * @param {*} data 
26
+ * @returns 
27
+ */
28
+export const deleteCharacterWord = (id) => request({
29
+  url: `/admin/character-word/${id}`, method: 'delete'
30
+})
31
+/**
32
+ * 更新特征词
33
+ * @param {*} data 
34
+ * @returns 
35
+ */
36
+export const UpdateCharacterWord = (data, id) => request({
37
+  url: `/admin/character-word/${id}`, method: 'put', data
38
+})
39
+/**
40
+ * 查询特征词详情
41
+ * @param {*} params 
42
+ * @returns 
43
+ */
44
+export const getCharacterWordDetail = (id) => request({
45
+  url: `/admin/character-word/${id}`
46
+})

+ 18
- 15
src/components/CharacterResult/edit.vue Dosyayı Görüntüle

@@ -1,6 +1,6 @@
1 1
 <template>
2 2
   <div class="body_edit">
3
-    <h2 style="text-align: center">题目编辑</h2>
3
+    <h2 style="text-align: center">特征实例编辑</h2>
4 4
     <el-form ref="form" :model="form" label-width="150px" size="mini">
5 5
       <el-form-item label="实例名称:">
6 6
         <el-input v-model="form.name"></el-input>
@@ -13,7 +13,6 @@
13 13
       </el-form-item>
14 14
 
15 15
       <el-form-item label="特征词:">
16
-        <TagComponents :value='value' @change='handleChange'/>
17 16
       </el-form-item>
18 17
       <el-form-item>
19 18
         <el-button type="primary" @click="onSubmit">确定</el-button>
@@ -23,13 +22,14 @@
23 22
   </div>
24 23
 </template>
25 24
 <script>
26
-import { saveQuestion } from "@/api/question";
25
+import { saveCharacterResult } from "@/api/characterLib";
27 26
 import UploadImage from "@/components/UploadImage/index.vue";
28
-import TagComponents from '../TagComponents/index.vue'
29 27
 export default {
28
+  props:{
29
+    libId:String
30
+  },
30 31
   data() {
31 32
     return {
32
-      value:[],
33 33
       form: {
34 34
         name: undefined,
35 35
         thumb: undefined,
@@ -42,18 +42,22 @@ export default {
42 42
 
43 43
   methods: {
44 44
     onReset() {
45
-
45
+      this.form={
46
+        name: undefined,
47
+        thumb: undefined,
48
+        desc: undefined,
49
+        libId:undefined,
50
+        wordList:[]
51
+      }
46 52
     },
47 53
     onSubmit() {
48
-      console.log(this.value)
54
+      this.form.libId=this.libId
55
+      console.log(this.form)
49 56
       
50
-      // this.form.option = this.rightList.toString();
51
-      // saveQuestion(this.form).then((res) => {
52
-      //   console.log(res);
53
-      // });
54
-    },
55
-    handleChange(val){
56
-      console.log(val)
57
+      saveCharacterResult(this.form).then((res) => {
58
+        this.$message('添加实例成功')
59
+        console.log(res);
60
+      });
57 61
     }
58 62
   },
59 63
   //进入页面执行的方法
@@ -63,7 +67,6 @@ export default {
63 67
   },
64 68
   components: {
65 69
     UploadImage,
66
-    TagComponents
67 70
   },
68 71
 };
69 72
 </script>

+ 28
- 12
src/components/TagComponents/index.vue Dosyayı Görüntüle

@@ -20,7 +20,7 @@
20 20
     >
21 21
     </el-input>
22 22
     <el-button v-else class="button-new-tag" size="small" @click="showInput"
23
-      >添加修饰词</el-button
23
+      >添加特征词</el-button
24 24
     >
25 25
   </div>
26 26
 </template>
@@ -35,14 +35,37 @@ export default {
35 35
   },
36 36
   data() {
37 37
     return {
38
-      dynamicTags: [],
39 38
       inputVisible: false,
40 39
       inputValue: "",
41 40
     };
42 41
   },
42
+  computed: {
43
+    dynamicTags() {
44
+      let tags = [];
45
+      this.value.map((item) => {
46
+        tags.push(item.word);
47
+      });
48
+      return tags;
49
+    },
50
+  },
43 51
   methods: {
52
+    //删除特征词
44 53
     handleClose(tag) {
45
-      this.dynamicTags.splice(this.dynamicTags.indexOf(tag), 1);
54
+      if (this.value && this.value[0].wordId) {
55
+        this.$confirm("确认删除该修饰词?", {
56
+          showCancelButton: true,
57
+          confirmButtonText: "确定",
58
+          cancelButtonText: "取消",
59
+        })
60
+          .then((_) => {
61
+            this.$emit("handleDelete", tag);
62
+            this.dynamicTags.splice(this.dynamicTags.indexOf(tag), 1);
63
+          })
64
+          .catch((_) => {});
65
+      } else {
66
+        this.dynamicTags.splice(this.dynamicTags.indexOf(tag), 1);
67
+        this.$emit("handleDelete", tag);
68
+      }
46 69
     },
47 70
 
48 71
     showInput() {
@@ -51,24 +74,17 @@ export default {
51 74
         this.$refs.saveTagInput.$refs.input.focus();
52 75
       });
53 76
     },
54
-
77
+    //添加特征词
55 78
     handleInputConfirm() {
56 79
       let inputValue = this.inputValue;
57 80
       if (inputValue) {
58 81
         this.dynamicTags.push(inputValue);
82
+        this.$emit("handleAdd", inputValue);
59 83
       }
60 84
       this.inputVisible = false;
61 85
       this.inputValue = "";
62
-    }
63
-  },
64
-  watch: {
65
-    dynamicTags() {
66
-      this.$emit("change", this.dynamicTags);
67 86
     },
68 87
   },
69
-  mounted(){
70
-    this.dynamicTags=this.value
71
-  }
72 88
 };
73 89
 </script>
74 90
 <style>

+ 61
- 23
src/views/characterLibManage/add.vue Dosyayı Görüntüle

@@ -1,33 +1,53 @@
1 1
 <template>
2 2
   <div class="body_edit">
3 3
     <h2 style="text-align: center">特征库新增</h2>
4
-    <el-form ref="form" :model="form" label-width="150px" size="mini">
5
-      <el-form-item label="特征库名称:">
6
-        <el-input v-model="form.name"></el-input>
7
-      </el-form-item>
8
-      <el-form-item label="特征库图标:">
9
-        <UploadImage />
10
-      </el-form-item>
11
-      <el-form-item label="特征库描述:">
12
-        <el-input type="textarea" v-model="form.remark"></el-input>
13
-      </el-form-item>
14
-      <el-form-item>
15
-        <el-button type="primary" @click="onSubmit">添加</el-button>
16
-        <el-button @click="onCancel">取消</el-button>
17
-      </el-form-item>
18
-    </el-form>
4
+    <el-row :gutter="20">
5
+      <el-col :span="15">
6
+        <el-form
7
+          ref="form"
8
+          :model="characterLib"
9
+          label-width="150px"
10
+          size="mini"
11
+        >
12
+          <el-form-item label="特征库名称:">
13
+            <el-input v-model="characterLib.name"></el-input>
14
+          </el-form-item>
15
+          <el-form-item label="特征库图标:">
16
+            <UploadImage />
17
+          </el-form-item>
18
+          <el-form-item label="特征库描述:">
19
+            <el-input type="textarea" v-model="characterLib.remark"></el-input>
20
+          </el-form-item>
21
+
22
+          <el-form-item>
23
+            <el-button type="primary" @click="onSubmit">添加</el-button>
24
+            <el-button @click="onCancel">取消</el-button>
25
+          </el-form-item>
26
+        </el-form>
27
+      </el-col>
28
+      <el-col :span="5">
29
+        特征词列表
30
+        <TagComponents
31
+          :value="characterLib.wordList"
32
+          @handleDelete="handleDelete"
33
+          @handleAdd="handleAdd"
34
+        />
35
+      </el-col>
36
+    </el-row>
19 37
   </div>
20 38
 </template>
21 39
 <script>
22 40
 import { saveCharacterLib } from "@/api/characterLib";
23
-import UploadImage from '@/components/UploadImage/index.vue'
41
+import UploadImage from "@/components/UploadImage/index.vue";
42
+import TagComponents from "@/components/TagComponents/index.vue";
24 43
 export default {
25 44
   data() {
26 45
     return {
27
-      form: {
46
+      characterLib: {
28 47
         name: undefined,
29 48
         icon: undefined,
30
-        remark:undefined
49
+        remark: undefined,
50
+        wordList: [],
31 51
       },
32 52
     };
33 53
   },
@@ -37,15 +57,33 @@ export default {
37 57
       this.$router.go(-1);
38 58
     },
39 59
     onSubmit() {
40
-      saveCharacterLib(this.form).then((res) => {
41
-        this.$message('保存成功');
60
+      saveCharacterLib(this.characterLib).then((res) => {
61
+        this.$message("保存成功");
42 62
         this.$router.go(-1);
43 63
       });
44 64
     },
65
+    handleDelete(val) {
66
+      this.characterLib.wordList.map((item) => {
67
+        if (item.word === val) {
68
+          this.characterLib.wordList.splice(
69
+            this.characterLib.wordList.indexOf(item),
70
+            1
71
+          );
72
+        }
73
+      });
74
+    },
75
+    handleAdd(val) {
76
+      this.characterLib.wordList.push({
77
+        libId: undefined,
78
+        word: val,
79
+        wordId: undefined,
80
+      });
81
+    },
82
+  },
83
+  components: {
84
+    UploadImage,
85
+    TagComponents,
45 86
   },
46
-  components:{
47
-    UploadImage
48
-  }
49 87
 };
50 88
 </script>
51 89
 <style>

+ 64
- 4
src/views/characterLibManage/edit.vue Dosyayı Görüntüle

@@ -25,23 +25,34 @@
25 25
           </el-form-item>
26 26
         </el-form>
27 27
       </el-col>
28
-      <el-col :span="5"> 特征词列表 </el-col>
28
+      <el-col :span="5">
29
+        特征词列表
30
+        <TagComponents
31
+          :value="characterLib.wordList"
32
+          @handleDelete="handleDelete"
33
+          @handleAdd="handleAdd"
34
+        />
35
+      </el-col>
29 36
     </el-row>
30 37
     <el-row :gutter="20">
31 38
       <el-col :span="10">
32 39
         <CharacterResult />
33 40
       </el-col>
34
-      <el-col :span="10"> 实例详情 
35
-        <CharacterResultEdit />
41
+      <el-col :span="10">
42
+        实例详情
43
+        <CharacterResultEdit :libId="characterLib.libId" />
36 44
       </el-col>
37 45
     </el-row>
38 46
   </div>
39 47
 </template>
40 48
 <script>
41 49
 import { UpdateCharacterLib, getCharacterLibDetail } from "@/api/characterLib";
50
+import { deleteCharacterWord, saveCharacterWord } from "@/api/characterWord";
42 51
 import UploadImage from "@/components/UploadImage/index.vue";
43 52
 import CharacterResult from "@/components/CharacterResult/index.vue";
44 53
 import CharacterResultEdit from "@/components/CharacterResult/edit.vue";
54
+import TagComponents from "@/components/TagComponents/index.vue";
55
+
45 56
 export default {
46 57
   data() {
47 58
     return {
@@ -66,6 +77,54 @@ export default {
66 77
         }
67 78
       );
68 79
     },
80
+    handleDelete(val) {
81
+      if (this.characterLib.libId) {
82
+        let nowWordId = undefined;
83
+        this.characterLib.wordList.map((item) => {
84
+          if (item.word === val) {
85
+            nowWordId = item.wordId;
86
+          }
87
+        });
88
+        // 调用删除接口
89
+        deleteCharacterWord(nowWordId).then(() => {
90
+          this.characterLib.wordList.map((item) => {
91
+            if (item.word === val) {
92
+              this.characterLib.wordList.splice(
93
+                this.characterLib.wordList.indexOf(item),
94
+                1
95
+              );
96
+            }
97
+          });
98
+        });
99
+      } else {
100
+        // 直接删除当前项
101
+        this.characterLib.wordList.map((item) => {
102
+          if (item.word === val) {
103
+            this.characterLib.wordList.splice(
104
+              this.characterLib.wordList.indexOf(item),
105
+              1
106
+            );
107
+          }
108
+        });
109
+      }
110
+    },
111
+    handleAdd(val) {
112
+      if (this.characterLib.libId) {
113
+        saveCharacterWord({
114
+          libId: this.characterLib.libId,
115
+          word: val,
116
+          wordId: undefined,
117
+        }).then((res) => {
118
+          this.characterLib.wordList.push(res.data);
119
+        });
120
+      } else {
121
+        this.characterLib.wordList.push({
122
+          libId: this.characterLib.libId,
123
+          word: val,
124
+          wordId: undefined,
125
+        });
126
+      }
127
+    },
69 128
   },
70 129
   //进入页面执行的方法
71 130
   mounted: function () {
@@ -78,7 +137,8 @@ export default {
78 137
   components: {
79 138
     UploadImage,
80 139
     CharacterResult,
81
-    CharacterResultEdit
140
+    CharacterResultEdit,
141
+    TagComponents,
82 142
   },
83 143
 };
84 144
 </script>