浏览代码

类型管理

CzRger 3 月之前
父节点
当前提交
db56981cb5

+ 5 - 2
web/app/components/header/account-setting/knowledges-page/index.tsx

@@ -36,8 +36,11 @@ const KnowledgesPage = () => {
   const { userProfile, currentWorkspace, isCurrentWorkspaceOwner, isCurrentWorkspaceManager, systemFeatures } = useAppContext()
   const { userProfile, currentWorkspace, isCurrentWorkspaceOwner, isCurrentWorkspaceManager, systemFeatures } = useAppContext()
   const { data, mutate }: any = useSWR(
   const { data, mutate }: any = useSWR(
     {
     {
-      url: '/workspaces/123123',
-      params: {},
+      url: '/external_applications',
+      params: {
+        page: 1,
+        limit: 1000,
+      },
     },
     },
     fetchKnowledges,
     fetchKnowledges,
   )
   )

+ 7 - 8
web/app/components/header/account-setting/types-page/detail-modal/index.tsx

@@ -18,22 +18,21 @@ const InviteModal = ({
 
 
   const handleSave = useCallback(async () => {
   const handleSave = useCallback(async () => {
     try {
     try {
-      let res: any = () => {}
+      let res
       if (transfer.mode === 'add') {
       if (transfer.mode === 'add') {
         res = await addType({
         res = await addType({
-          url: '/workspaces/123123',
-          body: { name },
+          url: '/tags',
+          body: { name, type: 'knowledge_category' },
         })
         })
       }
       }
       else {
       else {
         res = await editType({
         res = await editType({
-          url: '/workspaces/123123',
-          body: { id: transfer.id, name },
+          url: `/tags/${transfer.row.id}`,
+          body: { name },
         })
         })
       }
       }
-      const { result }: any = res
-      console.log(result)
-      if (result === 'success') {
+      const { id }: any = res
+      if (id) {
         onCancel()
         onCancel()
         onSend()
         onSend()
       }
       }

+ 37 - 8
web/app/components/header/account-setting/types-page/index.tsx

@@ -8,7 +8,7 @@ import DetailModal from './detail-modal'
 import { useContext } from 'use-context-selector'
 import { useContext } from 'use-context-selector'
 import { RiAddLine } from '@remixicon/react'
 import { RiAddLine } from '@remixicon/react'
 import { useTranslation } from 'react-i18next'
 import { useTranslation } from 'react-i18next'
-import { fetchTypes } from '@/service/common'
+import { delType, fetchTypes } from '@/service/common'
 import I18n from '@/context/i18n'
 import I18n from '@/context/i18n'
 import { useAppContext } from '@/context/app-context'
 import { useAppContext } from '@/context/app-context'
 import LogoEmbeddedChatHeader from '@/app/components/base/logo/logo-embedded-chat-header'
 import LogoEmbeddedChatHeader from '@/app/components/base/logo/logo-embedded-chat-header'
@@ -19,6 +19,7 @@ import UpgradeBtn from '@/app/components/billing/upgrade-btn'
 import { NUM_INFINITE } from '@/app/components/billing/config'
 import { NUM_INFINITE } from '@/app/components/billing/config'
 import { LanguagesSupported } from '@/i18n/language'
 import { LanguagesSupported } from '@/i18n/language'
 import cn from '@/utils/classnames'
 import cn from '@/utils/classnames'
+import Confirm from '@/app/components/base/confirm'
 dayjs.extend(relativeTime)
 dayjs.extend(relativeTime)
 
 
 const TypesPage = () => {
 const TypesPage = () => {
@@ -28,21 +29,37 @@ const TypesPage = () => {
   const { userProfile, currentWorkspace, isCurrentWorkspaceOwner, isCurrentWorkspaceManager, systemFeatures } = useAppContext()
   const { userProfile, currentWorkspace, isCurrentWorkspaceOwner, isCurrentWorkspaceManager, systemFeatures } = useAppContext()
   const { data, mutate }: any = useSWR(
   const { data, mutate }: any = useSWR(
     {
     {
-      url: '/workspaces/123123',
-      params: {},
+      url: '/tags/page',
+      params: {
+        page: 1,
+        limit: 1000,
+        tag_type: 'knowledge_category',
+      },
     },
     },
     fetchTypes,
     fetchTypes,
   )
   )
   const [detailModalVisible, setDetailModalVisible] = useState(false)
   const [detailModalVisible, setDetailModalVisible] = useState(false)
   const [transfer, setTransfer] = useState<any>({
   const [transfer, setTransfer] = useState<any>({
     mode: 'add',
     mode: 'add',
-    id: null,
+    row: {},
   })
   })
   const typeList = data?.data || []
   const typeList = data?.data || []
   const { plan, enableBilling } = useProviderContext()
   const { plan, enableBilling } = useProviderContext()
   const isNotUnlimitedMemberPlan = enableBilling && plan.type !== Plan.team && plan.type !== Plan.enterprise
   const isNotUnlimitedMemberPlan = enableBilling && plan.type !== Plan.team && plan.type !== Plan.enterprise
   const isMemberFull = enableBilling && isNotUnlimitedMemberPlan && typeList.length >= plan.total.teamMembers
   const isMemberFull = enableBilling && isNotUnlimitedMemberPlan && typeList.length >= plan.total.teamMembers
-
+  const [showConfirmDelete, setShowConfirmDelete] = useState(false)
+  const [row, setRow] = useState<any>({})
+  const handleDel = async () => {
+    try {
+      await delType({
+        url: `/tags/${row.id}`,
+        body: {},
+      })
+      setShowConfirmDelete(false)
+      mutate()
+    }
+    catch (e) { }
+  }
   return (
   return (
     <>
     <>
       <div className='flex flex-col'>
       <div className='flex flex-col'>
@@ -93,9 +110,9 @@ const TypesPage = () => {
               typeList.map((type: any) => (
               typeList.map((type: any) => (
                 <div key={type.id} className='flex justify-between border-b border-divider-subtle'>
                 <div key={type.id} className='flex justify-between border-b border-divider-subtle'>
                   <div className='system-sm-regular flex shrink-0 grow items-center px-3 py-2 text-text-secondary'>{type.name}</div>
                   <div className='system-sm-regular flex shrink-0 grow items-center px-3 py-2 text-text-secondary'>{type.name}</div>
-                  <div className='system-sm-regular w-[200px] shrink-0 items-center py-2 text-center text-text-secondary'>{type.relation}</div>
+                  <div className='system-sm-regular w-[200px] shrink-0 items-center py-2 text-center text-text-secondary'>{type.binding_count}</div>
                   <div className='flex w-[120px] shrink-0 items-center justify-center'>
                   <div className='flex w-[120px] shrink-0 items-center justify-center'>
-                    <Button variant='ghost-accent' size='small' className={cn('shrink-0')} disabled={!isCurrentWorkspaceManager || isMemberFull || Number(type.relation) > 0}
+                    <Button variant='ghost-accent' size='small' className={cn('shrink-0')} disabled={!isCurrentWorkspaceManager || isMemberFull || Number(type.binding_count) > 0}
                       onClick={() => {
                       onClick={() => {
                         setTransfer({
                         setTransfer({
                           mode: 'edit',
                           mode: 'edit',
@@ -106,7 +123,10 @@ const TypesPage = () => {
                       <RiAddLine className='mr-1 h-4 w-4' />
                       <RiAddLine className='mr-1 h-4 w-4' />
                       编辑
                       编辑
                     </Button>
                     </Button>
-                    <Button variant='ghost' size='small' className={cn('shrink-0 text-red-600')} disabled={!isCurrentWorkspaceManager || isMemberFull} onClick={() => setDetailModalVisible(true)}>
+                    <Button variant='ghost' size='small' className={cn('shrink-0 text-red-600')} disabled={!isCurrentWorkspaceManager || isMemberFull} onClick={() => {
+                      setRow(type)
+                      setShowConfirmDelete(true)
+                    }}>
                       <RiAddLine className='mr-1 h-4 w-4' />
                       <RiAddLine className='mr-1 h-4 w-4' />
                       刪除
                       刪除
                     </Button>
                     </Button>
@@ -128,6 +148,15 @@ const TypesPage = () => {
           />
           />
         )
         )
       }
       }
+      {showConfirmDelete && (
+        <Confirm
+          title="删除确认"
+          content={`请确认是否删除${row.name}?`}
+          isShow={showConfirmDelete}
+          onConfirm={handleDel}
+          onCancel={() => setShowConfirmDelete(false)}
+        />
+      )}
     </>
     </>
   )
   )
 }
 }

+ 56 - 65
web/service/common.ts

@@ -101,47 +101,47 @@ export const fetchMembers: Fetcher<{ accounts: Member[] | null }, { url: string;
   return get<{ accounts: Member[] | null }>(url, { params })
   return get<{ accounts: Member[] | null }>(url, { params })
 }
 }
 
 
-export const fetchTypes = ({ url, params }) => {
-  // return get<{ accounts: Member[] | null }>(url, { params })
+export const fetchTypes = ({ url, params }: any) => {
   console.log('查询类型列表')
   console.log('查询类型列表')
-  return new Promise((resolve) => {
-    setTimeout(() => {
-      const arr: any = []
-      for (let i = 1; i < 10; i++) {
-        arr.push({
-          id: i,
-          name: `类型${i}`,
-          relation: i % 2,
-        })
-      }
-      resolve({
-        data: arr,
-      })
-    }, 1000)
-  })
-}
-
-export const fetchKnowledges = ({ url, params }) => {
-  // return get<{ accounts: Member[] | null }>(url, { params })
+  return get(url, { params })
+  // return new Promise((resolve) => {
+  //   setTimeout(() => {
+  //     const arr: any = []
+  //     for (let i = 1; i < 10; i++) {
+  //       arr.push({
+  //         id: i,
+  //         name: `类型${i}`,
+  //         relation: i % 2,
+  //       })
+  //     }
+  //     resolve({
+  //       data: arr,
+  //     })
+  //   }, 1000)
+  // })
+}
+
+export const fetchKnowledges = ({ url, params }: any) => {
   console.log('查询知识服务')
   console.log('查询知识服务')
-  return new Promise((resolve) => {
-    setTimeout(() => {
-      const arr: any = []
-      for (let i = 1; i < 10; i++) {
-        arr.push({
-          id: i,
-          serviceType: i % 3 + 1,
-          serviceName: `深圳口岸服务网${i}`,
-          url: '74.10.28.118',
-          status: i % 2,
-          time: '2021-09-22 14:22:22',
-        })
-      }
-      resolve({
-        data: arr,
-      })
-    }, 1000)
-  })
+  return get(url, { params })
+  // return new Promise((resolve) => {
+  //   setTimeout(() => {
+  //     const arr: any = []
+  //     for (let i = 1; i < 10; i++) {
+  //       arr.push({
+  //         id: i,
+  //         serviceType: i % 3 + 1,
+  //         serviceName: `深圳口岸服务网${i}`,
+  //         url: '74.10.28.118',
+  //         status: i % 2,
+  //         time: '2021-09-22 14:22:22',
+  //       })
+  //     }
+  //     resolve({
+  //       data: arr,
+  //     })
+  //   }, 1000)
+  // })
 }
 }
 
 
 export const fetchMoulds = ({ url, params }) => {
 export const fetchMoulds = ({ url, params }) => {
@@ -191,31 +191,22 @@ export const deleteMemberOrCancelInvitation: Fetcher<CommonResponse, { url: stri
   return del<CommonResponse>(url)
   return del<CommonResponse>(url)
 }
 }
 
 
-export const addType = ({ url, body }) => {
-  // return post<InvitationResponse>(url, { body })
-  console.log('新增类型', body)
-  return new Promise((resolve) => {
-    setTimeout(() => {
-      resolve({
-        result: 'success',
-      })
-    }, 1000)
-  })
+export const addType = ({ url, body }: any) => {
+  console.log('新增类型', url, body)
+  return post(url, { body })
 }
 }
 
 
-export const editType = ({ url, body }) => {
-  // return post<InvitationResponse>(url, { body })
-  console.log('编辑类型', body)
-  return new Promise((resolve) => {
-    setTimeout(() => {
-      resolve({
-        result: 'success',
-      })
-    }, 1000)
-  })
+export const editType = ({ url, body }: any) => {
+  console.log('编辑类型', url, body)
+  return patch(url, { body })
+}
+
+export const delType = ({ url, body }: any) => {
+  console.log('删除类型', url, body)
+  return del(url, { body })
 }
 }
 
 
-export const addKnowledge = ({ url, body }) => {
+export const addKnowledge = ({ url, body }: any) => {
   // return post<InvitationResponse>(url, { body })
   // return post<InvitationResponse>(url, { body })
   console.log('新增知识', body)
   console.log('新增知识', body)
   return new Promise((resolve) => {
   return new Promise((resolve) => {
@@ -227,7 +218,7 @@ export const addKnowledge = ({ url, body }) => {
   })
   })
 }
 }
 
 
-export const editKnowledge = ({ url, body }) => {
+export const editKnowledge = ({ url, body }: any) => {
   // return post<InvitationResponse>(url, { body })
   // return post<InvitationResponse>(url, { body })
   console.log('编辑知识', body)
   console.log('编辑知识', body)
   return new Promise((resolve) => {
   return new Promise((resolve) => {
@@ -239,7 +230,7 @@ export const editKnowledge = ({ url, body }) => {
   })
   })
 }
 }
 
 
-export const addMouldFile = ({ url, body }) => {
+export const addMouldFile = ({ url, body }: any) => {
   // return post<InvitationResponse>(url, { body })
   // return post<InvitationResponse>(url, { body })
   console.log('新增模板文件', body)
   console.log('新增模板文件', body)
   return new Promise((resolve) => {
   return new Promise((resolve) => {
@@ -251,7 +242,7 @@ export const addMouldFile = ({ url, body }) => {
   })
   })
 }
 }
 
 
-export const delMouldFile = ({ url, body }) => {
+export const delMouldFile = ({ url, body }: any) => {
   // return post<InvitationResponse>(url, { body })
   // return post<InvitationResponse>(url, { body })
   console.log('删除模板文件', body)
   console.log('删除模板文件', body)
   return new Promise((resolve) => {
   return new Promise((resolve) => {
@@ -263,7 +254,7 @@ export const delMouldFile = ({ url, body }) => {
   })
   })
 }
 }
 
 
-export const handleExamine = ({ url, body }) => {
+export const handleExamine = ({ url, body }: any) => {
   // return post<InvitationResponse>(url, { body })
   // return post<InvitationResponse>(url, { body })
   console.log('处理上下线审核', body)
   console.log('处理上下线审核', body)
   return new Promise((resolve) => {
   return new Promise((resolve) => {
@@ -275,7 +266,7 @@ export const handleExamine = ({ url, body }) => {
   })
   })
 }
 }
 
 
-export const applyExamine = ({ url, body }) => {
+export const applyExamine = ({ url, body }: any) => {
   // return post<InvitationResponse>(url, { body })
   // return post<InvitationResponse>(url, { body })
   console.log('提交上下线审核', body)
   console.log('提交上下线审核', body)
   return new Promise((resolve) => {
   return new Promise((resolve) => {