Browse Source

知识库列表

CzRger 3 weeks ago
parent
commit
55d286a261

+ 8 - 0
src/api/modules/knowledge/collect.ts

@@ -0,0 +1,8 @@
+import { get, post, put, del } from '@/api/request'
+
+// 创建收藏
+export const datasetCollections = (params) =>
+  post(`/dataset/collections`, params, {})
+// 删除收藏
+export const datasetCollectionsDel = (id) =>
+  del(`/dataset/collections/${id}`, {}, {})

+ 5 - 0
src/api/modules/knowledge/group.ts

@@ -0,0 +1,5 @@
+import { get, post, put, del } from '@/api/request'
+
+// 根据租户获取所有分组
+export const datasetGroupsGetAllByTenantId = (tenantId) =>
+  get(`/dataset-groups/getAllByTenantId/${tenantId}`, {}, {})

+ 6 - 0
src/api/modules/knowledge/index.ts

@@ -1,4 +1,10 @@
 import { get, post } from '@/api/request'
 
+// 知识库分页
 export const datasetsGetAllByPage = (params) =>
   post('/datasets/getAllByPage', params, {})
+// 知识库绑定标签
+export const datasetsTagsBinding = (params) =>
+  post('/datasets/tags/binding', params, {})
+// 知识库收藏
+export const datasetsCollect = (params) => post('/datasets/collect', params, {})

+ 6 - 2
src/api/modules/knowledge/tags.ts

@@ -1,6 +1,10 @@
-import { get, post } from '@/api/request'
+import { get, post, put, del } from '@/api/request'
 
-// 标签列表
+// 根据租户获取所以标签列表
 export const tagsTenant = (tenantId) => get(`/tags/tenant/${tenantId}`, {}, {})
 // 标签新增
 export const tagsAdd = (params) => post(`/tags`, params, {})
+// 标签修改
+export const tagsEdit = (params) => put(`/tags`, params, {})
+// 标签删除
+export const tagsDel = (id) => del(`/tags/${id}`, {}, {})

+ 34 - 0
src/api/request.ts

@@ -18,6 +18,22 @@ export const get = (url = '', params: any = {}, config: any = {}) => {
       })
   })
 }
