mirror of
https://github.com/APIParkLab/APIPark.git
synced 2026-06-14 20:41:15 +08:00
Compare commits
7 Commits
v1.4.0-beta
...
fix/152
| Author | SHA1 | Date | |
|---|---|---|---|
| c69a1bcb5d | |||
| b8512841b8 | |||
| 2c2227701d | |||
| 5b1f6b4670 | |||
| 0aa5ffd2c2 | |||
| 197d227cd6 | |||
| b77ce23b39 |
@@ -4,48 +4,48 @@ import { Icon } from '@iconify/react/dist/iconify.js'
|
|||||||
import { Button, Dropdown } from 'antd'
|
import { Button, Dropdown } from 'antd'
|
||||||
import { memo, useEffect, useMemo } from 'react'
|
import { memo, useEffect, useMemo } from 'react'
|
||||||
|
|
||||||
|
const LanguageItems = [
|
||||||
|
{
|
||||||
|
key: 'en-US',
|
||||||
|
label: (
|
||||||
|
<Button key="en" type="text" className="flex items-center p-0 bg-transparent border-none">
|
||||||
|
English
|
||||||
|
</Button>
|
||||||
|
),
|
||||||
|
title: 'English'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'ja-JP',
|
||||||
|
label: (
|
||||||
|
<Button key="jp" type="text" className="flex items-center p-0 bg-transparent border-none">
|
||||||
|
日本語
|
||||||
|
</Button>
|
||||||
|
),
|
||||||
|
title: '日本語'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'zh-TW',
|
||||||
|
label: (
|
||||||
|
<Button key="tw" type="text" className="flex items-center p-0 bg-transparent border-none">
|
||||||
|
繁體中文
|
||||||
|
</Button>
|
||||||
|
),
|
||||||
|
title: '繁體中文'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'zh-CN',
|
||||||
|
label: (
|
||||||
|
<Button key="cn" type="text" className="flex items-center p-0 bg-transparent border-none">
|
||||||
|
简体中文
|
||||||
|
</Button>
|
||||||
|
),
|
||||||
|
title: '简体中文'
|
||||||
|
}
|
||||||
|
]
|
||||||
const LanguageSetting = ({ mode = 'light' }: { mode?: 'dark' | 'light' }) => {
|
const LanguageSetting = ({ mode = 'light' }: { mode?: 'dark' | 'light' }) => {
|
||||||
const { dispatch, state } = useGlobalContext()
|
const { dispatch, state } = useGlobalContext()
|
||||||
const items = [
|
|
||||||
{
|
|
||||||
key: 'en-US',
|
|
||||||
label: (
|
|
||||||
<Button key="en" type="text" className="flex items-center p-0 bg-transparent border-none">
|
|
||||||
English
|
|
||||||
</Button>
|
|
||||||
),
|
|
||||||
title: 'English'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: 'ja-JP',
|
|
||||||
label: (
|
|
||||||
<Button key="jp" type="text" className="flex items-center p-0 bg-transparent border-none">
|
|
||||||
日本語
|
|
||||||
</Button>
|
|
||||||
),
|
|
||||||
title: '日本語'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: 'zh-TW',
|
|
||||||
label: (
|
|
||||||
<Button key="tw" type="text" className="flex items-center p-0 bg-transparent border-none">
|
|
||||||
繁體中文
|
|
||||||
</Button>
|
|
||||||
),
|
|
||||||
title: '繁體中文'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
key: 'zh-CN',
|
|
||||||
label: (
|
|
||||||
<Button key="cn" type="text" className="flex items-center p-0 bg-transparent border-none">
|
|
||||||
简体中文
|
|
||||||
</Button>
|
|
||||||
),
|
|
||||||
title: '简体中文'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
|
|
||||||
const langLabel = useMemo(() => items.find((item) => item?.key === state.language)?.title, [state.language])
|
const langLabel = useMemo(() => LanguageItems.find((item) => item?.key === state.language)?.title, [state.language])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const savedLang = i18n.language || sessionStorage.getItem('i18nextLng')
|
const savedLang = i18n.language || sessionStorage.getItem('i18nextLng')
|
||||||
@@ -53,17 +53,17 @@ const LanguageSetting = ({ mode = 'light' }: { mode?: 'dark' | 'light' }) => {
|
|||||||
dispatch({ type: 'UPDATE_LANGUAGE', language: savedLang })
|
dispatch({ type: 'UPDATE_LANGUAGE', language: savedLang })
|
||||||
} else if (!savedLang) {
|
} else if (!savedLang) {
|
||||||
const browserLang = navigator.language
|
const browserLang = navigator.language
|
||||||
const supportedLang = items.find((item) => item.key === browserLang) ? browserLang : 'zh-CN'
|
const supportedLang = LanguageItems.find((item) => item.key === browserLang) ? browserLang : 'zh-CN'
|
||||||
|
if (state.language === supportedLang) return
|
||||||
dispatch({ type: 'UPDATE_LANGUAGE', language: supportedLang })
|
dispatch({ type: 'UPDATE_LANGUAGE', language: supportedLang })
|
||||||
i18n.changeLanguage(supportedLang)
|
i18n.changeLanguage(supportedLang)
|
||||||
}
|
}
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dropdown
|
<Dropdown
|
||||||
trigger={['hover']}
|
trigger={['hover']}
|
||||||
menu={{
|
menu={{
|
||||||
items,
|
items: LanguageItems,
|
||||||
style: { minWidth: '80px' },
|
style: { minWidth: '80px' },
|
||||||
onClick: (e) => {
|
onClick: (e) => {
|
||||||
const { key } = e
|
const { key } = e
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
|
import { PERMISSION_DEFINITION } from '@common/const/permissions'
|
||||||
|
import { $t } from '@common/locales'
|
||||||
import { Button, Tooltip, Upload } from 'antd'
|
import { Button, Tooltip, Upload } from 'antd'
|
||||||
import { ReactElement, cloneElement, useEffect, useMemo, useState } from 'react'
|
import { ReactElement, cloneElement, useEffect, useMemo, useState } from 'react'
|
||||||
import { useGlobalContext } from '../../contexts/GlobalStateContext'
|
import { useGlobalContext } from '../../contexts/GlobalStateContext'
|
||||||
import { PERMISSION_DEFINITION } from '@common/const/permissions'
|
|
||||||
import { $t } from '@common/locales'
|
|
||||||
|
|
||||||
type WithPermissionProps = {
|
type WithPermissionProps = {
|
||||||
access?: string | string[]
|
access?: string | string[]
|
||||||
|
|||||||
@@ -342,7 +342,7 @@ export const GlobalProvider: FC<{ children: ReactNode }> = ({ children }) => {
|
|||||||
updateDate: '2024-07-01',
|
updateDate: '2024-07-01',
|
||||||
powered: 'Powered by https://apipark.com',
|
powered: 'Powered by https://apipark.com',
|
||||||
mainPage: '/guide/page',
|
mainPage: '/guide/page',
|
||||||
language: 'en-US',
|
language: sessionStorage.getItem('i18nextLng') || 'en-US',
|
||||||
pluginsLoaded: false
|
pluginsLoaded: false
|
||||||
})
|
})
|
||||||
const [accessData, setAccessData] = useState<Map<string, string[]>>(new Map())
|
const [accessData, setAccessData] = useState<Map<string, string[]>>(new Map())
|
||||||
@@ -510,7 +510,7 @@ export const useGlobalContext = () => {
|
|||||||
updateDate: '',
|
updateDate: '',
|
||||||
powered: '',
|
powered: '',
|
||||||
mainPage: '',
|
mainPage: '',
|
||||||
language: 'en-US',
|
language: sessionStorage.getItem('i18nextLng') || 'en-US',
|
||||||
pluginsLoaded: false
|
pluginsLoaded: false
|
||||||
},
|
},
|
||||||
dispatch: () => {},
|
dispatch: () => {},
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import i18n from 'i18next'
|
import i18n from 'i18next'
|
||||||
import { initReactI18next } from 'react-i18next'
|
import { initReactI18next, useTranslation } from 'react-i18next'
|
||||||
// i18next-browser-languagedetector插件 这是一个 i18next 语言检测插件,用于检测浏览器中的用户语言,
|
// i18next-browser-languagedetector插件 这是一个 i18next 语言检测插件,用于检测浏览器中的用户语言,
|
||||||
import crc32 from 'crc/crc32'
|
import crc32 from 'crc/crc32'
|
||||||
import LanguageDetector from 'i18next-browser-languagedetector'
|
import LanguageDetector from 'i18next-browser-languagedetector'
|
||||||
@@ -39,23 +39,22 @@ i18n
|
|||||||
.init({
|
.init({
|
||||||
// 初始化
|
// 初始化
|
||||||
resources, // 本地多语言数据
|
resources, // 本地多语言数据
|
||||||
// fallbackLng: config.lang, // 默认当前环境的语言
|
supportedLngs: ['zh-CN', 'en-US', 'zh-TW', 'ja-JP'],
|
||||||
detection: {
|
detection: {
|
||||||
caches: ['localStorage', 'sessionStorage', 'cookie']
|
caches: ['localStorage', 'sessionStorage', 'cookie']
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// --------这里是i18next-scanner新增的配置-------------
|
// --------这里是i18next-scanner新增的配置-------------
|
||||||
|
// 用于非 React 组件中的翻译
|
||||||
export const $t = (key: string, params?: any[]): string => {
|
export const $t = (key: string, params?: any[]): string => {
|
||||||
const hashKey = `K${crc32(key).toString(16)}` // 将中文转换成crc32格式去匹配对应的json语言包
|
// 将中文转换成crc32格式去匹配对应的json语言包
|
||||||
|
const hashKey = `K${crc32(key).toString(16)}`
|
||||||
let words = i18n.t(hashKey)
|
let words = i18n.t(hashKey)
|
||||||
// const { t } = useTranslation(); // 通过hooks
|
|
||||||
// let words = t(hashKey);
|
|
||||||
if (words === hashKey) {
|
if (words === hashKey) {
|
||||||
words = key
|
words = key
|
||||||
}
|
}
|
||||||
|
|
||||||
// 配置传递参数的场景, 目前仅支持数组,可在此拓展
|
|
||||||
if (Array.isArray(params)) {
|
if (Array.isArray(params)) {
|
||||||
const reg = /\((\d)\)/g
|
const reg = /\((\d)\)/g
|
||||||
words = words.replace(reg, (a: string, b: number) => {
|
words = words.replace(reg, (a: string, b: number) => {
|
||||||
@@ -65,4 +64,25 @@ export const $t = (key: string, params?: any[]): string => {
|
|||||||
return words
|
return words
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 用于 React 组件中的翻译
|
||||||
|
export const useI18n = () => {
|
||||||
|
const { t } = useTranslation()
|
||||||
|
|
||||||
|
return (key: string, params?: any[]): string => {
|
||||||
|
const hashKey = `K${crc32(key).toString(16)}`
|
||||||
|
let words = t(hashKey)
|
||||||
|
if (words === hashKey) {
|
||||||
|
words = key
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Array.isArray(params)) {
|
||||||
|
const reg = /\((\d)\)/g
|
||||||
|
words = words.replace(reg, (a: string, b: number) => {
|
||||||
|
return params[b]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return words
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default i18n
|
export default i18n
|
||||||
|
|||||||
@@ -18,7 +18,11 @@ export const checkAccess: (access: AccessDataType, accessData: Map<string, strin
|
|||||||
if (accLevel === 'team') {
|
if (accLevel === 'team') {
|
||||||
accessSet = new Set(Array.from(accessSet).concat(accessData?.get('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>) => {
|
const hasIntersection = (arr1: string[], set1: Set<string>) => {
|
||||||
|
|||||||
@@ -151,15 +151,15 @@ function App() {
|
|||||||
form={{ validateMessages }}
|
form={{ validateMessages }}
|
||||||
>
|
>
|
||||||
<PluginEventHubProvider>
|
<PluginEventHubProvider>
|
||||||
<AppAntd className="h-full" message={{ maxCount: 1 }}>
|
<GlobalProvider>
|
||||||
<PluginSlotHubProvider>
|
<AppAntd className="h-full" message={{ maxCount: 1 }}>
|
||||||
<GlobalProvider>
|
<PluginSlotHubProvider>
|
||||||
<BreadcrumbProvider>
|
<BreadcrumbProvider>
|
||||||
<RenderRoutes />
|
<RenderRoutes />
|
||||||
</BreadcrumbProvider>
|
</BreadcrumbProvider>
|
||||||
</GlobalProvider>
|
</PluginSlotHubProvider>
|
||||||
</PluginSlotHubProvider>
|
</AppAntd>
|
||||||
</AppAntd>
|
</GlobalProvider>
|
||||||
</PluginEventHubProvider>
|
</PluginEventHubProvider>
|
||||||
</ConfigProvider>
|
</ConfigProvider>
|
||||||
</StyleProvider>
|
</StyleProvider>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import InsidePage from '@common/components/aoplatform/InsidePage'
|
import InsidePage from '@common/components/aoplatform/InsidePage'
|
||||||
import { $t } from '@common/locales'
|
import { useI18n } from '@common/locales'
|
||||||
import { Tabs } from 'antd'
|
import { Tabs } from 'antd'
|
||||||
import { useEffect, useState } from 'react'
|
import { useEffect, useState } from 'react'
|
||||||
import { useSearchParams } from 'react-router-dom'
|
import { useSearchParams } from 'react-router-dom'
|
||||||
@@ -10,6 +10,7 @@ import { AiSettingProvider } from './contexts/AiSettingContext'
|
|||||||
const CONTENT_STYLE = { height: 'calc(-300px + 100vh)' } as const
|
const CONTENT_STYLE = { height: 'calc(-300px + 100vh)' } as const
|
||||||
|
|
||||||
const AiSettingContent = () => {
|
const AiSettingContent = () => {
|
||||||
|
const $t = useI18n()
|
||||||
const [searchParams, setSearchParams] = useSearchParams()
|
const [searchParams, setSearchParams] = useSearchParams()
|
||||||
const [activeKey, setActiveKey] = useState(searchParams.get('status') === 'unconfigure' ? 'config' : 'flow')
|
const [activeKey, setActiveKey] = useState(searchParams.get('status') === 'unconfigure' ? 'config' : 'flow')
|
||||||
|
|
||||||
|
|||||||
@@ -1,33 +1,26 @@
|
|||||||
import InsidePage from "@common/components/aoplatform/InsidePage";
|
import InsidePage from '@common/components/aoplatform/InsidePage'
|
||||||
import { $t } from "@common/locales";
|
import { useI18n } from '@common/locales'
|
||||||
import ServiceCategory from "./ServiceCategory";
|
import { Col, Row } from 'antd'
|
||||||
import ApiRequestSetting from "./ApiRequestSetting";
|
import ApiRequestSetting from './ApiRequestSetting'
|
||||||
import { Row, Col } from "antd";
|
import ServiceCategory from './ServiceCategory'
|
||||||
|
|
||||||
export default function CommonPage(){
|
export default function CommonPage() {
|
||||||
return (
|
const $t = useI18n()
|
||||||
<InsidePage
|
|
||||||
pageTitle={$t('常规设置')}
|
return (
|
||||||
showBorder={false}
|
<InsidePage pageTitle={$t('常规设置')} showBorder={false} contentClassName="pr-PAGE_INSIDE_X" scrollPage={false}>
|
||||||
contentClassName="pr-PAGE_INSIDE_X"
|
<Row className="mb-btnybase">
|
||||||
scrollPage={false}
|
<Col>
|
||||||
>
|
<span className="font-bold mr-[13px]">{$t('API 请求设置')}</span>
|
||||||
<Row className="mb-btnybase" >
|
</Col>
|
||||||
<Col >
|
</Row>
|
||||||
<span className="font-bold mr-[13px]">
|
<ApiRequestSetting />
|
||||||
{$t('API 请求设置')}
|
<Row className="mb-btnybase mt-[40px]">
|
||||||
</span>
|
<Col>
|
||||||
</Col>
|
<span className="font-bold mr-[13px]">{$t('服务分类')}</span>
|
||||||
</Row>
|
</Col>
|
||||||
<ApiRequestSetting />
|
</Row>
|
||||||
<Row className="mb-btnybase mt-[40px]">
|
<ServiceCategory />
|
||||||
<Col >
|
</InsidePage>
|
||||||
<span className="font-bold mr-[13px]">
|
)
|
||||||
{$t('服务分类')}
|
}
|
||||||
</span>
|
|
||||||
</Col>
|
|
||||||
</Row>
|
|
||||||
<ServiceCategory />
|
|
||||||
</InsidePage>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ export default function ServiceCategory() {
|
|||||||
const { accessData } = useGlobalContext()
|
const { accessData } = useGlobalContext()
|
||||||
const [loading, setLoading] = useState<boolean>(false)
|
const [loading, setLoading] = useState<boolean>(false)
|
||||||
|
|
||||||
const onDrop: TreeProps['onDrop'] = info => {
|
const onDrop: TreeProps['onDrop'] = (info) => {
|
||||||
const dropKey = info.node.key
|
const dropKey = info.node.key
|
||||||
const dragKey = info.dragNode.key
|
const dragKey = info.dragNode.key
|
||||||
const dropPos = info.node.pos.split('-')
|
const dropPos = info.node.pos.split('-')
|
||||||
@@ -59,7 +59,7 @@ export default function ServiceCategory() {
|
|||||||
|
|
||||||
if (!info.dropToGap) {
|
if (!info.dropToGap) {
|
||||||
// Drop on the content
|
// Drop on the content
|
||||||
loop(data, dropKey, item => {
|
loop(data, dropKey, (item) => {
|
||||||
item.children = item.children || []
|
item.children = item.children || []
|
||||||
// where to insert. New item was inserted to the start of the array in this example, but can be anywhere
|
// where to insert. New item was inserted to the start of the array in this example, but can be anywhere
|
||||||
item.children.unshift(dragObj)
|
item.children.unshift(dragObj)
|
||||||
@@ -129,9 +129,9 @@ export default function ServiceCategory() {
|
|||||||
const treeData = useMemo(() => {
|
const treeData = useMemo(() => {
|
||||||
setExpandedKeys([])
|
setExpandedKeys([])
|
||||||
const loop = (data: CategorizesType[]): DataNode[] =>
|
const loop = (data: CategorizesType[]): DataNode[] =>
|
||||||
data?.map(item => {
|
data?.map((item) => {
|
||||||
if (item.children) {
|
if (item.children) {
|
||||||
setExpandedKeys(prev => [...prev, item.id])
|
setExpandedKeys((prev) => [...prev, item.id])
|
||||||
return {
|
return {
|
||||||
title: (
|
title: (
|
||||||
<TreeWithMore stopClick={false} dropdownMenu={dropdownMenu(item as CategorizesType)}>
|
<TreeWithMore stopClick={false} dropdownMenu={dropdownMenu(item as CategorizesType)}>
|
||||||
@@ -169,40 +169,22 @@ export default function ServiceCategory() {
|
|||||||
return !checkAccess(permission, accessData)
|
return !checkAccess(permission, accessData)
|
||||||
}
|
}
|
||||||
|
|
||||||
const openModal = (
|
const openModal = (type: 'addCate' | 'addChildCate' | 'renameCate' | 'delete', entity?: CategorizesType) => {
|
||||||
type: 'addCate' | 'addChildCate' | 'renameCate' | 'delete',
|
|
||||||
entity?: CategorizesType
|
|
||||||
) => {
|
|
||||||
let title: string = ''
|
let title: string = ''
|
||||||
let content: string | React.ReactNode = ''
|
let content: string | React.ReactNode = ''
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'addCate':
|
case 'addCate': {
|
||||||
title = $t('添加分类')
|
title = $t('添加分类')
|
||||||
content = (
|
content = <ServiceHubCategoryConfig ref={addRef} type={type} />
|
||||||
<ServiceHubCategoryConfig WithPermission={WithPermission} ref={addRef} type={type} />
|
|
||||||
)
|
|
||||||
break
|
break
|
||||||
|
}
|
||||||
case 'addChildCate':
|
case 'addChildCate':
|
||||||
title = $t('添加子分类')
|
title = $t('添加子分类')
|
||||||
content = (
|
content = <ServiceHubCategoryConfig ref={addChildRef} type={type} entity={entity} />
|
||||||
<ServiceHubCategoryConfig
|
|
||||||
WithPermission={WithPermission}
|
|
||||||
ref={addChildRef}
|
|
||||||
type={type}
|
|
||||||
entity={entity}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
break
|
break
|
||||||
case 'renameCate':
|
case 'renameCate':
|
||||||
title = $t('重命名分类')
|
title = $t('重命名分类')
|
||||||
content = (
|
content = <ServiceHubCategoryConfig ref={renameRef} type={type} entity={entity} />
|
||||||
<ServiceHubCategoryConfig
|
|
||||||
WithPermission={WithPermission}
|
|
||||||
ref={renameRef}
|
|
||||||
type={type}
|
|
||||||
entity={entity}
|
|
||||||
/>
|
|
||||||
)
|
|
||||||
break
|
break
|
||||||
case 'delete':
|
case 'delete':
|
||||||
title = $t('删除')
|
title = $t('删除')
|
||||||
@@ -215,19 +197,19 @@ export default function ServiceCategory() {
|
|||||||
onOk: () => {
|
onOk: () => {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'addCate':
|
case 'addCate':
|
||||||
return addRef.current?.save().then(res => {
|
return addRef.current?.save().then((res) => {
|
||||||
if (res === true) getCategoryList()
|
if (res === true) getCategoryList()
|
||||||
})
|
})
|
||||||
case 'addChildCate':
|
case 'addChildCate':
|
||||||
return addChildRef.current?.save().then(res => {
|
return addChildRef.current?.save().then((res) => {
|
||||||
if (res === true) getCategoryList()
|
if (res === true) getCategoryList()
|
||||||
})
|
})
|
||||||
case 'renameCate':
|
case 'renameCate':
|
||||||
return renameRef.current?.save().then(res => {
|
return renameRef.current?.save().then((res) => {
|
||||||
if (res === true) getCategoryList()
|
if (res === true) getCategoryList()
|
||||||
})
|
})
|
||||||
case 'delete':
|
case 'delete':
|
||||||
return deleteCate(entity!).then(res => {
|
return deleteCate(entity!).then((res) => {
|
||||||
if (res === true) getCategoryList()
|
if (res === true) getCategoryList()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -249,7 +231,7 @@ export default function ServiceCategory() {
|
|||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
eoParams: { catalogue: entity.id }
|
eoParams: { catalogue: entity.id }
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then((response) => {
|
||||||
const { code, msg } = response
|
const { code, msg } = response
|
||||||
if (code === STATUS_CODE.SUCCESS) {
|
if (code === STATUS_CODE.SUCCESS) {
|
||||||
message.success(msg || $t(RESPONSE_TIPS.success))
|
message.success(msg || $t(RESPONSE_TIPS.success))
|
||||||
@@ -259,14 +241,14 @@ export default function ServiceCategory() {
|
|||||||
reject(msg || $t(RESPONSE_TIPS.error))
|
reject(msg || $t(RESPONSE_TIPS.error))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(errorInfo => reject(errorInfo))
|
.catch((errorInfo) => reject(errorInfo))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const sortCategories = (newData: CategorizesType[]) => {
|
const sortCategories = (newData: CategorizesType[]) => {
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
fetchData<BasicResponse<null>>('catalogue/sort', { method: 'PUT', eoBody: newData })
|
fetchData<BasicResponse<null>>('catalogue/sort', { method: 'PUT', eoBody: newData })
|
||||||
.then(response => {
|
.then((response) => {
|
||||||
const { code, msg } = response
|
const { code, msg } = response
|
||||||
if (code === STATUS_CODE.SUCCESS) {
|
if (code === STATUS_CODE.SUCCESS) {
|
||||||
getCategoryList()
|
getCategoryList()
|
||||||
@@ -288,7 +270,7 @@ export default function ServiceCategory() {
|
|||||||
fetchData<BasicResponse<{ catalogues: CategorizesType[]; tags: EntityItem[] }>>('catalogues', {
|
fetchData<BasicResponse<{ catalogues: CategorizesType[]; tags: EntityItem[] }>>('catalogues', {
|
||||||
method: 'GET'
|
method: 'GET'
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then((response) => {
|
||||||
const { code, data, msg } = response
|
const { code, data, msg } = response
|
||||||
if (code === STATUS_CODE.SUCCESS) {
|
if (code === STATUS_CODE.SUCCESS) {
|
||||||
setGData(data.catalogues)
|
setGData(data.catalogues)
|
||||||
@@ -308,11 +290,7 @@ export default function ServiceCategory() {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="border border-solid border-BORDER p-[20px] rounded-[10px] ">
|
<div className="border border-solid border-BORDER p-[20px] rounded-[10px] ">
|
||||||
<Spin
|
<Spin indicator={<LoadingOutlined style={{ fontSize: 24 }} spin />} spinning={loading} className="">
|
||||||
indicator={<LoadingOutlined style={{ fontSize: 24 }} spin />}
|
|
||||||
spinning={loading}
|
|
||||||
className=""
|
|
||||||
>
|
|
||||||
<Tree
|
<Tree
|
||||||
showIcon
|
showIcon
|
||||||
draggable
|
draggable
|
||||||
|
|||||||
@@ -10,132 +10,131 @@ import {
|
|||||||
import { App, Form, Input } from 'antd'
|
import { App, Form, Input } from 'antd'
|
||||||
import { forwardRef, useEffect, useImperativeHandle } from 'react'
|
import { forwardRef, useEffect, useImperativeHandle } from 'react'
|
||||||
|
|
||||||
export const ServiceHubCategoryConfig = forwardRef<
|
export const ServiceHubCategoryConfig = forwardRef<ServiceHubCategoryConfigHandle, ServiceHubCategoryConfigProps>(
|
||||||
ServiceHubCategoryConfigHandle,
|
(props, ref) => {
|
||||||
ServiceHubCategoryConfigProps
|
const { message } = App.useApp()
|
||||||
>((props, ref) => {
|
const [form] = Form.useForm()
|
||||||
const { message } = App.useApp()
|
const { type, entity } = props
|
||||||
const [form] = Form.useForm()
|
const { fetchData } = useFetch()
|
||||||
const { type, entity } = props
|
|
||||||
const { fetchData } = useFetch()
|
|
||||||
|
|
||||||
const save: () => Promise<boolean | string> = () => {
|
const save: () => Promise<boolean | string> = () => {
|
||||||
const url: string = 'catalogue'
|
const url: string = 'catalogue'
|
||||||
let method: string
|
let method: string
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'addCate':
|
case 'addCate':
|
||||||
case 'addChildCate':
|
case 'addChildCate':
|
||||||
method = 'POST'
|
method = 'POST'
|
||||||
break
|
break
|
||||||
case 'renameCate':
|
case 'renameCate':
|
||||||
method = 'PUT'
|
method = 'PUT'
|
||||||
break
|
break
|
||||||
}
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
if (!url || !method) {
|
|
||||||
reject($t(RESPONSE_TIPS.error))
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
form
|
return new Promise((resolve, reject) => {
|
||||||
.validateFields()
|
if (!url || !method) {
|
||||||
.then(value => {
|
reject($t(RESPONSE_TIPS.error))
|
||||||
fetchData<BasicResponse<null>>(url, {
|
return
|
||||||
method,
|
}
|
||||||
eoBody: value,
|
form
|
||||||
eoParams: { ...(type === 'renameCate' ? { catalogue: value.id } : undefined) }
|
.validateFields()
|
||||||
})
|
.then((value) => {
|
||||||
.then(response => {
|
fetchData<BasicResponse<null>>(url, {
|
||||||
const { code, msg } = response
|
method,
|
||||||
if (code === STATUS_CODE.SUCCESS) {
|
eoBody: value,
|
||||||
message.success(msg || $t(RESPONSE_TIPS.success))
|
eoParams: { ...(type === 'renameCate' ? { catalogue: value.id } : undefined) }
|
||||||
resolve(true)
|
|
||||||
} else {
|
|
||||||
message.error(msg || $t(RESPONSE_TIPS.error))
|
|
||||||
reject(msg || $t(RESPONSE_TIPS.error))
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.catch(errorInfo => reject(errorInfo))
|
.then((response) => {
|
||||||
})
|
const { code, msg } = response
|
||||||
.catch(errorInfo => reject(errorInfo))
|
if (code === STATUS_CODE.SUCCESS) {
|
||||||
})
|
message.success(msg || $t(RESPONSE_TIPS.success))
|
||||||
}
|
resolve(true)
|
||||||
|
} else {
|
||||||
useImperativeHandle(ref, () => ({
|
message.error(msg || $t(RESPONSE_TIPS.error))
|
||||||
save
|
reject(msg || $t(RESPONSE_TIPS.error))
|
||||||
}))
|
}
|
||||||
|
})
|
||||||
useEffect(() => {
|
.catch((errorInfo) => reject(errorInfo))
|
||||||
switch (type) {
|
})
|
||||||
case 'addCate':
|
.catch((errorInfo) => reject(errorInfo))
|
||||||
form.setFieldsValue({})
|
})
|
||||||
break
|
|
||||||
case 'addChildCate':
|
|
||||||
form.setFieldsValue({ parent: entity!.id })
|
|
||||||
break
|
|
||||||
case 'renameCate':
|
|
||||||
form.setFieldsValue(entity)
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}, [])
|
|
||||||
|
|
||||||
return (
|
useImperativeHandle(ref, () => ({
|
||||||
<WithPermission
|
save
|
||||||
access={
|
}))
|
||||||
type === 'addCate'
|
|
||||||
? 'system.api_market.service_classification.add'
|
useEffect(() => {
|
||||||
: 'system.api_market.service_classification.edit'
|
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>
|
<Form.Item<ServiceHubCategoryConfigFieldType>
|
||||||
label={$t('父分类 ID')}
|
label={$t('ID')}
|
||||||
name="parent"
|
name="id"
|
||||||
hidden
|
hidden
|
||||||
rules={[{ required: true, whitespace: true }]}
|
rules={[{ required: true, whitespace: true }]}
|
||||||
>
|
>
|
||||||
<Input className="w-INPUT_NORMAL" placeholder={$t(PLACEHOLDER.input)} />
|
<Input className="w-INPUT_NORMAL" placeholder={$t(PLACEHOLDER.input)} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
)}
|
||||||
|
{(type === 'addCate' || type === 'renameCate') && (
|
||||||
<Form.Item<ServiceHubCategoryConfigFieldType>
|
<Form.Item<ServiceHubCategoryConfigFieldType>
|
||||||
label={$t('子分类名称')}
|
label={$t('分类名称')}
|
||||||
name="name"
|
name="name"
|
||||||
rules={[{ required: true, whitespace: true }]}
|
rules={[{ required: true, whitespace: true }]}
|
||||||
>
|
>
|
||||||
<Input className="w-INPUT_NORMAL" placeholder={$t(PLACEHOLDER.input)} />
|
<Input className="w-INPUT_NORMAL" placeholder={$t(PLACEHOLDER.input)} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
</>
|
)}
|
||||||
)}
|
|
||||||
</Form>
|
{type === 'addChildCate' && (
|
||||||
</WithPermission>
|
<>
|
||||||
)
|
<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 { EntityItem } from '@common/const/type'
|
||||||
import { SubscribeEnum, SubscribeFromEnum } from '@core/const/system/const'
|
import { SubscribeEnum, SubscribeFromEnum } from '@core/const/system/const'
|
||||||
import WithPermission from '@common/components/aoplatform/WithPermission'
|
import { DefaultOptionType } from 'antd/es/select'
|
||||||
|
|
||||||
export type ServiceBasicInfoType = {
|
export type ServiceBasicInfoType = {
|
||||||
app: EntityItem
|
app: EntityItem
|
||||||
@@ -37,7 +36,6 @@ export type ServiceHubCategoryConfigFieldType = {
|
|||||||
export type ServiceHubCategoryConfigProps = {
|
export type ServiceHubCategoryConfigProps = {
|
||||||
type: 'addCate' | 'addChildCate' | 'renameCate'
|
type: 'addCate' | 'addChildCate' | 'renameCate'
|
||||||
entity?: { [k: string]: unknown }
|
entity?: { [k: string]: unknown }
|
||||||
WithPermission: typeof WithPermission
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ServiceHubCategoryConfigHandle = {
|
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 { BasicResponse, DATA_SHOW_TYPE_OPTIONS, RESPONSE_TIPS, STATUS_CODE } from '@common/const/const'
|
||||||
import { SimpleTeamItem } from '@common/const/type'
|
import { SimpleTeamItem } from '@common/const/type'
|
||||||
import { useBreadcrumb } from '@common/contexts/BreadcrumbContext'
|
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 { useFetch } from '@common/hooks/http'
|
||||||
import { $t } from '@common/locales'
|
import { $t } from '@common/locales'
|
||||||
import { RouterParams } from '@core/components/aoplatform/RenderRoutes'
|
import { RouterParams } from '@core/components/aoplatform/RenderRoutes'
|
||||||
@@ -158,28 +158,8 @@ export default function ServiceHubManagement() {
|
|||||||
switch (type) {
|
switch (type) {
|
||||||
case 'add':
|
case 'add':
|
||||||
title = $t('添加消费者')
|
title = $t('添加消费者')
|
||||||
content = (
|
content = <ManagementConfig ref={addManagementRef} dataShowType={dataShowType} type={type} teamId={teamId!} />
|
||||||
<GlobalProvider>
|
|
||||||
<ManagementConfig ref={addManagementRef} dataShowType={dataShowType} type={type} teamId={teamId!} />
|
|
||||||
</GlobalProvider>
|
|
||||||
)
|
|
||||||
break
|
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({
|
modal.confirm({
|
||||||
|
|||||||
Reference in New Issue
Block a user