1
0
mirror of https://github.com/1Panel-dev/1Panel.git synced 2025-01-22 09:49:16 +08:00

182 lines
6.3 KiB
Vue
Raw Normal View History

2022-10-11 17:46:52 +08:00
<template>
<div>
<el-card width="30%" v-if="dockerStatus != 'Running'" class="mask-prompt">
<span style="font-size: 14px">{{ $t('container.serviceUnavailable') }}</span>
<el-button type="primary" link style="font-size: 14px; margin-bottom: 5px" @click="goSetting">
{{ $t('container.setting') }}
</el-button>
<span style="font-size: 14px">{{ $t('container.startIn') }}</span>
</el-card>
<LayoutContent v-loading="loading" :title="$t('container.volume')" :class="{ mask: dockerStatus != 'Running' }">
<template #toolbar>
2023-02-07 18:48:32 +08:00
<el-row>
2023-02-10 15:55:56 +08:00
<el-col :span="16">
2023-02-07 18:48:32 +08:00
<el-button type="primary" @click="onCreate()">
{{ $t('container.createVolume') }}
</el-button>
<el-button type="primary" plain :disabled="selects.length === 0" @click="batchDelete(null)">
{{ $t('commons.button.delete') }}
</el-button>
</el-col>
2023-02-10 15:55:56 +08:00
<el-col :span="8">
<TableSetting @search="search()" />
2023-02-07 18:48:32 +08:00
<div class="search-button">
<el-input
v-model="searchName"
clearable
@clear="search()"
suffix-icon="Search"
@keyup.enter="search()"
@blur="search()"
:placeholder="$t('commons.button.search')"
></el-input>
</div>
</el-col>
</el-row>
</template>
<template #main>
2023-01-30 09:39:37 +08:00
<ComplexTable
:pagination-config="paginationConfig"
v-model:selects="selects"
:data="data"
@search="search"
>
<el-table-column type="selection" fix />
2023-02-23 11:39:47 +08:00
<el-table-column :label="$t('commons.table.name')" min-width="80" prop="name" fix>
2023-01-30 09:39:37 +08:00
<template #default="{ row }">
<Tooltip @click="onInspect(row.name)" :text="row.name" />
2023-01-30 09:39:37 +08:00
</template>
</el-table-column>
<el-table-column
:label="$t('container.mountpoint')"
show-overflow-tooltip
min-width="120"
prop="mountpoint"
/>
<el-table-column
:label="$t('container.driver')"
show-overflow-tooltip
min-width="80"
prop="driver"
/>
<el-table-column
prop="createdAt"
min-width="90"
:label="$t('commons.table.date')"
2023-01-16 15:55:53 +08:00
:formatter="dateFormat"
2023-01-30 09:39:37 +08:00
/>
<fu-table-operations :buttons="buttons" :label="$t('commons.table.operate')" fix />
</ComplexTable>
</template>
</LayoutContent>
2022-10-11 17:46:52 +08:00
2022-11-18 16:14:23 +08:00
<CodemirrorDialog ref="codemirror" />
2022-10-11 17:46:52 +08:00
<CreateDialog @search="search" ref="dialogCreateRef" />
</div>
</template>
<script lang="ts" setup>
2023-01-30 09:39:37 +08:00
import LayoutContent from '@/layout/layout-content.vue';
import Tooltip from '@/components/tooltip/index.vue';
2022-10-11 17:46:52 +08:00
import ComplexTable from '@/components/complex-table/index.vue';
2023-02-10 15:55:56 +08:00
import TableSetting from '@/components/table-setting/index.vue';
2022-10-11 17:46:52 +08:00
import CreateDialog from '@/views/container/volume/create/index.vue';
2022-11-18 16:14:23 +08:00
import CodemirrorDialog from '@/components/codemirror-dialog/codemirror.vue';
2022-10-11 17:46:52 +08:00
import { reactive, onMounted, ref } from 'vue';
2023-01-16 15:55:53 +08:00
import { dateFormat } from '@/utils/util';
import { deleteVolume, searchVolume, inspect, loadDockerStatus } from '@/api/modules/container';
2022-10-11 17:46:52 +08:00
import { Container } from '@/api/interface/container';
import i18n from '@/lang';
import { useDeleteData } from '@/hooks/use-delete-data';
import router from '@/routers';
2022-10-11 17:46:52 +08:00
const loading = ref();
2022-10-11 19:47:16 +08:00
const detailInfo = ref();
2022-11-18 16:14:23 +08:00
const codemirror = ref();
2022-10-11 19:47:16 +08:00
2022-10-11 17:46:52 +08:00
const data = ref();
const selects = ref<any>([]);
const paginationConfig = reactive({
2022-12-06 18:24:26 +08:00
currentPage: 1,
2022-10-11 17:46:52 +08:00
pageSize: 10,
total: 0,
});
2023-02-07 18:48:32 +08:00
const searchName = ref();
2022-10-11 17:46:52 +08:00
const dockerStatus = ref();
const loadStatus = async () => {
const res = await loadDockerStatus();
dockerStatus.value = res.data;
if (dockerStatus.value === 'Running') {
search();
}
};
const goSetting = async () => {
router.push({ name: 'ContainerSetting' });
};
2022-10-11 17:46:52 +08:00
const dialogCreateRef = ref<DialogExpose>();
interface DialogExpose {
acceptParams: () => void;
}
const onCreate = async () => {
dialogCreateRef.value!.acceptParams();
};
const search = async () => {
const params = {
2023-02-07 18:48:32 +08:00
info: searchName.value,
2022-12-06 18:24:26 +08:00
page: paginationConfig.currentPage,
2022-10-11 17:46:52 +08:00
pageSize: paginationConfig.pageSize,
};
loading.value = true;
await searchVolume(params)
.then((res) => {
loading.value = false;
data.value = res.data.items || [];
paginationConfig.total = res.data.total;
})
.catch(() => {
loading.value = false;
});
2022-10-11 17:46:52 +08:00
};
2022-10-11 19:47:16 +08:00
const onInspect = async (id: string) => {
const res = await inspect({ id: id, type: 'volume' });
detailInfo.value = JSON.stringify(JSON.parse(res.data), null, 2);
2022-11-18 16:14:23 +08:00
let param = {
header: i18n.global.t('commons.button.view'),
detailInfo: detailInfo.value,
};
codemirror.value!.acceptParams(param);
2022-10-11 19:47:16 +08:00
};
2022-10-11 17:46:52 +08:00
const batchDelete = async (row: Container.VolumeInfo | null) => {
let names: Array<string> = [];
2022-10-11 17:46:52 +08:00
if (row === null) {
selects.value.forEach((item: Container.VolumeInfo) => {
names.push(item.name);
2022-10-11 17:46:52 +08:00
});
} else {
names.push(row.name);
2022-10-11 17:46:52 +08:00
}
await useDeleteData(deleteVolume, { names: names }, 'commons.msg.delete');
2022-10-11 17:46:52 +08:00
search();
};
const buttons = [
{
label: i18n.global.t('commons.button.delete'),
click: (row: Container.VolumeInfo) => {
batchDelete(row);
},
},
];
onMounted(() => {
loadStatus();
2022-10-11 17:46:52 +08:00
});
</script>