ACS
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,708 @@
|
||||
<template>
|
||||
<div class="image-categories-container" v-loading="loading">
|
||||
<!-- 页面标题 -->
|
||||
<div class="page-header">
|
||||
<h2>镜像分类管理</h2>
|
||||
<p class="page-description">管理不同服务器下的镜像分类</p>
|
||||
</div>
|
||||
|
||||
<!-- 操作栏 -->
|
||||
<el-card class="search-card">
|
||||
<el-form :inline="true" class="search-form">
|
||||
<el-form-item label="服务器">
|
||||
<el-select
|
||||
v-model="selectedServer"
|
||||
placeholder="请选择服务器"
|
||||
clearable
|
||||
@change="handleServerChange"
|
||||
style="width: 220px"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in serverList"
|
||||
:key="item.server_id"
|
||||
:label="item.name"
|
||||
:value="item.server_id"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="分类名称">
|
||||
<el-input
|
||||
v-model="searchKey"
|
||||
placeholder="搜索分类名称"
|
||||
clearable
|
||||
@input="handleSearch"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button
|
||||
type="primary"
|
||||
@click="handleAddCategory"
|
||||
:disabled="!selectedServer"
|
||||
>
|
||||
<el-icon><plus /></el-icon>添加分类
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-card>
|
||||
|
||||
<!-- 表格 -->
|
||||
<el-card class="table-card">
|
||||
<el-table
|
||||
v-loading="loading"
|
||||
:data="filteredCategoryList"
|
||||
style="width: 100%"
|
||||
border
|
||||
stripe
|
||||
highlight-current-row
|
||||
>
|
||||
<el-table-column type="index" width="60" align="center" label="序号" />
|
||||
<el-table-column prop="name" label="分类名称" min-width="150" />
|
||||
<el-table-column label="分类图标" align="center" width="100">
|
||||
<template #default="scope">
|
||||
<el-avatar
|
||||
v-if="scope.row.class_ico"
|
||||
:size="40"
|
||||
:src="scope.row.class_ico"
|
||||
fit="cover"
|
||||
/>
|
||||
<el-icon v-else :size="20"><picture /></el-icon>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="所属服务器" min-width="150">
|
||||
<template #default="scope">
|
||||
<el-tag type="info">{{ getServerName(scope.row.server_id) }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="created_at" label="创建时间" min-width="180">
|
||||
<template #default="scope">
|
||||
{{ scope.row.created_at }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="200" align="center" fixed="right">
|
||||
<template #default="scope">
|
||||
<el-button
|
||||
type="success"
|
||||
link
|
||||
@click="handleEditCategory(scope.row)"
|
||||
>
|
||||
<el-icon><edit /></el-icon>编辑
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<!-- 分页器 -->
|
||||
<div class="pagination-container">
|
||||
<el-pagination
|
||||
background
|
||||
:current-page="currentPage"
|
||||
:page-size="pageSize"
|
||||
:page-sizes="[10, 20, 50, 100]"
|
||||
layout="total, sizes, prev, pager, next"
|
||||
:total="totalCount"
|
||||
@size-change="handleSizeChange"
|
||||
@current-change="handleCurrentChange"
|
||||
/>
|
||||
</div>
|
||||
</el-card>
|
||||
|
||||
<!-- 添加/编辑分类对话框 -->
|
||||
<el-dialog
|
||||
v-model="dialogVisible"
|
||||
:title="isEdit ? '编辑分类' : '添加分类'"
|
||||
width="500px"
|
||||
destroy-on-close
|
||||
>
|
||||
<el-form
|
||||
ref="categoryFormRef"
|
||||
:model="categoryForm"
|
||||
:rules="categoryRules"
|
||||
label-width="100px"
|
||||
>
|
||||
<el-form-item label="所属服务器" prop="server_id" v-if="!isEdit">
|
||||
<el-select
|
||||
v-model="categoryForm.server_id"
|
||||
placeholder="请选择服务器"
|
||||
style="width: 100%"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in serverList"
|
||||
:key="item.server_id"
|
||||
:label="item.name"
|
||||
:value="item.server_id"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="分类名称" prop="class_name">
|
||||
<el-input v-model="categoryForm.class_name" placeholder="请输入分类名称" />
|
||||
</el-form-item>
|
||||
<el-form-item label="分类图标" prop="class_icon">
|
||||
<div class="image-icon-upload">
|
||||
<div class="preview-container">
|
||||
<img
|
||||
v-if="categoryForm.class_icon"
|
||||
:src="categoryForm.class_icon"
|
||||
class="preview-icon"
|
||||
/>
|
||||
<div v-else class="empty-preview">
|
||||
<el-icon><picture /></el-icon>
|
||||
</div>
|
||||
</div>
|
||||
<div class="upload-buttons">
|
||||
<el-button type="primary" @click="$refs.fileInput.click()">选择文件</el-button>
|
||||
<input ref="fileInput" type="file" style="display: none" @change="onFileSelected" />
|
||||
<div class="el-upload__tip" v-if="selectedFileName">
|
||||
已选择: {{ selectedFileName }}
|
||||
</div>
|
||||
<el-button @click="picSwitch = true; getpicList()">从素材库选择</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button @click="dialogVisible = false">取 消</el-button>
|
||||
<el-button type="primary" @click="submitCategoryForm" :loading="submitLoading">
|
||||
确 定
|
||||
</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<!-- 素材库对话框 -->
|
||||
<el-dialog v-model="picSwitch" title="素材库" width="70%" :before-close="() => picSwitch = false">
|
||||
<div class="pic-search">
|
||||
<el-input
|
||||
v-model="picPagin.key"
|
||||
placeholder="请输入搜索内容"
|
||||
style="width: 300px; margin-bottom: 20px"
|
||||
@blur="getpicList()"
|
||||
>
|
||||
<template #append>
|
||||
<el-button @click="getpicList()">
|
||||
<el-icon><search /></el-icon>
|
||||
</el-button>
|
||||
</template>
|
||||
</el-input>
|
||||
</div>
|
||||
<div class="piclist">
|
||||
<div
|
||||
v-for="(item, index) in picList"
|
||||
:key="index"
|
||||
class="icon"
|
||||
:class="{ choose: currentIndex === index }"
|
||||
@click="selectImage(index, item)"
|
||||
>
|
||||
<img :src="`${mainUrl}/v1/attachment/get_attachment?aid=${item.attachment_id}`" />
|
||||
<div class="tit">{{ item.title ? item.title.slice(0, 8) : '未命名' }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="pagination-container" style="margin-top: 20px">
|
||||
<el-pagination
|
||||
background
|
||||
layout="total, sizes, prev, pager, next"
|
||||
:total="total"
|
||||
:current-page="picPagin.page"
|
||||
:page-size="picPagin.count"
|
||||
:page-sizes="[10, 20, 50, 100]"
|
||||
@current-change="CurrentPageChange"
|
||||
@size-change="PageSizeChange"
|
||||
/>
|
||||
</div>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button @click="picSwitch = false">取消</el-button>
|
||||
<el-button type="primary" @click="tochoose">确认选择</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive, computed, onMounted } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { Search, Plus, Picture, Edit } from '@element-plus/icons-vue'
|
||||
import dayjs from 'dayjs'
|
||||
import { getServer } from '@/utils/acs/server'
|
||||
import { getImageTypeList, createImageType, updateImageType } from '@/utils/acs/mirror'
|
||||
import { uploadFile, getFileList } from '@/utils/acs/message'
|
||||
import { mainUrl } from '@/utils/request'
|
||||
|
||||
// 数据
|
||||
const loading = ref(false)
|
||||
const submitLoading = ref(false)
|
||||
const serverList = ref([])
|
||||
const categoryList = ref([])
|
||||
const selectedServer = ref('')
|
||||
const searchKey = ref('')
|
||||
const currentPage = ref(1)
|
||||
const pageSize = ref(10)
|
||||
const totalCount = ref(0)
|
||||
const dialogVisible = ref(false)
|
||||
const isEdit = ref(false)
|
||||
const categoryFormRef = ref(null)
|
||||
const selectedFileName = ref(null)
|
||||
|
||||
const categoryForm = reactive({
|
||||
server_id: '',
|
||||
class_id: '',
|
||||
class_name: '',
|
||||
class_icon: ''
|
||||
})
|
||||
|
||||
const categoryRules = {
|
||||
server_id: [
|
||||
{ required: true, message: '请选择所属服务器', trigger: 'change' }
|
||||
],
|
||||
class_name: [
|
||||
{ required: true, message: '请输入分类名称', trigger: 'blur' },
|
||||
{ min: 2, max: 50, message: '长度在 2 到 50 个字符', trigger: 'blur' }
|
||||
]
|
||||
}
|
||||
|
||||
// 素材库相关
|
||||
const picSwitch = ref(false)
|
||||
const picPagin = reactive({
|
||||
count: 50,
|
||||
page: 1,
|
||||
key: '',
|
||||
user_type: 1
|
||||
})
|
||||
const picList = ref([])
|
||||
const total = ref(10)
|
||||
const currentIndex = ref(null)
|
||||
|
||||
// 计算属性:过滤分类列表
|
||||
const filteredCategoryList = computed(() => {
|
||||
if (!searchKey.value) {
|
||||
return categoryList.value
|
||||
}
|
||||
return categoryList.value.filter(item =>
|
||||
item.name && item.name.toLowerCase().includes(searchKey.value.toLowerCase())
|
||||
)
|
||||
})
|
||||
|
||||
// 生命周期钩子
|
||||
onMounted(async () => {
|
||||
await fetchServerList()
|
||||
})
|
||||
|
||||
// 方法
|
||||
const fetchServerList = async () => {
|
||||
try {
|
||||
loading.value = true
|
||||
// 获取服务器列表,这里包含了所有类型的服务器
|
||||
const response = await getServer(1, 100, '', '')
|
||||
if (response.data.code === 200) {
|
||||
serverList.value = response.data.data || []
|
||||
// 如果没有选择服务器但有服务器列表数据,默认选择第一个服务器
|
||||
if (serverList.value.length > 0 && !selectedServer.value) {
|
||||
selectedServer.value = serverList.value[0].server_id
|
||||
// 获取默认服务器的分类列表
|
||||
fetchCategoryList()
|
||||
}
|
||||
} else {
|
||||
ElMessage.error('获取服务器列表失败:' + response.data.message)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取服务器列表出错:', error)
|
||||
ElMessage.error('获取服务器列表出错')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const fetchCategoryList = async () => {
|
||||
if (!selectedServer.value) {
|
||||
categoryList.value = []
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
loading.value = true
|
||||
const response = await getImageTypeList(selectedServer.value)
|
||||
if (response.data.code === 200) {
|
||||
categoryList.value = response.data.data || []
|
||||
totalCount.value = categoryList.value.length
|
||||
} else {
|
||||
ElMessage.error('获取镜像分类失败:' + response.data.message)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取镜像分类出错:', error)
|
||||
ElMessage.error('获取镜像分类出错')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const handleServerChange = () => {
|
||||
currentPage.value = 1
|
||||
fetchCategoryList()
|
||||
}
|
||||
|
||||
const handleSearch = () => {
|
||||
currentPage.value = 1
|
||||
}
|
||||
|
||||
const handleSizeChange = (val) => {
|
||||
pageSize.value = val
|
||||
currentPage.value = 1
|
||||
}
|
||||
|
||||
const handleCurrentChange = (val) => {
|
||||
currentPage.value = val
|
||||
}
|
||||
|
||||
const handleAddCategory = () => {
|
||||
isEdit.value = false
|
||||
categoryForm.server_id = selectedServer.value
|
||||
categoryForm.class_id = ''
|
||||
categoryForm.class_name = ''
|
||||
categoryForm.class_icon = ''
|
||||
selectedFileName.value = null
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
const handleEditCategory = (row) => {
|
||||
isEdit.value = true
|
||||
categoryForm.server_id = row.server_id
|
||||
categoryForm.class_id = row.class_id
|
||||
categoryForm.class_name = row.name
|
||||
categoryForm.class_icon = row.class_ico
|
||||
selectedFileName.value = null
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
|
||||
// 处理文件变更
|
||||
const onFileSelected = (event) => {
|
||||
const file = event.target.files[0]
|
||||
if (file) {
|
||||
selectedFileName.value = file.name
|
||||
const isImage = /^image\/(jpeg|png|jpg|gif)$/.test(file.type)
|
||||
const isLt2M = file.size / 1024 / 1024 < 2
|
||||
|
||||
if (!isImage) {
|
||||
ElMessage.error('上传图标只能是图片格式!')
|
||||
return
|
||||
}
|
||||
if (!isLt2M) {
|
||||
ElMessage.error('上传图标大小不能超过 2MB!')
|
||||
return
|
||||
}
|
||||
|
||||
uploadFile({ file: file }).then((res) => {
|
||||
if (res.data.code == 200) {
|
||||
ElMessage.success('上传成功')
|
||||
categoryForm.class_icon = mainUrl + '/v1/attachment/get_attachment?aid=' + res.data.data.attachment_id
|
||||
} else {
|
||||
ElMessage.error('上传失败:' + res.data.message)
|
||||
}
|
||||
}).catch((error) => {
|
||||
console.error('上传文件出错:', error)
|
||||
ElMessage.error('上传失败')
|
||||
})
|
||||
} else {
|
||||
selectedFileName.value = null
|
||||
}
|
||||
}
|
||||
|
||||
const submitCategoryForm = () => {
|
||||
categoryFormRef.value.validate(async (valid) => {
|
||||
if (!valid) return
|
||||
|
||||
try {
|
||||
submitLoading.value = true
|
||||
let response
|
||||
|
||||
if (isEdit.value) {
|
||||
// 编辑分类
|
||||
response = await updateImageType(
|
||||
categoryForm.class_id,
|
||||
categoryForm.class_name,
|
||||
categoryForm.class_icon
|
||||
)
|
||||
} else {
|
||||
// 添加分类
|
||||
response = await createImageType(
|
||||
categoryForm.server_id,
|
||||
categoryForm.class_name,
|
||||
categoryForm.class_icon
|
||||
)
|
||||
}
|
||||
|
||||
if (response.data.code === 200) {
|
||||
ElMessage.success(isEdit.value ? '更新分类成功' : '添加分类成功')
|
||||
dialogVisible.value = false
|
||||
fetchCategoryList()
|
||||
} else {
|
||||
ElMessage.error((isEdit.value ? '更新分类失败:' : '添加分类失败:') + response.data.message)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(isEdit.value ? '更新分类出错:' : '添加分类出错:', error)
|
||||
ElMessage.error(isEdit.value ? '更新分类出错' : '添加分类出错')
|
||||
} finally {
|
||||
submitLoading.value = false
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 素材库相关方法
|
||||
const getpicList = () => {
|
||||
getFileList(picPagin).then(res => {
|
||||
if (res.data.code === 200) {
|
||||
picList.value = res.data.data || []
|
||||
total.value = res.data.count || 0
|
||||
} else {
|
||||
ElMessage.error('获取图片列表失败:' + res.data.message)
|
||||
}
|
||||
}).catch((error) => {
|
||||
console.error('获取图片列表出错:', error)
|
||||
ElMessage.error('获取图片列表失败')
|
||||
})
|
||||
}
|
||||
|
||||
const selectImage = (index, data) => {
|
||||
currentIndex.value = index
|
||||
}
|
||||
|
||||
const CurrentPageChange = async newPage => {
|
||||
picPagin.page = newPage
|
||||
getpicList()
|
||||
}
|
||||
|
||||
const PageSizeChange = async newSize => {
|
||||
picPagin.count = newSize
|
||||
getpicList()
|
||||
}
|
||||
|
||||
const tochoose = () => {
|
||||
if (currentIndex.value != null) {
|
||||
categoryForm.class_icon = `${mainUrl}/v1/attachment/get_attachment?aid=${picList.value[currentIndex.value].attachment_id}`
|
||||
picSwitch.value = false
|
||||
ElMessage.success('已选择图标')
|
||||
} else {
|
||||
ElMessage.warning('请先选择一个图标')
|
||||
}
|
||||
}
|
||||
|
||||
const getServerName = (serverId) => {
|
||||
const server = serverList.value.find(item => item.server_id === serverId)
|
||||
return server ? server.name : '--'
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.image-categories-container {
|
||||
padding: 24px;
|
||||
background-color: #f5f7fa;
|
||||
min-height: calc(100vh - 60px);
|
||||
}
|
||||
|
||||
.page-header {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
margin-bottom: 24px;
|
||||
background: #fff;
|
||||
padding: 16px 24px;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.page-header h2 {
|
||||
margin: 0;
|
||||
font-size: 22px;
|
||||
color: #303133;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.page-description {
|
||||
margin-top: 8px;
|
||||
color: #6b7280;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.search-card {
|
||||
margin-bottom: 24px;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.search-form {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 16px;
|
||||
padding: 8px;
|
||||
}
|
||||
|
||||
.table-card {
|
||||
margin-bottom: 24px;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.pagination-container {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
margin-top: 16px;
|
||||
padding: 0 16px 16px;
|
||||
}
|
||||
|
||||
/* 图片上传区域样式 */
|
||||
.image-icon-upload {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.preview-container {
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
border: 1px dashed #d9d9d9;
|
||||
border-radius: 8px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
overflow: hidden;
|
||||
background-color: #f5f7fa;
|
||||
}
|
||||
|
||||
.preview-icon {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: contain;
|
||||
}
|
||||
|
||||
.empty-preview {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
color: #8c939d;
|
||||
}
|
||||
|
||||
.empty-preview .el-icon {
|
||||
font-size: 28px;
|
||||
}
|
||||
|
||||
.upload-buttons {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.el-upload__tip {
|
||||
font-size: 12px;
|
||||
color: #606266;
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
/* 素材库样式 */
|
||||
.piclist {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 16px;
|
||||
margin: 16px 0;
|
||||
}
|
||||
|
||||
.piclist .icon {
|
||||
width: 100px;
|
||||
height: 110px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
padding: 12px;
|
||||
border-radius: 8px;
|
||||
border: 1px solid #ebeef5;
|
||||
transition: all 0.3s;
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
.piclist .icon:hover {
|
||||
cursor: pointer;
|
||||
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
|
||||
transform: translateY(-3px);
|
||||
}
|
||||
|
||||
.piclist .icon img {
|
||||
width: 60px;
|
||||
height: 60px;
|
||||
object-fit: contain;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.piclist .icon .tit {
|
||||
margin-top: 10px;
|
||||
font-size: 13px;
|
||||
text-align: center;
|
||||
width: 100%;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
color: #606266;
|
||||
}
|
||||
|
||||
.piclist .choose {
|
||||
border-color: #409EFF;
|
||||
box-shadow: 0 0 12px rgba(64, 158, 255, 0.6);
|
||||
background-color: #ecf5ff;
|
||||
}
|
||||
|
||||
/* 对话框样式优化 */
|
||||
:deep(.el-dialog__header) {
|
||||
border-bottom: 1px solid #ebeef5;
|
||||
padding: 16px 20px;
|
||||
}
|
||||
|
||||
:deep(.el-dialog__body) {
|
||||
padding: 24px;
|
||||
}
|
||||
|
||||
:deep(.el-dialog__footer) {
|
||||
border-top: 1px solid #ebeef5;
|
||||
padding: 16px 20px;
|
||||
}
|
||||
|
||||
:deep(.el-form-item__label) {
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
:deep(.el-table) {
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
:deep(.el-table th) {
|
||||
background-color: #f5f7fa;
|
||||
color: #606266;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
:deep(.el-table__row:hover) {
|
||||
background-color: #ecf5ff !important;
|
||||
}
|
||||
|
||||
:deep(.el-button--link) {
|
||||
padding: 4px 8px;
|
||||
}
|
||||
|
||||
:deep(.el-button--link):hover {
|
||||
background-color: #f0f2f5;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
/* 响应式调整 */
|
||||
@media (max-width: 768px) {
|
||||
.image-icon-upload {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.upload-buttons {
|
||||
margin-top: 12px;
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,728 @@
|
||||
<template>
|
||||
<div class="image-requests-container">
|
||||
<div class="page-header">
|
||||
<h2>申请镜像</h2>
|
||||
<div class="header-actions">
|
||||
<el-button type="primary" @click="handleAdd">
|
||||
<el-icon><plus /></el-icon>申请镜像
|
||||
</el-button>
|
||||
<el-button @click="handleRefresh">
|
||||
<el-icon><refresh /></el-icon>刷新
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 提示信息 -->
|
||||
<el-alert
|
||||
type="info"
|
||||
show-icon
|
||||
:closable="false"
|
||||
class="info-alert"
|
||||
>
|
||||
<el-icon><info-filled /></el-icon>
|
||||
申请的镜像需要经过安全审核,审核通过后可在创建云电脑或容器时使用,审核结果将通过站内信通知。
|
||||
</el-alert>
|
||||
|
||||
<!-- 搜索区域 -->
|
||||
<el-card class="search-card">
|
||||
<el-form :inline="true" :model="searchForm" class="search-form">
|
||||
<el-form-item label="镜像名称">
|
||||
<el-input v-model="searchForm.name" placeholder="请输入镜像名称" clearable />
|
||||
</el-form-item>
|
||||
<el-form-item label="镜像类型">
|
||||
<el-select v-model="searchForm.type" placeholder="请选择镜像类型" clearable>
|
||||
<el-option label="Docker镜像" value="docker" />
|
||||
<el-option label="Windows镜像" value="windows" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="申请状态">
|
||||
<el-select v-model="searchForm.status" placeholder="请选择状态" clearable>
|
||||
<el-option label="已通过" value="approved" />
|
||||
<el-option label="审核中" value="pending" />
|
||||
<el-option label="已拒绝" value="rejected" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="handleSearch">
|
||||
<el-icon><search /></el-icon>搜索
|
||||
</el-button>
|
||||
<el-button @click="resetSearch">
|
||||
<el-icon><refresh /></el-icon>重置
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-card>
|
||||
|
||||
<!-- 数据表格 -->
|
||||
<el-card class="table-card">
|
||||
<el-table
|
||||
v-loading="loading"
|
||||
:data="tableData"
|
||||
border
|
||||
style="width: 100%"
|
||||
row-key="id"
|
||||
>
|
||||
<el-table-column prop="id" label="申请ID" width="150" align="center" />
|
||||
<el-table-column prop="name" label="镜像名称" min-width="180" show-overflow-tooltip />
|
||||
<el-table-column prop="type" label="类型" width="120" align="center">
|
||||
<template #default="scope">
|
||||
<el-tag :type="scope.row.type === 'docker' ? 'success' : 'primary'">
|
||||
{{ scope.row.type === 'docker' ? 'Docker' : 'Windows' }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="requestTime" label="申请时间" width="180" align="center" />
|
||||
<el-table-column prop="status" label="状态" width="100" align="center">
|
||||
<template #default="scope">
|
||||
<el-tag :type="getStatusType(scope.row.status)">
|
||||
{{ getStatusText(scope.row.status) }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="220" align="center" fixed="right">
|
||||
<template #default="scope">
|
||||
<el-button type="primary" link @click="handleView(scope.row)">
|
||||
<el-icon><view /></el-icon>查看详情
|
||||
</el-button>
|
||||
<el-button
|
||||
v-if="scope.row.status === 'rejected'"
|
||||
type="primary"
|
||||
link
|
||||
@click="handleResubmit(scope.row)"
|
||||
>
|
||||
<el-icon><refresh /></el-icon>重新提交
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<!-- 分页 -->
|
||||
<div class="pagination-container">
|
||||
<el-pagination
|
||||
v-model:current-page="pagination.currentPage"
|
||||
v-model:page-size="pagination.pageSize"
|
||||
:page-sizes="[10, 20, 50, 100]"
|
||||
:total="pagination.total"
|
||||
layout="total, sizes, prev, pager, next, jumper"
|
||||
@size-change="handleSizeChange"
|
||||
@current-change="handleCurrentChange"
|
||||
/>
|
||||
</div>
|
||||
</el-card>
|
||||
|
||||
<!-- 申请镜像对话框 -->
|
||||
<el-dialog
|
||||
v-model="requestDialogVisible"
|
||||
title="申请镜像"
|
||||
width="700px"
|
||||
:before-close="handleDialogClose"
|
||||
>
|
||||
<el-form :model="requestForm" label-width="120px" :rules="rules" ref="requestFormRef">
|
||||
<el-form-item label="镜像类型" prop="type">
|
||||
<el-radio-group v-model="requestForm.type">
|
||||
<el-radio label="docker">Docker镜像</el-radio>
|
||||
<el-radio label="windows">Windows镜像</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="镜像名称" prop="name">
|
||||
<el-input v-model="requestForm.name" placeholder="请输入镜像名称,例如:MySQL 8.0" />
|
||||
</el-form-item>
|
||||
|
||||
<template v-if="requestForm.type === 'docker'">
|
||||
<el-form-item label="Docker镜像地址" prop="dockerImage">
|
||||
<el-input v-model="requestForm.dockerImage" placeholder="请输入Docker镜像地址,例如:mysql:8.0">
|
||||
<template #prepend>
|
||||
<el-select v-model="requestForm.dockerSource" style="width: 120px">
|
||||
<el-option label="Docker Hub" value="dockerhub" />
|
||||
<el-option label="自定义" value="custom" />
|
||||
</el-select>
|
||||
</template>
|
||||
</el-input>
|
||||
<div class="form-tip">Docker Hub格式:mysql:8.0;自建仓库格式:namespace/repo:tag</div>
|
||||
</el-form-item>
|
||||
|
||||
<el-divider content-position="left">环境变量配置</el-divider>
|
||||
|
||||
<div class="env-vars-container">
|
||||
<div class="env-vars-header">
|
||||
<div class="env-var-name">变量名</div>
|
||||
<div class="env-var-value">变量值</div>
|
||||
<div class="env-var-action"></div>
|
||||
</div>
|
||||
|
||||
<div v-for="(env, index) in requestForm.envVars" :key="index" class="env-vars-item">
|
||||
<el-input v-model="env.key" placeholder="KEY" />
|
||||
<el-input v-model="env.value" placeholder="VALUE" />
|
||||
<el-button circle type="danger" @click="removeEnvVar(index)">
|
||||
<el-icon><delete /></el-icon>
|
||||
</el-button>
|
||||
</div>
|
||||
|
||||
<el-button type="primary" plain @click="addEnvVar" class="add-env-btn">
|
||||
<el-icon><plus /></el-icon>添加环境变量
|
||||
</el-button>
|
||||
</div>
|
||||
|
||||
<el-divider content-position="left">暴露端口</el-divider>
|
||||
|
||||
<div class="ports-container">
|
||||
<div class="ports-header">
|
||||
<div class="port-container">容器端口</div>
|
||||
<div class="port-protocol">协议</div>
|
||||
<div class="port-desc">描述</div>
|
||||
<div class="port-action"></div>
|
||||
</div>
|
||||
|
||||
<div v-for="(port, index) in requestForm.ports" :key="index" class="ports-item">
|
||||
<el-input-number v-model="port.containerPort" :min="1" :max="65535" controls-position="right" />
|
||||
<el-select v-model="port.protocol">
|
||||
<el-option label="TCP" value="TCP" />
|
||||
<el-option label="UDP" value="UDP" />
|
||||
</el-select>
|
||||
<el-input v-model="port.description" placeholder="请填写用途描述" />
|
||||
<el-button circle type="danger" @click="removePort(index)">
|
||||
<el-icon><delete /></el-icon>
|
||||
</el-button>
|
||||
</div>
|
||||
|
||||
<el-button type="primary" plain @click="addPort" class="add-port-btn">
|
||||
<el-icon><plus /></el-icon>添加端口
|
||||
</el-button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template v-else>
|
||||
<el-form-item label="Windows版本" prop="windowsVersion">
|
||||
<el-select v-model="requestForm.windowsVersion" placeholder="请选择Windows版本" style="width: 100%">
|
||||
<el-option label="Windows Server 2019" value="2019" />
|
||||
<el-option label="Windows Server 2022" value="2022" />
|
||||
<el-option label="Windows 10" value="10" />
|
||||
<el-option label="Windows 11" value="11" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="镜像链接" prop="windowsImageUrl">
|
||||
<el-input v-model="requestForm.windowsImageUrl" placeholder="请输入Windows镜像的下载链接" />
|
||||
<div class="form-tip">提供ISO镜像的下载链接,支持微软官方、MSDN等其他合法渠道的镜像</div>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="激活方式" prop="activationMethod">
|
||||
<el-radio-group v-model="requestForm.activationMethod">
|
||||
<el-radio label="kms">KMS激活</el-radio>
|
||||
<el-radio label="key">产品密钥</el-radio>
|
||||
<el-radio label="none">不需要激活</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
</template>
|
||||
|
||||
<el-form-item label="申请理由" prop="reason">
|
||||
<el-input
|
||||
v-model="requestForm.reason"
|
||||
type="textarea"
|
||||
:rows="4"
|
||||
placeholder="请详细说明申请该镜像的用途和理由"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button @click="handleDialogClose">取消</el-button>
|
||||
<el-button type="primary" @click="submitForm">提交申请</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<!-- 查看详情对话框 -->
|
||||
<el-dialog
|
||||
v-model="detailDialogVisible"
|
||||
title="申请详情"
|
||||
width="700px"
|
||||
:before-close="handleDialogClose"
|
||||
>
|
||||
<div v-if="currentRequest.id" class="request-detail">
|
||||
<el-descriptions :column="2" border>
|
||||
<el-descriptions-item label="申请ID" :span="2">{{ currentRequest.id }}</el-descriptions-item>
|
||||
<el-descriptions-item label="镜像名称">{{ currentRequest.name }}</el-descriptions-item>
|
||||
<el-descriptions-item label="镜像类型">
|
||||
<el-tag :type="currentRequest.type === 'docker' ? 'success' : 'primary'">
|
||||
{{ currentRequest.type === 'docker' ? 'Docker' : 'Windows' }}
|
||||
</el-tag>
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="申请时间">{{ currentRequest.requestTime }}</el-descriptions-item>
|
||||
<el-descriptions-item label="状态">
|
||||
<el-tag :type="getStatusType(currentRequest.status)">
|
||||
{{ getStatusText(currentRequest.status) }}
|
||||
</el-tag>
|
||||
</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
|
||||
<el-divider content-position="left">详细信息</el-divider>
|
||||
|
||||
<template v-if="currentRequest.type === 'docker'">
|
||||
<el-descriptions :column="1" border>
|
||||
<el-descriptions-item label="Docker镜像地址">
|
||||
{{ currentRequest.dockerSource === 'dockerhub' ? 'Docker Hub: ' : '自定义: ' }}{{ currentRequest.dockerImage }}
|
||||
</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
|
||||
<div v-if="currentRequest.envVars && currentRequest.envVars.length > 0">
|
||||
<el-divider content-position="left">环境变量</el-divider>
|
||||
<el-table :data="currentRequest.envVars" border style="width: 100%">
|
||||
<el-table-column prop="key" label="变量名" />
|
||||
<el-table-column prop="value" label="变量值" />
|
||||
</el-table>
|
||||
</div>
|
||||
|
||||
<div v-if="currentRequest.ports && currentRequest.ports.length > 0">
|
||||
<el-divider content-position="left">端口配置</el-divider>
|
||||
<el-table :data="currentRequest.ports" border style="width: 100%">
|
||||
<el-table-column prop="containerPort" label="容器端口" width="120" />
|
||||
<el-table-column prop="protocol" label="协议" width="100" />
|
||||
<el-table-column prop="description" label="描述" />
|
||||
</el-table>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template v-else>
|
||||
<el-descriptions :column="1" border>
|
||||
<el-descriptions-item label="Windows版本">
|
||||
{{ getWindowsVersionText(currentRequest.windowsVersion) }}
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="镜像链接">
|
||||
{{ currentRequest.windowsImageUrl }}
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="激活方式">
|
||||
{{ getActivationMethodText(currentRequest.activationMethod) }}
|
||||
</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
</template>
|
||||
|
||||
<el-divider content-position="left">申请理由</el-divider>
|
||||
<div class="request-reason">{{ currentRequest.reason }}</div>
|
||||
|
||||
<template v-if="currentRequest.reviewComment">
|
||||
<el-divider content-position="left">审核意见</el-divider>
|
||||
<div class="review-comment">{{ currentRequest.reviewComment }}</div>
|
||||
</template>
|
||||
</div>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive, onMounted } from 'vue'
|
||||
import {
|
||||
Plus, Refresh, Search, View, Delete, InfoFilled
|
||||
} from '@element-plus/icons-vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
|
||||
// 搜索表单
|
||||
const searchForm = reactive({
|
||||
name: '',
|
||||
type: '',
|
||||
status: ''
|
||||
})
|
||||
|
||||
// 重置搜索
|
||||
const resetSearch = () => {
|
||||
searchForm.name = ''
|
||||
searchForm.type = ''
|
||||
searchForm.status = ''
|
||||
handleSearch()
|
||||
}
|
||||
|
||||
// 表格数据
|
||||
const loading = ref(false)
|
||||
const tableData = ref([])
|
||||
|
||||
// 分页
|
||||
const pagination = reactive({
|
||||
currentPage: 1,
|
||||
pageSize: 10,
|
||||
total: 0
|
||||
})
|
||||
|
||||
// 处理页码变化
|
||||
const handleCurrentChange = (val) => {
|
||||
pagination.currentPage = val
|
||||
fetchData()
|
||||
}
|
||||
|
||||
// 处理每页条数变化
|
||||
const handleSizeChange = (val) => {
|
||||
pagination.pageSize = val
|
||||
fetchData()
|
||||
}
|
||||
|
||||
// 对话框相关
|
||||
const requestDialogVisible = ref(false)
|
||||
const detailDialogVisible = ref(false)
|
||||
const currentRequest = ref({})
|
||||
|
||||
// 表单对象和规则
|
||||
const requestFormRef = ref(null)
|
||||
const requestForm = reactive({
|
||||
type: 'docker',
|
||||
name: '',
|
||||
dockerSource: 'dockerhub',
|
||||
dockerImage: '',
|
||||
windowsVersion: '',
|
||||
windowsImageUrl: '',
|
||||
activationMethod: 'kms',
|
||||
reason: '',
|
||||
envVars: [],
|
||||
ports: []
|
||||
})
|
||||
|
||||
const rules = {
|
||||
type: [{ required: true, message: '请选择镜像类型', trigger: 'change' }],
|
||||
name: [{ required: true, message: '请输入镜像名称', trigger: 'blur' }],
|
||||
dockerImage: [{ required: true, message: '请输入Docker镜像地址', trigger: 'blur' }],
|
||||
windowsVersion: [{ required: true, message: '请选择Windows版本', trigger: 'change' }],
|
||||
windowsImageUrl: [{ required: true, message: '请输入镜像链接', trigger: 'blur' }],
|
||||
activationMethod: [{ required: true, message: '请选择激活方式', trigger: 'change' }],
|
||||
reason: [{ required: true, message: '请输入申请理由', trigger: 'blur' }]
|
||||
}
|
||||
|
||||
// 状态标签样式
|
||||
const getStatusType = (status) => {
|
||||
const map = {
|
||||
approved: 'success',
|
||||
pending: 'warning',
|
||||
rejected: 'danger'
|
||||
}
|
||||
return map[status] || 'info'
|
||||
}
|
||||
|
||||
const getStatusText = (status) => {
|
||||
const map = {
|
||||
approved: '已通过',
|
||||
pending: '审核中',
|
||||
rejected: '已拒绝'
|
||||
}
|
||||
return map[status] || '未知'
|
||||
}
|
||||
|
||||
// Windows版本文本
|
||||
const getWindowsVersionText = (version) => {
|
||||
const map = {
|
||||
'2019': 'Windows Server 2019',
|
||||
'2022': 'Windows Server 2022',
|
||||
'10': 'Windows 10',
|
||||
'11': 'Windows 11'
|
||||
}
|
||||
return map[version] || '未知'
|
||||
}
|
||||
|
||||
// 激活方式文本
|
||||
const getActivationMethodText = (method) => {
|
||||
const map = {
|
||||
kms: 'KMS激活',
|
||||
key: '产品密钥',
|
||||
none: '不需要激活'
|
||||
}
|
||||
return map[method] || '未知'
|
||||
}
|
||||
|
||||
// 处理搜索
|
||||
const handleSearch = () => {
|
||||
pagination.currentPage = 1
|
||||
fetchData()
|
||||
}
|
||||
|
||||
// 刷新数据
|
||||
const handleRefresh = () => {
|
||||
fetchData()
|
||||
}
|
||||
|
||||
// 添加环境变量
|
||||
const addEnvVar = () => {
|
||||
requestForm.envVars.push({ key: '', value: '' })
|
||||
}
|
||||
|
||||
// 移除环境变量
|
||||
const removeEnvVar = (index) => {
|
||||
requestForm.envVars.splice(index, 1)
|
||||
}
|
||||
|
||||
// 添加端口
|
||||
const addPort = () => {
|
||||
requestForm.ports.push({ containerPort: 80, protocol: 'TCP', description: '' })
|
||||
}
|
||||
|
||||
// 移除端口
|
||||
const removePort = (index) => {
|
||||
requestForm.ports.splice(index, 1)
|
||||
}
|
||||
|
||||
// 获取数据
|
||||
const fetchData = () => {
|
||||
loading.value = true
|
||||
|
||||
// 模拟API请求
|
||||
setTimeout(() => {
|
||||
// 这里应该是真实的API请求
|
||||
const mockData = [
|
||||
{
|
||||
id: 'REQ20240501001',
|
||||
name: 'MySQL 8.0',
|
||||
type: 'docker',
|
||||
requestTime: '2024-05-01 10:23:45',
|
||||
status: 'approved',
|
||||
dockerSource: 'dockerhub',
|
||||
dockerImage: 'mysql:8.0',
|
||||
envVars: [
|
||||
{ key: 'MYSQL_ROOT_PASSWORD', value: 'password' },
|
||||
{ key: 'MYSQL_DATABASE', value: 'testdb' }
|
||||
],
|
||||
ports: [
|
||||
{ containerPort: 3306, protocol: 'TCP', description: 'MySQL默认端口' }
|
||||
],
|
||||
reason: '用于开发测试环境,需要MySQL数据库服务',
|
||||
reviewComment: '审核通过,已添加到镜像列表'
|
||||
},
|
||||
{
|
||||
id: 'REQ20240502001',
|
||||
name: 'Windows Server 2022',
|
||||
type: 'windows',
|
||||
requestTime: '2024-05-02 14:30:12',
|
||||
status: 'pending',
|
||||
windowsVersion: '2022',
|
||||
windowsImageUrl: 'https://example.com/windows-server-2022.iso',
|
||||
activationMethod: 'kms',
|
||||
reason: '用于测试Windows Server 2022的新功能和兼容性'
|
||||
},
|
||||
{
|
||||
id: 'REQ20240503001',
|
||||
name: 'Redis 7.0',
|
||||
type: 'docker',
|
||||
requestTime: '2024-05-03 09:15:36',
|
||||
status: 'rejected',
|
||||
dockerSource: 'dockerhub',
|
||||
dockerImage: 'redis:7.0',
|
||||
envVars: [],
|
||||
ports: [
|
||||
{ containerPort: 6379, protocol: 'TCP', description: 'Redis默认端口' }
|
||||
],
|
||||
reason: '用于缓存服务',
|
||||
reviewComment: '镜像存在安全漏洞,请使用Redis 7.0.2或更高版本'
|
||||
}
|
||||
]
|
||||
|
||||
tableData.value = mockData
|
||||
pagination.total = mockData.length
|
||||
loading.value = false
|
||||
}, 500)
|
||||
}
|
||||
|
||||
// 申请镜像
|
||||
const handleAdd = () => {
|
||||
requestForm.type = 'docker'
|
||||
requestForm.name = ''
|
||||
requestForm.dockerSource = 'dockerhub'
|
||||
requestForm.dockerImage = ''
|
||||
requestForm.windowsVersion = ''
|
||||
requestForm.windowsImageUrl = ''
|
||||
requestForm.activationMethod = 'kms'
|
||||
requestForm.reason = ''
|
||||
requestForm.envVars = []
|
||||
requestForm.ports = []
|
||||
requestDialogVisible.value = true
|
||||
}
|
||||
|
||||
// 查看详情
|
||||
const handleView = (row) => {
|
||||
currentRequest.value = { ...row }
|
||||
detailDialogVisible.value = true
|
||||
}
|
||||
|
||||
// 重新提交
|
||||
const handleResubmit = (row) => {
|
||||
// 复制原有申请的信息到表单
|
||||
requestForm.type = row.type
|
||||
requestForm.name = row.name
|
||||
|
||||
if (row.type === 'docker') {
|
||||
requestForm.dockerSource = row.dockerSource
|
||||
requestForm.dockerImage = row.dockerImage
|
||||
requestForm.envVars = [...row.envVars]
|
||||
requestForm.ports = [...row.ports]
|
||||
} else {
|
||||
requestForm.windowsVersion = row.windowsVersion
|
||||
requestForm.windowsImageUrl = row.windowsImageUrl
|
||||
requestForm.activationMethod = row.activationMethod
|
||||
}
|
||||
|
||||
requestForm.reason = row.reason
|
||||
requestDialogVisible.value = true
|
||||
}
|
||||
|
||||
// 关闭对话框
|
||||
const handleDialogClose = () => {
|
||||
requestDialogVisible.value = false
|
||||
detailDialogVisible.value = false
|
||||
if (requestFormRef.value) {
|
||||
requestFormRef.value.resetFields()
|
||||
}
|
||||
}
|
||||
|
||||
// 提交表单
|
||||
const submitForm = async () => {
|
||||
if (!requestFormRef.value) return
|
||||
|
||||
await requestFormRef.value.validate((valid) => {
|
||||
if (valid) {
|
||||
// 这里应该是API请求
|
||||
ElMessage.success('申请提交成功,请等待审核')
|
||||
requestDialogVisible.value = false
|
||||
fetchData()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 初始加载
|
||||
onMounted(() => {
|
||||
fetchData()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.image-requests-container {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.page-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.header-actions {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.info-alert {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.search-card {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.search-form {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.table-card {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.pagination-container {
|
||||
margin-top: 20px;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
/* 表单样式 */
|
||||
.form-tip {
|
||||
font-size: 12px;
|
||||
color: #909399;
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
/* 环境变量配置样式 */
|
||||
.env-vars-container {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.env-vars-header {
|
||||
display: flex;
|
||||
margin-bottom: 10px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.env-vars-item {
|
||||
display: flex;
|
||||
margin-bottom: 10px;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.env-var-name {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.env-var-value {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.env-var-action {
|
||||
width: 40px;
|
||||
}
|
||||
|
||||
.add-env-btn {
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
/* 端口配置样式 */
|
||||
.ports-container {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.ports-header {
|
||||
display: flex;
|
||||
margin-bottom: 10px;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.ports-item {
|
||||
display: flex;
|
||||
margin-bottom: 10px;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.port-container {
|
||||
width: 150px;
|
||||
}
|
||||
|
||||
.port-protocol {
|
||||
width: 120px;
|
||||
}
|
||||
|
||||
.port-desc {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.port-action {
|
||||
width: 40px;
|
||||
}
|
||||
|
||||
.add-port-btn {
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
/* 详情样式 */
|
||||
.request-detail {
|
||||
padding: 0 10px;
|
||||
}
|
||||
|
||||
.request-reason {
|
||||
background-color: #f8f8f8;
|
||||
padding: 15px;
|
||||
border-radius: 4px;
|
||||
margin-top: 10px;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
.review-comment {
|
||||
background-color: #f0f9eb;
|
||||
padding: 15px;
|
||||
border-radius: 4px;
|
||||
margin-top: 10px;
|
||||
white-space: pre-wrap;
|
||||
border-left: 4px solid #67c23a;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,904 @@
|
||||
<template>
|
||||
<div class="vm-images-container" v-loading="loading">
|
||||
<div class="page-header">
|
||||
<h2>虚拟机镜像</h2>
|
||||
<div class="header-actions">
|
||||
<el-button type="primary" @click="toLoad(selectedServer)" :disabled="!selectedServer">
|
||||
<el-icon><plus /></el-icon>添加镜像
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 搜索区域 -->
|
||||
<el-card class="search-card">
|
||||
<el-form :inline="true" :model="searchForm" class="search-form">
|
||||
<el-form-item label="服务器">
|
||||
<el-select
|
||||
v-model="selectedServer"
|
||||
placeholder="请选择服务器"
|
||||
clearable
|
||||
@change="handleServerChange"
|
||||
style="width: 220px"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in serverList"
|
||||
:key="item.server_id"
|
||||
:label="item.name"
|
||||
:value="item.server_id"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="镜像名称">
|
||||
<el-input v-model="searchForm.name" placeholder="请输入镜像名称" clearable />
|
||||
</el-form-item>
|
||||
<el-form-item label="操作系统">
|
||||
<el-select v-model="searchForm.os" placeholder="请选择操作系统" clearable>
|
||||
<el-option label="Windows" value="windows" />
|
||||
<el-option label="Ubuntu" value="ubuntu" />
|
||||
<el-option label="CentOS" value="centos" />
|
||||
<el-option label="Debian" value="debian" />
|
||||
<el-option label="其他" value="other" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="状态">
|
||||
<el-select v-model="searchForm.status" placeholder="请选择状态" clearable>
|
||||
<el-option label="可用" value="available" />
|
||||
<el-option label="创建中" value="creating" />
|
||||
<el-option label="已禁用" value="disabled" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="handleSearch">
|
||||
<el-icon><search /></el-icon>搜索
|
||||
</el-button>
|
||||
<el-button @click="resetSearch">
|
||||
<el-icon><refresh /></el-icon>重置
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-card>
|
||||
|
||||
<!-- 镜像列表 -->
|
||||
<el-card class="table-card" v-if="selectedServer">
|
||||
<el-table
|
||||
v-loading="tableLoading"
|
||||
:data="currentImages"
|
||||
border
|
||||
style="width: 100%"
|
||||
row-key="id"
|
||||
>
|
||||
<el-table-column type="index" label="序号" width="60" align="center" />
|
||||
<el-table-column label="镜像信息" min-width="250">
|
||||
<template #default="scope">
|
||||
<div class="image-info-cell">
|
||||
<img :src="mainUrl + scope.row.image_ico" class="table-image-logo" />
|
||||
<div class="image-info-content">
|
||||
<div class="image-name-row">
|
||||
<span class="table-image-name">{{ scope.row.name }}</span>
|
||||
</div>
|
||||
<div class="image-desc-row">{{ scope.row.description || '暂无描述' }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="show_name" label="展示名称" width="120" show-overflow-tooltip />
|
||||
<el-table-column label="状态" width="100" align="center">
|
||||
<template #default="scope">
|
||||
<el-tag :type="getStatusType(scope.row.state)">
|
||||
{{ getStatusText(scope.row.state) }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="created_at" label="创建时间" width="180" align="center" />
|
||||
<el-table-column label="操作" width="250" align="center" fixed="right">
|
||||
<template #default="scope">
|
||||
<el-button
|
||||
type="primary"
|
||||
link
|
||||
@click="handleCreateVM(scope.row)"
|
||||
v-if="scope.row.state === 1"
|
||||
>
|
||||
<el-icon><monitor /></el-icon>创建虚拟机
|
||||
</el-button>
|
||||
<el-button type="success" link @click="handleEdit(scope.row)">
|
||||
<el-icon><edit /></el-icon>编辑
|
||||
</el-button>
|
||||
<el-button type="danger" link @click="handleDelete(scope.row)">
|
||||
<el-icon><delete /></el-icon>删除
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<!-- 分页 -->
|
||||
<div class="pagination-container">
|
||||
<el-pagination
|
||||
background
|
||||
layout="total, sizes, prev, pager, next"
|
||||
:total="totalCount"
|
||||
:current-page="currentPage"
|
||||
:page-size="pageSize"
|
||||
:page-sizes="[10, 20, 50, 100]"
|
||||
@update:current-page="handleCurrentPageChange"
|
||||
@update:page-size="handleSizeChange"
|
||||
/>
|
||||
</div>
|
||||
</el-card>
|
||||
|
||||
<!-- 未选择服务器时的提示 -->
|
||||
<el-empty
|
||||
v-if="!selectedServer && !loading"
|
||||
description="请选择一个服务器查看镜像列表"
|
||||
class="empty-tip"
|
||||
/>
|
||||
|
||||
<!-- 镜像表单对话框 -->
|
||||
<el-dialog
|
||||
v-model="dialogVisible"
|
||||
:title="editOr ? '编辑镜像' : '添加镜像'"
|
||||
width="600px"
|
||||
:before-close="handleDialogClose"
|
||||
>
|
||||
<el-form :model="imageForm" label-width="120px" :rules="rules" ref="imageFormRef">
|
||||
<el-form-item label="镜像名称" prop="name">
|
||||
<el-input v-model="imageForm.name" placeholder="请输入镜像名称" />
|
||||
</el-form-item>
|
||||
<el-form-item label="文件路径" prop="path" v-if="!editOr">
|
||||
<el-input v-model="imageForm.path" placeholder="请输入镜像文件路径" />
|
||||
</el-form-item>
|
||||
<el-form-item label="展示名称" prop="show_name">
|
||||
<el-input v-model="imageForm.show_name" placeholder="请输入展示名称" />
|
||||
</el-form-item>
|
||||
<el-form-item label="分类" prop="class_id" v-if="!editOr">
|
||||
<el-select v-model="imageForm.class_id" placeholder="请选择分类" clearable style="width: 100%">
|
||||
<el-option v-for="item in categoryList" :key="item.class_id" :label="item.name" :value="item.class_id" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="图标" prop="image_ico">
|
||||
<div class="image-icon-upload">
|
||||
<img v-if="imageForm.image_ico" :src="mainUrl + imageForm.image_ico" class="preview-icon" />
|
||||
<div class="upload-buttons">
|
||||
<el-button type="primary" @click="$refs.fileInput.click()">选择文件</el-button>
|
||||
<input ref="fileInput" type="file" style="display: none" @change="onFileSelected" />
|
||||
<div class="el-upload__tip" v-if="selectedFileName">
|
||||
已选择: {{ selectedFileName }}
|
||||
</div>
|
||||
<el-button @click="picSwitch = true; getpicList()">从素材库选择</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</el-form-item>
|
||||
<el-form-item label="套餐" prop="plan_id">
|
||||
<el-select v-model="imageForm.plan_id" placeholder="请选择套餐" style="width: 100%">
|
||||
<el-option v-for="item in planlist" :key="item.id" :label="item.name" :value="item.id" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="描述" prop="description">
|
||||
<el-input
|
||||
v-model="imageForm.description"
|
||||
type="textarea"
|
||||
:rows="3"
|
||||
placeholder="请输入镜像描述"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button @click="getit">一键粘贴内容</el-button>
|
||||
<el-button @click="copyit">一键复制内容</el-button>
|
||||
<el-button @click="handleDialogClose">取消</el-button>
|
||||
<el-button type="primary" @click="submitForm">确认</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<!-- 素材库对话框 -->
|
||||
<el-dialog v-model="picSwitch" title="素材库" width="70%" :before-close="() => picSwitch = false">
|
||||
<div class="pic-search">
|
||||
<el-input
|
||||
v-model="picPagin.key"
|
||||
placeholder="请输入搜索内容"
|
||||
style="width: 300px; margin-bottom: 20px"
|
||||
@blur="getpicList()"
|
||||
>
|
||||
<template #append>
|
||||
<el-button @click="getpicList()">
|
||||
<el-icon><search /></el-icon>
|
||||
</el-button>
|
||||
</template>
|
||||
</el-input>
|
||||
</div>
|
||||
<div class="piclist">
|
||||
<div
|
||||
v-for="(item, index) in picList"
|
||||
:key="index"
|
||||
class="icon"
|
||||
:class="{ choose: currentIndex === index }"
|
||||
@click="selectImage(index, item)"
|
||||
>
|
||||
<img :src="`${mainUrl}/v1/attachment/get_attachment?aid=${item.attachment_id}`" />
|
||||
<div class="tit">{{ item.title ? item.title.slice(0, 8) : '未命名' }}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="pagination-container" style="margin-top: 20px">
|
||||
<el-pagination
|
||||
background
|
||||
layout="total, sizes, prev, pager, next"
|
||||
:total="total"
|
||||
:current-page="picPagin.page"
|
||||
:page-size="picPagin.count"
|
||||
:page-sizes="[10, 20, 50, 100]"
|
||||
@current-change="CurrentPageChange"
|
||||
@size-change="PageSizeChange"
|
||||
/>
|
||||
</div>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button @click="picSwitch = false">取消</el-button>
|
||||
<el-button type="primary" @click="tochoose">确认选择</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive, onMounted } from 'vue'
|
||||
import {
|
||||
Plus, Search, Refresh, Edit, Delete, TurnOff, Open, Monitor
|
||||
} from '@element-plus/icons-vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { getServer, getServerPlan } from '@/utils/acs/server'
|
||||
import {
|
||||
editMirror, delMirror, getUserMirrorList, addVirtualMirror, getImageTypeList
|
||||
} from '@/utils/acs/mirror'
|
||||
import { uploadFile, getFileList } from '@/utils/acs/message'
|
||||
import { mainUrl } from '@/utils/request'
|
||||
|
||||
// 搜索表单
|
||||
const searchForm = reactive({
|
||||
name: '',
|
||||
os: '',
|
||||
status: ''
|
||||
})
|
||||
|
||||
// 重置搜索
|
||||
const resetSearch = () => {
|
||||
searchForm.name = ''
|
||||
searchForm.os = ''
|
||||
searchForm.status = ''
|
||||
handleSearch()
|
||||
}
|
||||
|
||||
// 表格数据
|
||||
const loading = ref(false)
|
||||
const tableLoading = ref(false)
|
||||
const serverList = ref([])
|
||||
const selectedServer = ref('')
|
||||
const currentImages = ref([])
|
||||
const currentPage = ref(1)
|
||||
const pageSize = ref(10)
|
||||
const totalCount = ref(0)
|
||||
|
||||
// 对话框相关
|
||||
const dialogVisible = ref(false)
|
||||
const editOr = ref(false)
|
||||
const selectedFileName = ref(null)
|
||||
const planlist = ref([])
|
||||
const nowserver_id = ref('')
|
||||
|
||||
// 表单对象和规则
|
||||
const imageFormRef = ref(null)
|
||||
const imageForm = reactive({
|
||||
id: '',
|
||||
name: '',
|
||||
show_name: '',
|
||||
description: '',
|
||||
server_type: 'hyperV',
|
||||
plan_id: '',
|
||||
image_ico: '',
|
||||
server_id: '',
|
||||
path: '',
|
||||
class_id: ''
|
||||
})
|
||||
|
||||
const rules = {
|
||||
name: [{ required: true, message: '请输入镜像名称', trigger: 'blur' }],
|
||||
path: [{ required: true, message: '请输入镜像文件路径', trigger: 'blur' }],
|
||||
show_name: [{ required: true, message: '请输入展示名称', trigger: 'blur' }],
|
||||
// plan_id: [{ required: true, message: '请选择套餐', trigger: 'change' }]
|
||||
}
|
||||
|
||||
// 素材库相关
|
||||
const picSwitch = ref(false)
|
||||
const picPagin = reactive({
|
||||
count: 50,
|
||||
page: 1,
|
||||
key: '',
|
||||
user_type: 1
|
||||
})
|
||||
const picList = ref([])
|
||||
const total = ref(10)
|
||||
const currentIndex = ref(null)
|
||||
const categoryList = ref([])
|
||||
|
||||
// 获取操作系统图标
|
||||
const getOsIcon = (os) => {
|
||||
const icons = {
|
||||
windows: 'https://cdn.jsdelivr.net/gh/devicons/devicon/icons/windows8/windows8-original.svg',
|
||||
ubuntu: 'https://cdn.jsdelivr.net/gh/devicons/devicon/icons/ubuntu/ubuntu-plain.svg',
|
||||
centos: 'https://cdn.jsdelivr.net/gh/devicons/devicon/icons/redhat/redhat-original.svg',
|
||||
debian: 'https://cdn.jsdelivr.net/gh/devicons/devicon/icons/debian/debian-original.svg',
|
||||
other: 'https://cdn.jsdelivr.net/gh/devicons/devicon/icons/linux/linux-original.svg'
|
||||
}
|
||||
return icons[os] || icons.other
|
||||
}
|
||||
|
||||
// 状态标签样式
|
||||
const getStatusType = (state) => {
|
||||
const map = {
|
||||
0: 'warning',
|
||||
1: 'success',
|
||||
2: 'danger'
|
||||
}
|
||||
return map[state] || 'info'
|
||||
}
|
||||
|
||||
const getStatusText = (state) => {
|
||||
const map = {
|
||||
0: '上传中',
|
||||
1: '可用',
|
||||
2: '上传失败'
|
||||
}
|
||||
return map[state] || '未知'
|
||||
}
|
||||
|
||||
// 处理搜索
|
||||
const handleSearch = () => {
|
||||
if (selectedServer.value) {
|
||||
fetchImageList()
|
||||
}
|
||||
}
|
||||
|
||||
// 处理服务器变更
|
||||
const handleServerChange = () => {
|
||||
currentPage.value = 1
|
||||
if (selectedServer.value) {
|
||||
fetchImageList()
|
||||
} else {
|
||||
currentImages.value = []
|
||||
totalCount.value = 0
|
||||
}
|
||||
}
|
||||
|
||||
// 获取服务器列表
|
||||
const fetchServerList = async () => {
|
||||
try {
|
||||
loading.value = true
|
||||
const response = await getServer(1, 100, '', 'hyperV')
|
||||
if (response.data.code === 200) {
|
||||
serverList.value = response.data.data || []
|
||||
// 如果有服务器列表且没有选择服务器,默认选择第一个
|
||||
if (serverList.value.length > 0 && !selectedServer.value) {
|
||||
selectedServer.value = serverList.value[0].server_id
|
||||
await fetchImageList()
|
||||
}
|
||||
} else {
|
||||
ElMessage.error('获取服务器列表失败:' + response.data.message)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取服务器列表出错:', error)
|
||||
ElMessage.error('获取服务器列表出错')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 获取镜像列表
|
||||
const fetchImageList = async () => {
|
||||
if (!selectedServer.value) return
|
||||
|
||||
try {
|
||||
tableLoading.value = true
|
||||
const response = await getUserMirrorList({
|
||||
server_id: selectedServer.value,
|
||||
count: pageSize.value,
|
||||
page: currentPage.value,
|
||||
key: searchForm.name || ''
|
||||
})
|
||||
|
||||
if (response.data.code === 200) {
|
||||
currentImages.value = response.data.data || []
|
||||
totalCount.value = response.data.count || 0
|
||||
} else {
|
||||
ElMessage.error('获取镜像列表失败:' + response.data.message)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取镜像列表出错:', error)
|
||||
ElMessage.error('获取镜像列表出错')
|
||||
} finally {
|
||||
tableLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 分页相关
|
||||
const handleCurrentPageChange = (newPage) => {
|
||||
currentPage.value = newPage
|
||||
fetchImageList()
|
||||
}
|
||||
|
||||
const handleSizeChange = (newSize) => {
|
||||
pageSize.value = newSize
|
||||
currentPage.value = 1
|
||||
fetchImageList()
|
||||
}
|
||||
|
||||
// 获取镜像分类列表
|
||||
const fetchCategoryList = async (serverId) => {
|
||||
try {
|
||||
const response = await getImageTypeList(serverId)
|
||||
if (response.data.code === 200) {
|
||||
categoryList.value = response.data.data || []
|
||||
} else {
|
||||
ElMessage.error('获取镜像分类失败:' + response.data.message)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取镜像分类出错:', error)
|
||||
ElMessage.error('获取镜像分类列表失败')
|
||||
}
|
||||
}
|
||||
|
||||
// 新增镜像
|
||||
const toLoad = async (data) => {
|
||||
dialogVisible.value = true
|
||||
editOr.value = false
|
||||
Object.keys(imageForm).forEach(key => {
|
||||
imageForm[key] = ''
|
||||
})
|
||||
imageForm.server_id = data
|
||||
nowserver_id.value = data
|
||||
try {
|
||||
// 获取套餐列表
|
||||
let res = await getServerPlan({ server_id: data })
|
||||
planlist.value = res.data.data.map(item => {
|
||||
return {
|
||||
name: item.name,
|
||||
id: item.plan_id,
|
||||
}
|
||||
})
|
||||
// 获取分类列表
|
||||
await fetchCategoryList(data)
|
||||
} catch (error) {
|
||||
ElMessage.error('获取数据失败')
|
||||
}
|
||||
}
|
||||
|
||||
// 处理文件变更
|
||||
const onFileSelected = (event) => {
|
||||
const file = event.target.files[0]
|
||||
if (file) {
|
||||
selectedFileName.value = file.name
|
||||
uploadFile({ file: file }).then((res) => {
|
||||
if (res.data.code == 200) {
|
||||
ElMessage.success('上传成功')
|
||||
selectedFileName.value = null
|
||||
imageForm.image_ico = '/v1/attachment/get_attachment?aid=' + res.data.data.attachment_id
|
||||
}
|
||||
}).catch(() => {
|
||||
ElMessage.error('上传失败')
|
||||
})
|
||||
} else {
|
||||
selectedFileName.value = null
|
||||
}
|
||||
}
|
||||
|
||||
// 添加镜像
|
||||
const handleAdd = () => {
|
||||
if (!selectedServer.value) {
|
||||
ElMessage.warning('请先选择一个服务器')
|
||||
return
|
||||
}
|
||||
toLoad(selectedServer.value)
|
||||
}
|
||||
|
||||
// 编辑镜像
|
||||
const handleEdit = async (row) => {
|
||||
try {
|
||||
let res = await getServerPlan({ server_id: row.server_id })
|
||||
planlist.value = res.data.data.map(item => {
|
||||
return {
|
||||
name: item.name,
|
||||
id: item.plan_id,
|
||||
}
|
||||
})
|
||||
// 获取分类列表
|
||||
await fetchCategoryList(row.server_id)
|
||||
|
||||
editOr.value = true
|
||||
dialogVisible.value = true
|
||||
for (const key in row) {
|
||||
if (row.hasOwnProperty(key)) {
|
||||
imageForm[key] = row[key]
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
ElMessage.error('获取数据失败')
|
||||
}
|
||||
}
|
||||
|
||||
// 删除镜像
|
||||
const handleDelete = (row) => {
|
||||
ElMessageBox.confirm(`确定要删除镜像"${row.name}"吗?删除后不可恢复!`, '警告', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'error'
|
||||
}).then(() => {
|
||||
delMirror({ server_id: row.server_id, image_id: row.id }).then((res) => {
|
||||
if (res.data.code == 200) {
|
||||
ElMessage.success('删除成功')
|
||||
fetchImageList()
|
||||
} else {
|
||||
ElMessage.error(res.data.msg || '删除失败')
|
||||
}
|
||||
}).catch(() => {
|
||||
ElMessage.error('删除失败')
|
||||
})
|
||||
}).catch(() => {})
|
||||
}
|
||||
|
||||
// 创建虚拟机
|
||||
const handleCreateVM = (row) => {
|
||||
ElMessage.success(`正在使用镜像"${row.name}"创建虚拟机,请前往虚拟机管理页面查看`)
|
||||
}
|
||||
|
||||
// 关闭对话框
|
||||
const handleDialogClose = () => {
|
||||
dialogVisible.value = false
|
||||
if (imageFormRef.value) {
|
||||
imageFormRef.value.resetFields()
|
||||
}
|
||||
}
|
||||
|
||||
// 提交表单
|
||||
const submitForm = async () => {
|
||||
if (!imageFormRef.value) return
|
||||
|
||||
await imageFormRef.value.validate((valid) => {
|
||||
if (valid) {
|
||||
if (editOr.value) {
|
||||
imageForm.image_id = imageForm.id
|
||||
delete imageForm.id
|
||||
editMirror(imageForm).then(res => {
|
||||
if (res.data.code == 200) {
|
||||
dialogVisible.value = false
|
||||
ElMessage.success('编辑成功')
|
||||
fetchImageList()
|
||||
} else {
|
||||
ElMessage.error(res.data.msg || '编辑失败')
|
||||
}
|
||||
}).catch(() => {
|
||||
ElMessage.error('编辑失败')
|
||||
})
|
||||
} else {
|
||||
addVirtualMirror(imageForm).then(res => {
|
||||
if (res.data.code == 200) {
|
||||
dialogVisible.value = false
|
||||
ElMessage.success('添加成功')
|
||||
fetchImageList()
|
||||
} else {
|
||||
ElMessage.error(res.data.msg || '添加失败')
|
||||
}
|
||||
}).catch((e) => {
|
||||
ElMessage.error('添加失败')
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 素材库相关
|
||||
const getpicList = () => {
|
||||
getFileList(picPagin).then(res => {
|
||||
picList.value = res.data.data
|
||||
total.value = res.data.count
|
||||
}).catch(() => {
|
||||
ElMessage.error('获取图片列表失败')
|
||||
})
|
||||
}
|
||||
|
||||
const selectImage = (index, data) => {
|
||||
currentIndex.value = index
|
||||
}
|
||||
|
||||
const CurrentPageChange = async newPage => {
|
||||
picPagin.page = newPage
|
||||
getpicList()
|
||||
}
|
||||
|
||||
const PageSizeChange = async newSize => {
|
||||
picPagin.count = newSize
|
||||
getpicList()
|
||||
}
|
||||
|
||||
const tochoose = () => {
|
||||
if (currentIndex.value != null) {
|
||||
imageForm.image_ico = `/v1/attachment/get_attachment?aid=${picList.value[currentIndex.value].attachment_id}`
|
||||
picSwitch.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 复制粘贴相关
|
||||
const copytext = ref({})
|
||||
const copyit = async () => {
|
||||
copytext.value = JSON.parse(JSON.stringify(imageForm))
|
||||
ElMessage.success('复制成功')
|
||||
await navigator.clipboard.writeText(JSON.stringify(copytext.value))
|
||||
}
|
||||
|
||||
const getit = async () => {
|
||||
try {
|
||||
const text = await navigator.clipboard.readText()
|
||||
Object.keys(JSON.parse(text)).forEach(key => {
|
||||
imageForm[key] = JSON.parse(text)[key]
|
||||
})
|
||||
imageForm.server_id = nowserver_id.value
|
||||
ElMessage.success('粘贴成功')
|
||||
return text
|
||||
} catch (err) {
|
||||
ElMessage.error('无法读取剪贴板内容,请检查获取到的格式')
|
||||
}
|
||||
}
|
||||
|
||||
// 初始加载
|
||||
onMounted(() => {
|
||||
fetchServerList()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.vm-images-container {
|
||||
padding: 24px;
|
||||
background-color: #f5f7fa;
|
||||
min-height: calc(100vh - 60px);
|
||||
}
|
||||
|
||||
.page-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 24px;
|
||||
background: #fff;
|
||||
padding: 16px 24px;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.page-header h2 {
|
||||
margin: 0;
|
||||
font-size: 22px;
|
||||
color: #303133;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.header-actions {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.search-card {
|
||||
margin-bottom: 24px;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.search-form {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 16px;
|
||||
padding: 8px;
|
||||
}
|
||||
|
||||
.table-card {
|
||||
margin-bottom: 24px;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.image-info-cell {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 10px 0;
|
||||
}
|
||||
|
||||
.table-image-logo {
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
border-radius: 6px;
|
||||
object-fit: contain;
|
||||
background-color: #f5f7fa;
|
||||
border: 1px solid #ebeef5;
|
||||
padding: 4px;
|
||||
}
|
||||
|
||||
.image-info-content {
|
||||
flex: 1;
|
||||
margin-left: 15px;
|
||||
}
|
||||
|
||||
.image-name-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
.table-image-name {
|
||||
font-weight: 600;
|
||||
margin-right: 12px;
|
||||
color: #303133;
|
||||
font-size: 15px;
|
||||
}
|
||||
|
||||
.image-desc-row {
|
||||
color: #909399;
|
||||
font-size: 13px;
|
||||
line-height: 1.6;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
}
|
||||
|
||||
.pagination-container {
|
||||
margin-top: 20px;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
padding: 0 16px 16px;
|
||||
}
|
||||
|
||||
.empty-tip {
|
||||
margin-top: 50px;
|
||||
}
|
||||
|
||||
.image-icon-upload {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.preview-icon {
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
border-radius: 6px;
|
||||
object-fit: contain;
|
||||
background-color: #f5f7fa;
|
||||
border: 1px solid #ebeef5;
|
||||
padding: 4px;
|
||||
}
|
||||
|
||||
.upload-buttons {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.el-upload__tip {
|
||||
line-height: 1.5;
|
||||
color: #909399;
|
||||
font-size: 12px;
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
||||
/* 素材库样式 */
|
||||
.piclist {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 16px;
|
||||
margin: 16px 0;
|
||||
}
|
||||
|
||||
.piclist .icon {
|
||||
width: 100px;
|
||||
height: 110px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
padding: 12px;
|
||||
border-radius: 8px;
|
||||
border: 1px solid #ebeef5;
|
||||
transition: all 0.3s;
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
.piclist .icon:hover {
|
||||
cursor: pointer;
|
||||
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
|
||||
transform: translateY(-3px);
|
||||
}
|
||||
|
||||
.piclist .icon img {
|
||||
width: 60px;
|
||||
height: 60px;
|
||||
object-fit: contain;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.piclist .icon .tit {
|
||||
margin-top: 10px;
|
||||
font-size: 13px;
|
||||
text-align: center;
|
||||
width: 100%;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
color: #606266;
|
||||
}
|
||||
|
||||
.piclist .choose {
|
||||
border-color: #409EFF;
|
||||
box-shadow: 0 0 12px rgba(64, 158, 255, 0.6);
|
||||
background-color: #ecf5ff;
|
||||
}
|
||||
|
||||
/* 对话框样式优化 */
|
||||
:deep(.el-dialog__header) {
|
||||
border-bottom: 1px solid #ebeef5;
|
||||
padding: 16px 20px;
|
||||
}
|
||||
|
||||
:deep(.el-dialog__body) {
|
||||
padding: 24px;
|
||||
}
|
||||
|
||||
:deep(.el-dialog__footer) {
|
||||
border-top: 1px solid #ebeef5;
|
||||
padding: 16px 20px;
|
||||
}
|
||||
|
||||
:deep(.el-form-item__label) {
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
:deep(.el-table) {
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
:deep(.el-table th) {
|
||||
background-color: #f5f7fa;
|
||||
color: #606266;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
:deep(.el-table__row:hover) {
|
||||
background-color: #ecf5ff !important;
|
||||
}
|
||||
|
||||
:deep(.el-button--link) {
|
||||
padding: 4px 8px;
|
||||
}
|
||||
|
||||
:deep(.el-button--link):hover {
|
||||
background-color: #f0f2f5;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
/* 响应式调整 */
|
||||
@media (max-width: 768px) {
|
||||
.image-info-cell {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.image-info-content {
|
||||
margin-left: 0;
|
||||
margin-top: 12px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.table-image-logo {
|
||||
width: 60px;
|
||||
height: 60px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
@@ -0,0 +1,423 @@
|
||||
<template>
|
||||
<div class="announcements-container">
|
||||
<div class="page-header">
|
||||
<h2>官方公告</h2>
|
||||
<el-button type="primary" @click="handleAdd">
|
||||
<el-icon><plus /></el-icon>发布公告
|
||||
</el-button>
|
||||
</div>
|
||||
|
||||
<!-- 搜索区域 -->
|
||||
<el-card class="search-card">
|
||||
<el-form :inline="true" :model="searchForm" class="search-form">
|
||||
<el-form-item label="公告标题">
|
||||
<el-input v-model="searchForm.title" placeholder="请输入公告标题" clearable />
|
||||
</el-form-item>
|
||||
<el-form-item label="发布时间">
|
||||
<el-date-picker
|
||||
v-model="searchForm.dateRange"
|
||||
type="daterange"
|
||||
range-separator="至"
|
||||
start-placeholder="开始日期"
|
||||
end-placeholder="结束日期"
|
||||
format="YYYY-MM-DD"
|
||||
value-format="YYYY-MM-DD"
|
||||
clearable
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="状态">
|
||||
<el-select v-model="searchForm.status" placeholder="请选择状态" clearable>
|
||||
<el-option label="已发布" value="published" />
|
||||
<el-option label="草稿" value="draft" />
|
||||
<el-option label="已下线" value="offline" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="handleSearch">
|
||||
<el-icon><search /></el-icon>搜索
|
||||
</el-button>
|
||||
<el-button @click="resetSearch">
|
||||
<el-icon><refresh /></el-icon>重置
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-card>
|
||||
|
||||
<!-- 数据表格 -->
|
||||
<el-card class="table-card">
|
||||
<el-table
|
||||
v-loading="loading"
|
||||
:data="tableData"
|
||||
border
|
||||
style="width: 100%"
|
||||
row-key="id"
|
||||
>
|
||||
<el-table-column type="index" label="序号" width="60" align="center" />
|
||||
<el-table-column prop="title" label="公告标题" min-width="200" show-overflow-tooltip />
|
||||
<el-table-column prop="publisher" label="发布人" width="120" align="center" />
|
||||
<el-table-column prop="publishTime" label="发布时间" width="180" align="center" />
|
||||
<el-table-column prop="viewCount" label="查看数" width="100" align="center" />
|
||||
<el-table-column prop="status" label="状态" width="100" align="center">
|
||||
<template #default="scope">
|
||||
<el-tag :type="getStatusType(scope.row.status)">
|
||||
{{ getStatusText(scope.row.status) }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="220" align="center" fixed="right">
|
||||
<template #default="scope">
|
||||
<el-button type="primary" link @click="handleView(scope.row)">
|
||||
<el-icon><view /></el-icon>查看
|
||||
</el-button>
|
||||
<el-button type="primary" link @click="handleEdit(scope.row)">
|
||||
<el-icon><edit /></el-icon>编辑
|
||||
</el-button>
|
||||
<el-button
|
||||
type="primary"
|
||||
link
|
||||
@click="handleChangeStatus(scope.row)"
|
||||
v-if="scope.row.status !== 'offline'"
|
||||
>
|
||||
<el-icon><turn-off /></el-icon>下线
|
||||
</el-button>
|
||||
<el-button
|
||||
type="primary"
|
||||
link
|
||||
@click="handleDelete(scope.row)"
|
||||
v-if="scope.row.status === 'offline'"
|
||||
>
|
||||
<el-icon><delete /></el-icon>删除
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<!-- 分页 -->
|
||||
<div class="pagination-container">
|
||||
<el-pagination
|
||||
v-model:current-page="pagination.currentPage"
|
||||
v-model:page-size="pagination.pageSize"
|
||||
:page-sizes="[10, 20, 50, 100]"
|
||||
:total="pagination.total"
|
||||
layout="total, sizes, prev, pager, next, jumper"
|
||||
@size-change="handleSizeChange"
|
||||
@current-change="handleCurrentChange"
|
||||
/>
|
||||
</div>
|
||||
</el-card>
|
||||
|
||||
<!-- 公告详情对话框 -->
|
||||
<el-dialog
|
||||
v-model="dialogVisible"
|
||||
:title="dialogTitle"
|
||||
width="800px"
|
||||
:before-close="handleDialogClose"
|
||||
>
|
||||
<div v-if="dialogType === 'view'" class="announcement-detail">
|
||||
<h2 class="detail-title">{{ currentAnnouncement.title }}</h2>
|
||||
<div class="detail-info">
|
||||
<span>发布人: {{ currentAnnouncement.publisher }}</span>
|
||||
<span>发布时间: {{ currentAnnouncement.publishTime }}</span>
|
||||
<span>状态: {{ getStatusText(currentAnnouncement.status) }}</span>
|
||||
</div>
|
||||
<div class="detail-content" v-html="currentAnnouncement.content"></div>
|
||||
</div>
|
||||
<div v-else>
|
||||
<el-form :model="announcementForm" label-width="120px" :rules="rules" ref="announcementFormRef">
|
||||
<el-form-item label="公告标题" prop="title">
|
||||
<el-input v-model="announcementForm.title" placeholder="请输入公告标题" />
|
||||
</el-form-item>
|
||||
<el-form-item label="公告内容" prop="content">
|
||||
<el-input
|
||||
v-model="announcementForm.content"
|
||||
type="textarea"
|
||||
:rows="10"
|
||||
placeholder="请输入公告内容"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="状态" prop="status">
|
||||
<el-radio-group v-model="announcementForm.status">
|
||||
<el-radio label="published">立即发布</el-radio>
|
||||
<el-radio label="draft">保存为草稿</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
<template #footer>
|
||||
<div class="dialog-footer" v-if="dialogType !== 'view'">
|
||||
<el-button @click="handleDialogClose">取消</el-button>
|
||||
<el-button type="primary" @click="submitForm">确认</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive, onMounted, computed } from 'vue'
|
||||
import {
|
||||
Plus, Search, Refresh, View, Edit, TurnOff, Delete
|
||||
} from '@element-plus/icons-vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
|
||||
// 搜索表单
|
||||
const searchForm = reactive({
|
||||
title: '',
|
||||
dateRange: [],
|
||||
status: ''
|
||||
})
|
||||
|
||||
// 重置搜索
|
||||
const resetSearch = () => {
|
||||
searchForm.title = ''
|
||||
searchForm.dateRange = []
|
||||
searchForm.status = ''
|
||||
handleSearch()
|
||||
}
|
||||
|
||||
// 表格数据
|
||||
const loading = ref(false)
|
||||
const tableData = ref([])
|
||||
|
||||
// 分页
|
||||
const pagination = reactive({
|
||||
currentPage: 1,
|
||||
pageSize: 10,
|
||||
total: 0
|
||||
})
|
||||
|
||||
// 处理页码变化
|
||||
const handleCurrentChange = (val) => {
|
||||
pagination.currentPage = val
|
||||
fetchData()
|
||||
}
|
||||
|
||||
// 处理每页条数变化
|
||||
const handleSizeChange = (val) => {
|
||||
pagination.pageSize = val
|
||||
fetchData()
|
||||
}
|
||||
|
||||
// 对话框相关
|
||||
const dialogVisible = ref(false)
|
||||
const dialogType = ref('') // 'add', 'edit', 'view'
|
||||
const dialogTitle = computed(() => {
|
||||
if (dialogType.value === 'add') return '发布公告'
|
||||
if (dialogType.value === 'edit') return '编辑公告'
|
||||
return '公告详情'
|
||||
})
|
||||
|
||||
// 当前选中的公告
|
||||
const currentAnnouncement = ref({})
|
||||
|
||||
// 表单对象和规则
|
||||
const announcementFormRef = ref(null)
|
||||
const announcementForm = reactive({
|
||||
id: '',
|
||||
title: '',
|
||||
content: '',
|
||||
status: 'published'
|
||||
})
|
||||
|
||||
const rules = {
|
||||
title: [{ required: true, message: '请输入公告标题', trigger: 'blur' }],
|
||||
content: [{ required: true, message: '请输入公告内容', trigger: 'blur' }],
|
||||
status: [{ required: true, message: '请选择状态', trigger: 'change' }]
|
||||
}
|
||||
|
||||
// 状态标签样式
|
||||
const getStatusType = (status) => {
|
||||
const map = {
|
||||
published: 'success',
|
||||
draft: 'info',
|
||||
offline: 'danger'
|
||||
}
|
||||
return map[status] || 'info'
|
||||
}
|
||||
|
||||
const getStatusText = (status) => {
|
||||
const map = {
|
||||
published: '已发布',
|
||||
draft: '草稿',
|
||||
offline: '已下线'
|
||||
}
|
||||
return map[status] || '未知'
|
||||
}
|
||||
|
||||
// 处理搜索
|
||||
const handleSearch = () => {
|
||||
pagination.currentPage = 1
|
||||
fetchData()
|
||||
}
|
||||
|
||||
// 获取数据
|
||||
const fetchData = () => {
|
||||
loading.value = true
|
||||
|
||||
// 模拟API请求
|
||||
setTimeout(() => {
|
||||
// 这里应该是真实的API请求
|
||||
const mockData = []
|
||||
for (let i = 0; i < pagination.pageSize; i++) {
|
||||
const id = (pagination.currentPage - 1) * pagination.pageSize + i + 1
|
||||
if (id > 35) break // 模拟总数
|
||||
|
||||
mockData.push({
|
||||
id: `announcement-${id}`,
|
||||
title: `关于云服务平台升级维护的公告 ${id}`,
|
||||
publisher: '系统管理员',
|
||||
publishTime: '2023-10-15 08:30:00',
|
||||
viewCount: Math.floor(Math.random() * 1000),
|
||||
status: ['published', 'draft', 'offline'][Math.floor(Math.random() * 3)],
|
||||
content: `<p>尊敬的用户:</p>
|
||||
<p>为了提供更好的服务体验,我们的云服务平台将于2023年10月20日凌晨2:00-6:00进行系统升级维护。</p>
|
||||
<p>维护期间,部分功能可能暂时无法使用,给您带来的不便敬请谅解。</p>
|
||||
<p>感谢您的理解与支持!</p>`
|
||||
})
|
||||
}
|
||||
|
||||
tableData.value = mockData
|
||||
pagination.total = 35
|
||||
loading.value = false
|
||||
}, 500)
|
||||
}
|
||||
|
||||
// 添加公告
|
||||
const handleAdd = () => {
|
||||
dialogType.value = 'add'
|
||||
dialogVisible.value = true
|
||||
announcementForm.id = ''
|
||||
announcementForm.title = ''
|
||||
announcementForm.content = ''
|
||||
announcementForm.status = 'published'
|
||||
}
|
||||
|
||||
// 查看公告
|
||||
const handleView = (row) => {
|
||||
dialogType.value = 'view'
|
||||
dialogVisible.value = true
|
||||
currentAnnouncement.value = { ...row }
|
||||
}
|
||||
|
||||
// 编辑公告
|
||||
const handleEdit = (row) => {
|
||||
dialogType.value = 'edit'
|
||||
dialogVisible.value = true
|
||||
announcementForm.id = row.id
|
||||
announcementForm.title = row.title
|
||||
announcementForm.content = row.content
|
||||
announcementForm.status = row.status
|
||||
}
|
||||
|
||||
// 更改公告状态(下线)
|
||||
const handleChangeStatus = (row) => {
|
||||
ElMessageBox.confirm(`确定要下线"${row.title}"吗?`, '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}).then(() => {
|
||||
// 这里应该是API请求
|
||||
ElMessage.success('操作成功')
|
||||
fetchData()
|
||||
}).catch(() => {})
|
||||
}
|
||||
|
||||
// 删除公告
|
||||
const handleDelete = (row) => {
|
||||
ElMessageBox.confirm(`确定要删除"${row.title}"吗?删除后不可恢复!`, '警告', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'error'
|
||||
}).then(() => {
|
||||
// 这里应该是API请求
|
||||
ElMessage.success('删除成功')
|
||||
fetchData()
|
||||
}).catch(() => {})
|
||||
}
|
||||
|
||||
// 关闭对话框
|
||||
const handleDialogClose = () => {
|
||||
dialogVisible.value = false
|
||||
if (announcementFormRef.value) {
|
||||
announcementFormRef.value.resetFields()
|
||||
}
|
||||
}
|
||||
|
||||
// 提交表单
|
||||
const submitForm = async () => {
|
||||
if (!announcementFormRef.value) return
|
||||
|
||||
await announcementFormRef.value.validate((valid) => {
|
||||
if (valid) {
|
||||
// 这里应该是API请求
|
||||
ElMessage.success(dialogType.value === 'add' ? '发布成功' : '更新成功')
|
||||
dialogVisible.value = false
|
||||
fetchData()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 初始加载
|
||||
onMounted(() => {
|
||||
fetchData()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.announcements-container {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.page-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.search-card {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.search-form {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.table-card {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.pagination-container {
|
||||
margin-top: 20px;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
/* 公告详情样式 */
|
||||
.announcement-detail {
|
||||
padding: 0 20px;
|
||||
}
|
||||
|
||||
.detail-title {
|
||||
text-align: center;
|
||||
margin-bottom: 20px;
|
||||
font-size: 22px;
|
||||
color: #303133;
|
||||
}
|
||||
|
||||
.detail-info {
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
color: #909399;
|
||||
margin-bottom: 30px;
|
||||
font-size: 14px;
|
||||
border-bottom: 1px solid #EBEEF5;
|
||||
padding-bottom: 15px;
|
||||
}
|
||||
|
||||
.detail-content {
|
||||
line-height: 1.8;
|
||||
color: #606266;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,490 @@
|
||||
<template>
|
||||
<div class="news-container">
|
||||
<div class="page-header">
|
||||
<h2>新闻咨询</h2>
|
||||
<el-button type="primary" @click="handleAdd">
|
||||
<el-icon><plus /></el-icon>发布新闻
|
||||
</el-button>
|
||||
</div>
|
||||
|
||||
<!-- 搜索区域 -->
|
||||
<el-card class="search-card">
|
||||
<el-form :inline="true" :model="searchForm" class="search-form">
|
||||
<el-form-item label="新闻标题">
|
||||
<el-input v-model="searchForm.title" placeholder="请输入新闻标题" clearable />
|
||||
</el-form-item>
|
||||
<el-form-item label="新闻分类">
|
||||
<el-select v-model="searchForm.category" placeholder="请选择分类" clearable>
|
||||
<el-option label="产品动态" value="product" />
|
||||
<el-option label="技术干货" value="technology" />
|
||||
<el-option label="行业资讯" value="industry" />
|
||||
<el-option label="活动公告" value="activity" />
|
||||
<el-option label="其他" value="other" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="发布时间">
|
||||
<el-date-picker
|
||||
v-model="searchForm.dateRange"
|
||||
type="daterange"
|
||||
range-separator="至"
|
||||
start-placeholder="开始日期"
|
||||
end-placeholder="结束日期"
|
||||
format="YYYY-MM-DD"
|
||||
value-format="YYYY-MM-DD"
|
||||
clearable
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="handleSearch">
|
||||
<el-icon><search /></el-icon>搜索
|
||||
</el-button>
|
||||
<el-button @click="resetSearch">
|
||||
<el-icon><refresh /></el-icon>重置
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-card>
|
||||
|
||||
<!-- 新闻列表卡片 -->
|
||||
<div v-loading="loading" class="news-list">
|
||||
<el-card class="table-card">
|
||||
<el-table
|
||||
:data="newsData"
|
||||
border
|
||||
style="width: 100%"
|
||||
row-key="id"
|
||||
>
|
||||
<el-table-column type="index" label="序号" width="60" align="center" />
|
||||
<el-table-column prop="title" label="新闻标题" min-width="200" show-overflow-tooltip />
|
||||
<el-table-column prop="category" label="新闻分类" width="120" align="center">
|
||||
<template #default="scope">
|
||||
<el-tag :type="getCategoryType(scope.row.category)">
|
||||
{{ getCategoryText(scope.row.category) }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="author" label="作者" width="150" align="center" />
|
||||
<el-table-column prop="publishTime" label="发布时间" width="120" align="center" />
|
||||
<el-table-column prop="viewCount" label="阅读量" width="100" align="center" />
|
||||
<el-table-column label="操作" width="220" align="center" fixed="right">
|
||||
<template #default="scope">
|
||||
<el-button type="primary" link @click="handleView(scope.row)">
|
||||
<el-icon><view /></el-icon>查看
|
||||
</el-button>
|
||||
<el-button type="primary" link @click="handleEdit(scope.row)">
|
||||
<el-icon><edit /></el-icon>编辑
|
||||
</el-button>
|
||||
<el-button type="danger" link @click="handleDelete(scope.row)">
|
||||
<el-icon><delete /></el-icon>删除
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<!-- 分页 -->
|
||||
<div class="pagination-container">
|
||||
<el-pagination
|
||||
v-model:current-page="pagination.currentPage"
|
||||
v-model:page-size="pagination.pageSize"
|
||||
:page-sizes="[10, 20, 50, 100]"
|
||||
:total="pagination.total"
|
||||
layout="total, sizes, prev, pager, next, jumper"
|
||||
@size-change="handleSizeChange"
|
||||
@current-change="handleCurrentChange"
|
||||
/>
|
||||
</div>
|
||||
</el-card>
|
||||
</div>
|
||||
|
||||
<!-- 新闻详情对话框 -->
|
||||
<el-dialog
|
||||
v-model="dialogVisible"
|
||||
:title="dialogTitle"
|
||||
width="800px"
|
||||
:before-close="handleDialogClose"
|
||||
>
|
||||
<div v-if="dialogType === 'view'" class="news-detail">
|
||||
<h2 class="detail-title">{{ currentNews.title }}</h2>
|
||||
<div class="detail-info">
|
||||
<span>
|
||||
<el-tag :type="getCategoryType(currentNews.category)" size="small">
|
||||
{{ getCategoryText(currentNews.category) }}
|
||||
</el-tag>
|
||||
</span>
|
||||
<span><el-icon><user /></el-icon> {{ currentNews.author }}</span>
|
||||
<span><el-icon><calendar /></el-icon> {{ currentNews.publishTime }}</span>
|
||||
<span><el-icon><view /></el-icon> {{ currentNews.viewCount }} 次阅读</span>
|
||||
</div>
|
||||
<el-image class="detail-cover" :src="currentNews.coverImage" fit="cover" />
|
||||
<div class="detail-content" v-html="currentNews.content"></div>
|
||||
</div>
|
||||
<div v-else>
|
||||
<el-form :model="newsForm" label-width="120px" :rules="rules" ref="newsFormRef">
|
||||
<el-form-item label="新闻标题" prop="title">
|
||||
<el-input v-model="newsForm.title" placeholder="请输入新闻标题" />
|
||||
</el-form-item>
|
||||
<el-form-item label="新闻分类" prop="category">
|
||||
<el-select v-model="newsForm.category" placeholder="请选择分类" style="width: 100%">
|
||||
<el-option label="产品动态" value="product" />
|
||||
<el-option label="技术干货" value="technology" />
|
||||
<el-option label="行业资讯" value="industry" />
|
||||
<el-option label="活动公告" value="activity" />
|
||||
<el-option label="其他" value="other" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="封面图片" prop="coverImage">
|
||||
<el-input v-model="newsForm.coverImage" placeholder="请输入图片URL" />
|
||||
<div class="upload-tip">
|
||||
<el-icon><info-filled /></el-icon> 实际使用时应为图片上传组件
|
||||
</div>
|
||||
</el-form-item>
|
||||
<el-form-item label="简介摘要" prop="summary">
|
||||
<el-input
|
||||
v-model="newsForm.summary"
|
||||
type="textarea"
|
||||
:rows="3"
|
||||
placeholder="请输入新闻简介(100字以内)"
|
||||
maxlength="100"
|
||||
show-word-limit
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="新闻内容" prop="content">
|
||||
<el-input
|
||||
v-model="newsForm.content"
|
||||
type="textarea"
|
||||
:rows="8"
|
||||
placeholder="请输入新闻正文内容"
|
||||
/>
|
||||
<div class="upload-tip">
|
||||
<el-icon><info-filled /></el-icon> 实际使用时应为富文本编辑器
|
||||
</div>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
<template #footer>
|
||||
<div class="dialog-footer" v-if="dialogType !== 'view'">
|
||||
<el-button @click="handleDialogClose">取消</el-button>
|
||||
<el-button type="primary" @click="submitForm">确认</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive, onMounted, computed } from 'vue'
|
||||
import {
|
||||
Plus, Search, Refresh, View, Edit, Delete,
|
||||
User, Calendar, Picture, InfoFilled
|
||||
} from '@element-plus/icons-vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
|
||||
// 搜索表单
|
||||
const searchForm = reactive({
|
||||
title: '',
|
||||
category: '',
|
||||
dateRange: []
|
||||
})
|
||||
|
||||
// 重置搜索
|
||||
const resetSearch = () => {
|
||||
searchForm.title = ''
|
||||
searchForm.category = ''
|
||||
searchForm.dateRange = []
|
||||
handleSearch()
|
||||
}
|
||||
|
||||
// 新闻数据
|
||||
const loading = ref(false)
|
||||
const newsData = ref([])
|
||||
|
||||
// 分页
|
||||
const pagination = reactive({
|
||||
currentPage: 1,
|
||||
pageSize: 10,
|
||||
total: 0
|
||||
})
|
||||
|
||||
// 处理页码变化
|
||||
const handleCurrentChange = (val) => {
|
||||
pagination.currentPage = val
|
||||
fetchData()
|
||||
}
|
||||
|
||||
// 处理每页条数变化
|
||||
const handleSizeChange = (val) => {
|
||||
pagination.pageSize = val
|
||||
fetchData()
|
||||
}
|
||||
|
||||
// 对话框相关
|
||||
const dialogVisible = ref(false)
|
||||
const dialogType = ref('') // 'add', 'edit', 'view'
|
||||
const dialogTitle = computed(() => {
|
||||
if (dialogType.value === 'add') return '发布新闻'
|
||||
if (dialogType.value === 'edit') return '编辑新闻'
|
||||
return '新闻详情'
|
||||
})
|
||||
|
||||
// 当前选中的新闻
|
||||
const currentNews = ref({})
|
||||
|
||||
// 表单对象和规则
|
||||
const newsFormRef = ref(null)
|
||||
const newsForm = reactive({
|
||||
id: '',
|
||||
title: '',
|
||||
category: '',
|
||||
coverImage: '',
|
||||
summary: '',
|
||||
content: ''
|
||||
})
|
||||
|
||||
const rules = {
|
||||
title: [{ required: true, message: '请输入新闻标题', trigger: 'blur' }],
|
||||
category: [{ required: true, message: '请选择新闻分类', trigger: 'change' }],
|
||||
coverImage: [{ required: true, message: '请输入封面图片URL', trigger: 'blur' }],
|
||||
summary: [{ required: true, message: '请输入新闻简介', trigger: 'blur' }],
|
||||
content: [{ required: true, message: '请输入新闻内容', trigger: 'blur' }]
|
||||
}
|
||||
|
||||
// 新闻分类标签
|
||||
const getCategoryType = (category) => {
|
||||
const map = {
|
||||
product: 'primary',
|
||||
technology: 'success',
|
||||
industry: 'info',
|
||||
activity: 'warning',
|
||||
other: ''
|
||||
}
|
||||
return map[category] || ''
|
||||
}
|
||||
|
||||
const getCategoryText = (category) => {
|
||||
const map = {
|
||||
product: '产品动态',
|
||||
technology: '技术干货',
|
||||
industry: '行业资讯',
|
||||
activity: '活动公告',
|
||||
other: '其他'
|
||||
}
|
||||
return map[category] || '未知'
|
||||
}
|
||||
|
||||
// 处理搜索
|
||||
const handleSearch = () => {
|
||||
pagination.currentPage = 1
|
||||
fetchData()
|
||||
}
|
||||
|
||||
// 获取数据
|
||||
const fetchData = () => {
|
||||
loading.value = true
|
||||
|
||||
// 模拟API请求
|
||||
setTimeout(() => {
|
||||
// 这里应该是真实的API请求
|
||||
const mockData = []
|
||||
const categories = ['product', 'technology', 'industry', 'activity', 'other']
|
||||
|
||||
for (let i = 0; i < pagination.pageSize; i++) {
|
||||
const id = (pagination.currentPage - 1) * pagination.pageSize + i + 1
|
||||
if (id > 32) break // 模拟总数
|
||||
|
||||
const category = categories[Math.floor(Math.random() * categories.length)]
|
||||
|
||||
mockData.push({
|
||||
id: `news-${id}`,
|
||||
title: `零零七云计算平台${getCategoryText(category)}新闻 ${id}`,
|
||||
category,
|
||||
author: '零零七云计算小编',
|
||||
publishTime: '2023-10-12',
|
||||
viewCount: Math.floor(Math.random() * 1000),
|
||||
coverImage: `https://picsum.photos/id/${id + 30}/800/400`,
|
||||
summary: '零零七云计算平台重磅升级,新增多项功能特性,提供更优质的云服务体验。本次升级包含计算资源优化、存储系统升级、网络性能提升等多方面改进。',
|
||||
content: `<p>尊敬的用户:</p>
|
||||
<p>我们很高兴地宣布,零零七云计算平台已完成重大升级,带来全新的用户体验和技术改进。</p>
|
||||
<h3>一、主要升级内容</h3>
|
||||
<ol>
|
||||
<li>计算资源全面升级,性能提升30%</li>
|
||||
<li>存储系统架构优化,读写速度大幅提升</li>
|
||||
<li>网络架构重构,带宽翻倍,延迟降低</li>
|
||||
<li>控制台界面优化,操作更加便捷</li>
|
||||
<li>API接口全面升级,兼容性更好</li>
|
||||
</ol>
|
||||
<h3>二、升级优势</h3>
|
||||
<p>本次升级将为您带来更稳定、高效的云服务体验。我们的技术团队持续致力于提供业界领先的云计算解决方案。</p>
|
||||
<h3>三、后续计划</h3>
|
||||
<p>我们将继续投入研发,计划在年底前推出更多创新功能,敬请期待!</p>
|
||||
<p>感谢您一直以来对零零七云计算的支持与信任!</p>`
|
||||
})
|
||||
}
|
||||
|
||||
newsData.value = mockData
|
||||
pagination.total = 32
|
||||
loading.value = false
|
||||
}, 500)
|
||||
}
|
||||
|
||||
// 添加新闻
|
||||
const handleAdd = () => {
|
||||
dialogType.value = 'add'
|
||||
dialogVisible.value = true
|
||||
newsForm.id = ''
|
||||
newsForm.title = ''
|
||||
newsForm.category = ''
|
||||
newsForm.coverImage = ''
|
||||
newsForm.summary = ''
|
||||
newsForm.content = ''
|
||||
}
|
||||
|
||||
// 查看新闻
|
||||
const handleView = (row) => {
|
||||
dialogType.value = 'view'
|
||||
dialogVisible.value = true
|
||||
currentNews.value = { ...row }
|
||||
}
|
||||
|
||||
// 编辑新闻
|
||||
const handleEdit = (row) => {
|
||||
dialogType.value = 'edit'
|
||||
dialogVisible.value = true
|
||||
newsForm.id = row.id
|
||||
newsForm.title = row.title
|
||||
newsForm.category = row.category
|
||||
newsForm.coverImage = row.coverImage
|
||||
newsForm.summary = row.summary
|
||||
newsForm.content = row.content
|
||||
}
|
||||
|
||||
// 删除新闻
|
||||
const handleDelete = (row) => {
|
||||
ElMessageBox.confirm(`确定要删除"${row.title}"吗?删除后不可恢复!`, '警告', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'error'
|
||||
}).then(() => {
|
||||
// 这里应该是API请求
|
||||
ElMessage.success('删除成功')
|
||||
fetchData()
|
||||
}).catch(() => {})
|
||||
}
|
||||
|
||||
// 关闭对话框
|
||||
const handleDialogClose = () => {
|
||||
dialogVisible.value = false
|
||||
if (newsFormRef.value) {
|
||||
newsFormRef.value.resetFields()
|
||||
}
|
||||
}
|
||||
|
||||
// 提交表单
|
||||
const submitForm = async () => {
|
||||
if (!newsFormRef.value) return
|
||||
|
||||
await newsFormRef.value.validate((valid) => {
|
||||
if (valid) {
|
||||
// 这里应该是API请求
|
||||
ElMessage.success(dialogType.value === 'add' ? '发布成功' : '更新成功')
|
||||
dialogVisible.value = false
|
||||
fetchData()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 初始加载
|
||||
onMounted(() => {
|
||||
fetchData()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.news-container {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.page-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.search-card {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.search-form {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.news-list {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.table-card {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.pagination-container {
|
||||
margin-top: 20px;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
/* 新闻详情样式 */
|
||||
.news-detail {
|
||||
padding: 0 20px;
|
||||
}
|
||||
|
||||
.detail-title {
|
||||
text-align: center;
|
||||
margin-bottom: 20px;
|
||||
font-size: 22px;
|
||||
color: #303133;
|
||||
}
|
||||
|
||||
.detail-info {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
color: #909399;
|
||||
margin-bottom: 20px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.detail-info span {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin: 0 10px;
|
||||
}
|
||||
|
||||
.detail-info .el-icon {
|
||||
margin-right: 5px;
|
||||
}
|
||||
|
||||
.detail-cover {
|
||||
width: 100%;
|
||||
max-height: 400px;
|
||||
margin-bottom: 20px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.detail-content {
|
||||
line-height: 1.8;
|
||||
color: #606266;
|
||||
}
|
||||
|
||||
.upload-tip {
|
||||
margin-top: 5px;
|
||||
color: #909399;
|
||||
font-size: 12px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.upload-tip .el-icon {
|
||||
margin-right: 5px;
|
||||
color: #E6A23C;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,498 @@
|
||||
<template>
|
||||
<div class="policies-container">
|
||||
<div class="page-header">
|
||||
<h2>官方政策</h2>
|
||||
<el-button type="primary" @click="handleAdd">
|
||||
<el-icon><plus /></el-icon>发布政策
|
||||
</el-button>
|
||||
</div>
|
||||
|
||||
<!-- 搜索区域 -->
|
||||
<el-card class="search-card">
|
||||
<el-form :inline="true" :model="searchForm" class="search-form">
|
||||
<el-form-item label="政策标题">
|
||||
<el-input v-model="searchForm.title" placeholder="请输入政策标题" clearable />
|
||||
</el-form-item>
|
||||
<el-form-item label="政策类型">
|
||||
<el-select v-model="searchForm.type" placeholder="请选择政策类型" clearable>
|
||||
<el-option label="服务条款" value="terms" />
|
||||
<el-option label="定价政策" value="pricing" />
|
||||
<el-option label="隐私政策" value="privacy" />
|
||||
<el-option label="合规政策" value="compliance" />
|
||||
<el-option label="其他" value="other" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="发布时间">
|
||||
<el-date-picker
|
||||
v-model="searchForm.dateRange"
|
||||
type="daterange"
|
||||
range-separator="至"
|
||||
start-placeholder="开始日期"
|
||||
end-placeholder="结束日期"
|
||||
format="YYYY-MM-DD"
|
||||
value-format="YYYY-MM-DD"
|
||||
clearable
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="handleSearch">
|
||||
<el-icon><search /></el-icon>搜索
|
||||
</el-button>
|
||||
<el-button @click="resetSearch">
|
||||
<el-icon><refresh /></el-icon>重置
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-card>
|
||||
|
||||
<!-- 数据表格 -->
|
||||
<el-card class="table-card">
|
||||
<el-table
|
||||
v-loading="loading"
|
||||
:data="tableData"
|
||||
border
|
||||
style="width: 100%"
|
||||
row-key="id"
|
||||
>
|
||||
<el-table-column type="index" label="序号" width="60" align="center" />
|
||||
<el-table-column prop="title" label="政策标题" min-width="200" show-overflow-tooltip />
|
||||
<el-table-column prop="type" label="政策类型" width="120" align="center">
|
||||
<template #default="scope">
|
||||
<el-tag :type="getPolicyTypeTag(scope.row.type)">
|
||||
{{ getPolicyTypeText(scope.row.type) }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="publisher" label="发布人" width="120" align="center" />
|
||||
<el-table-column prop="publishTime" label="发布时间" width="180" align="center" />
|
||||
<el-table-column prop="effectiveTime" label="生效时间" width="180" align="center" />
|
||||
<el-table-column prop="status" label="状态" width="100" align="center">
|
||||
<template #default="scope">
|
||||
<el-tag :type="getStatusType(scope.row.status)">
|
||||
{{ getStatusText(scope.row.status) }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="220" align="center" fixed="right">
|
||||
<template #default="scope">
|
||||
<el-button type="primary" link @click="handleView(scope.row)">
|
||||
<el-icon><view /></el-icon>查看
|
||||
</el-button>
|
||||
<el-button type="primary" link @click="handleEdit(scope.row)">
|
||||
<el-icon><edit /></el-icon>编辑
|
||||
</el-button>
|
||||
<el-button
|
||||
type="primary"
|
||||
link
|
||||
@click="handleChangeStatus(scope.row)"
|
||||
v-if="scope.row.status === 'active'"
|
||||
>
|
||||
<el-icon><turn-off /></el-icon>下线
|
||||
</el-button>
|
||||
<el-button
|
||||
type="primary"
|
||||
link
|
||||
@click="handleDelete(scope.row)"
|
||||
v-if="scope.row.status === 'inactive'"
|
||||
>
|
||||
<el-icon><delete /></el-icon>删除
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<!-- 分页 -->
|
||||
<div class="pagination-container">
|
||||
<el-pagination
|
||||
v-model:current-page="pagination.currentPage"
|
||||
v-model:page-size="pagination.pageSize"
|
||||
:page-sizes="[10, 20, 50, 100]"
|
||||
:total="pagination.total"
|
||||
layout="total, sizes, prev, pager, next, jumper"
|
||||
@size-change="handleSizeChange"
|
||||
@current-change="handleCurrentChange"
|
||||
/>
|
||||
</div>
|
||||
</el-card>
|
||||
|
||||
<!-- 政策详情对话框 -->
|
||||
<el-dialog
|
||||
v-model="dialogVisible"
|
||||
:title="dialogTitle"
|
||||
width="800px"
|
||||
:before-close="handleDialogClose"
|
||||
>
|
||||
<div v-if="dialogType === 'view'" class="policy-detail">
|
||||
<h2 class="detail-title">{{ currentPolicy.title }}</h2>
|
||||
<div class="detail-info">
|
||||
<span>类型: {{ getPolicyTypeText(currentPolicy.type) }}</span>
|
||||
<span>发布人: {{ currentPolicy.publisher }}</span>
|
||||
<span>发布时间: {{ currentPolicy.publishTime }}</span>
|
||||
<span>生效时间: {{ currentPolicy.effectiveTime }}</span>
|
||||
<span>状态: {{ getStatusText(currentPolicy.status) }}</span>
|
||||
</div>
|
||||
<div class="detail-content" v-html="currentPolicy.content"></div>
|
||||
</div>
|
||||
<div v-else>
|
||||
<el-form :model="policyForm" label-width="120px" :rules="rules" ref="policyFormRef">
|
||||
<el-form-item label="政策标题" prop="title">
|
||||
<el-input v-model="policyForm.title" placeholder="请输入政策标题" />
|
||||
</el-form-item>
|
||||
<el-form-item label="政策类型" prop="type">
|
||||
<el-select v-model="policyForm.type" placeholder="请选择政策类型" style="width: 100%">
|
||||
<el-option label="服务条款" value="terms" />
|
||||
<el-option label="定价政策" value="pricing" />
|
||||
<el-option label="隐私政策" value="privacy" />
|
||||
<el-option label="合规政策" value="compliance" />
|
||||
<el-option label="其他" value="other" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="生效时间" prop="effectiveTime">
|
||||
<el-date-picker
|
||||
v-model="policyForm.effectiveTime"
|
||||
type="datetime"
|
||||
placeholder="选择生效时间"
|
||||
format="YYYY-MM-DD HH:mm:ss"
|
||||
value-format="YYYY-MM-DD HH:mm:ss"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="政策内容" prop="content">
|
||||
<el-input
|
||||
v-model="policyForm.content"
|
||||
type="textarea"
|
||||
:rows="10"
|
||||
placeholder="请输入政策内容"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="状态" prop="status">
|
||||
<el-radio-group v-model="policyForm.status">
|
||||
<el-radio label="active">立即生效</el-radio>
|
||||
<el-radio label="pending">计划中</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
<template #footer>
|
||||
<div class="dialog-footer" v-if="dialogType !== 'view'">
|
||||
<el-button @click="handleDialogClose">取消</el-button>
|
||||
<el-button type="primary" @click="submitForm">确认</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive, onMounted, computed } from 'vue'
|
||||
import {
|
||||
Plus, Search, Refresh, View, Edit, TurnOff, Delete
|
||||
} from '@element-plus/icons-vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
|
||||
// 搜索表单
|
||||
const searchForm = reactive({
|
||||
title: '',
|
||||
type: '',
|
||||
dateRange: []
|
||||
})
|
||||
|
||||
// 重置搜索
|
||||
const resetSearch = () => {
|
||||
searchForm.title = ''
|
||||
searchForm.type = ''
|
||||
searchForm.dateRange = []
|
||||
handleSearch()
|
||||
}
|
||||
|
||||
// 表格数据
|
||||
const loading = ref(false)
|
||||
const tableData = ref([])
|
||||
|
||||
// 分页
|
||||
const pagination = reactive({
|
||||
currentPage: 1,
|
||||
pageSize: 10,
|
||||
total: 0
|
||||
})
|
||||
|
||||
// 处理页码变化
|
||||
const handleCurrentChange = (val) => {
|
||||
pagination.currentPage = val
|
||||
fetchData()
|
||||
}
|
||||
|
||||
// 处理每页条数变化
|
||||
const handleSizeChange = (val) => {
|
||||
pagination.pageSize = val
|
||||
fetchData()
|
||||
}
|
||||
|
||||
// 对话框相关
|
||||
const dialogVisible = ref(false)
|
||||
const dialogType = ref('') // 'add', 'edit', 'view'
|
||||
const dialogTitle = computed(() => {
|
||||
if (dialogType.value === 'add') return '发布政策'
|
||||
if (dialogType.value === 'edit') return '编辑政策'
|
||||
return '政策详情'
|
||||
})
|
||||
|
||||
// 当前选中的政策
|
||||
const currentPolicy = ref({})
|
||||
|
||||
// 表单对象和规则
|
||||
const policyFormRef = ref(null)
|
||||
const policyForm = reactive({
|
||||
id: '',
|
||||
title: '',
|
||||
type: '',
|
||||
effectiveTime: '',
|
||||
content: '',
|
||||
status: 'active'
|
||||
})
|
||||
|
||||
const rules = {
|
||||
title: [{ required: true, message: '请输入政策标题', trigger: 'blur' }],
|
||||
type: [{ required: true, message: '请选择政策类型', trigger: 'change' }],
|
||||
effectiveTime: [{ required: true, message: '请选择生效时间', trigger: 'change' }],
|
||||
content: [{ required: true, message: '请输入政策内容', trigger: 'blur' }],
|
||||
status: [{ required: true, message: '请选择状态', trigger: 'change' }]
|
||||
}
|
||||
|
||||
// 政策类型标签
|
||||
const getPolicyTypeTag = (type) => {
|
||||
const map = {
|
||||
terms: '',
|
||||
pricing: 'success',
|
||||
privacy: 'warning',
|
||||
compliance: 'danger',
|
||||
other: 'info'
|
||||
}
|
||||
return map[type] || 'info'
|
||||
}
|
||||
|
||||
const getPolicyTypeText = (type) => {
|
||||
const map = {
|
||||
terms: '服务条款',
|
||||
pricing: '定价政策',
|
||||
privacy: '隐私政策',
|
||||
compliance: '合规政策',
|
||||
other: '其他'
|
||||
}
|
||||
return map[type] || '未知'
|
||||
}
|
||||
|
||||
// 状态标签样式
|
||||
const getStatusType = (status) => {
|
||||
const map = {
|
||||
active: 'success',
|
||||
pending: 'warning',
|
||||
inactive: 'info'
|
||||
}
|
||||
return map[status] || 'info'
|
||||
}
|
||||
|
||||
const getStatusText = (status) => {
|
||||
const map = {
|
||||
active: '已生效',
|
||||
pending: '计划中',
|
||||
inactive: '已下线'
|
||||
}
|
||||
return map[status] || '未知'
|
||||
}
|
||||
|
||||
// 处理搜索
|
||||
const handleSearch = () => {
|
||||
pagination.currentPage = 1
|
||||
fetchData()
|
||||
}
|
||||
|
||||
// 获取数据
|
||||
const fetchData = () => {
|
||||
loading.value = true
|
||||
|
||||
// 模拟API请求
|
||||
setTimeout(() => {
|
||||
// 这里应该是真实的API请求
|
||||
const mockData = []
|
||||
const types = ['terms', 'pricing', 'privacy', 'compliance', 'other']
|
||||
const statuses = ['active', 'pending', 'inactive']
|
||||
|
||||
for (let i = 0; i < pagination.pageSize; i++) {
|
||||
const id = (pagination.currentPage - 1) * pagination.pageSize + i + 1
|
||||
if (id > 28) break // 模拟总数
|
||||
|
||||
const type = types[Math.floor(Math.random() * types.length)]
|
||||
const status = statuses[Math.floor(Math.random() * statuses.length)]
|
||||
|
||||
mockData.push({
|
||||
id: `policy-${id}`,
|
||||
title: `云平台${getPolicyTypeText(type)}(${id})`,
|
||||
type,
|
||||
publisher: '系统管理员',
|
||||
publishTime: '2023-09-30 14:00:00',
|
||||
effectiveTime: '2023-10-01 00:00:00',
|
||||
status,
|
||||
content: `<p><strong>第一条:总则</strong></p>
|
||||
<p>本政策适用于零零七云平台所有用户,请您仔细阅读并理解本政策的所有内容。</p>
|
||||
<p><strong>第二条:服务内容</strong></p>
|
||||
<p>本平台提供云计算、存储和网络等基础设施服务,以及相关的技术支持和咨询服务。</p>
|
||||
<p><strong>第三条:用户权利与义务</strong></p>
|
||||
<p>用户在使用本平台服务时,应当遵守中华人民共和国法律法规和平台规则,不得利用平台服务从事违法活动。</p>`
|
||||
})
|
||||
}
|
||||
|
||||
tableData.value = mockData
|
||||
pagination.total = 28
|
||||
loading.value = false
|
||||
}, 500)
|
||||
}
|
||||
|
||||
// 添加政策
|
||||
const handleAdd = () => {
|
||||
dialogType.value = 'add'
|
||||
dialogVisible.value = true
|
||||
policyForm.id = ''
|
||||
policyForm.title = ''
|
||||
policyForm.type = ''
|
||||
policyForm.effectiveTime = ''
|
||||
policyForm.content = ''
|
||||
policyForm.status = 'active'
|
||||
}
|
||||
|
||||
// 查看政策
|
||||
const handleView = (row) => {
|
||||
dialogType.value = 'view'
|
||||
dialogVisible.value = true
|
||||
currentPolicy.value = { ...row }
|
||||
}
|
||||
|
||||
// 编辑政策
|
||||
const handleEdit = (row) => {
|
||||
dialogType.value = 'edit'
|
||||
dialogVisible.value = true
|
||||
policyForm.id = row.id
|
||||
policyForm.title = row.title
|
||||
policyForm.type = row.type
|
||||
policyForm.effectiveTime = row.effectiveTime
|
||||
policyForm.content = row.content
|
||||
policyForm.status = row.status
|
||||
}
|
||||
|
||||
// 更改政策状态(下线)
|
||||
const handleChangeStatus = (row) => {
|
||||
ElMessageBox.confirm(`确定要下线"${row.title}"吗?`, '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}).then(() => {
|
||||
// 这里应该是API请求
|
||||
ElMessage.success('操作成功')
|
||||
fetchData()
|
||||
}).catch(() => {})
|
||||
}
|
||||
|
||||
// 删除政策
|
||||
const handleDelete = (row) => {
|
||||
ElMessageBox.confirm(`确定要删除"${row.title}"吗?删除后不可恢复!`, '警告', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'error'
|
||||
}).then(() => {
|
||||
// 这里应该是API请求
|
||||
ElMessage.success('删除成功')
|
||||
fetchData()
|
||||
}).catch(() => {})
|
||||
}
|
||||
|
||||
// 关闭对话框
|
||||
const handleDialogClose = () => {
|
||||
dialogVisible.value = false
|
||||
if (policyFormRef.value) {
|
||||
policyFormRef.value.resetFields()
|
||||
}
|
||||
}
|
||||
|
||||
// 提交表单
|
||||
const submitForm = async () => {
|
||||
if (!policyFormRef.value) return
|
||||
|
||||
await policyFormRef.value.validate((valid) => {
|
||||
if (valid) {
|
||||
// 这里应该是API请求
|
||||
ElMessage.success(dialogType.value === 'add' ? '发布成功' : '更新成功')
|
||||
dialogVisible.value = false
|
||||
fetchData()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 初始加载
|
||||
onMounted(() => {
|
||||
fetchData()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.policies-container {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.page-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.search-card {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.search-form {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.table-card {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.pagination-container {
|
||||
margin-top: 20px;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
/* 政策详情样式 */
|
||||
.policy-detail {
|
||||
padding: 0 20px;
|
||||
}
|
||||
|
||||
.detail-title {
|
||||
text-align: center;
|
||||
margin-bottom: 20px;
|
||||
font-size: 22px;
|
||||
color: #303133;
|
||||
}
|
||||
|
||||
.detail-info {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: space-around;
|
||||
color: #909399;
|
||||
margin-bottom: 30px;
|
||||
font-size: 14px;
|
||||
border-bottom: 1px solid #EBEEF5;
|
||||
padding-bottom: 15px;
|
||||
}
|
||||
|
||||
.detail-info span {
|
||||
margin: 5px 10px;
|
||||
}
|
||||
|
||||
.detail-content {
|
||||
line-height: 1.8;
|
||||
color: #606266;
|
||||
}
|
||||
</style>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,314 @@
|
||||
<template>
|
||||
<div class="vm-list-container">
|
||||
<div class="filter-section">
|
||||
<el-input
|
||||
v-model="searchKey"
|
||||
placeholder="输入关键字搜索"
|
||||
style="width: 200px; margin-right: 10px;"
|
||||
clearable
|
||||
@input="handleSearch"
|
||||
/>
|
||||
<el-button type="primary" @click="handleSearch">
|
||||
<el-icon><search /></el-icon>搜索
|
||||
</el-button>
|
||||
<el-button @click="resetSearch">
|
||||
<el-icon><refresh /></el-icon>重置
|
||||
</el-button>
|
||||
</div>
|
||||
|
||||
<el-table
|
||||
v-loading="loading"
|
||||
:data="vmList"
|
||||
style="width: 100%"
|
||||
border
|
||||
>
|
||||
<el-table-column prop="instance_id" label="ID" width="100" />
|
||||
<el-table-column prop="name" label="名称" />
|
||||
<el-table-column prop="user_id" label="用户ID" width="100" />
|
||||
<el-table-column label="创建时间" width="180">
|
||||
<template #default="scope">
|
||||
{{ scope.row.created_at }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="到期时间" width="180">
|
||||
<template #default="scope">
|
||||
{{ scope.row.become_time }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="状态" width="100">
|
||||
<template #default="scope">
|
||||
<el-tag :type="getStatusType(scope.row.state)">
|
||||
{{ getStatusText(scope.row.state) }}
|
||||
</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="250" fixed="right">
|
||||
<template #default="scope">
|
||||
<el-button
|
||||
type="primary"
|
||||
link
|
||||
size="small"
|
||||
@click="handleManage(scope.row)"
|
||||
>
|
||||
<el-icon><menu /></el-icon>管理
|
||||
</el-button>
|
||||
<el-button
|
||||
type="success"
|
||||
link
|
||||
size="small"
|
||||
@click="handleStart(scope.row)"
|
||||
:disabled="scope.row.state === 'running'"
|
||||
>
|
||||
<el-icon><video-play /></el-icon>启动
|
||||
</el-button>
|
||||
<el-button
|
||||
type="warning"
|
||||
link
|
||||
size="small"
|
||||
@click="handleStop(scope.row)"
|
||||
:disabled="scope.row.state === 'stopped'"
|
||||
>
|
||||
<el-icon><video-pause /></el-icon>停止
|
||||
</el-button>
|
||||
<el-button
|
||||
type="info"
|
||||
link
|
||||
size="small"
|
||||
@click="handleRestart(scope.row)"
|
||||
:disabled="scope.row.state !== 'running'"
|
||||
>
|
||||
<el-icon><refresh-right /></el-icon>重启
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<div class="pagination-container">
|
||||
<el-pagination
|
||||
v-model:current-page="currentPage"
|
||||
v-model:page-size="pageSize"
|
||||
:page-sizes="[10, 20, 50, 100]"
|
||||
:total="total"
|
||||
layout="total, sizes, prev, pager, next, jumper"
|
||||
@size-change="handleSizeChange"
|
||||
@current-change="handleCurrentChange"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, onMounted, defineProps, watch } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { ElMessage, ElMessageBox } from 'element-plus';
|
||||
import {
|
||||
Search, Refresh, Menu, VideoPlay, VideoPause, RefreshRight
|
||||
} from '@element-plus/icons-vue';
|
||||
import {
|
||||
getContainer,
|
||||
startInstance,
|
||||
stopInstance,
|
||||
restartInstance
|
||||
} from '@/utils/acs/server';
|
||||
|
||||
const props = defineProps({
|
||||
ID: {
|
||||
type: String,
|
||||
required: true
|
||||
}
|
||||
});
|
||||
|
||||
const router = useRouter();
|
||||
const loading = ref(false);
|
||||
const vmList = ref([]);
|
||||
const total = ref(0);
|
||||
const currentPage = ref(1);
|
||||
const pageSize = ref(10);
|
||||
const searchKey = ref('');
|
||||
|
||||
// 获取虚拟机列表
|
||||
const fetchVmList = async () => {
|
||||
loading.value = true;
|
||||
try {
|
||||
const response = await getContainer({
|
||||
server_id: props.ID,
|
||||
page: currentPage.value,
|
||||
count: pageSize.value,
|
||||
key: searchKey.value,
|
||||
user_id: ''
|
||||
});
|
||||
|
||||
if (response && response.data && response.data.code === 200) {
|
||||
vmList.value = response.data.data || [];
|
||||
total.value = response.data.count || 0;
|
||||
} else {
|
||||
ElMessage.error('获取虚拟机列表失败');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取虚拟机列表出错:', error);
|
||||
ElMessage.error('获取虚拟机列表出错');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
// 获取状态类型
|
||||
const getStatusType = (state) => {
|
||||
switch (state) {
|
||||
case 'running':
|
||||
return 'success';
|
||||
case 'stopped':
|
||||
return 'danger';
|
||||
case 'paused':
|
||||
return 'warning';
|
||||
default:
|
||||
return 'info';
|
||||
}
|
||||
};
|
||||
|
||||
// 获取状态文本
|
||||
const getStatusText = (state) => {
|
||||
switch (state) {
|
||||
case 'running':
|
||||
return '运行中';
|
||||
case 'stopped':
|
||||
return '已停止';
|
||||
case 'paused':
|
||||
return '已暂停';
|
||||
case 'creating':
|
||||
return '创建中';
|
||||
case 'error':
|
||||
return '错误';
|
||||
default:
|
||||
return '未知';
|
||||
}
|
||||
};
|
||||
|
||||
// 处理搜索
|
||||
const handleSearch = () => {
|
||||
currentPage.value = 1;
|
||||
fetchVmList();
|
||||
};
|
||||
|
||||
// 重置搜索
|
||||
const resetSearch = () => {
|
||||
searchKey.value = '';
|
||||
currentPage.value = 1;
|
||||
fetchVmList();
|
||||
};
|
||||
|
||||
// 处理页码变化
|
||||
const handleCurrentChange = (val) => {
|
||||
currentPage.value = val;
|
||||
fetchVmList();
|
||||
};
|
||||
|
||||
// 处理每页条数变化
|
||||
const handleSizeChange = (val) => {
|
||||
pageSize.value = val;
|
||||
currentPage.value = 1;
|
||||
fetchVmList();
|
||||
};
|
||||
|
||||
// 管理虚拟机
|
||||
const handleManage = (row) => {
|
||||
router.push(`/servers/vm?instance_id=${row.instance_id}`);
|
||||
};
|
||||
|
||||
// 启动虚拟机
|
||||
const handleStart = async (row) => {
|
||||
try {
|
||||
const res = await startInstance(row.instance_id);
|
||||
if (res && res.data && res.data.code === 200) {
|
||||
ElMessage.success('启动指令已发送');
|
||||
setTimeout(() => {
|
||||
fetchVmList();
|
||||
}, 2000);
|
||||
} else {
|
||||
ElMessage.error('启动失败: ' + (res.data.message || '未知错误'));
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('启动虚拟机出错:', error);
|
||||
ElMessage.error('启动虚拟机出错');
|
||||
}
|
||||
};
|
||||
|
||||
// 停止虚拟机
|
||||
const handleStop = async (row) => {
|
||||
try {
|
||||
ElMessageBox.confirm('确定要停止该虚拟机吗?', '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}).then(async () => {
|
||||
const res = await stopInstance(row.instance_id);
|
||||
if (res && res.data && res.data.code === 200) {
|
||||
ElMessage.success('停止指令已发送');
|
||||
setTimeout(() => {
|
||||
fetchVmList();
|
||||
}, 2000);
|
||||
} else {
|
||||
ElMessage.error('停止失败: ' + (res.data.message || '未知错误'));
|
||||
}
|
||||
}).catch(() => {});
|
||||
} catch (error) {
|
||||
console.error('停止虚拟机出错:', error);
|
||||
ElMessage.error('停止虚拟机出错');
|
||||
}
|
||||
};
|
||||
|
||||
// 重启虚拟机
|
||||
const handleRestart = async (row) => {
|
||||
try {
|
||||
ElMessageBox.confirm('确定要重启该虚拟机吗?', '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}).then(async () => {
|
||||
const res = await restartInstance(row.instance_id);
|
||||
if (res && res.data && res.data.code === 200) {
|
||||
ElMessage.success('重启指令已发送');
|
||||
setTimeout(() => {
|
||||
fetchVmList();
|
||||
}, 2000);
|
||||
} else {
|
||||
ElMessage.error('重启失败: ' + (res.data.message || '未知错误'));
|
||||
}
|
||||
}).catch(() => {});
|
||||
} catch (error) {
|
||||
console.error('重启虚拟机出错:', error);
|
||||
ElMessage.error('重启虚拟机出错');
|
||||
}
|
||||
};
|
||||
|
||||
// 监听ID变化
|
||||
watch(() => props.ID, (newVal) => {
|
||||
if (newVal) {
|
||||
fetchVmList();
|
||||
}
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
if (props.ID) {
|
||||
fetchVmList();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.vm-list-container {
|
||||
padding: 10px 0;
|
||||
}
|
||||
|
||||
.filter-section {
|
||||
margin-bottom: 20px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.pagination-container {
|
||||
margin-top: 20px;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,340 @@
|
||||
<template>
|
||||
<div class="chart-container">
|
||||
<el-row :gutter="20">
|
||||
<el-col :span="12">
|
||||
<el-card class="chart-card">
|
||||
<template #header>
|
||||
<div class="card-header">
|
||||
<span>CPU使用率</span>
|
||||
</div>
|
||||
</template>
|
||||
<div ref="cpuChart" class="chart"></div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-card class="chart-card">
|
||||
<template #header>
|
||||
<div class="card-header">
|
||||
<span>内存使用率</span>
|
||||
</div>
|
||||
</template>
|
||||
<div ref="memoryChart" class="chart"></div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row :gutter="20" style="margin-top: 20px;">
|
||||
<el-col :span="12">
|
||||
<el-card class="chart-card">
|
||||
<template #header>
|
||||
<div class="card-header">
|
||||
<span>磁盘使用率</span>
|
||||
</div>
|
||||
</template>
|
||||
<div ref="diskChart" class="chart"></div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-card class="chart-card">
|
||||
<template #header>
|
||||
<div class="card-header">
|
||||
<span>网络流量</span>
|
||||
</div>
|
||||
</template>
|
||||
<div ref="networkChart" class="chart"></div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, onMounted, onBeforeUnmount, defineProps } from 'vue';
|
||||
import { useRoute } from 'vue-router';
|
||||
import * as echarts from 'echarts';
|
||||
import { getServerStatus, getTraffic, getDiskInfo } from '@/utils/acs/server';
|
||||
|
||||
const props = defineProps({
|
||||
Type: {
|
||||
type: String,
|
||||
required: true
|
||||
}
|
||||
});
|
||||
|
||||
const route = useRoute();
|
||||
const cpuChart = ref(null);
|
||||
const memoryChart = ref(null);
|
||||
const diskChart = ref(null);
|
||||
const networkChart = ref(null);
|
||||
|
||||
let cpuChartInstance = null;
|
||||
let memoryChartInstance = null;
|
||||
let diskChartInstance = null;
|
||||
let networkChartInstance = null;
|
||||
|
||||
// 定时器ID
|
||||
let timer = null;
|
||||
|
||||
// 初始化图表
|
||||
const initCharts = () => {
|
||||
// 初始化CPU图表
|
||||
cpuChartInstance = echarts.init(cpuChart.value);
|
||||
const cpuOption = {
|
||||
tooltip: {
|
||||
formatter: '{a} <br/>{b} : {c}%'
|
||||
},
|
||||
series: [
|
||||
{
|
||||
name: 'CPU',
|
||||
type: 'gauge',
|
||||
detail: { formatter: '{value}%' },
|
||||
data: [{ value: 0, name: '使用率' }],
|
||||
axisLine: {
|
||||
lineStyle: {
|
||||
width: 30,
|
||||
color: [
|
||||
[0.3, '#67C23A'],
|
||||
[0.7, '#E6A23C'],
|
||||
[1, '#F56C6C']
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
cpuChartInstance.setOption(cpuOption);
|
||||
|
||||
// 初始化内存图表
|
||||
memoryChartInstance = echarts.init(memoryChart.value);
|
||||
const memoryOption = {
|
||||
tooltip: {
|
||||
formatter: '{a} <br/>{b} : {c}%'
|
||||
},
|
||||
series: [
|
||||
{
|
||||
name: '内存',
|
||||
type: 'gauge',
|
||||
detail: { formatter: '{value}%' },
|
||||
data: [{ value: 0, name: '使用率' }],
|
||||
axisLine: {
|
||||
lineStyle: {
|
||||
width: 30,
|
||||
color: [
|
||||
[0.3, '#67C23A'],
|
||||
[0.7, '#E6A23C'],
|
||||
[1, '#F56C6C']
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
memoryChartInstance.setOption(memoryOption);
|
||||
|
||||
// 初始化磁盘图表
|
||||
diskChartInstance = echarts.init(diskChart.value);
|
||||
const diskOption = {
|
||||
tooltip: {
|
||||
trigger: 'item',
|
||||
formatter: '{a} <br/>{b} : {c} ({d}%)'
|
||||
},
|
||||
legend: {
|
||||
orient: 'vertical',
|
||||
left: 'left',
|
||||
data: ['已使用', '可用']
|
||||
},
|
||||
series: [
|
||||
{
|
||||
name: '磁盘空间',
|
||||
type: 'pie',
|
||||
radius: '55%',
|
||||
center: ['50%', '60%'],
|
||||
data: [
|
||||
{ value: 0, name: '已使用' },
|
||||
{ value: 100, name: '可用' }
|
||||
],
|
||||
emphasis: {
|
||||
itemStyle: {
|
||||
shadowBlur: 10,
|
||||
shadowOffsetX: 0,
|
||||
shadowColor: 'rgba(0, 0, 0, 0.5)'
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
diskChartInstance.setOption(diskOption);
|
||||
|
||||
// 初始化网络流量图表
|
||||
networkChartInstance = echarts.init(networkChart.value);
|
||||
const networkOption = {
|
||||
tooltip: {
|
||||
trigger: 'axis'
|
||||
},
|
||||
legend: {
|
||||
data: ['上传', '下载']
|
||||
},
|
||||
xAxis: {
|
||||
type: 'category',
|
||||
boundaryGap: false,
|
||||
data: Array(10).fill('').map((_, i) => `${i}`)
|
||||
},
|
||||
yAxis: {
|
||||
type: 'value',
|
||||
axisLabel: {
|
||||
formatter: '{value} MB/s'
|
||||
}
|
||||
},
|
||||
series: [
|
||||
{
|
||||
name: '上传',
|
||||
type: 'line',
|
||||
data: Array(10).fill(0),
|
||||
areaStyle: {}
|
||||
},
|
||||
{
|
||||
name: '下载',
|
||||
type: 'line',
|
||||
data: Array(10).fill(0),
|
||||
areaStyle: {}
|
||||
}
|
||||
]
|
||||
};
|
||||
networkChartInstance.setOption(networkOption);
|
||||
};
|
||||
|
||||
// 更新图表数据
|
||||
const updateCharts = async () => {
|
||||
try {
|
||||
// 获取服务器状态
|
||||
const statusRes = await getServerStatus(route.query.server_id);
|
||||
if (statusRes && statusRes.data && statusRes.data.code === 200) {
|
||||
const statusData = statusRes.data.data;
|
||||
|
||||
// 更新CPU图表
|
||||
if (cpuChartInstance) {
|
||||
const cpuUsage = statusData.cpu_usage || 0;
|
||||
cpuChartInstance.setOption({
|
||||
series: [
|
||||
{
|
||||
data: [{ value: parseFloat(cpuUsage).toFixed(2), name: '使用率' }]
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
// 更新内存图表
|
||||
if (memoryChartInstance) {
|
||||
const memoryUsage = statusData.memory_usage || 0;
|
||||
memoryChartInstance.setOption({
|
||||
series: [
|
||||
{
|
||||
data: [{ value: parseFloat(memoryUsage).toFixed(2), name: '使用率' }]
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 获取磁盘信息
|
||||
const diskRes = await getDiskInfo(route.query.server_id);
|
||||
if (diskRes && diskRes.data && diskRes.data.code === 200) {
|
||||
const diskData = diskRes.data.data;
|
||||
if (diskChartInstance && diskData) {
|
||||
const used = diskData.used || 0;
|
||||
const available = diskData.available || 100;
|
||||
diskChartInstance.setOption({
|
||||
series: [
|
||||
{
|
||||
data: [
|
||||
{ value: used, name: '已使用' },
|
||||
{ value: available, name: '可用' }
|
||||
]
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 获取网络流量
|
||||
const trafficRes = await getTraffic(route.query.server_id);
|
||||
if (trafficRes && trafficRes.data && trafficRes.data.code === 200) {
|
||||
const trafficData = trafficRes.data.data;
|
||||
if (networkChartInstance && trafficData) {
|
||||
// 假设API返回的是最近的流量数据点
|
||||
const uploadData = trafficData.upload || Array(10).fill(0);
|
||||
const downloadData = trafficData.download || Array(10).fill(0);
|
||||
|
||||
networkChartInstance.setOption({
|
||||
series: [
|
||||
{
|
||||
data: uploadData.slice(-10)
|
||||
},
|
||||
{
|
||||
data: downloadData.slice(-10)
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('更新图表数据失败:', error);
|
||||
}
|
||||
};
|
||||
|
||||
// 调整图表大小
|
||||
const resizeCharts = () => {
|
||||
cpuChartInstance && cpuChartInstance.resize();
|
||||
memoryChartInstance && memoryChartInstance.resize();
|
||||
diskChartInstance && diskChartInstance.resize();
|
||||
networkChartInstance && networkChartInstance.resize();
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
// 初始化图表
|
||||
initCharts();
|
||||
|
||||
// 定时更新数据
|
||||
updateCharts();
|
||||
timer = setInterval(updateCharts, 30000); // 每30秒更新一次
|
||||
|
||||
// 监听窗口大小变化
|
||||
window.addEventListener('resize', resizeCharts);
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
// 清除定时器
|
||||
if (timer) {
|
||||
clearInterval(timer);
|
||||
timer = null;
|
||||
}
|
||||
|
||||
// 移除事件监听
|
||||
window.removeEventListener('resize', resizeCharts);
|
||||
|
||||
// 销毁图表实例
|
||||
cpuChartInstance && cpuChartInstance.dispose();
|
||||
memoryChartInstance && memoryChartInstance.dispose();
|
||||
diskChartInstance && diskChartInstance.dispose();
|
||||
networkChartInstance && networkChartInstance.dispose();
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.chart-container {
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.chart-card {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.card-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.chart {
|
||||
height: 300px;
|
||||
}
|
||||
</style>
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user