|
118 | 118 | </template> |
119 | 119 | todo |
120 | 120 | </n-descriptions-item> |
121 | | - <n-descriptions-item label="标签"> |
122 | | - <span class="select-all">todo</span> |
| 121 | + <n-descriptions-item class="w-1/2"> |
| 122 | + <template #label> |
| 123 | + 标签 |
| 124 | + <n-button quaternary round type="primary" @click="addTag"> |
| 125 | + <Icon name="ri:edit-2-line" class="mr-2" /> |
| 126 | + </n-button> |
| 127 | + </template> |
| 128 | + <n-tag |
| 129 | + class="m-2" |
| 130 | + v-for="(tag, index) in tags" |
| 131 | + type="info" |
| 132 | + @click="editTag(index)" |
| 133 | + closable |
| 134 | + @close="handledeleteTag(index)"> |
| 135 | + {{ tag.Key }}:{{ tag.Value }} |
| 136 | + </n-tag> |
123 | 137 | </n-descriptions-item> |
124 | 138 | <n-descriptions-item> |
125 | 139 | <template #label> |
|
132 | 146 | </n-descriptions-item> |
133 | 147 | </n-descriptions> |
134 | 148 | </n-card> |
| 149 | + <!-- tag --> |
| 150 | + <n-modal v-model:show="showTagModal" title="设置tag" preset="card" draggable :style="{ width: '550px' }"> |
| 151 | + <n-form ref="formRef" inline :label-width="80" :model="tagFormValue"> |
| 152 | + <n-form-item label="标签key" path="user.name"> |
| 153 | + <n-input v-model:value="tagFormValue.name" placeholder="输入标签key" /> |
| 154 | + </n-form-item> |
| 155 | + <n-form-item label="标签值" path="phone"> |
| 156 | + <n-input v-model:value="tagFormValue.value" placeholder="输入标签值" /> |
| 157 | + </n-form-item> |
| 158 | + <n-form-item> |
| 159 | + <n-button type="primary" @click="submitTagForm">确认</n-button> |
| 160 | + <n-button class="mx-4" @click="showTagModal = false">取消</n-button> |
| 161 | + </n-form-item> |
| 162 | + </n-form> |
| 163 | + </n-modal> |
135 | 164 | </template> |
136 | 165 |
|
137 | 166 | <script setup lang="ts"> |
138 | | -import { computed } from 'vue'; |
| 167 | +import { computed } from "vue" |
| 168 | +
|
| 169 | +const router = useRouter() |
| 170 | +const { $s3Client } = useNuxtApp() |
| 171 | +const message = useMessage() |
| 172 | +const props = defineProps<{ bucket: string }>() |
| 173 | +
|
| 174 | +const bucketName = computed(() => props.bucket as string) |
| 175 | +
|
| 176 | +const { headBucket, getBucketTagging, putBucketTagging, deleteBucketTagging } = useBucket({}) |
| 177 | +
|
| 178 | +/********tag */ |
| 179 | +// 定义标签的类型 |
| 180 | +interface Tag { |
| 181 | + Key: string |
| 182 | + Value: string |
| 183 | +} |
| 184 | +const showTagModal = ref(false) |
| 185 | +
|
| 186 | +const tagFormValue = ref({ |
| 187 | + name: "", |
| 188 | + value: "", |
| 189 | +}) |
| 190 | +// 获取标签 |
| 191 | +const resp: any = await getBucketTagging(bucketName.value) |
| 192 | +const tags = ref<Tag[]>(resp.TagSet || []) |
| 193 | +
|
| 194 | +const addTag = () => { |
| 195 | + nowTagIndex.value = -1 |
| 196 | + tagFormValue.value = { name: "", value: "" } // 清空表单 |
| 197 | + showTagModal.value = true |
| 198 | +} |
| 199 | +
|
| 200 | +const submitTagForm = () => { |
| 201 | + if (!tagFormValue.value.name || !tagFormValue.value.value) { |
| 202 | + message.error("请填写完整的标签信息") |
| 203 | + return |
| 204 | + } |
139 | 205 |
|
140 | | -const router = useRouter(); |
141 | | -const { $s3Client } = useNuxtApp(); |
142 | | -const message = useMessage(); |
143 | | -const props = defineProps<{ bucket: string }>(); |
| 206 | + if (nowTagIndex.value === -1) { |
| 207 | + tags.value.push({ Key: tagFormValue.value.name, Value: tagFormValue.value.value }) |
| 208 | + } |
| 209 | + if (nowTagIndex.value !== -1) { |
| 210 | + tags.value[nowTagIndex.value] = { Key: tagFormValue.value.name, Value: tagFormValue.value.value } |
| 211 | + } |
| 212 | + // 调用 putBucketTagging 接口 |
| 213 | + putBucketTagging(bucketName.value, { TagSet: tags.value }) |
| 214 | + .then(() => { |
| 215 | + showTagModal.value = false // 关闭模态框 |
| 216 | + message.success("标签更新成功") |
| 217 | + }) |
| 218 | + .catch((error) => { |
| 219 | + message.error("标签更新失败: " + error.message) |
| 220 | + }) |
| 221 | +} |
144 | 222 |
|
145 | | -const bucketName = computed(() => props.bucket as string); |
| 223 | +const nowTagIndex = ref(-1) |
| 224 | +// 编辑标签 |
| 225 | +const editTag = (index: number) => { |
| 226 | + nowTagIndex.value = index |
| 227 | + const nowTag = tags.value[index] |
| 228 | + tagFormValue.value = { name: nowTag.Key, value: nowTag.Value } // 填充表单 |
| 229 | + showTagModal.value = true // 打开模态框 |
| 230 | +} |
| 231 | +const handledeleteTag = (index: number) => { |
| 232 | + nowTagIndex.value = index |
| 233 | + tags.value.splice(index, 1) // 从标签列表中删除 |
146 | 234 |
|
147 | | -const { headBucket } = useBucket({}); |
| 235 | + // 调用 putBucketTagging 接口 |
| 236 | + putBucketTagging(bucketName.value, { TagSet: tags.value }) |
| 237 | + .then(() => { |
| 238 | + message.success("标签更新成功") |
| 239 | + }) |
| 240 | + .catch((error) => { |
| 241 | + message.error("删除标签失败: " + error.message) |
| 242 | + }) |
| 243 | +} |
| 244 | +/********tag */ |
148 | 245 |
|
149 | 246 | // 在服务端获取数据 |
150 | 247 | const { |
151 | 248 | data: bucket, |
152 | 249 | status, |
153 | 250 | refresh, |
154 | | -} = useAsyncData(`head-bucket&${bucketName.value}`, () => headBucket(bucketName.value)); |
| 251 | +} = useAsyncData(`head-bucket&${bucketName.value}`, () => headBucket(bucketName.value)) |
155 | 252 | </script> |
0 commit comments