|
| 1 | +<template> |
| 2 | + <div> |
| 3 | + <page-header> |
| 4 | + <template #title> |
| 5 | + <h1 class="text-2xl font-bold">分层</h1> |
| 6 | + </template> |
| 7 | + </page-header> |
| 8 | + <page-content class="flex flex-col gap-4"> |
| 9 | + <div class="flex items-center justify-between"> |
| 10 | + <div class="flex items-center justify-between"> |
| 11 | + <n-input v-model:value="searchTerm" placeholder="搜索"> |
| 12 | + <template #prefix> |
| 13 | + <Icon name="ri:search-2-line" /> |
| 14 | + </template> |
| 15 | + </n-input> |
| 16 | + </div> |
| 17 | + |
| 18 | + <div class="flex items-center gap-4"> |
| 19 | + <n-button @click="() => addForm()"> |
| 20 | + <Icon name="ri:add-line" class="mr-2" /> |
| 21 | + <span>添加分层</span> |
| 22 | + </n-button> |
| 23 | + <n-button @click="async () => refresh()"> |
| 24 | + <Icon name="ri:refresh-line" class="mr-2" /> |
| 25 | + <span>刷新</span> |
| 26 | + </n-button> |
| 27 | + </div> |
| 28 | + </div> |
| 29 | + <n-data-table class="border dark:border-neutral-700 rounded overflow-hidden" :columns="columns" :data="filteredData" :pagination="false" :bordered="false" /> |
| 30 | + <tiers-new-form ref='newFormRef'></tiers-new-form> |
| 31 | + </page-content> |
| 32 | + </div> |
| 33 | +</template> |
| 34 | + |
| 35 | +<script lang="ts" setup> |
| 36 | +import { Icon } from '#components' |
| 37 | +import dayjs from 'dayjs' |
| 38 | +import { NButton, NSpace, type DataTableColumns ,NPopconfirm} from 'naive-ui' |
| 39 | +
|
| 40 | +const searchTerm = ref(''); |
| 41 | +
|
| 42 | +interface RowData { |
| 43 | + Name: string; |
| 44 | + CreationDate: string; |
| 45 | +} |
| 46 | +
|
| 47 | +const columns: DataTableColumns<RowData> = [ |
| 48 | + { |
| 49 | + title: '分层类型', |
| 50 | + // dataIndex: 'name', |
| 51 | + key: 'Name', |
| 52 | + }, |
| 53 | + { |
| 54 | + title: 'Endpoint', |
| 55 | + // dataIndex: 'name', |
| 56 | + key: 'Endpoint', |
| 57 | + }, |
| 58 | + { |
| 59 | + title: '存储空间', |
| 60 | + // dataIndex: 'name', |
| 61 | + key: 'Bucket', |
| 62 | + }, |
| 63 | + { |
| 64 | + title: '创建时间', |
| 65 | + // dataIndex: 'creationDate', |
| 66 | + key: 'CreationDate', |
| 67 | + render: (row: RowData) => { |
| 68 | + return dayjs(row.CreationDate).format('YYYY-MM-DD HH:mm:ss'); |
| 69 | + }, |
| 70 | + }, |
| 71 | + { |
| 72 | + title: '操作', |
| 73 | + key: 'actions', |
| 74 | + align: 'center', |
| 75 | + width: 140, |
| 76 | + render: (row: RowData) => { |
| 77 | + return h( |
| 78 | + NSpace, |
| 79 | + { |
| 80 | + justify: 'center', |
| 81 | + }, |
| 82 | + { |
| 83 | + default: () => [ |
| 84 | + h( |
| 85 | + NPopconfirm, |
| 86 | + { onPositiveClick: () => deleteItem(row) }, |
| 87 | + { |
| 88 | + default: () => "确认删除", |
| 89 | + trigger: () => |
| 90 | + h( |
| 91 | + NButton, |
| 92 | + { size: "small", secondary: true }, |
| 93 | + { |
| 94 | + default: () => "", |
| 95 | + icon: () => h(Icon, { name: "ri:delete-bin-5-line" }), |
| 96 | + } |
| 97 | + ), |
| 98 | + } |
| 99 | + ), |
| 100 | + h( |
| 101 | + NButton, |
| 102 | + { |
| 103 | + size: 'small', |
| 104 | + secondary: true, |
| 105 | + onClick: (e) => handleRowClick(row,e), |
| 106 | + }, |
| 107 | + { |
| 108 | + default: () => '', |
| 109 | + icon: () => h(Icon, { name: 'ri:settings-5-line' }), |
| 110 | + } |
| 111 | + ), |
| 112 | + |
| 113 | + ], |
| 114 | + } |
| 115 | + ); |
| 116 | + }, |
| 117 | + }, |
| 118 | +]; |
| 119 | +
|
| 120 | +const { data, refresh } = await useAsyncData( |
| 121 | + 'tiers', |
| 122 | + async () => { |
| 123 | + // const response = await listBuckets(); |
| 124 | + // return response |
| 125 | + return [] |
| 126 | + }, |
| 127 | + { default: () => [] } |
| 128 | +); |
| 129 | +
|
| 130 | +const filteredData = computed(() => { |
| 131 | + if (!searchTerm.value) { |
| 132 | + return data.value; |
| 133 | + } |
| 134 | +
|
| 135 | + const term = searchTerm.value.toLowerCase(); |
| 136 | + return data.value.filter(bucket => |
| 137 | + bucket |
| 138 | + ); |
| 139 | +}); |
| 140 | +
|
| 141 | +const infoRef = ref(); |
| 142 | +const handleRowClick = (row: RowData,e: Event) => { |
| 143 | + e.stopPropagation(); |
| 144 | + infoRef.value.openDrawer(row.Name); |
| 145 | +}; |
| 146 | +
|
| 147 | +const message = useMessage(); |
| 148 | +const deleteItem = async (row: RowData) => { |
| 149 | +
|
| 150 | + // delete(row.Name).then(()=>{ |
| 151 | + // message.success("删除成功") |
| 152 | + // refresh(); |
| 153 | +
|
| 154 | + // }).catch((error)=>{ |
| 155 | + // message.error("删除失败") |
| 156 | + // }) |
| 157 | + |
| 158 | +}; |
| 159 | +
|
| 160 | +const newFormRef = ref(); |
| 161 | +const addForm = async () => { |
| 162 | + newFormRef.value.open(); |
| 163 | +}; |
| 164 | +
|
| 165 | +</script> |
0 commit comments