+export const del = (url = '', params: any = {}, config: any = {}) => {
+  return new Promise((resolve, reject) => {
+    const rUrl = (import.meta as any).env.VITE_BASE_API_PROXY + url
+    request
+      .delete(rUrl, {
+        params,
+        ...config,
+      })
+      .then((res: any) => {
+        resultHandle(res, resolve, reject, rUrl)
+      })
+      .catch((res: any) => {
+        resultHandle(res, resolve, reject, rUrl)
+      })
+  })
+}
 export const post = (url = '', params: any = {}, config: any = {}) => {
   return new Promise((resolve, reject) => {
     const rUrl = (import.meta as any).env.VITE_BASE_API_PROXY + url
@@ -28,6 +44,24 @@ export const post = (url = '', params: any = {}, config: any = {}) => {
       .then((res: any) => {
         resultHandle(res, resolve, reject, rUrl)
       })
+      .catch((res: any) => {
+        resultHandle(res, resolve, reject, rUrl)
+      })
+  })
+}
+export const put = (url = '', params: any = {}, config: any = {}) => {
+  return new Promise((resolve, reject) => {
+    const rUrl = (import.meta as any).env.VITE_BASE_API_PROXY + url
+    request
+      .put(rUrl, params, {
+        ...config,
+      })
+      .then((res: any) => {
+        resultHandle(res, resolve, reject, rUrl)
+      })
+      .catch((res: any) => {
+        resultHandle(res, resolve, reject, rUrl)
+      })
   })
 }
 

+ 3 - 0
src/stores/modules/app.ts

@@ -4,6 +4,9 @@ import { userInfo } from '@/api/modules/global/login'
 export const useAppStore = defineStore('app', {
   state: () => ({
     userInfo: null,
+    tenantInfo: {
+      id: 0,
+    },
   }),
   getters: {},
   actions: {

+ 24 - 14
src/stores/modules/dictionary.ts

@@ -1,6 +1,7 @@
 import { defineStore } from 'pinia'
 import { tagsTenant } from '@/api/modules/knowledge/tags'
 import { ElMessage } from 'element-plus'
+import { datasetGroupsGetAllByTenantId } from '@/api/modules/knowledge/group'
 
 const listToMap = (list, labelKey = 'label', valueKey = 'value') => {
   const map = new Map()
@@ -28,38 +29,47 @@ export const useDictionaryStore = defineStore('dictionary', {
     // },
   },
   actions: {
-    initKnowledgeTags() {
+    initKnowledgeTags(tenantId) {
       if (!this.knowledgeTags.waiting) {
         this.knowledgeTags.waiting = true
-        tagsTenant(0)
+        tagsTenant(tenantId)
           .then(({ data }: any) => {
             const arr: any = data.map((v) => {
               v.label = v.name
               v.value = v.id
-              v.total = 0
+              v.total = v.targetSize
               return v
             })
             this.knowledgeTags.list = arr
             this.knowledgeTags.map = listToMap(arr)
-            this.knowledgeTags.waiting = false
           })
           .catch(({ message }: any) => {
             ElMessage.error(message)
           })
+          .finally(() => {
+            this.knowledgeTags.waiting = false
+          })
       }
     },
-    initKnowledgeGroups() {
+    initKnowledgeGroups(tenantId) {
       if (!this.knowledgeGroups.waiting) {
         this.knowledgeGroups.waiting = true
-        setTimeout(() => {
-          const arr: any = []
-          for (let i = 0; i < 100; i++) {
-            arr.push({ label: '分组' + i, value: i + '', total: i })
-          }
-          this.knowledgeGroups.list = arr
-          this.knowledgeGroups.map = listToMap(arr)
-          this.knowledgeGroups.waiting = false
-        }, 1000)
+        datasetGroupsGetAllByTenantId(tenantId)
+          .then(({ data }: any) => {
+            const arr: any = data.map((v) => {
+              v.label = v.name
+              v.value = v.id
+              return v
+            })
+            this.knowledgeGroups.list = arr
+            this.knowledgeGroups.map = listToMap(arr)
+          })
+          .catch(({ message }: any) => {
+            ElMessage.error(message)
+          })
+          .finally(() => {
+            this.knowledgeGroups.waiting = false
+          })
       }
     },
   },

+ 3 - 2
src/views/global/login/index.vue

@@ -72,9 +72,10 @@ import { computed, getCurrentInstance, reactive, ref, onMounted } from 'vue'
 import { User, Lock, Clock } from '@element-plus/icons-vue'
 import { ElMessage } from 'element-plus'
 import { loginCaptcha, loginSubmit } from '@/api/modules/global/login'
-import CzrForm from '@/components/czr-ui/CzrForm.vue'
 import { useRouter } from 'vue-router'
+import { useAppStore } from '@/stores'
 
+const AppStore = useAppStore()
 const router = useRouter()
 const emit = defineEmits([])
 const props = defineProps({})
@@ -84,7 +85,7 @@ const state: any = reactive({
     username: 'super-admin',
     password: 'Ai@2025',
     captcha: '',
-    tenantId: 0,
+    tenantId: AppStore.tenantInfo?.id,
   },
   loading: false,
   codeImg: '',

+ 1 - 3
src/views/manage/knowledge/documents/document/index.vue

@@ -345,9 +345,7 @@ onMounted(() => {
   initDictionary()
   onReset()
 })
-const initDictionary = () => {
-  DictionaryStore.initKnowledgeGroups()
-}
+const initDictionary = () => {}
 </script>
 
 <style lang="scss" scoped>

+ 1 - 3
src/views/manage/knowledge/documents/qa/index.vue

@@ -291,9 +291,7 @@ onMounted(() => {
   initDictionary()
   onReset()
 })
-const initDictionary = () => {
-  DictionaryStore.initKnowledgeGroups()
-}
+const initDictionary = () => {}
 </script>
 
 <style lang="scss" scoped>

+ 57 - 10
src/views/manage/knowledge/index.vue

@@ -149,7 +149,7 @@
                   />
                 </el-tooltip>
                 <el-tooltip
-                  :content="row.p7 ? '取消收藏' : '收藏'"
+                  :content="row.datasetCollection ? '取消收藏' : '收藏'"
                   effect="light"
                   placement="top"
                 >
@@ -157,7 +157,8 @@
                     name="star"
                     size="15"
                     class="__hover"
-                    :active="!!row.p7"
+                    :active="!!row.datasetCollection"
+                    @click.stop="onStart(row)"
                   />
                 </el-tooltip>
               </div>
@@ -182,7 +183,14 @@ import { useAppStore, useDialogStore, useDictionaryStore } from '@/stores'
 import { ElMessage } from 'element-plus'
 import tagsSelect from './tags-select.vue'
 import detailCom from './detail.vue'
-import { datasetsGetAllByPage } from '@/api/modules/knowledge'
+import {
+  datasetsGetAllByPage,
+  datasetsTagsBinding,
+} from '@/api/modules/knowledge'
+import {
+  datasetCollections,
+  datasetCollectionsDel,
+} from '@/api/modules/knowledge/collect'
 
 const AppStore = useAppStore()
 const DialogStore = useDialogStore()
@@ -223,7 +231,6 @@ watch(
 watch(
   () => state.query.form,
   (n) => {
-    console.log(n)
     if (state.query.init) {
       onSearch()
     }
@@ -239,7 +246,7 @@ const onPage = (pageNum, pageSize) => {
     pageSize: pageSize,
   }
   const params = {
-    tenantId: 0,
+    tenantId: AppStore.tenantInfo?.id,
     page: state.query.page.pageNum,
     size: state.query.page.pageSize,
   }
@@ -268,11 +275,12 @@ const onPage = (pageNum, pageSize) => {
     .then(({ data }: any) => {
       state.query.result.total = data.totalElements
       state.query.result.data = [{ empty: true }, ...data.content]
-      state.query.loading = false
     })
     .catch(({ message }: any) => {
       ElMessage.error(message)
-      state.loading = false
+    })
+    .finally(() => {
+      state.query.loading = false
     })
 }
 const onSearch = () => {
@@ -311,11 +319,50 @@ const onDel = (row: any) => {
   })
 }
 const onChangeTag = (row, tags) => {
-  row.tags = tags
-  // onSearch()
+  datasetsTagsBinding({
+    datasetId: row.id,
+    tag_ids: tags,
+  })
+    .then(() => {
+      ElMessage.success('标签绑定成功!')
+    })
+    .catch(({ message }: any) => {
+      ElMessage.error(message)
+    })
+    .finally(() => {
+      onSearch()
+    })
+}
+const onStart = (row) => {
+  if (row.datasetCollection) {
+    datasetCollectionsDel(row.id)
+      .then(() => {
+        ElMessage.success('取消收藏成功!')
+      })
+      .catch(({ message }: any) => {
+        ElMessage.error(message)
+      })
+      .finally(() => {
+        onSearch()
+      })
+  } else {
+    datasetCollections({
+      tenantId: AppStore.tenantInfo?.id,
+      targetId: row.id,
+    })
+      .then(() => {
+        ElMessage.success('收藏成功!')
+      })
+      .catch(({ message }: any) => {
+        ElMessage.error(message)
+      })
+      .finally(() => {
+        onSearch()
+      })
+  }
 }
 const initDictionary = () => {
-  DictionaryStore.initKnowledgeGroups()
+  DictionaryStore.initKnowledgeGroups(AppStore.tenantInfo?.id)
 }
 onMounted(() => {
   initDictionary()

+ 68 - 19
src/views/manage/knowledge/tags-select.vue

@@ -20,9 +20,8 @@
         >
           <SvgIcon name="tag" size="14" class="mr-1" />
           <span class="max-w-[5rem]" v-title>{{
-            value
+            value?.length > 0
               ? value
-                  .split(',')
                   .map((v) => DictionaryStore.knowledgeTags.map.get(v) || v)
                   .join(',')
               : '添加标签'
@@ -117,7 +116,10 @@
     :show-submit="false"
     :show-close="false"
   >
-    <div class="bm-form mb-[1rem] flex flex-wrap gap-2">
+    <div
+      class="bm-form mb-[1rem] flex flex-wrap gap-2"
+      v-loading="state.loading"
+    >
       <template v-for="item in DictionaryStore.knowledgeTags.list">
         <template v-if="item.__edit">
           <div
@@ -166,15 +168,18 @@ import {
   computed,
   getCurrentInstance,
   onBeforeMount,
+  onMounted,
   reactive,
   ref,
   watch,
 } from 'vue'
 import { domRootHasAttr } from '@/utils/czr-util'
-import { useDialogStore, useDictionaryStore } from '@/stores'
+import { useAppStore, useDialogStore, useDictionaryStore } from '@/stores'
 import { Search } from '@element-plus/icons-vue'
 import { ElMessage } from 'element-plus'
+import { tagsAdd, tagsDel, tagsEdit } from '@/api/modules/knowledge/tags'
 
+const AppStore = useAppStore()
 const DictionaryStore = useDictionaryStore()
 const DialogStore = useDialogStore()
 const emit = defineEmits(['onChange'])
@@ -185,20 +190,44 @@ const props = defineProps({
 })
 const { proxy }: any = getCurrentInstance()
 const state: any = reactive({
+  loading: false,
   show: false,
   text: '',
   valueMap: new Map(),
   showDialog: false,
+  init: false,
 })
 const onAdd = () => {
-  state.text = ''
-  ElMessage.success('创建标签成功!')
-  DictionaryStore.initKnowledgeTags()
+  tagsAdd({
+    tenantId: AppStore.tenantInfo?.id,
+    name: state.text,
+    type: 'dataset',
+  })
+    .then(() => {
+      state.text = ''
+      ElMessage.success('创建标签成功!')
+    })
+    .catch(({ message }: any) => {
+      ElMessage.error(message)
+    })
+    .finally(() => {
+      DictionaryStore.initKnowledgeTags(AppStore.tenantInfo?.id)
+    })
 }
 const onDel = (row) => {
   const delHandle = () => {
-    ElMessage.success('删除标签成功!')
-    DictionaryStore.initKnowledgeTags()
+    state.loading = true
+    tagsDel(row.id)
+      .then(() => {
+        ElMessage.success('删除标签成功!')
+      })
+      .catch(({ message }: any) => {
+        ElMessage.error(message)
+      })
+      .finally(() => {
+        DictionaryStore.initKnowledgeTags(AppStore.tenantInfo?.id)
+        state.loading = false
+      })
   }
   if (row.total > 0) {
     DialogStore.confirm({
@@ -216,8 +245,23 @@ const onEdit = (row) => {
   if (!row.__value) {
     row.__edit = false
   } else {
-    ElMessage.success('修改标签成功!')
-    DictionaryStore.initKnowledgeTags()
+    state.loading = true
+    tagsEdit({
+      tenantId: AppStore.tenantInfo?.id,
+      id: String(row.id),
+      name: row.__value,
+    })
+      .then(() => {
+        ElMessage.success('修改标签成功!')
+      })
+      .catch(({ message }: any) => {
+        row.__edit = false
+        ElMessage.error(message)
+      })
+      .finally(() => {
+        DictionaryStore.initKnowledgeTags(AppStore.tenantInfo?.id)
+        state.loading = false
+      })
   }
 }
 
@@ -229,12 +273,14 @@ const onMouseDown = (e) => {
 watch(
   () => state.show,
   (n) => {
-    if (n) {
-      state.text = ''
-      document.addEventListener('mousedown', onMouseDown)
-    } else {
-      document.removeEventListener('mousedown', onMouseDown)
-      emit('onChange', Array.from(state.valueMap.keys()).join(','))
+    if (state.init) {
+      if (n) {
+        state.text = ''
+        document.addEventListener('mousedown', onMouseDown)
+      } else {
+        document.removeEventListener('mousedown', onMouseDown)
+        emit('onChange', Array.from(state.valueMap.keys()))
+      }
     }
   },
   { immediate: true },
@@ -244,7 +290,7 @@ watch(
   (n) => {
     const map = new Map()
     if (n) {
-      n.split(',').forEach((v) => {
+      n?.forEach((v) => {
         map.set(v, v)
       })
     }
@@ -253,7 +299,10 @@ watch(
   { immediate: true },
 )
 onBeforeMount(() => {
-  DictionaryStore.initKnowledgeTags()
+  DictionaryStore.initKnowledgeTags(AppStore.tenantInfo?.id)
+})
+onMounted(() => {
+  state.init = true
 })
 </script>
 

+ 1 - 3
src/views/manage/model/index.vue

@@ -304,9 +304,7 @@ onMounted(() => {
   initDictionary()
   onReset()
 })
-const initDictionary = () => {
-  DictionaryStore.initKnowledgeGroups()
-}
+const initDictionary = () => {}
 </script>
 
 <style lang="scss" scoped>