From 8f36c1bc30376275766dd24be1589737d727edfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=E9=98=B3?= Date: Sat, 4 Jan 2025 18:24:02 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=89=E6=8B=A9=E5=AD=98=E5=82=A8=E5=B9=B3?= =?UTF-8?q?=E5=8F=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/Oss.ts | 7 ++-- src/pages/Oss/index.tsx | 71 +++++++++++++++++++++++------------------ src/types/app/oss.d.ts | 1 + 3 files changed, 46 insertions(+), 33 deletions(-) diff --git a/src/api/Oss.ts b/src/api/Oss.ts index fe70069..a236032 100644 --- a/src/api/Oss.ts +++ b/src/api/Oss.ts @@ -17,10 +17,13 @@ export const getOssDataAPI = (id?: number) => Request("GET", `/oss/${id}`) export const getOssListAPI = () => Request("POST", `/oss/list`) // 获取启用的OSS列表 -export const getOssEnableListAPI = () => Request("POST", `/oss/getEnableOss`) +export const getOssEnableListAPI = () => Request("GET", `/oss/getEnableOss`) // 启用OSS export const enableOssDataAPI = (id: number) => Request("PATCH", `/oss/enable/${id}`) // 禁用OSS -export const disableOssDataAPI = (id: number) => Request("PATCH", `/oss/disable/${id}`) \ No newline at end of file +export const disableOssDataAPI = (id: number) => Request("PATCH", `/oss/disable/${id}`) + +// 获取支持的OSS平台列表 +export const getOssPlatformListAPI = () => Request<{ name: string, value: string }[]>("GET", `/oss/platform`) \ No newline at end of file diff --git a/src/pages/Oss/index.tsx b/src/pages/Oss/index.tsx index b787709..625f959 100644 --- a/src/pages/Oss/index.tsx +++ b/src/pages/Oss/index.tsx @@ -1,6 +1,6 @@ import { useState, useEffect } from 'react'; -import { Table, Button, Form, Input, Popconfirm, message, Card, Modal, Tag } from 'antd'; -import { addOssDataAPI, delOssDataAPI, editOssDataAPI, getOssListAPI, enableOssDataAPI, disableOssDataAPI, getOssDataAPI } from '@/api/Oss'; +import { Table, Button, Form, Input, Popconfirm, message, Card, Modal, Select } from 'antd'; +import { addOssDataAPI, delOssDataAPI, editOssDataAPI, getOssListAPI, enableOssDataAPI, disableOssDataAPI, getOssDataAPI, getOssPlatformListAPI } from '@/api/Oss'; import type { Oss } from '@/types/app/oss'; import Title from '@/components/Title'; import type { ColumnsType } from 'antd/es/table'; @@ -12,6 +12,7 @@ const StoragePage = () => { const [isModalOpen, setIsModalOpen] = useState(false); const [oss, setOss] = useState({} as Oss); const [ossList, setOssList] = useState([]); + const [platformList, setPlatformList] = useState<{ label: string, value: string, disabled: boolean }[]>([]); const [form] = Form.useForm(); const columns: ColumnsType = [ @@ -32,20 +33,15 @@ const StoragePage = () => { }, { title: '平台', - dataIndex: 'platform', - key: 'platform', + dataIndex: 'platformName', + key: 'platformName', align: 'center', - width: 120, - render: (text: string) => ( -
{text}
- ) + width: 120 }, - // { title: 'Access Key', dataIndex: 'accessKey', key: 'accessKey' }, - // { title: 'Secret Key', dataIndex: 'secretKey', key: 'secretKey' }, { title: '地域', dataIndex: 'endPoint', key: 'endPoint' }, { title: '存储桶', dataIndex: 'bucketName', key: 'bucketName' }, { title: '域名', dataIndex: 'domain', key: 'domain' }, - { title: '根目录', dataIndex: 'basePath', key: 'basePath', align: 'center', width: 120 }, + { title: '文件目录', dataIndex: 'basePath', key: 'basePath', align: 'center', width: 120 }, { title: '操作', key: 'action', @@ -70,15 +66,32 @@ const StoragePage = () => { } ]; + // 获取支持的平台列表 + const getOssPlatformList = async () => { + // 获取已经使用的平台 + const selectPlatformList = ossList.map(item => item.platform) + + const { data } = await getOssPlatformListAPI(); + setPlatformList(data.map(item => ( + { + label: item.name, + value: item.value, + // 限制一个平台只能添加一个 + disabled: selectPlatformList.includes(item.value) + } + ))); + }; + const getOssList = async () => { setLoading(true); const { data } = await getOssListAPI(); - setOssList(data as Oss[]); + setOssList(data); setLoading(false); }; useEffect(() => { getOssList(); + getOssPlatformList() }, []); const handleEnable = async (id: number) => { @@ -110,6 +123,7 @@ const StoragePage = () => { const handleAdd = () => { setOss({} as Oss); form.resetFields(); + form.setFieldsValue({}); setIsModalOpen(true); }; @@ -135,11 +149,11 @@ const StoragePage = () => { setIsModalOpen(false); getOssList(); form.resetFields(); + setBtnLoading(false); } catch (error) { console.error('表单验证失败:', error); + setBtnLoading(false); } - - setBtnLoading(false); }; return ( @@ -172,18 +186,13 @@ const StoragePage = () => {
- - - + {!oss.id && + + - + { - + diff --git a/src/types/app/oss.d.ts b/src/types/app/oss.d.ts index 4380e29..4026079 100644 --- a/src/types/app/oss.d.ts +++ b/src/types/app/oss.d.ts @@ -1,6 +1,7 @@ export interface Oss { id?: number; platform: string; + platformName?:string; accessKey: string; secretKey: string; endPoint: string;