mirror of
https://github.com/APIParkLab/APIPark.git
synced 2026-06-14 20:41:15 +08:00
Compare commits
6 Commits
feature/1.4
...
fix/152
| Author | SHA1 | Date | |
|---|---|---|---|
| c69a1bcb5d | |||
| b8512841b8 | |||
| 2c2227701d | |||
| 5b1f6b4670 | |||
| 197d227cd6 | |||
| b77ce23b39 |
@@ -1,8 +1,8 @@
|
||||
import { PERMISSION_DEFINITION } from '@common/const/permissions'
|
||||
import { $t } from '@common/locales'
|
||||
import { Button, Tooltip, Upload } from 'antd'
|
||||
import { ReactElement, cloneElement, useEffect, useMemo, useState } from 'react'
|
||||
import { useGlobalContext } from '../../contexts/GlobalStateContext'
|
||||
import { PERMISSION_DEFINITION } from '@common/const/permissions'
|
||||
import { $t } from '@common/locales'
|
||||
|
||||
type WithPermissionProps = {
|
||||
access?: string | string[]
|
||||
|
||||
@@ -18,7 +18,11 @@ export const checkAccess: (access: AccessDataType, accessData: Map<string, strin
|
||||
if (accLevel === 'team') {
|
||||
accessSet = new Set(Array.from(accessSet).concat(accessData?.get('team') || []))
|
||||
}
|
||||
return accessSet!.size > 0 ? hasIntersection(neededBackendAccessArr, accessSet) : false
|
||||
if (!accessSet!.size) {
|
||||
return false
|
||||
}
|
||||
const hasAccess = hasIntersection(neededBackendAccessArr, accessSet)
|
||||
return hasAccess
|
||||
}
|
||||
|
||||
const hasIntersection = (arr1: string[], set1: Set<string>) => {
|
||||
|
||||
@@ -151,15 +151,15 @@ function App() {
|
||||
form={{ validateMessages }}
|
||||
>
|
||||
<PluginEventHubProvider>
|
||||
<AppAntd className="h-full" message={{ maxCount: 1 }}>
|
||||
<PluginSlotHubProvider>
|
||||
<GlobalProvider>
|
||||
<GlobalProvider>
|
||||
<AppAntd className="h-full" message={{ maxCount: 1 }}>
|
||||
<PluginSlotHubProvider>
|
||||
<BreadcrumbProvider>
|
||||
<RenderRoutes />
|
||||
</BreadcrumbProvider>
|
||||
</GlobalProvider>
|
||||
</PluginSlotHubProvider>
|
||||
</AppAntd>
|
||||
</PluginSlotHubProvider>
|
||||
</AppAntd>
|
||||
</GlobalProvider>
|
||||
</PluginEventHubProvider>
|
||||
</ConfigProvider>
|
||||
</StyleProvider>
|
||||
|
||||
@@ -28,7 +28,7 @@ export default function ServiceCategory() {
|
||||
const { accessData } = useGlobalContext()
|
||||
const [loading, setLoading] = useState<boolean>(false)
|
||||
|
||||
const onDrop: TreeProps['onDrop'] = info => {
|
||||
const onDrop: TreeProps['onDrop'] = (info) => {
|
||||
const dropKey = info.node.key
|
||||
const dragKey = info.dragNode.key
|
||||
const dropPos = info.node.pos.split('-')
|
||||
@@ -59,7 +59,7 @@ export default function ServiceCategory() {
|
||||
|
||||
if (!info.dropToGap) {
|
||||
// Drop on the content
|
||||
loop(data, dropKey, item => {
|
||||
loop(data, dropKey, (item) => {
|
||||
item.children = item.children || []
|
||||
// where to insert. New item was inserted to the start of the array in this example, but can be anywhere
|
||||
item.children.unshift(dragObj)
|
||||
@@ -129,9 +129,9 @@ export default function ServiceCategory() {
|
||||
const treeData = useMemo(() => {
|
||||
setExpandedKeys([])
|
||||
const loop = (data: CategorizesType[]): DataNode[] =>
|
||||
data?.map(item => {
|
||||
data?.map((item) => {
|
||||
if (item.children) {
|
||||
setExpandedKeys(prev => [...prev, item.id])
|
||||
setExpandedKeys((prev) => [...prev, item.id])
|
||||
return {
|
||||
title: (
|
||||
<TreeWithMore stopClick={false} dropdownMenu={dropdownMenu(item as CategorizesType)}>
|
||||
@@ -169,40 +169,22 @@ export default function ServiceCategory() {
|
||||
return !checkAccess(permission, accessData)
|
||||
}
|
||||
|
||||
const openModal = (
|
||||
type: 'addCate' | 'addChildCate' | 'renameCate' | 'delete',
|
||||
entity?: CategorizesType
|
||||
) => {
|
||||
const openModal = (type: 'addCate' | 'addChildCate' | 'renameCate' | 'delete', entity?: CategorizesType) => {
|
||||
let title: string = ''
|
||||
let content: string | React.ReactNode = ''
|
||||
switch (type) {
|
||||
case 'addCate':
|
||||
case 'addCate': {
|
||||
title = $t('添加分类')
|
||||
content = (
|
||||
<ServiceHubCategoryConfig WithPermission={WithPermission} ref={addRef} type={type} />
|
||||
)
|
||||
content = <ServiceHubCategoryConfig ref={addRef} type={type} />
|
||||
break
|
||||
}
|
||||
case 'addChildCate':
|
||||
title = $t('添加子分类')
|
||||
content = (
|
||||
<ServiceHubCategoryConfig
|
||||
WithPermission={WithPermission}
|
||||
ref={addChildRef}
|
||||
type={type}
|
||||
entity={entity}
|
||||
/>
|
||||
)
|
||||
content = <ServiceHubCategoryConfig ref={addChildRef} type={type} entity={entity} />
|
||||
break
|
||||
case 'renameCate':
|
||||
title = $t('重命名分类')
|
||||
content = (
|
||||
<ServiceHubCategoryConfig
|
||||
WithPermission={WithPermission}
|
||||
ref={renameRef}
|
||||
type={type}
|
||||
entity={entity}
|
||||
/>
|
||||
)
|
||||
content = <ServiceHubCategoryConfig ref={renameRef} type={type} entity={entity} />
|
||||
break
|
||||
case 'delete':
|
||||
title = $t('删除')
|
||||
@@ -215,19 +197,19 @@ export default function ServiceCategory() {
|
||||
onOk: () => {
|
||||
switch (type) {
|
||||
case 'addCate':
|
||||
return addRef.current?.save().then(res => {
|
||||
return addRef.current?.save().then((res) => {
|
||||
if (res === true) getCategoryList()
|
||||
})
|
||||
case 'addChildCate':
|
||||
return addChildRef.current?.save().then(res => {
|
||||
return addChildRef.current?.save().then((res) => {
|
||||
if (res === true) getCategoryList()
|
||||
})
|
||||
case 'renameCate':
|
||||
return renameRef.current?.save().then(res => {
|
||||
return renameRef.current?.save().then((res) => {
|
||||
if (res === true) getCategoryList()
|
||||
})
|
||||
case 'delete':
|
||||
return deleteCate(entity!).then(res => {
|
||||
return deleteCate(entity!).then((res) => {
|
||||
if (res === true) getCategoryList()
|
||||
})
|
||||
}
|
||||
@@ -249,7 +231,7 @@ export default function ServiceCategory() {
|
||||
method: 'DELETE',
|
||||
eoParams: { catalogue: entity.id }
|
||||
})
|
||||
.then(response => {
|
||||
.then((response) => {
|
||||
const { code, msg } = response
|
||||
if (code === STATUS_CODE.SUCCESS) {
|
||||
message.success(msg || $t(RESPONSE_TIPS.success))
|
||||
@@ -259,14 +241,14 @@ export default function ServiceCategory() {
|
||||
reject(msg || $t(RESPONSE_TIPS.error))
|
||||
}
|
||||
})
|
||||
.catch(errorInfo => reject(errorInfo))
|
||||
.catch((errorInfo) => reject(errorInfo))
|
||||
})
|
||||
}
|
||||
|
||||
const sortCategories = (newData: CategorizesType[]) => {
|
||||
setLoading(true)
|
||||
fetchData<BasicResponse<null>>('catalogue/sort', { method: 'PUT', eoBody: newData })
|
||||
.then(response => {
|
||||
.then((response) => {
|
||||
const { code, msg } = response
|
||||
if (code === STATUS_CODE.SUCCESS) {
|
||||
getCategoryList()
|
||||
@@ -288,7 +270,7 @@ export default function ServiceCategory() {
|
||||
fetchData<BasicResponse<{ catalogues: CategorizesType[]; tags: EntityItem[] }>>('catalogues', {
|
||||
method: 'GET'
|
||||
})
|
||||
.then(response => {
|
||||
.then((response) => {
|
||||
const { code, data, msg } = response
|
||||
if (code === STATUS_CODE.SUCCESS) {
|
||||
setGData(data.catalogues)
|
||||
@@ -308,11 +290,7 @@ export default function ServiceCategory() {
|
||||
|
||||
return (
|
||||
<div className="border border-solid border-BORDER p-[20px] rounded-[10px] ">
|
||||
<Spin
|
||||
indicator={<LoadingOutlined style={{ fontSize: 24 }} spin />}
|
||||
spinning={loading}
|
||||
className=""
|
||||
>
|
||||
<Spin indicator={<LoadingOutlined style={{ fontSize: 24 }} spin />} spinning={loading} className="">
|
||||
<Tree
|
||||
showIcon
|
||||
draggable
|
||||
|
||||
@@ -10,132 +10,131 @@ import {
|
||||
import { App, Form, Input } from 'antd'
|
||||
import { forwardRef, useEffect, useImperativeHandle } from 'react'
|
||||
|
||||
export const ServiceHubCategoryConfig = forwardRef<
|
||||
ServiceHubCategoryConfigHandle,
|
||||
ServiceHubCategoryConfigProps
|
||||
>((props, ref) => {
|
||||
const { message } = App.useApp()
|
||||
const [form] = Form.useForm()
|
||||
const { type, entity } = props
|
||||
const { fetchData } = useFetch()
|
||||
export const ServiceHubCategoryConfig = forwardRef<ServiceHubCategoryConfigHandle, ServiceHubCategoryConfigProps>(
|
||||
(props, ref) => {
|
||||
const { message } = App.useApp()
|
||||
const [form] = Form.useForm()
|
||||
const { type, entity } = props
|
||||
const { fetchData } = useFetch()
|
||||
|
||||
const save: () => Promise<boolean | string> = () => {
|
||||
const url: string = 'catalogue'
|
||||
let method: string
|
||||
switch (type) {
|
||||
case 'addCate':
|
||||
case 'addChildCate':
|
||||
method = 'POST'
|
||||
break
|
||||
case 'renameCate':
|
||||
method = 'PUT'
|
||||
break
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!url || !method) {
|
||||
reject($t(RESPONSE_TIPS.error))
|
||||
return
|
||||
const save: () => Promise<boolean | string> = () => {
|
||||
const url: string = 'catalogue'
|
||||
let method: string
|
||||
switch (type) {
|
||||
case 'addCate':
|
||||
case 'addChildCate':
|
||||
method = 'POST'
|
||||
break
|
||||
case 'renameCate':
|
||||
method = 'PUT'
|
||||
break
|
||||
}
|
||||
form
|
||||
.validateFields()
|
||||
.then(value => {
|
||||
fetchData<BasicResponse<null>>(url, {
|
||||
method,
|
||||
eoBody: value,
|
||||
eoParams: { ...(type === 'renameCate' ? { catalogue: value.id } : undefined) }
|
||||
})
|
||||
.then(response => {
|
||||
const { code, msg } = response
|
||||
if (code === STATUS_CODE.SUCCESS) {
|
||||
message.success(msg || $t(RESPONSE_TIPS.success))
|
||||
resolve(true)
|
||||
} else {
|
||||
message.error(msg || $t(RESPONSE_TIPS.error))
|
||||
reject(msg || $t(RESPONSE_TIPS.error))
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!url || !method) {
|
||||
reject($t(RESPONSE_TIPS.error))
|
||||
return
|
||||
}
|
||||
form
|
||||
.validateFields()
|
||||
.then((value) => {
|
||||
fetchData<BasicResponse<null>>(url, {
|
||||
method,
|
||||
eoBody: value,
|
||||
eoParams: { ...(type === 'renameCate' ? { catalogue: value.id } : undefined) }
|
||||
})
|
||||
.catch(errorInfo => reject(errorInfo))
|
||||
})
|
||||
.catch(errorInfo => reject(errorInfo))
|
||||
})
|
||||
}
|
||||
|
||||
useImperativeHandle(ref, () => ({
|
||||
save
|
||||
}))
|
||||
|
||||
useEffect(() => {
|
||||
switch (type) {
|
||||
case 'addCate':
|
||||
form.setFieldsValue({})
|
||||
break
|
||||
case 'addChildCate':
|
||||
form.setFieldsValue({ parent: entity!.id })
|
||||
break
|
||||
case 'renameCate':
|
||||
form.setFieldsValue(entity)
|
||||
break
|
||||
.then((response) => {
|
||||
const { code, msg } = response
|
||||
if (code === STATUS_CODE.SUCCESS) {
|
||||
message.success(msg || $t(RESPONSE_TIPS.success))
|
||||
resolve(true)
|
||||
} else {
|
||||
message.error(msg || $t(RESPONSE_TIPS.error))
|
||||
reject(msg || $t(RESPONSE_TIPS.error))
|
||||
}
|
||||
})
|
||||
.catch((errorInfo) => reject(errorInfo))
|
||||
})
|
||||
.catch((errorInfo) => reject(errorInfo))
|
||||
})
|
||||
}
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<WithPermission
|
||||
access={
|
||||
type === 'addCate'
|
||||
? 'system.api_market.service_classification.add'
|
||||
: 'system.api_market.service_classification.edit'
|
||||
useImperativeHandle(ref, () => ({
|
||||
save
|
||||
}))
|
||||
|
||||
useEffect(() => {
|
||||
switch (type) {
|
||||
case 'addCate':
|
||||
form.setFieldsValue({})
|
||||
break
|
||||
case 'addChildCate':
|
||||
form.setFieldsValue({ parent: entity!.id })
|
||||
break
|
||||
case 'renameCate':
|
||||
form.setFieldsValue(entity)
|
||||
break
|
||||
}
|
||||
>
|
||||
<Form
|
||||
layout="vertical"
|
||||
scrollToFirstError
|
||||
labelAlign="left"
|
||||
form={form}
|
||||
className="mx-auto"
|
||||
name="serviceHubCategoryConfig"
|
||||
autoComplete="off"
|
||||
>
|
||||
{type === 'renameCate' && (
|
||||
<Form.Item<ServiceHubCategoryConfigFieldType>
|
||||
label={$t('ID')}
|
||||
name="id"
|
||||
hidden
|
||||
rules={[{ required: true, whitespace: true }]}
|
||||
>
|
||||
<Input className="w-INPUT_NORMAL" placeholder={$t(PLACEHOLDER.input)} />
|
||||
</Form.Item>
|
||||
)}
|
||||
{(type === 'addCate' || type === 'renameCate') && (
|
||||
<Form.Item<ServiceHubCategoryConfigFieldType>
|
||||
label={$t('分类名称')}
|
||||
name="name"
|
||||
rules={[{ required: true, whitespace: true }]}
|
||||
>
|
||||
<Input className="w-INPUT_NORMAL" placeholder={$t(PLACEHOLDER.input)} />
|
||||
</Form.Item>
|
||||
)}
|
||||
}, [])
|
||||
|
||||
{type === 'addChildCate' && (
|
||||
<>
|
||||
return (
|
||||
<WithPermission
|
||||
access={
|
||||
type === 'addCate'
|
||||
? 'system.api_market.service_classification.add'
|
||||
: 'system.api_market.service_classification.edit'
|
||||
}
|
||||
>
|
||||
<Form
|
||||
layout="vertical"
|
||||
scrollToFirstError
|
||||
labelAlign="left"
|
||||
form={form}
|
||||
className="mx-auto"
|
||||
name="serviceHubCategoryConfig"
|
||||
autoComplete="off"
|
||||
>
|
||||
{type === 'renameCate' && (
|
||||
<Form.Item<ServiceHubCategoryConfigFieldType>
|
||||
label={$t('父分类 ID')}
|
||||
name="parent"
|
||||
label={$t('ID')}
|
||||
name="id"
|
||||
hidden
|
||||
rules={[{ required: true, whitespace: true }]}
|
||||
>
|
||||
<Input className="w-INPUT_NORMAL" placeholder={$t(PLACEHOLDER.input)} />
|
||||
</Form.Item>
|
||||
|
||||
)}
|
||||
{(type === 'addCate' || type === 'renameCate') && (
|
||||
<Form.Item<ServiceHubCategoryConfigFieldType>
|
||||
label={$t('子分类名称')}
|
||||
label={$t('分类名称')}
|
||||
name="name"
|
||||
rules={[{ required: true, whitespace: true }]}
|
||||
>
|
||||
<Input className="w-INPUT_NORMAL" placeholder={$t(PLACEHOLDER.input)} />
|
||||
</Form.Item>
|
||||
</>
|
||||
)}
|
||||
</Form>
|
||||
</WithPermission>
|
||||
)
|
||||
})
|
||||
)}
|
||||
|
||||
{type === 'addChildCate' && (
|
||||
<>
|
||||
<Form.Item<ServiceHubCategoryConfigFieldType>
|
||||
label={$t('父分类 ID')}
|
||||
name="parent"
|
||||
hidden
|
||||
rules={[{ required: true, whitespace: true }]}
|
||||
>
|
||||
<Input className="w-INPUT_NORMAL" placeholder={$t(PLACEHOLDER.input)} />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item<ServiceHubCategoryConfigFieldType>
|
||||
label={$t('子分类名称')}
|
||||
name="name"
|
||||
rules={[{ required: true, whitespace: true }]}
|
||||
>
|
||||
<Input className="w-INPUT_NORMAL" placeholder={$t(PLACEHOLDER.input)} />
|
||||
</Form.Item>
|
||||
</>
|
||||
)}
|
||||
</Form>
|
||||
</WithPermission>
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { DefaultOptionType } from 'antd/es/select'
|
||||
import { EntityItem } from '@common/const/type'
|
||||
import { SubscribeEnum, SubscribeFromEnum } from '@core/const/system/const'
|
||||
import WithPermission from '@common/components/aoplatform/WithPermission'
|
||||
import { DefaultOptionType } from 'antd/es/select'
|
||||
|
||||
export type ServiceBasicInfoType = {
|
||||
app: EntityItem
|
||||
@@ -37,7 +36,6 @@ export type ServiceHubCategoryConfigFieldType = {
|
||||
export type ServiceHubCategoryConfigProps = {
|
||||
type: 'addCate' | 'addChildCate' | 'renameCate'
|
||||
entity?: { [k: string]: unknown }
|
||||
WithPermission: typeof WithPermission
|
||||
}
|
||||
|
||||
export type ServiceHubCategoryConfigHandle = {
|
||||
|
||||
@@ -5,7 +5,7 @@ import WithPermission from '@common/components/aoplatform/WithPermission'
|
||||
import { BasicResponse, DATA_SHOW_TYPE_OPTIONS, RESPONSE_TIPS, STATUS_CODE } from '@common/const/const'
|
||||
import { SimpleTeamItem } from '@common/const/type'
|
||||
import { useBreadcrumb } from '@common/contexts/BreadcrumbContext'
|
||||
import { GlobalProvider, useGlobalContext } from '@common/contexts/GlobalStateContext'
|
||||
import { useGlobalContext } from '@common/contexts/GlobalStateContext'
|
||||
import { useFetch } from '@common/hooks/http'
|
||||
import { $t } from '@common/locales'
|
||||
import { RouterParams } from '@core/components/aoplatform/RenderRoutes'
|
||||
@@ -158,28 +158,8 @@ export default function ServiceHubManagement() {
|
||||
switch (type) {
|
||||
case 'add':
|
||||
title = $t('添加消费者')
|
||||
content = (
|
||||
<GlobalProvider>
|
||||
<ManagementConfig ref={addManagementRef} dataShowType={dataShowType} type={type} teamId={teamId!} />
|
||||
</GlobalProvider>
|
||||
)
|
||||
content = <ManagementConfig ref={addManagementRef} dataShowType={dataShowType} type={type} teamId={teamId!} />
|
||||
break
|
||||
// case 'edit':{
|
||||
// title='配置 Open Api'
|
||||
// message.loading('正在加载数据')
|
||||
// const {code,data,msg} = await fetchData<BasicResponse<{app:ManagementConfigFieldType}>>('external-app',{method:'GET',eoParams:{id:entity!.id}})
|
||||
// message.destroy()
|
||||
// if(code === STATUS_CODE.SUCCESS){
|
||||
// content=<ManagementConfig ref={editManagementRef} type={type} entity={data.app}/>
|
||||
// }else{
|
||||
// message.error(msg || $t(RESPONSE_TIPS.error))
|
||||
// return
|
||||
// }
|
||||
// break;}
|
||||
// case 'delete':
|
||||
// title='删除'
|
||||
// content='该数据删除后将无法找回,请确认是否删除?'
|
||||
// break;
|
||||
}
|
||||
|
||||
modal.confirm({
|
||||
|
||||
Reference in New Issue
Block a user