From fbb42fbc108c855a9e78f294f5c901151578fb29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E7=99=BB=E5=B1=B1?= Date: Fri, 9 May 2025 17:43:02 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=20tier?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/tiers/new-form.vue | 52 ++++++++++++++++++++++++++++------- composables/useTiers.ts | 46 +++++++++++++++++++++++++++++++ i18n/locales/en-US.json | 5 +++- i18n/locales/zh-CN.json | 4 ++- pages/tiers/index.vue | 16 ++++++----- 5 files changed, 104 insertions(+), 19 deletions(-) create mode 100644 composables/useTiers.ts diff --git a/components/tiers/new-form.vue b/components/tiers/new-form.vue index 9990c1a..914bd32 100644 --- a/components/tiers/new-form.vue +++ b/components/tiers/new-form.vue @@ -45,7 +45,10 @@ - + + + + {{ t('Cancel') }} @@ -75,8 +78,10 @@ import { NSelect, NButton, } from 'naive-ui' +import { useTiers } from '#imports' const { t } = useI18n() +const usetier = useTiers() const formRef = ref(null) const formData = ref({ @@ -87,18 +92,20 @@ const formData = ref({ secretkey: '', bucket: '', prefix: '', - regio: '', + region: '', + storageclass: 'STANDARD', // 新增字段,默认值为 STANDARD }) const typeOptions = [ { label: t('RustFS'), value: 'rustfs', iconUrl: RustfsIcon }, { label: t('Minio'), value: 'minio', iconUrl: MinioIcon }, - { label: t('Google Cloud Storage'), value: 'google', iconUrl: GoogleIcon }, - { label: t('AWS S3'), value: 'AWS', iconUrl: AWSIcon }, - { label: t('Azure'), value: 'azure', iconUrl: AzureIcon }, - { label: t('Aliyun'), value: 'aliyun', iconUrl: AliyunIcon }, - { label: t('Tencent Cloud'), value: 'tqyun', iconUrl: TqyunIcon }, - { label: t('Huawei Cloud'), value: 'hwyun', iconUrl: HwcloudIcon }, - { label: t('Baidu Cloud'), value: 'bdyun', iconUrl: BaiduIcon }, + { label: t('AWS S3'), value: 's3', iconUrl: AWSIcon }, + // 暂未支持 + // { label: t('Google Cloud Storage'), value: 'google', iconUrl: GoogleIcon }, + // { label: t('Azure'), value: 'azure', iconUrl: AzureIcon }, + // { label: t('Aliyun'), value: 'aliyun', iconUrl: AliyunIcon }, + // { label: t('Tencent Cloud'), value: 'tqyun', iconUrl: TqyunIcon }, + // { label: t('Huawei Cloud'), value: 'hwyun', iconUrl: HwcloudIcon }, + // { label: t('Baidu Cloud'), value: 'bdyun', iconUrl: BaiduIcon }, ] const rules = { @@ -116,11 +123,36 @@ const open = () => { defineExpose({ open }) + +const emmit = defineEmits(['search']) const handleSave = () => { formRef.value?.validate((errors) => { if (!errors) { - console.log(t('Submit data'), formData.value) + // {"type":"minio","minio":{"name":"COLDTIER","endpoint":"","bucket":"","prefix":"","region":"","accesskey":"","secretkey":""}} // 调用保存接口 + const data = { + type: formData.value.type, + [formData.value.type]: { + name: formData.value.name, + endpoint: formData.value.endpoint, + bucket: formData.value.bucket, + prefix: formData.value.prefix, + region: formData.value.region, + accesskey: formData.value.accesskey, + secretkey: formData.value.secretkey, + storageclass: formData.value.storageclass, // 新增字段 + }, + } + console.log(t('Submit data'), data) + + usetier.addTiers(data).then((res) => { + if (res.code === 200) { + visible.value = false + } + // 处理成功逻辑 + console.log('保存成功', res) + emit('search') + }) } }) } diff --git a/composables/useTiers.ts b/composables/useTiers.ts new file mode 100644 index 0000000..0de55f1 --- /dev/null +++ b/composables/useTiers.ts @@ -0,0 +1,46 @@ +export const useTiers = () => { + const { $api } = useNuxtApp() + /** + * 添加分层 + * + *'{"type":"minio","minio":{"name":"COLDTIER","endpoint":"","bucket":"","prefix":"","region":"","accesskey":"","secretkey":""}}' + * {"type":"rustfs","rustfs":{"name":"COLDTIER","endpoint":"","bucket":"","prefix":"","region":"","accesskey":"","secretkey":""}} + * {"type":"s3","s3":{"name":"S3COLDTIER","endpoint":"","bucket":"","prefix":"","region":"","accesskey":"","secretkey":"","storageclass":"STANDAR + * + */ + const addTiers = async (data: any)=> { + return await $api.post('/tier',data) + } + + + /** + * 编辑分层 + * @returns + */ + const updateTiers = async (name: string, data: any) =>{ + return await $api.put(`/tier/${encodeURIComponent(name)}`, data) + } + + /** + * 获取分层列表 + * @returns + */ + const listTiers = async () =>{ + return await $api.get('/tier') + } + + /** + * 删除分层列表 + * @returns + */ + const removeTiers = async (name: string) => { + return await $api.delete(`/tier/${encodeURIComponent(name)}`, {}) + } + + return { + addTiers, + updateTiers, + listTiers, + removeTiers + } +} diff --git a/i18n/locales/en-US.json b/i18n/locales/en-US.json index 599ee4d..4d0278b 100644 --- a/i18n/locales/en-US.json +++ b/i18n/locales/en-US.json @@ -267,5 +267,8 @@ "Remote Site": "Remote Site", "Endpoint Required": "Endpoint Required", "Access Key Required": "Access Key Required", - "Secret Key Required": "Secret Key Required" + "Secret Key Required": "Secret Key Required", + "StorageClass": "Storage Class", + "Please Enter storage class": "Please Enter storage class(e.g., STANDARD, IA, GLACIER)" + } diff --git a/i18n/locales/zh-CN.json b/i18n/locales/zh-CN.json index bd3ac6e..1e8a51b 100644 --- a/i18n/locales/zh-CN.json +++ b/i18n/locales/zh-CN.json @@ -456,5 +456,7 @@ "Description": "描述", "Are you sure you want to delete all selected keys?": "您确定要删除所有选中的密钥吗?", "Please select at least one item": "请至少选择一项", - "Get Data Failed": "获取数据失败" + "Get Data Failed": "获取数据失败", + "StorageClass": "存储类型", + "Please Enter storage class": "请输入存储类型" } diff --git a/pages/tiers/index.vue b/pages/tiers/index.vue index 48ec810..9ef94a5 100644 --- a/pages/tiers/index.vue +++ b/pages/tiers/index.vue @@ -27,7 +27,7 @@ - + @@ -37,6 +37,7 @@ import { Icon } from '#components' import dayjs from 'dayjs' import { NButton, NSpace, type DataTableColumns ,NPopconfirm} from 'naive-ui' import { useI18n } from 'vue-i18n' +const usetier = useTiers() const { t } = useI18n() const searchTerm = ref(''); @@ -116,11 +117,10 @@ const columns: DataTableColumns = [ ]; const { data, refresh } = await useAsyncData( - 'tiers', + 'tier', async () => { - // const response = await listBuckets(); - // return response - return [] + const response = await usetier.listTiers(); + return response }, { default: () => [] } ); @@ -131,8 +131,10 @@ const filteredData = computed(() => { } const term = searchTerm.value.toLowerCase(); - return data.value.filter(bucket => - bucket + return data.value.filter((tier:any) => + tier.name.toLowerCase().includes(term) || + tier.endpoint.toLowerCase().includes(term) || + tier.bucket.toLowerCase().includes(term) ); });