Browse Source

feat(词库管理): 添加点击事件以创建新词库并获取词库列表

在词库管理页面中,新增了点击事件 `handleAddCategory`,允许用户通过弹窗输入词库名称并创建新词库。同时,添加了 `getList` 方法,用于在页面加载时获取词库列表数据,并在 `onMounted` 钩子中调用。这些改动提高了词库管理的交互性和数据实时性。
weieryang 8 months ago
parent
commit
5bcb8b8085
1 changed files with 43 additions and 3 deletions
  1. 43 3
      src/views/rules/words.vue

+ 43 - 3
src/views/rules/words.vue

@@ -7,12 +7,12 @@
7 7
         <div class="grid grid-cols-8 gap-4">
8 8
           <div 
9 9
            
10
-            class="flex flex-col items-center p-4 border rounded-lg hover:bg-gray-50 hover:border-blue-500 shadow-sm relative group h-full">
10
+            class="flex flex-col items-center p-4 border rounded-lg hover:bg-gray-50 hover:border-blue-500 shadow-sm relative group h-full"
11
+            @click="handleAddCategory">
11 12
             <span 
12 13
               class="flex flex-col justify-center items-center flex-1 w-full cursor-pointer hover:text-blue-500">
13 14
               <el-icon class="text-2xl"><Plus /></el-icon>
14 15
             </span>
15
-          
16 16
           </div>
17 17
           <div 
18 18
             v-for="(item, index) in wordCategories" 
@@ -119,7 +119,9 @@
119 119
 </template>
120 120
 
121 121
 <script lang="ts" setup name="RuleWord">
122
-import { ref } from 'vue'
122
+import { onMounted, ref } from 'vue'
123
+import { ElMessageBox } from 'element-plus'
124
+import { createPageData, getPageListData } from '@/api/main/system/system'
123 125
 
124 126
 const wordCategories = ref([
125 127
   { name: '敏感词', count: 12 },
@@ -188,4 +190,42 @@ const handleDelete = (index: number) => {
188 190
 const handleEdit = (index: number) => {
189 191
   console.log('编辑词库:', index)
190 192
 }
193
+
194
+const handleAddCategory = async () => {
195
+  try {
196
+    const { value } = await ElMessageBox.prompt('请输入词库名称', '新建词库', {
197
+      confirmButtonText: '确定',
198
+      cancelButtonText: '取消',
199
+      inputPattern: /^\S+$/,
200
+      inputErrorMessage: '词库名称不能为空'
201
+    })
202
+
203
+    if (!value.trim()) return;
204
+    const params = {
205
+      term: value.trim(),
206
+      type: 1,
207
+    };
208
+
209
+    const {state} = await createPageData('/quality/searchLexicon', params);
210
+    // 新增数据增加到词库列表第一个里面
211
+    if (state === 'success') wordCategories.value = [{ name: value.trim(), count: 0 }, ...wordCategories.value];
212
+    
213
+    
214
+  } catch (error) {
215
+    // 用户取消输入
216
+  }
217
+}
218
+
219
+const getList = () => {
220
+  getPageListData('/quality/searchLexicon', {page: 1, size: 10000}).then((res) => {
221
+    console.log(res);
222
+    if (res.state === 'success') {
223
+      wordCategories.value = res.data.map((item: any) => ({ name: item.term, count: item.count }));
224
+    }
225
+  });
226
+}
227
+
228
+onMounted(() => {
229
+  getList();
230
+})
191 231
 </script>