Feat: delete image

This commit is contained in:
Lazy 2023-10-18 22:54:33 +08:00
parent eb01bd67a0
commit 6721f1e271
3 changed files with 42 additions and 16 deletions

View File

@ -6,12 +6,13 @@ export const ImageList = useDefineApi<
{ {
params: { params: {
remote_uuid: string; remote_uuid: string;
imageId?: string;
}; };
method: string;
}, },
ImageInfo[] ImageInfo[]
>({ >({
url: "/api/environment/image", url: "/api/environment/image"
method: "GET"
}); });
// 获取网络模式 // 获取网络模式

View File

@ -1,7 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref, computed, onMounted, h } from "vue"; import { ref, computed, onMounted, h } from "vue";
import { t } from "@/lang/i18n"; import { t } from "@/lang/i18n";
import { Modal, message } from "ant-design-vue"; import { Modal, message, notification } from "ant-design-vue";
import { DownOutlined, PlusOutlined } from "@ant-design/icons-vue"; import { DownOutlined, PlusOutlined } from "@ant-design/icons-vue";
import CardPanel from "@/components/CardPanel.vue"; import CardPanel from "@/components/CardPanel.vue";
import BetweenMenus from "@/components/BetweenMenus.vue"; import BetweenMenus from "@/components/BetweenMenus.vue";
@ -18,23 +18,24 @@ const { getMetaOrRouteValue } = useLayoutCardTools(props.card);
const daemonId: string | undefined = getMetaOrRouteValue("daemonId"); const daemonId: string | undefined = getMetaOrRouteValue("daemonId");
const screen = useScreen(); const screen = useScreen();
const { execute: getImageListApi, state: images, isLoading: ImageListLoading } = ImageList(); const { execute: execImageList, state: images, isLoading: ImageListLoading } = ImageList();
const getImageList = async () => { const getImageList = async () => {
try { try {
await getImageListApi({ await execImageList({
params: { params: {
remote_uuid: daemonId ?? "" remote_uuid: daemonId ?? ""
} },
method: "GET"
}); });
if (images.value) dataSource.value = images.value; if (images.value) imageDataSource.value = images.value;
} catch (err: any) { } catch (err: any) {
console.error(err); console.error(err);
return message.error(err.message); return message.error(err.message);
} }
}; };
const dataSource = ref<ImageInfo[]>(); const imageDataSource = ref<ImageInfo[]>();
const columns = computed(() => { const imageColumns = computed(() => {
return arrayFilter([ return arrayFilter([
{ {
align: "center", align: "center",
@ -89,6 +90,25 @@ const showDetail = (info: ImageInfo) => {
}); });
}; };
const delImage = async (item: ImageInfo) => {
try {
await execImageList({
params: {
remote_uuid: daemonId ?? "",
imageId: item.RepoTags[0]
},
method: "DELETE"
});
notification["info"]({
message: t("删除指令已发出"),
description: t("请耐心等待,使用刷新功能加载列表,稍后此镜像预计将会被删除")
});
} catch (err: any) {
console.error(err);
return message.error(err.message);
}
};
onMounted(async () => { onMounted(async () => {
await getImageList(); await getImageList();
}); });
@ -129,10 +149,9 @@ onMounted(async () => {
}} }}
</a-typography-text> </a-typography-text>
</a-typography-paragraph> </a-typography-paragraph>
<a-table <a-table
:data-source="dataSource" :data-source="imageDataSource"
:columns="columns" :columns="imageColumns"
:pagination="{ :pagination="{
pageSize: 10, pageSize: 10,
showSizeChanger: true showSizeChanger: true
@ -145,9 +164,14 @@ onMounted(async () => {
<a-button class="mr-8" size="" @click="showDetail(record)"> <a-button class="mr-8" size="" @click="showDetail(record)">
{{ t("详情") }} {{ t("详情") }}
</a-button> </a-button>
<a-button size="" danger> <a-popconfirm
{{ t("删除") }} :title="t('此操作将永久删除该镜像, 是否继续?')"
</a-button> @confirm="delImage(record)"
>
<a-button size="" danger>
{{ t("删除") }}
</a-button>
</a-popconfirm>
</template> </template>
</template> </template>
</a-table> </a-table>

View File

@ -57,7 +57,8 @@ const loadImages = async () => {
const images = await getImageList({ const images = await getImageList({
params: { params: {
remote_uuid: props.daemonId ?? "" remote_uuid: props.daemonId ?? ""
} },
method: "GET"
}); });
if (images.value) { if (images.value) {
dockerImages.value = [t("--- 新建镜像 ---")]; dockerImages.value = [t("--- 新建镜像 ---")];