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

160 lines
5.5 KiB
Vue
Raw Normal View History

2022-10-11 17:46:52 +08:00
<template>
<div>
2022-10-17 16:04:39 +08:00
<Submenu activeName="volume" />
<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>
<el-card style="margin-top: 20px" :class="{ mask: dockerStatus != 'Running' }">
2023-01-30 09:39:37 +08:00
<LayoutContent :header="$t('container.volume')">
<ComplexTable
:pagination-config="paginationConfig"
v-model:selects="selects"
:data="data"
@search="search"
>
<template #toolbar>
<el-button icon="Plus" type="primary" @click="onCreate()">
{{ $t('commons.button.create') }}
</el-button>
<el-button type="danger" plain :disabled="selects.length === 0" @click="batchDelete(null)">
{{ $t('commons.button.delete') }}
</el-button>
2022-10-11 19:47:16 +08:00
</template>
2023-01-30 09:39:37 +08:00
<el-table-column type="selection" fix />
<el-table-column
:label="$t('commons.table.name')"
show-overflow-tooltip
min-width="80"
prop="name"
fix
>
<template #default="{ row }">
<el-link @click="onInspect(row.name)" type="primary">{{ row.name }}</el-link>
</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')"
:formatter="dateFromat"
/>
<fu-table-operations :buttons="buttons" :label="$t('commons.table.operate')" fix />
</ComplexTable>
</LayoutContent>
2022-10-11 17:46:52 +08:00
</el-card>
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';
2022-10-11 17:46:52 +08:00
import ComplexTable from '@/components/complex-table/index.vue';
import CreateDialog from '@/views/container/volume/create/index.vue';
2022-10-17 16:04:39 +08:00
import Submenu from '@/views/container/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';
import { dateFromat } 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
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,
});
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 = {
2022-12-06 18:24:26 +08:00
page: paginationConfig.currentPage,
2022-10-11 17:46:52 +08:00
pageSize: paginationConfig.pageSize,
};
2022-10-17 09:10:06 +08:00
await searchVolume(params).then((res) => {
2022-12-06 18:24:26 +08:00
data.value = res.data.items || [];
2022-10-11 17:46:52 +08:00
paginationConfig.total = res.data.total;
});
};
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>