ACS
This commit is contained in:
@@ -0,0 +1,409 @@
|
||||
<template>
|
||||
<div class="login-container">
|
||||
<!-- 登录表单区域 -->
|
||||
<div class="login-form-container">
|
||||
<div class="login-content">
|
||||
<div class="login-header">
|
||||
<h1 class="system-name">零零七云计算后台控制面板</h1>
|
||||
</div>
|
||||
<h2 class="welcome-text">欢迎回来</h2>
|
||||
<p class="sub-title">登录您的账户以继续访问</p>
|
||||
|
||||
<el-form
|
||||
ref="loginFormRef"
|
||||
:model="loginForm"
|
||||
:rules="loginRules"
|
||||
class="login-form"
|
||||
>
|
||||
<el-form-item prop="username">
|
||||
<el-input
|
||||
v-model="loginForm.username"
|
||||
placeholder="请输入用户名"
|
||||
:prefix-icon="User"
|
||||
clearable
|
||||
size="large"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item prop="password">
|
||||
<el-input
|
||||
v-model="loginForm.password"
|
||||
type="password"
|
||||
placeholder="请输入密码"
|
||||
:prefix-icon="Lock"
|
||||
show-password
|
||||
clearable
|
||||
size="large"
|
||||
@keyup.enter="handleLogin"
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
<div class="login-options">
|
||||
<el-checkbox v-model="rememberMe">
|
||||
<span class="remember-text">记住我</span>
|
||||
</el-checkbox>
|
||||
<el-button link type="primary" class="forget-btn" @click="forgetPassword">忘记密码?</el-button>
|
||||
</div>
|
||||
|
||||
<el-button
|
||||
type="primary"
|
||||
class="login-button"
|
||||
:loading="loading"
|
||||
@click="handleLogin"
|
||||
>
|
||||
{{ loading ? '登录中...' : '登录' }}
|
||||
</el-button>
|
||||
|
||||
</el-form>
|
||||
</div>
|
||||
|
||||
<div class="login-footer">
|
||||
<p class="copyright">Copyright © 2025 零零七云计算 All Rights Reserved.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 装饰区域 -->
|
||||
<div class="login-decoration">
|
||||
<div class="decoration-content">
|
||||
<h2 class="slogan">新一代企业级管理系统</h2>
|
||||
<p class="description">基于 Vue3 + Element Plus 的现代化管理系统</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { User, Lock, Monitor, Connection } from '@element-plus/icons-vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import {getUserInfo, userLogin} from "@/api/login.js";
|
||||
|
||||
const router = useRouter()
|
||||
const loginFormRef = ref(null)
|
||||
const loading = ref(false)
|
||||
const rememberMe = ref(false)
|
||||
|
||||
const loginForm = reactive({
|
||||
username: '',
|
||||
password: ''
|
||||
})
|
||||
|
||||
const loginRules = {
|
||||
username: [
|
||||
{ required: true, message: '请输入用户名', trigger: 'blur' },
|
||||
{ min: 3, max: 20, message: '长度在 3 到 20 个字符', trigger: 'blur' }
|
||||
],
|
||||
password: [
|
||||
{ required: true, message: '请输入密码', trigger: 'blur' },
|
||||
{ min: 6, max: 20, message: '长度在 6 到 20 个字符', trigger: 'blur' }
|
||||
]
|
||||
}
|
||||
|
||||
const forgetPassword = () => {
|
||||
ElMessage.warning('请前往官网重置密码!')
|
||||
}
|
||||
const handleLogin = () => {
|
||||
loginFormRef.value?.validate(async valid =>{
|
||||
window.localStorage.removeItem('token')
|
||||
if (valid) {
|
||||
loading.value = true
|
||||
let resp = await userLogin(loginForm.username, loginForm.password)
|
||||
loading.value = false
|
||||
if(resp.code === 200){
|
||||
|
||||
window.localStorage.setItem('token',resp.data.token)
|
||||
let userInfo = await getUserInfo()
|
||||
if(userInfo.data.is_admin){
|
||||
await router.push('/dashboard')
|
||||
} else {
|
||||
ElMessage.warning('你不是管理员,不能登陆到后台控制面板')
|
||||
}
|
||||
}else{
|
||||
ElMessage.error(resp.message)
|
||||
}
|
||||
|
||||
}
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.login-container {
|
||||
display: flex;
|
||||
min-height: 100vh;
|
||||
background-color: #f5f7fa;
|
||||
}
|
||||
|
||||
.login-form-container {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 40px;
|
||||
background: #fff;
|
||||
position: relative;
|
||||
max-width: 520px;
|
||||
}
|
||||
|
||||
.login-content {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
max-width: 360px;
|
||||
margin: 0 auto;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.login-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-bottom: 48px;
|
||||
}
|
||||
|
||||
.logo {
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
margin-right: 16px;
|
||||
}
|
||||
|
||||
.system-name {
|
||||
font-size: 28px;
|
||||
font-weight: 600;
|
||||
background: linear-gradient(45deg, #1890ff, #36cfc9);
|
||||
-webkit-background-clip: text;
|
||||
color: transparent;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.welcome-text {
|
||||
font-size: 28px;
|
||||
font-weight: 600;
|
||||
color: #1f2937;
|
||||
margin: 0 0 8px 0;
|
||||
}
|
||||
|
||||
.sub-title {
|
||||
font-size: 16px;
|
||||
color: #6b7280;
|
||||
margin: 0 0 40px 0;
|
||||
}
|
||||
|
||||
.login-form :deep(.el-input) {
|
||||
--el-input-height: 44px;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.login-form :deep(.el-input__wrapper) {
|
||||
box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.login-form :deep(.el-input__inner) {
|
||||
font-size: 15px;
|
||||
}
|
||||
|
||||
.login-options {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin: 16px 0 24px;
|
||||
}
|
||||
|
||||
.remember-text {
|
||||
color: #4b5563;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.forget-btn {
|
||||
font-size: 14px;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.login-button {
|
||||
width: 100%;
|
||||
height: 44px;
|
||||
font-size: 16px;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 32px;
|
||||
}
|
||||
|
||||
.divider {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin: 0 0 24px;
|
||||
color: #9ca3af;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.divider::before,
|
||||
.divider::after {
|
||||
content: '';
|
||||
flex: 1;
|
||||
height: 1px;
|
||||
background: #e5e7eb;
|
||||
}
|
||||
|
||||
.divider-text {
|
||||
padding: 0 16px;
|
||||
}
|
||||
|
||||
.social-login {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.social-btn {
|
||||
width: 44px;
|
||||
height: 44px;
|
||||
border-radius: 8px;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.social-btn:hover {
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
.wechat {
|
||||
background: #07c160;
|
||||
border-color: #07c160;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.dingtalk {
|
||||
background: #1890ff;
|
||||
border-color: #1890ff;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.github {
|
||||
background: #24292e;
|
||||
border-color: #24292e;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.login-footer {
|
||||
text-align: center;
|
||||
color: #9ca3af;
|
||||
font-size: 14px;
|
||||
margin-top: 40px;
|
||||
}
|
||||
|
||||
/* 装饰区域样式 */
|
||||
.login-decoration {
|
||||
flex: 1.5;
|
||||
background: linear-gradient(135deg, #1890ff 0%, #36cfc9 100%);
|
||||
padding: 60px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.login-decoration::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background: url('../assets/grid.svg') repeat;
|
||||
opacity: 0.1;
|
||||
}
|
||||
|
||||
.decoration-content {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
color: white;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
}
|
||||
|
||||
.slogan {
|
||||
font-size: 42px;
|
||||
font-weight: 600;
|
||||
margin: 0 0 16px;
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
.description {
|
||||
font-size: 18px;
|
||||
opacity: 0.9;
|
||||
margin: 0 0 60px;
|
||||
}
|
||||
|
||||
.feature-list {
|
||||
display: grid;
|
||||
gap: 32px;
|
||||
max-width: 600px;
|
||||
}
|
||||
|
||||
.feature-item {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.feature-icon {
|
||||
font-size: 24px;
|
||||
padding: 12px;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
border-radius: 12px;
|
||||
}
|
||||
|
||||
.feature-info h3 {
|
||||
font-size: 18px;
|
||||
margin: 0 0 8px;
|
||||
}
|
||||
|
||||
.feature-info p {
|
||||
font-size: 14px;
|
||||
opacity: 0.8;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.decoration-footer {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.tech-stack {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
gap: 24px;
|
||||
}
|
||||
|
||||
.tech-icon {
|
||||
height: 32px;
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
@media (max-width: 1200px) {
|
||||
.login-decoration {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.login-form-container {
|
||||
max-width: none;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.login-form-container {
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.welcome-text {
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
.sub-title {
|
||||
font-size: 14px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
+46
-19
@@ -1,34 +1,61 @@
|
||||
<template>
|
||||
<div class="not-found">
|
||||
<h1>404</h1>
|
||||
<p>抱歉,页面不存在</p>
|
||||
<router-link to="/">返回首页</router-link>
|
||||
<div class="not-found-container">
|
||||
<div class="not-found-content">
|
||||
<img src="../assets/404.svg" alt="404" class="not-found-image" />
|
||||
<h1 class="not-found-title">404</h1>
|
||||
<h2 class="not-found-subtitle">抱歉,您访问的页面不存在</h2>
|
||||
<p class="not-found-desc">可能是链接错误或者该页面已被删除</p>
|
||||
<el-button type="primary" @click="backHome">返回首页</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'NotFound'
|
||||
<script setup>
|
||||
import { useRouter } from 'vue-router'
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
const backHome = () => {
|
||||
router.push('/dashboard')
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.not-found {
|
||||
padding: 40px;
|
||||
.not-found-container {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 100vh;
|
||||
background-color: #f0f2f5;
|
||||
}
|
||||
|
||||
.not-found-content {
|
||||
text-align: center;
|
||||
padding: 30px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
.not-found-image {
|
||||
width: 250px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.not-found-title {
|
||||
font-size: 72px;
|
||||
font-weight: bold;
|
||||
color: #1890ff;
|
||||
margin: 0;
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
.not-found-subtitle {
|
||||
font-size: 24px;
|
||||
color: #333;
|
||||
margin: 10px 0;
|
||||
}
|
||||
|
||||
.not-found-desc {
|
||||
font-size: 16px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #42b983;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
text-decoration: underline;
|
||||
margin: 20px 0 30px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,21 @@
|
||||
<template>
|
||||
<div></div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { onBeforeMount } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
|
||||
onBeforeMount(() => {
|
||||
const { params, query } = route
|
||||
const { path } = params
|
||||
|
||||
// 将path数组转换为路径字符串
|
||||
const redirectPath = Array.isArray(path) ? '/' + path.join('/') : '/' + path
|
||||
|
||||
router.replace({ path: redirectPath, query })
|
||||
})
|
||||
</script>
|
||||
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
@@ -0,0 +1,892 @@
|
||||
<template>
|
||||
<div class="dashboard-container">
|
||||
<!-- 统计卡片 -->
|
||||
<el-row :gutter="24">
|
||||
<el-col :xs="24" :sm="12" :md="12" :lg="6" :xl="6" v-for="(card, index) in statisticsCards" :key="index">
|
||||
<el-card class="stat-card" :class="card.class" shadow="hover">
|
||||
<div class="card-top">
|
||||
<div class="card-meta">
|
||||
<div class="card-title">{{ card.title }}</div>
|
||||
<div class="card-value">{{ card.value }}</div>
|
||||
</div>
|
||||
<div class="card-icon">
|
||||
<el-icon><component :is="card.icon" /></el-icon>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-footer">
|
||||
<span>较昨日</span>
|
||||
<span :class="card.trend > 0 ? 'up' : 'down'">
|
||||
{{ card.trend > 0 ? '+' : '' }}{{ card.trend }}%
|
||||
<el-icon v-if="card.trend > 0"><arrow-up /></el-icon>
|
||||
<el-icon v-else><arrow-down /></el-icon>
|
||||
</span>
|
||||
</div>
|
||||
<div class="progress-bar">
|
||||
<div class="progress-inner" :style="{width: card.progress + '%', background: card.progressColor}"></div>
|
||||
</div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<!-- 图表部分 -->
|
||||
<el-row :gutter="24" class="chart-row">
|
||||
<el-col :xs="24" :sm="24" :md="24" :lg="16" :xl="16">
|
||||
<el-card class="chart-card" shadow="hover">
|
||||
<div class="chart-header">
|
||||
<div class="chart-title">
|
||||
<h3>销售趋势</h3>
|
||||
<p>本期销售数据分析与预测</p>
|
||||
</div>
|
||||
<div class="chart-actions">
|
||||
<el-radio-group v-model="salesRange" size="small">
|
||||
<el-radio-button label="week">本周</el-radio-button>
|
||||
<el-radio-button label="month">本月</el-radio-button>
|
||||
<el-radio-button label="year">全年</el-radio-button>
|
||||
</el-radio-group>
|
||||
<el-dropdown class="chart-more">
|
||||
<el-button size="small" text>
|
||||
<el-icon><more-filled /></el-icon>
|
||||
</el-button>
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item>
|
||||
<el-icon><download /></el-icon> 导出数据
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item>
|
||||
<el-icon><refresh /></el-icon> 刷新
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item>
|
||||
<el-icon><setting /></el-icon> 配置
|
||||
</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</template>
|
||||
</el-dropdown>
|
||||
</div>
|
||||
</div>
|
||||
<div class="chart-overview">
|
||||
<div class="overview-item">
|
||||
<span class="label">总销售额</span>
|
||||
<span class="value">¥ 893,204</span>
|
||||
<span class="rate up">+21.5%</span>
|
||||
</div>
|
||||
<div class="overview-item">
|
||||
<span class="label">平均订单额</span>
|
||||
<span class="value">¥ 5,618</span>
|
||||
<span class="rate up">+6.8%</span>
|
||||
</div>
|
||||
<div class="overview-item">
|
||||
<span class="label">转化周期</span>
|
||||
<span class="value">24天</span>
|
||||
<span class="rate down">-2.3%</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="chart-container" ref="salesChartRef"></div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
<el-col :xs="24" :sm="24" :md="24" :lg="8" :xl="8">
|
||||
<el-card class="chart-card" shadow="hover">
|
||||
<div class="chart-header">
|
||||
<div class="chart-title">
|
||||
<h3>客户构成</h3>
|
||||
<p>客户群体分布情况</p>
|
||||
</div>
|
||||
<el-dropdown class="chart-more">
|
||||
<el-button size="small" text>
|
||||
<el-icon><more-filled /></el-icon>
|
||||
</el-button>
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item>
|
||||
<el-icon><download /></el-icon> 导出数据
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item>
|
||||
<el-icon><refresh /></el-icon> 刷新
|
||||
</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</template>
|
||||
</el-dropdown>
|
||||
</div>
|
||||
<div class="customer-legend">
|
||||
<div v-for="(item, index) in customerData" :key="index" class="legend-item">
|
||||
<span class="legend-color" :style="{background: item.color}"></span>
|
||||
<span class="legend-label">{{ item.name }}</span>
|
||||
<span class="legend-value">{{ item.percentage }}%</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="chart-container" ref="customerChartRef"></div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<!-- 最近活动和待办事项 -->
|
||||
<el-row :gutter="24" class="activity-row">
|
||||
<el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
|
||||
<el-card class="activity-card" shadow="hover">
|
||||
<div class="card-header-custom">
|
||||
<div class="header-left">
|
||||
<h3>最近活动</h3>
|
||||
<el-badge :value="activities.length" class="badge" type="primary" />
|
||||
</div>
|
||||
<el-link type="primary" :underline="false" class="view-all">
|
||||
查看全部 <el-icon class="el-icon--right"><right /></el-icon>
|
||||
</el-link>
|
||||
</div>
|
||||
<div class="timeline-container">
|
||||
<el-timeline>
|
||||
<el-timeline-item
|
||||
v-for="(activity, index) in activities"
|
||||
:key="index"
|
||||
:timestamp="activity.timestamp"
|
||||
:type="activity.type"
|
||||
:hollow="index !== 0"
|
||||
:size="index === 0 ? 'large' : 'normal'"
|
||||
>
|
||||
<div class="timeline-content">
|
||||
<div class="timeline-title">{{ activity.content }}</div>
|
||||
<div class="timeline-detail" v-if="activity.detail">{{ activity.detail }}</div>
|
||||
</div>
|
||||
</el-timeline-item>
|
||||
</el-timeline>
|
||||
</div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
<el-col :xs="24" :sm="24" :md="24" :lg="12" :xl="12">
|
||||
<el-card class="todo-card" shadow="hover">
|
||||
<div class="card-header-custom">
|
||||
<div class="header-left">
|
||||
<h3>待办事项</h3>
|
||||
<el-tag type="danger" size="small" effect="dark" class="task-tag">{{ todoList.length }} 任务</el-tag>
|
||||
</div>
|
||||
<el-button type="primary" size="small" plain class="add-btn">
|
||||
<el-icon><plus /></el-icon> 添加
|
||||
</el-button>
|
||||
</div>
|
||||
<div class="todo-filter">
|
||||
<el-radio-group v-model="todoFilter" size="small">
|
||||
<el-radio-button label="all">全部</el-radio-button>
|
||||
<el-radio-button label="today">今日</el-radio-button>
|
||||
<el-radio-button label="important">重要</el-radio-button>
|
||||
</el-radio-group>
|
||||
<el-dropdown>
|
||||
<el-button size="small" text>
|
||||
<el-icon><filter /></el-icon>
|
||||
</el-button>
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item>按优先级排序</el-dropdown-item>
|
||||
<el-dropdown-item>按截止日期排序</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</template>
|
||||
</el-dropdown>
|
||||
</div>
|
||||
<div class="todo-list">
|
||||
<div v-for="(todo, index) in todoList" :key="index" class="todo-item">
|
||||
<div class="todo-check">
|
||||
<el-checkbox size="large" />
|
||||
</div>
|
||||
<div class="todo-content">
|
||||
<div class="todo-title">{{ todo.title }}</div>
|
||||
<div class="todo-info">
|
||||
<el-tag :type="getPriorityType(todo.priority)" size="small" effect="plain">
|
||||
{{ todo.priority }}
|
||||
</el-tag>
|
||||
<span class="todo-date">
|
||||
<el-icon><calendar /></el-icon> {{ todo.deadline }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="todo-actions">
|
||||
<el-button type="primary" link size="small" circle>
|
||||
<el-icon><check /></el-icon>
|
||||
</el-button>
|
||||
<el-button type="danger" link size="small" circle>
|
||||
<el-icon><delete /></el-icon>
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, onMounted, watch, computed } from 'vue'
|
||||
import {
|
||||
User, ShoppingCart, Money, DataAnalysis,
|
||||
MoreFilled, ArrowUp, ArrowDown, Right,
|
||||
Download, Refresh, Check, Delete, Plus,
|
||||
Setting, Calendar, Filter
|
||||
} from '@element-plus/icons-vue'
|
||||
import * as echarts from 'echarts'
|
||||
import Qrcode from '@/components/Qrcode.vue'
|
||||
import {useUserStore} from "@/store/userStore.js";
|
||||
|
||||
const userStore = useUserStore()
|
||||
// 数据统计卡片
|
||||
const statisticsCards = ref([
|
||||
{
|
||||
title: '访问量',
|
||||
value: '8,846',
|
||||
icon: 'User',
|
||||
trend: 12.5,
|
||||
class: 'visitors',
|
||||
progress: 78,
|
||||
progressColor: 'rgba(24, 144, 255, 0.8)'
|
||||
},
|
||||
{
|
||||
title: '订单量',
|
||||
value: '1,257',
|
||||
icon: 'ShoppingCart',
|
||||
trend: 5.2,
|
||||
class: 'orders',
|
||||
progress: 65,
|
||||
progressColor: 'rgba(82, 196, 26, 0.8)'
|
||||
},
|
||||
{
|
||||
title: '销售额',
|
||||
value: '¥ 125,430',
|
||||
icon: 'Money',
|
||||
trend: -2.3,
|
||||
class: 'sales',
|
||||
progress: 52,
|
||||
progressColor: 'rgba(250, 173, 20, 0.8)'
|
||||
},
|
||||
{
|
||||
title: '转化率',
|
||||
value: '32.8%',
|
||||
icon: 'DataAnalysis',
|
||||
trend: 4.6,
|
||||
class: 'conversion',
|
||||
progress: 83,
|
||||
progressColor: 'rgba(114, 46, 209, 0.8)'
|
||||
}
|
||||
])
|
||||
|
||||
// 客户构成数据
|
||||
const customerData = ref([
|
||||
{ name: '企业客户', value: 1048, percentage: 33, color: '#1890ff' },
|
||||
{ name: '个人客户', value: 735, percentage: 23, color: '#52c41a' },
|
||||
{ name: '政府单位', value: 580, percentage: 18, color: '#fa8c16' },
|
||||
{ name: '教育机构', value: 484, percentage: 15, color: '#722ed1' },
|
||||
{ name: '其他', value: 300, percentage: 11, color: '#f759ab' }
|
||||
])
|
||||
|
||||
const salesRange = ref('month')
|
||||
const todoFilter = ref('all')
|
||||
const salesChartRef = ref(null)
|
||||
const customerChartRef = ref(null)
|
||||
let salesChart = null
|
||||
let customerChart = null
|
||||
|
||||
// 活动数据
|
||||
const activities = ref([
|
||||
{
|
||||
content: '王经理 完成了销售目标',
|
||||
detail: '超额完成15%的销售指标',
|
||||
timestamp: '刚刚',
|
||||
type: 'success'
|
||||
},
|
||||
{
|
||||
content: '李明 上传了新的销售报告',
|
||||
detail: '包含Q2季度各区域销售数据',
|
||||
timestamp: '10分钟前',
|
||||
type: 'primary'
|
||||
},
|
||||
{
|
||||
content: '系统更新了安全策略',
|
||||
timestamp: '1小时前',
|
||||
type: 'info'
|
||||
},
|
||||
{
|
||||
content: '张经理 分配了新的任务',
|
||||
detail: '关于新产品线的市场调研',
|
||||
timestamp: '昨天',
|
||||
type: 'warning'
|
||||
},
|
||||
{
|
||||
content: '年度销售会议即将开始',
|
||||
timestamp: '2天前',
|
||||
type: 'danger'
|
||||
}
|
||||
])
|
||||
|
||||
// 待办事项
|
||||
const todoList = ref([
|
||||
{ title: '完成季度销售报告', priority: '高', deadline: '2024-06-10' },
|
||||
{ title: '召开团队周会', priority: '中', deadline: '2024-06-12' },
|
||||
{ title: '审核营销方案', priority: '高', deadline: '2024-06-14' },
|
||||
{ title: '客户回访', priority: '低', deadline: '2024-06-18' }
|
||||
])
|
||||
|
||||
// 根据优先级返回标签类型
|
||||
const getPriorityType = (priority) => {
|
||||
switch (priority) {
|
||||
case '高': return 'danger'
|
||||
case '中': return 'warning'
|
||||
case '低': return 'info'
|
||||
default: return 'info'
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
initSalesChart()
|
||||
initCustomerChart()
|
||||
|
||||
// 窗口大小变化时重新调整图表大小
|
||||
window.addEventListener('resize', () => {
|
||||
salesChart?.resize()
|
||||
customerChart?.resize()
|
||||
})
|
||||
})
|
||||
|
||||
// 初始化销售趋势图表
|
||||
const initSalesChart = () => {
|
||||
if (!salesChartRef.value) return
|
||||
|
||||
salesChart = echarts.init(salesChartRef.value)
|
||||
const option = {
|
||||
tooltip: {
|
||||
trigger: 'axis',
|
||||
backgroundColor: 'rgba(255,255,255,0.9)',
|
||||
borderColor: '#e6e9ed',
|
||||
borderWidth: 1,
|
||||
textStyle: {
|
||||
color: '#5e6d82'
|
||||
},
|
||||
formatter: function(params) {
|
||||
let result = params[0].name + '<br/>';
|
||||
params.forEach(item => {
|
||||
result += `<div style="display:flex;align-items:center;margin:5px 0">
|
||||
<span style="display:inline-block;width:10px;height:10px;background:${item.color};margin-right:5px;border-radius:50%"></span>
|
||||
<span>${item.seriesName}: ${item.value} 元</span>
|
||||
</div>`;
|
||||
});
|
||||
return result;
|
||||
}
|
||||
},
|
||||
grid: {
|
||||
left: '3%',
|
||||
right: '4%',
|
||||
bottom: '8%',
|
||||
top: '5%',
|
||||
containLabel: true
|
||||
},
|
||||
xAxis: {
|
||||
type: 'category',
|
||||
boundaryGap: false,
|
||||
data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'],
|
||||
axisLine: {
|
||||
lineStyle: {
|
||||
color: '#e6e9ed'
|
||||
}
|
||||
},
|
||||
axisTick: {
|
||||
show: false
|
||||
},
|
||||
axisLabel: {
|
||||
color: '#5e6d82'
|
||||
}
|
||||
},
|
||||
yAxis: {
|
||||
type: 'value',
|
||||
axisLine: {
|
||||
show: false
|
||||
},
|
||||
axisTick: {
|
||||
show: false
|
||||
},
|
||||
axisLabel: {
|
||||
color: '#5e6d82'
|
||||
},
|
||||
splitLine: {
|
||||
lineStyle: {
|
||||
color: '#f0f3f8'
|
||||
}
|
||||
}
|
||||
},
|
||||
series: [
|
||||
{
|
||||
name: '销售额',
|
||||
type: 'line',
|
||||
smooth: true,
|
||||
symbolSize: 6,
|
||||
lineStyle: {
|
||||
width: 3,
|
||||
color: '#1890ff'
|
||||
},
|
||||
itemStyle: {
|
||||
color: '#1890ff',
|
||||
borderWidth: 2,
|
||||
borderColor: '#fff'
|
||||
},
|
||||
emphasis: {
|
||||
itemStyle: {
|
||||
shadowBlur: 10,
|
||||
shadowColor: 'rgba(24, 144, 255, 0.5)'
|
||||
}
|
||||
},
|
||||
areaStyle: {
|
||||
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
|
||||
{ offset: 0, color: 'rgba(24, 144, 255, 0.5)' },
|
||||
{ offset: 1, color: 'rgba(24, 144, 255, 0.05)' }
|
||||
])
|
||||
},
|
||||
data: [12000, 19000, 15000, 22000, 19000, 28000, 32000]
|
||||
}
|
||||
]
|
||||
}
|
||||
salesChart.setOption(option)
|
||||
}
|
||||
|
||||
// 初始化客户构成图表
|
||||
const initCustomerChart = () => {
|
||||
if (!customerChartRef.value) return
|
||||
|
||||
customerChart = echarts.init(customerChartRef.value)
|
||||
const option = {
|
||||
tooltip: {
|
||||
trigger: 'item',
|
||||
formatter: '{a} <br/>{b}: {c} ({d}%)',
|
||||
backgroundColor: 'rgba(255,255,255,0.9)',
|
||||
borderColor: '#e6e9ed',
|
||||
borderWidth: 1,
|
||||
textStyle: {
|
||||
color: '#5e6d82'
|
||||
}
|
||||
},
|
||||
series: [
|
||||
{
|
||||
name: '客户构成',
|
||||
type: 'pie',
|
||||
radius: ['55%', '75%'],
|
||||
center: ['50%', '50%'],
|
||||
avoidLabelOverlap: false,
|
||||
itemStyle: {
|
||||
borderRadius: 10,
|
||||
borderColor: '#fff',
|
||||
borderWidth: 2
|
||||
},
|
||||
label: {
|
||||
show: false
|
||||
},
|
||||
emphasis: {
|
||||
focus: 'self',
|
||||
scaleSize: 10,
|
||||
itemStyle: {
|
||||
shadowBlur: 10,
|
||||
shadowColor: 'rgba(0, 0, 0, 0.2)'
|
||||
}
|
||||
},
|
||||
labelLine: {
|
||||
show: false
|
||||
},
|
||||
data: customerData.value.map(item => ({
|
||||
value: item.value,
|
||||
name: item.name,
|
||||
itemStyle: {
|
||||
color: item.color
|
||||
}
|
||||
}))
|
||||
}
|
||||
]
|
||||
}
|
||||
customerChart.setOption(option)
|
||||
}
|
||||
|
||||
// 监听销售范围变化
|
||||
watch(salesRange, (newVal) => {
|
||||
// 根据选择的时间范围更新图表数据
|
||||
if (salesChart) {
|
||||
const xAxisData = newVal === 'week'
|
||||
? ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
|
||||
: newVal === 'month'
|
||||
? ['1日', '5日', '10日', '15日', '20日', '25日', '30日']
|
||||
: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月']
|
||||
|
||||
const seriesData = newVal === 'week'
|
||||
? [12000, 19000, 15000, 22000, 19000, 28000, 32000]
|
||||
: newVal === 'month'
|
||||
? [32000, 45000, 39000, 52000, 48000, 58000, 62000]
|
||||
: [158000, 165000, 180000, 220000, 210000, 252000, 265000, 270000, 285000, 302000, 318000, 350000]
|
||||
|
||||
salesChart.setOption({
|
||||
xAxis: {
|
||||
data: xAxisData
|
||||
},
|
||||
series: [{
|
||||
data: seriesData
|
||||
}]
|
||||
})
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.dashboard-container {
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
/* 统计卡片样式 */
|
||||
.stat-card {
|
||||
margin-bottom: 24px;
|
||||
border-radius: 12px;
|
||||
border: none;
|
||||
transition: all 0.3s;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.stat-card:hover {
|
||||
transform: translateY(-5px);
|
||||
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.08);
|
||||
}
|
||||
|
||||
.card-top {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 20px 20px 10px;
|
||||
}
|
||||
|
||||
.card-meta {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.card-title {
|
||||
font-size: 14px;
|
||||
color: #8c8c8c;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.card-value {
|
||||
font-size: 28px;
|
||||
font-weight: 600;
|
||||
color: #262626;
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
.card-icon {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 56px;
|
||||
height: 56px;
|
||||
border-radius: 12px;
|
||||
font-size: 28px;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.visitors .card-icon {
|
||||
background: linear-gradient(135deg, #1890ff, #096dd9);
|
||||
}
|
||||
|
||||
.orders .card-icon {
|
||||
background: linear-gradient(135deg, #52c41a, #389e0d);
|
||||
}
|
||||
|
||||
.sales .card-icon {
|
||||
background: linear-gradient(135deg, #faad14, #d48806);
|
||||
}
|
||||
|
||||
.conversion .card-icon {
|
||||
background: linear-gradient(135deg, #722ed1, #531dab);
|
||||
}
|
||||
|
||||
.card-footer {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-start;
|
||||
gap: 8px;
|
||||
padding: 0 20px 15px;
|
||||
font-size: 13px;
|
||||
color: #8c8c8c;
|
||||
}
|
||||
|
||||
.up {
|
||||
color: #52c41a;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 2px;
|
||||
}
|
||||
|
||||
.down {
|
||||
color: #f5222d;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 2px;
|
||||
}
|
||||
|
||||
.progress-bar {
|
||||
height: 4px;
|
||||
background-color: #f0f0f0;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.progress-inner {
|
||||
height: 100%;
|
||||
transition: width 0.8s ease;
|
||||
}
|
||||
|
||||
/* 图表样式 */
|
||||
.chart-row {
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.chart-card {
|
||||
margin-bottom: 24px;
|
||||
border-radius: 12px;
|
||||
border: none;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.chart-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: flex-start;
|
||||
padding: 20px 20px 0;
|
||||
}
|
||||
|
||||
.chart-title h3 {
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
color: #262626;
|
||||
margin: 0 0 4px;
|
||||
}
|
||||
|
||||
.chart-title p {
|
||||
font-size: 13px;
|
||||
color: #8c8c8c;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.chart-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.chart-more {
|
||||
margin-left: 8px;
|
||||
}
|
||||
|
||||
.chart-overview {
|
||||
display: flex;
|
||||
justify-content: flex-start;
|
||||
gap: 40px;
|
||||
padding: 15px 20px;
|
||||
border-bottom: 1px dashed #f0f0f0;
|
||||
}
|
||||
|
||||
.overview-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.overview-item .label {
|
||||
font-size: 13px;
|
||||
color: #8c8c8c;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.overview-item .value {
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
color: #262626;
|
||||
line-height: 1.2;
|
||||
}
|
||||
|
||||
.overview-item .rate {
|
||||
margin-top: 6px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.chart-container {
|
||||
height: 300px;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
/* 客户构成图表特有样式 */
|
||||
.customer-legend {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 16px;
|
||||
padding: 10px 20px;
|
||||
}
|
||||
|
||||
.legend-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.legend-color {
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
.legend-label {
|
||||
font-size: 13px;
|
||||
color: #262626;
|
||||
}
|
||||
|
||||
.legend-value {
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
color: #262626;
|
||||
}
|
||||
|
||||
/* 活动和待办事项 */
|
||||
.activity-row {
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.activity-card, .todo-card {
|
||||
height: 100%;
|
||||
border-radius: 12px;
|
||||
border: none;
|
||||
}
|
||||
|
||||
.card-header-custom {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 16px 20px;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
}
|
||||
|
||||
.header-left {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.header-left h3 {
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
color: #262626;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.view-all {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.timeline-container {
|
||||
padding: 20px;
|
||||
height: 350px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.timeline-content {
|
||||
padding: 12px 16px;
|
||||
background-color: #f9f9f9;
|
||||
border-radius: 8px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.timeline-title {
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: #262626;
|
||||
}
|
||||
|
||||
.timeline-detail {
|
||||
font-size: 13px;
|
||||
color: #8c8c8c;
|
||||
margin-top: 6px;
|
||||
}
|
||||
|
||||
/* 待办事项特有样式 */
|
||||
.task-tag {
|
||||
margin-left: 10px;
|
||||
}
|
||||
|
||||
.add-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.todo-filter {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
padding: 16px 20px;
|
||||
border-bottom: 1px solid #f0f0f0;
|
||||
}
|
||||
|
||||
.todo-list {
|
||||
padding: 10px 20px;
|
||||
height: 270px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.todo-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 12px 0;
|
||||
border-bottom: 1px solid #f5f5f5;
|
||||
}
|
||||
|
||||
.todo-item:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.todo-check {
|
||||
margin-right: 16px;
|
||||
}
|
||||
|
||||
.todo-content {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.todo-title {
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: #262626;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.todo-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.todo-date {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
font-size: 13px;
|
||||
color: #8c8c8c;
|
||||
}
|
||||
|
||||
.todo-actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.dashboard-container {
|
||||
padding: 12px;
|
||||
}
|
||||
|
||||
.chart-overview {
|
||||
flex-wrap: wrap;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.chart-container {
|
||||
height: 250px;
|
||||
}
|
||||
|
||||
.timeline-container,
|
||||
.todo-list {
|
||||
height: 320px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,525 @@
|
||||
<template>
|
||||
<div class="change-password-container">
|
||||
<div class="page-header">
|
||||
<h2 class="page-title">修改密码</h2>
|
||||
</div>
|
||||
|
||||
<div class="password-layout">
|
||||
<!-- 修改密码表单 -->
|
||||
<div class="password-form-container">
|
||||
<el-card shadow="hover" class="password-card">
|
||||
<template #header>
|
||||
<div class="card-header">
|
||||
<el-icon><lock /></el-icon>
|
||||
<span>密码修改</span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<el-form
|
||||
ref="passwordFormRef"
|
||||
:model="passwordForm"
|
||||
:rules="rules"
|
||||
label-width="120px"
|
||||
class="password-form"
|
||||
status-icon
|
||||
>
|
||||
<el-form-item label="当前密码" prop="oldPassword">
|
||||
<el-input
|
||||
v-model="passwordForm.oldPassword"
|
||||
type="password"
|
||||
placeholder="请输入当前密码"
|
||||
show-password
|
||||
prefix-icon="Key"
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="新密码" prop="newPassword">
|
||||
<el-input
|
||||
v-model="passwordForm.newPassword"
|
||||
type="password"
|
||||
placeholder="请输入新密码"
|
||||
show-password
|
||||
prefix-icon="Lock"
|
||||
/>
|
||||
|
||||
<!-- 密码强度指示器 -->
|
||||
<div class="password-strength" v-if="passwordForm.newPassword">
|
||||
<div class="strength-label">密码强度:</div>
|
||||
<div class="strength-bar">
|
||||
<div
|
||||
class="strength-indicator"
|
||||
:class="[
|
||||
passwordStrength === 'weak' ? 'weak' :
|
||||
passwordStrength === 'medium' ? 'medium' :
|
||||
passwordStrength === 'strong' ? 'strong' : ''
|
||||
]"
|
||||
:style="{ width: strengthPercentage + '%' }"
|
||||
></div>
|
||||
</div>
|
||||
<div class="strength-text" :class="passwordStrength">
|
||||
{{ passwordStrengthText }}
|
||||
</div>
|
||||
</div>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="确认新密码" prop="confirmPassword">
|
||||
<el-input
|
||||
v-model="passwordForm.confirmPassword"
|
||||
type="password"
|
||||
placeholder="请再次输入新密码"
|
||||
show-password
|
||||
prefix-icon="Check"
|
||||
/>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item>
|
||||
<el-button
|
||||
type="primary"
|
||||
@click="submitForm"
|
||||
:loading="loading"
|
||||
:disabled="submitDisabled"
|
||||
class="submit-btn"
|
||||
>
|
||||
保存修改
|
||||
</el-button>
|
||||
<el-button @click="resetForm">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-card>
|
||||
</div>
|
||||
|
||||
<!-- 密码规则说明 -->
|
||||
<div class="password-tips-container">
|
||||
<el-card shadow="hover" class="tips-card">
|
||||
<template #header>
|
||||
<div class="card-header">
|
||||
<el-icon><InfoFilled /></el-icon>
|
||||
<span>密码要求</span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div class="tips-content">
|
||||
<p class="tips-title">为了保障您的账号安全,密码需满足以下要求:</p>
|
||||
|
||||
<ul class="tips-list">
|
||||
<li class="tips-item" :class="{ passed: hasMinLength }">
|
||||
<el-icon :class="{ 'is-passed': hasMinLength }">
|
||||
<component :is="hasMinLength ? 'CircleCheck' : 'CircleClose'" />
|
||||
</el-icon>
|
||||
<span>长度至少8个字符</span>
|
||||
</li>
|
||||
<li class="tips-item" :class="{ passed: hasUpperCase }">
|
||||
<el-icon :class="{ 'is-passed': hasUpperCase }">
|
||||
<component :is="hasUpperCase ? 'CircleCheck' : 'CircleClose'" />
|
||||
</el-icon>
|
||||
<span>包含至少一个大写字母 (A-Z)</span>
|
||||
</li>
|
||||
<li class="tips-item" :class="{ passed: hasLowerCase }">
|
||||
<el-icon :class="{ 'is-passed': hasLowerCase }">
|
||||
<component :is="hasLowerCase ? 'CircleCheck' : 'CircleClose'" />
|
||||
</el-icon>
|
||||
<span>包含至少一个小写字母 (a-z)</span>
|
||||
</li>
|
||||
<li class="tips-item" :class="{ passed: hasNumber }">
|
||||
<el-icon :class="{ 'is-passed': hasNumber }">
|
||||
<component :is="hasNumber ? 'CircleCheck' : 'CircleClose'" />
|
||||
</el-icon>
|
||||
<span>包含至少一个数字 (0-9)</span>
|
||||
</li>
|
||||
<li class="tips-item" :class="{ passed: hasSpecialChar }">
|
||||
<el-icon :class="{ 'is-passed': hasSpecialChar }">
|
||||
<component :is="hasSpecialChar ? 'CircleCheck' : 'CircleClose'" />
|
||||
</el-icon>
|
||||
<span>包含至少一个特殊字符 (@$!%*#?&)</span>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div class="tips-note">
|
||||
<el-icon><Warning /></el-icon>
|
||||
<p>为了您的账户安全,请不要使用与其他网站相同的密码,并定期更换密码。</p>
|
||||
</div>
|
||||
</div>
|
||||
</el-card>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive, computed, watch } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import {
|
||||
Lock,
|
||||
Key,
|
||||
InfoFilled,
|
||||
CircleCheck,
|
||||
CircleClose,
|
||||
Warning,
|
||||
Check
|
||||
} from '@element-plus/icons-vue'
|
||||
|
||||
// 表单数据
|
||||
const passwordForm = reactive({
|
||||
oldPassword: '',
|
||||
newPassword: '',
|
||||
confirmPassword: ''
|
||||
})
|
||||
|
||||
// 表单引用
|
||||
const passwordFormRef = ref(null)
|
||||
|
||||
// 加载状态
|
||||
const loading = ref(false)
|
||||
|
||||
// 密码强度计算
|
||||
const hasMinLength = computed(() =>
|
||||
passwordForm.newPassword.length >= 8
|
||||
)
|
||||
|
||||
const hasUpperCase = computed(() =>
|
||||
/[A-Z]/.test(passwordForm.newPassword)
|
||||
)
|
||||
|
||||
const hasLowerCase = computed(() =>
|
||||
/[a-z]/.test(passwordForm.newPassword)
|
||||
)
|
||||
|
||||
const hasNumber = computed(() =>
|
||||
/\d/.test(passwordForm.newPassword)
|
||||
)
|
||||
|
||||
const hasSpecialChar = computed(() =>
|
||||
/[@$!%*#?&]/.test(passwordForm.newPassword)
|
||||
)
|
||||
|
||||
// 密码强度计算
|
||||
const passwordStrength = computed(() => {
|
||||
let score = 0
|
||||
|
||||
// 最低长度要求
|
||||
if (hasMinLength.value) score++
|
||||
|
||||
// 大写字母
|
||||
if (hasUpperCase.value) score++
|
||||
|
||||
// 小写字母
|
||||
if (hasLowerCase.value) score++
|
||||
|
||||
// 数字
|
||||
if (hasNumber.value) score++
|
||||
|
||||
// 特殊字符
|
||||
if (hasSpecialChar.value) score++
|
||||
|
||||
if (score <= 2) return 'weak'
|
||||
if (score <= 4) return 'medium'
|
||||
return 'strong'
|
||||
})
|
||||
|
||||
// 密码强度百分比
|
||||
const strengthPercentage = computed(() => {
|
||||
if (passwordStrength.value === 'weak') return 30
|
||||
if (passwordStrength.value === 'medium') return 70
|
||||
return 100
|
||||
})
|
||||
|
||||
// 密码强度文字描述
|
||||
const passwordStrengthText = computed(() => {
|
||||
if (passwordStrength.value === 'weak') return '弱'
|
||||
if (passwordStrength.value === 'medium') return '中'
|
||||
return '强'
|
||||
})
|
||||
|
||||
// 提交按钮是否禁用
|
||||
const submitDisabled = computed(() => {
|
||||
return (
|
||||
!passwordForm.oldPassword ||
|
||||
!passwordForm.newPassword ||
|
||||
!passwordForm.confirmPassword ||
|
||||
passwordStrength.value === 'weak'
|
||||
)
|
||||
})
|
||||
|
||||
// 密码强度校验
|
||||
const validatePasswordStrength = (rule, value, callback) => {
|
||||
if (value === '') {
|
||||
callback(new Error('请输入密码'))
|
||||
return
|
||||
}
|
||||
|
||||
if (!hasMinLength.value) {
|
||||
callback(new Error('密码长度至少为8个字符'))
|
||||
return
|
||||
}
|
||||
|
||||
if (!(hasUpperCase.value && hasLowerCase.value && hasNumber.value && hasSpecialChar.value)) {
|
||||
callback(new Error('密码必须包含大小写字母、数字和特殊字符'))
|
||||
return
|
||||
}
|
||||
|
||||
callback()
|
||||
}
|
||||
|
||||
// 确认密码校验
|
||||
const validateConfirmPassword = (rule, value, callback) => {
|
||||
if (value === '') {
|
||||
callback(new Error('请再次输入密码'))
|
||||
return
|
||||
}
|
||||
|
||||
if (value !== passwordForm.newPassword) {
|
||||
callback(new Error('两次输入的密码不一致'))
|
||||
return
|
||||
}
|
||||
|
||||
callback()
|
||||
}
|
||||
|
||||
// 表单校验规则
|
||||
const rules = {
|
||||
oldPassword: [
|
||||
{ required: true, message: '请输入当前密码', trigger: 'blur' },
|
||||
{ min: 6, message: '密码长度至少为6个字符', trigger: 'blur' }
|
||||
],
|
||||
newPassword: [
|
||||
{ required: true, message: '请输入新密码', trigger: 'blur' },
|
||||
{ validator: validatePasswordStrength, trigger: 'blur' }
|
||||
],
|
||||
confirmPassword: [
|
||||
{ required: true, message: '请再次输入新密码', trigger: 'blur' },
|
||||
{ validator: validateConfirmPassword, trigger: 'blur' }
|
||||
]
|
||||
}
|
||||
|
||||
// 提交表单
|
||||
const submitForm = async () => {
|
||||
if (!passwordFormRef.value) return
|
||||
|
||||
await passwordFormRef.value.validate(async (valid) => {
|
||||
if (valid) {
|
||||
try {
|
||||
loading.value = true
|
||||
|
||||
// 模拟API调用
|
||||
await new Promise(resolve => setTimeout(resolve, 1500))
|
||||
|
||||
// 这里应该调用API修改密码
|
||||
// const res = await api.changePassword(passwordForm)
|
||||
|
||||
ElMessage.success('密码修改成功,请重新登录')
|
||||
loading.value = false
|
||||
|
||||
// 清空表单
|
||||
resetForm()
|
||||
|
||||
// 实际项目中可能需要跳转到登录页
|
||||
// router.push('/login')
|
||||
} catch (error) {
|
||||
loading.value = false
|
||||
ElMessage.error('密码修改失败,请重试')
|
||||
console.error(error)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 重置表单
|
||||
const resetForm = () => {
|
||||
if (passwordFormRef.value) {
|
||||
passwordFormRef.value.resetFields()
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.change-password-container {
|
||||
padding: 24px;
|
||||
min-height: 100%;
|
||||
}
|
||||
|
||||
.page-header {
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.page-title {
|
||||
margin: 0;
|
||||
font-size: 24px;
|
||||
font-weight: 600;
|
||||
color: #1a1f36;
|
||||
}
|
||||
|
||||
.password-layout {
|
||||
display: flex;
|
||||
gap: 24px;
|
||||
}
|
||||
|
||||
.password-form-container {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.password-tips-container {
|
||||
width: 380px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.password-card,
|
||||
.tips-card {
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.05) !important;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.card-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
color: #1a1f36;
|
||||
}
|
||||
|
||||
.card-header .el-icon {
|
||||
margin-right: 8px;
|
||||
font-size: 18px;
|
||||
color: #409eff;
|
||||
}
|
||||
|
||||
.password-form {
|
||||
padding: 20px 0;
|
||||
}
|
||||
|
||||
.password-strength {
|
||||
margin-top: 8px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.strength-label {
|
||||
margin-right: 8px;
|
||||
font-size: 13px;
|
||||
color: #606266;
|
||||
margin-bottom: 2px;
|
||||
}
|
||||
|
||||
.strength-bar {
|
||||
width: 120px;
|
||||
height: 4px;
|
||||
background-color: #e4e7ed;
|
||||
border-radius: 2px;
|
||||
overflow: hidden;
|
||||
margin-right: 8px;
|
||||
margin-bottom: 2px;
|
||||
}
|
||||
|
||||
.strength-indicator {
|
||||
height: 100%;
|
||||
transition: width 0.3s ease, background-color 0.3s ease;
|
||||
}
|
||||
|
||||
.strength-indicator.weak {
|
||||
background-color: #f56c6c;
|
||||
}
|
||||
|
||||
.strength-indicator.medium {
|
||||
background-color: #e6a23c;
|
||||
}
|
||||
|
||||
.strength-indicator.strong {
|
||||
background-color: #67c23a;
|
||||
}
|
||||
|
||||
.strength-text {
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.strength-text.weak {
|
||||
color: #f56c6c;
|
||||
}
|
||||
|
||||
.strength-text.medium {
|
||||
color: #e6a23c;
|
||||
}
|
||||
|
||||
.strength-text.strong {
|
||||
color: #67c23a;
|
||||
}
|
||||
|
||||
.submit-btn {
|
||||
width: 120px;
|
||||
}
|
||||
|
||||
.tips-content {
|
||||
padding: 0 0 15px;
|
||||
}
|
||||
|
||||
.tips-title {
|
||||
margin-top: 0;
|
||||
margin-bottom: 16px;
|
||||
font-size: 14px;
|
||||
color: #606266;
|
||||
}
|
||||
|
||||
.tips-list {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 0 0 20px 0;
|
||||
}
|
||||
|
||||
.tips-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 8px 0;
|
||||
color: #606266;
|
||||
font-size: 14px;
|
||||
transition: color 0.3s;
|
||||
}
|
||||
|
||||
.tips-item .el-icon {
|
||||
margin-right: 8px;
|
||||
font-size: 16px;
|
||||
color: #c0c4cc;
|
||||
transition: color 0.3s;
|
||||
}
|
||||
|
||||
.tips-item .el-icon.is-passed {
|
||||
color: #67c23a;
|
||||
}
|
||||
|
||||
.tips-item.passed {
|
||||
color: #67c23a;
|
||||
}
|
||||
|
||||
.tips-note {
|
||||
background-color: #fdf6ec;
|
||||
border-radius: 4px;
|
||||
padding: 10px 12px;
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.tips-note .el-icon {
|
||||
color: #e6a23c;
|
||||
font-size: 16px;
|
||||
margin-right: 8px;
|
||||
margin-top: 3px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.tips-note p {
|
||||
margin: 0;
|
||||
font-size: 13px;
|
||||
color: #af8741;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
@media (max-width: 992px) {
|
||||
.password-layout {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.password-tips-container {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,529 @@
|
||||
<template>
|
||||
<div class="user-info-container">
|
||||
<div class="page-header">
|
||||
<h2 class="page-title">个人信息</h2>
|
||||
<div class="page-actions">
|
||||
<el-button type="primary" @click="handleEdit" v-if="!isEditing">
|
||||
<el-icon><edit /></el-icon>编辑资料
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="profile-layout">
|
||||
<!-- 左侧用户基本信息卡片 -->
|
||||
<div class="profile-sidebar">
|
||||
<div class="profile-card">
|
||||
<div class="profile-avatar-container">
|
||||
<el-avatar
|
||||
:size="120"
|
||||
:src="userInfo.avatar || 'https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png'"
|
||||
class="profile-avatar"
|
||||
/>
|
||||
<div class="profile-avatar-edit" v-if="isEditing">
|
||||
<el-upload
|
||||
class="avatar-uploader"
|
||||
action="/api/upload"
|
||||
:show-file-list="false"
|
||||
:on-success="handleAvatarSuccess"
|
||||
>
|
||||
<div class="upload-trigger">
|
||||
<el-icon><upload-filled /></el-icon>
|
||||
<span>更换头像</span>
|
||||
</div>
|
||||
</el-upload>
|
||||
</div>
|
||||
</div>
|
||||
<h3 class="profile-name">{{ userInfo.realName }}</h3>
|
||||
<div class="profile-title">{{ userInfo.position }}</div>
|
||||
<div class="profile-role">
|
||||
<el-tag type="success" effect="plain">{{ userInfo.role }}</el-tag>
|
||||
</div>
|
||||
<div class="profile-stats">
|
||||
<div class="stat-item">
|
||||
<div class="stat-value">{{ userInfo.department }}</div>
|
||||
<div class="stat-label">部门</div>
|
||||
</div>
|
||||
<div class="divider"></div>
|
||||
<div class="stat-item">
|
||||
<div class="stat-value">{{ formatDate(userInfo.lastLogin) }}</div>
|
||||
<div class="stat-label">最近登录</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 右侧详细信息内容 -->
|
||||
<div class="profile-content">
|
||||
<!-- 查看模式 -->
|
||||
<div v-if="!isEditing" class="info-display">
|
||||
<el-card shadow="hover" class="info-card">
|
||||
<template #header>
|
||||
<div class="card-header">
|
||||
<el-icon><user /></el-icon>
|
||||
<span>账号信息</span>
|
||||
</div>
|
||||
</template>
|
||||
<div class="info-list">
|
||||
<div class="info-item">
|
||||
<span class="info-label">用户名</span>
|
||||
<span class="info-value">{{ userInfo.username }}</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="info-label">真实姓名</span>
|
||||
<span class="info-value">{{ userInfo.realName }}</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="info-label">邮箱</span>
|
||||
<span class="info-value">{{ userInfo.email }}</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="info-label">手机号</span>
|
||||
<span class="info-value">{{ userInfo.phone }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</el-card>
|
||||
|
||||
<el-card shadow="hover" class="info-card bio-card">
|
||||
<template #header>
|
||||
<div class="card-header">
|
||||
<el-icon><document /></el-icon>
|
||||
<span>个人简介</span>
|
||||
</div>
|
||||
</template>
|
||||
<div class="bio-content">
|
||||
{{ userInfo.bio || '暂无个人简介' }}
|
||||
</div>
|
||||
</el-card>
|
||||
|
||||
<el-card shadow="hover" class="info-card">
|
||||
<template #header>
|
||||
<div class="card-header">
|
||||
<el-icon><timer /></el-icon>
|
||||
<span>时间信息</span>
|
||||
</div>
|
||||
</template>
|
||||
<div class="info-list">
|
||||
<div class="info-item">
|
||||
<span class="info-label">账号创建时间</span>
|
||||
<span class="info-value">{{ formatDateFull(userInfo.createTime) }}</span>
|
||||
</div>
|
||||
<div class="info-item">
|
||||
<span class="info-label">最后登录时间</span>
|
||||
<span class="info-value">{{ formatDateFull(userInfo.lastLogin) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</el-card>
|
||||
</div>
|
||||
|
||||
<!-- 编辑表单部分 -->
|
||||
<div v-else class="info-edit">
|
||||
<el-card shadow="hover" class="edit-card">
|
||||
<template #header>
|
||||
<div class="card-header">
|
||||
<el-icon><edit-pen /></el-icon>
|
||||
<span>编辑个人资料</span>
|
||||
</div>
|
||||
</template>
|
||||
<el-form ref="userFormRef" :model="userForm" :rules="rules" label-width="100px" class="edit-form">
|
||||
<el-form-item label="用户名" prop="username">
|
||||
<el-input v-model="userForm.username" disabled />
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="真实姓名" prop="realName">
|
||||
<el-input v-model="userForm.realName" />
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="邮箱" prop="email">
|
||||
<el-input v-model="userForm.email">
|
||||
<template #prefix>
|
||||
<el-icon><message /></el-icon>
|
||||
</template>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="手机号" prop="phone">
|
||||
<el-input v-model="userForm.phone">
|
||||
<template #prefix>
|
||||
<el-icon><phone /></el-icon>
|
||||
</template>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="部门">
|
||||
<el-input v-model="userForm.department">
|
||||
<template #prefix>
|
||||
<el-icon><office-building /></el-icon>
|
||||
</template>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="职位">
|
||||
<el-input v-model="userForm.position" />
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="个人简介">
|
||||
<el-input v-model="userForm.bio" type="textarea" :rows="4" resize="none" maxlength="200" show-word-limit />
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="submitForm" :loading="loading">保存</el-button>
|
||||
<el-button @click="cancelEdit">取消</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-card>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive, onMounted } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import {
|
||||
User, Edit, Document, Timer, EditPen, Message,
|
||||
Phone, OfficeBuilding, UploadFilled
|
||||
} from '@element-plus/icons-vue'
|
||||
|
||||
// 是否处于编辑模式
|
||||
const isEditing = ref(false)
|
||||
const loading = ref(false)
|
||||
|
||||
// 用户信息数据
|
||||
const userInfo = reactive({
|
||||
username: 'admin',
|
||||
realName: '管理员',
|
||||
email: 'admin@example.com',
|
||||
phone: '13800138000',
|
||||
department: '技术部',
|
||||
position: '系统管理员',
|
||||
role: '超级管理员',
|
||||
createTime: '2023-01-01 00:00:00',
|
||||
lastLogin: '2023-06-15 10:30:45',
|
||||
bio: '系统管理员,负责系统的日常维护和管理工作。拥有丰富的系统管理经验,精通Linux服务器配置和维护,熟悉网络安全,对系统性能优化有独到见解。',
|
||||
avatar: 'https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png'
|
||||
})
|
||||
|
||||
// 表单数据
|
||||
const userForm = reactive({...userInfo})
|
||||
|
||||
// 表单校验规则
|
||||
const rules = {
|
||||
realName: [
|
||||
{ required: true, message: '请输入真实姓名', trigger: 'blur' },
|
||||
{ min: 2, max: 20, message: '长度在 2 到 20 个字符', trigger: 'blur' }
|
||||
],
|
||||
email: [
|
||||
{ required: true, message: '请输入邮箱地址', trigger: 'blur' },
|
||||
{ type: 'email', message: '请输入正确的邮箱地址', trigger: 'blur' }
|
||||
],
|
||||
phone: [
|
||||
{ required: true, message: '请输入手机号', trigger: 'blur' },
|
||||
{ pattern: /^1[3-9]\d{9}$/, message: '请输入正确的手机号', trigger: 'blur' }
|
||||
]
|
||||
}
|
||||
|
||||
const userFormRef = ref(null)
|
||||
|
||||
// 日期格式化函数
|
||||
const formatDate = (dateStr) => {
|
||||
const date = new Date(dateStr)
|
||||
const now = new Date()
|
||||
|
||||
// 如果是今天,只显示时间
|
||||
if (date.toDateString() === now.toDateString()) {
|
||||
return date.toLocaleTimeString('zh-CN', { hour: '2-digit', minute: '2-digit' })
|
||||
}
|
||||
|
||||
// 否则显示日期
|
||||
return date.toLocaleDateString('zh-CN', { month: '2-digit', day: '2-digit' })
|
||||
}
|
||||
|
||||
// 完整日期格式化
|
||||
const formatDateFull = (dateStr) => {
|
||||
const date = new Date(dateStr)
|
||||
return date.toLocaleString('zh-CN', {
|
||||
year: 'numeric',
|
||||
month: '2-digit',
|
||||
day: '2-digit',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
second: '2-digit'
|
||||
})
|
||||
}
|
||||
|
||||
// 编辑按钮点击事件
|
||||
const handleEdit = () => {
|
||||
Object.assign(userForm, userInfo)
|
||||
isEditing.value = true
|
||||
}
|
||||
|
||||
// 取消编辑
|
||||
const cancelEdit = () => {
|
||||
isEditing.value = false
|
||||
}
|
||||
|
||||
// 提交表单
|
||||
const submitForm = async () => {
|
||||
if (!userFormRef.value) return
|
||||
|
||||
await userFormRef.value.validate(async (valid) => {
|
||||
if (valid) {
|
||||
try {
|
||||
loading.value = true
|
||||
// 模拟API调用
|
||||
await new Promise(resolve => setTimeout(resolve, 1000))
|
||||
|
||||
// 更新本地用户信息
|
||||
Object.assign(userInfo, userForm)
|
||||
ElMessage.success('个人信息更新成功')
|
||||
isEditing.value = false
|
||||
loading.value = false
|
||||
} catch (error) {
|
||||
loading.value = false
|
||||
ElMessage.error('保存失败,请重试')
|
||||
console.error(error)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 头像上传成功回调
|
||||
const handleAvatarSuccess = (res) => {
|
||||
userForm.avatar = res.url
|
||||
}
|
||||
|
||||
// 获取用户信息
|
||||
const fetchUserInfo = async () => {
|
||||
try {
|
||||
// 模拟API调用
|
||||
await new Promise(resolve => setTimeout(resolve, 500))
|
||||
// 实际项目中,应该从后端获取用户信息并更新userInfo
|
||||
} catch (error) {
|
||||
ElMessage.error('获取用户信息失败')
|
||||
console.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchUserInfo()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.user-info-container {
|
||||
padding: 24px;
|
||||
min-height: 100%;
|
||||
}
|
||||
|
||||
.page-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.page-title {
|
||||
margin: 0;
|
||||
font-size: 24px;
|
||||
font-weight: 600;
|
||||
color: #1a1f36;
|
||||
}
|
||||
|
||||
.profile-layout {
|
||||
display: flex;
|
||||
gap: 24px;
|
||||
}
|
||||
|
||||
.profile-sidebar {
|
||||
width: 300px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.profile-content {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.profile-card {
|
||||
background-color: #fff;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.05);
|
||||
padding: 30px;
|
||||
text-align: center;
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.profile-avatar-container {
|
||||
position: relative;
|
||||
margin-bottom: 20px;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.profile-avatar {
|
||||
border: 4px solid #fff;
|
||||
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.profile-avatar-edit {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
right: 0;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.upload-trigger {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
border-radius: 50%;
|
||||
background-color: #409eff;
|
||||
color: white;
|
||||
font-size: 12px;
|
||||
line-height: 1;
|
||||
box-shadow: 0 2px 8px rgba(64, 158, 255, 0.5);
|
||||
}
|
||||
|
||||
.upload-trigger span {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.upload-trigger:hover {
|
||||
width: auto;
|
||||
height: auto;
|
||||
border-radius: 18px;
|
||||
padding: 4px 12px;
|
||||
}
|
||||
|
||||
.upload-trigger:hover span {
|
||||
display: inline-block;
|
||||
margin-left: 4px;
|
||||
}
|
||||
|
||||
.profile-name {
|
||||
font-size: 22px;
|
||||
font-weight: 600;
|
||||
margin: 0 0 8px 0;
|
||||
color: #1a1f36;
|
||||
}
|
||||
|
||||
.profile-title {
|
||||
color: #667085;
|
||||
font-size: 16px;
|
||||
margin-bottom: 14px;
|
||||
}
|
||||
|
||||
.profile-role {
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.profile-stats {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
border-top: 1px solid #edf2f7;
|
||||
padding-top: 20px;
|
||||
}
|
||||
|
||||
.stat-item {
|
||||
flex: 1;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.stat-value {
|
||||
font-weight: 600;
|
||||
color: #333;
|
||||
font-size: 16px;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
color: #94a3b8;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.divider {
|
||||
width: 1px;
|
||||
height: 30px;
|
||||
background-color: #edf2f7;
|
||||
margin: 0 15px;
|
||||
}
|
||||
|
||||
.info-card {
|
||||
margin-bottom: 24px;
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.bio-card {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.card-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
color: #1a1f36;
|
||||
}
|
||||
|
||||
.card-header .el-icon {
|
||||
margin-right: 8px;
|
||||
font-size: 18px;
|
||||
color: #409eff;
|
||||
}
|
||||
|
||||
.info-list {
|
||||
display: grid;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.info-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.info-label {
|
||||
width: 120px;
|
||||
color: #64748b;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.info-value {
|
||||
color: #334155;
|
||||
font-weight: 500;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.bio-content {
|
||||
color: #475569;
|
||||
line-height: 1.6;
|
||||
font-size: 14px;
|
||||
white-space: pre-line;
|
||||
}
|
||||
|
||||
.edit-card {
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.edit-form {
|
||||
padding: 16px 0;
|
||||
}
|
||||
|
||||
@media (max-width: 992px) {
|
||||
.profile-layout {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.profile-sidebar {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.profile-card {
|
||||
padding: 20px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,309 @@
|
||||
<template>
|
||||
<div class="domain-whitelist-container">
|
||||
<!-- 搜索和操作栏 -->
|
||||
<el-card class="filter-container" shadow="never">
|
||||
<el-form :inline="true" :model="queryParams" class="search-form">
|
||||
<el-form-item label="域名">
|
||||
<el-input v-model="queryParams.domain" placeholder="请输入域名" clearable />
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="handleQuery">查询</el-button>
|
||||
<el-button @click="resetQuery">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<div class="action-bar">
|
||||
<el-button type="primary" @click="handleAdd">
|
||||
<el-icon><plus /></el-icon>新增域名
|
||||
</el-button>
|
||||
<el-button type="danger" :disabled="!selectedRows.length" @click="handleBatchDelete">
|
||||
<el-icon><delete /></el-icon>批量删除
|
||||
</el-button>
|
||||
</div>
|
||||
</el-card>
|
||||
|
||||
<!-- 域名列表 -->
|
||||
<el-card class="table-container" shadow="never">
|
||||
<el-table
|
||||
v-loading="loading"
|
||||
:data="domainList"
|
||||
@selection-change="handleSelectionChange"
|
||||
style="width: 100%"
|
||||
>
|
||||
<el-table-column type="selection" width="55" />
|
||||
<el-table-column prop="Id" label="ID" width="80" />
|
||||
<el-table-column prop="Domain" label="域名" min-width="200" >
|
||||
<template #default="{ row }">
|
||||
<el-link :href="`http://${row.Domain}`" target="_blank" type="primary">{{ row.Domain }}</el-link>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="CreatedAt" label="创建时间" width="180" :formatter="parseCreatedAt" />
|
||||
<el-table-column prop="UpdatedAt" label="更新时间" width="180" :formatter="parseUpdatedAt" />
|
||||
<el-table-column label="操作" width="100" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button type="danger" link @click="handleDelete(row)">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<!-- 分页 -->
|
||||
<el-pagination
|
||||
v-model:current-page="queryParams.pageNum"
|
||||
v-model:page-size="queryParams.pageSize"
|
||||
:page-sizes="[10, 20, 50, 100]"
|
||||
layout="total, sizes, prev, pager, next, jumper"
|
||||
:total="total"
|
||||
@size-change="handleSizeChange"
|
||||
@current-change="handleCurrentChange"
|
||||
background
|
||||
class="pagination"
|
||||
/>
|
||||
</el-card>
|
||||
|
||||
<!-- 域名表单对话框 -->
|
||||
<el-dialog
|
||||
v-model="dialogVisible"
|
||||
title="新增域名"
|
||||
width="500px"
|
||||
append-to-body
|
||||
>
|
||||
<el-form
|
||||
ref="domainFormRef"
|
||||
:model="domainForm"
|
||||
:rules="domainRules"
|
||||
label-width="80px"
|
||||
>
|
||||
<el-form-item label="域名" prop="domain">
|
||||
<el-input v-model="domainForm.domain" placeholder="请输入域名,例如: example.com" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button @click="dialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" @click="submitForm">确定</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive, onMounted } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { Plus, Delete } from '@element-plus/icons-vue'
|
||||
import { getDomainList, addDomain, deleteDomain, batchDeleteDomain } from '@/api/domain'
|
||||
|
||||
// 查询参数
|
||||
const queryParams = reactive({
|
||||
domain: '',
|
||||
pageNum: 1,
|
||||
pageSize: 10
|
||||
})
|
||||
|
||||
// 域名表单
|
||||
const domainForm = reactive({
|
||||
domain: ''
|
||||
})
|
||||
|
||||
// 表单规则
|
||||
const domainRules = {
|
||||
domain: [
|
||||
{ required: true, message: '请输入域名', trigger: 'blur' },
|
||||
{
|
||||
pattern: /^((?!-)[A-Za-z0-9-]{1,63}(?<!-)\.)+[A-Za-z]{2,6}$/,
|
||||
message: '请输入有效的域名格式',
|
||||
trigger: 'blur'
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
// 数据加载和分页相关
|
||||
const loading = ref(false)
|
||||
const total = ref(0)
|
||||
const domainList = ref([])
|
||||
const selectedRows = ref([])
|
||||
const dialogVisible = ref(false)
|
||||
const domainFormRef = ref(null)
|
||||
|
||||
// 获取域名列表数据
|
||||
const getList = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const params = {
|
||||
page: queryParams.pageNum,
|
||||
count: queryParams.pageSize,
|
||||
key_word: queryParams.domain
|
||||
}
|
||||
|
||||
const res = await getDomainList(params)
|
||||
domainList.value = res.data.data
|
||||
total.value = res.data.all_count
|
||||
} catch (error) {
|
||||
console.error('获取域名列表失败:', error)
|
||||
ElMessage.error('获取域名列表失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 查询按钮
|
||||
const handleQuery = () => {
|
||||
queryParams.pageNum = 1
|
||||
|
||||
getList()
|
||||
}
|
||||
|
||||
// 重置查询条件
|
||||
const resetQuery = () => {
|
||||
queryParams.domain = ''
|
||||
queryParams.dateRange = []
|
||||
queryParams.pageNum = 1
|
||||
getList()
|
||||
}
|
||||
|
||||
// 表格复选框选择
|
||||
const handleSelectionChange = (selection) => {
|
||||
selectedRows.value = selection
|
||||
}
|
||||
|
||||
// 分页大小变化处理
|
||||
const handleSizeChange = (size) => {
|
||||
queryParams.pageSize = size
|
||||
getList()
|
||||
}
|
||||
|
||||
// 分页页码变化处理
|
||||
const handleCurrentChange = (page) => {
|
||||
queryParams.pageNum = page
|
||||
getList()
|
||||
}
|
||||
|
||||
// 打开添加域名对话框
|
||||
const handleAdd = () => {
|
||||
domainForm.domain = ''
|
||||
dialogVisible.value = true
|
||||
// 下一帧等DOM渲染后获取表单ref
|
||||
setTimeout(() => {
|
||||
if (domainFormRef.value) {
|
||||
domainFormRef.value.resetFields()
|
||||
}
|
||||
}, 0)
|
||||
}
|
||||
|
||||
// 提交添加域名表单
|
||||
const submitForm = () => {
|
||||
if (!domainFormRef.value) return
|
||||
|
||||
domainFormRef.value.validate(async (valid) => {
|
||||
if (valid) {
|
||||
try {
|
||||
await addDomain({ domain: domainForm.domain })
|
||||
ElMessage.success('添加域名成功')
|
||||
dialogVisible.value = false
|
||||
getList()
|
||||
} catch (error) {
|
||||
console.error('添加域名失败:', error)
|
||||
ElMessage.error('添加域名失败')
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const parseCreatedAt = (item) => {
|
||||
return item.CreatedAt.replace('T', ' ').substring(0, 19)
|
||||
}
|
||||
|
||||
const parseUpdatedAt = (item) => {
|
||||
return item.UpdatedAt.replace('T', ' ').substring(0, 19)
|
||||
}
|
||||
// 删除单个域名
|
||||
const handleDelete = (row) => {
|
||||
ElMessageBox.confirm(`确认删除域名 ${row.domain} 吗?`, '警告', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}).then(async () => {
|
||||
try {
|
||||
await deleteDomain(row.Id)
|
||||
ElMessage.success('删除成功')
|
||||
getList()
|
||||
} catch (error) {
|
||||
console.error('删除域名失败:', error)
|
||||
ElMessage.error('删除失败')
|
||||
}
|
||||
}).catch(() => {})
|
||||
}
|
||||
|
||||
// 批量删除域名
|
||||
const handleBatchDelete = () => {
|
||||
if (selectedRows.value.length === 0) {
|
||||
ElMessage.warning('请选择要删除的域名')
|
||||
return
|
||||
}
|
||||
|
||||
const ids = selectedRows.value.map(item => item.Id)
|
||||
const domains = selectedRows.value.map(item => item.domain).join('、')
|
||||
|
||||
ElMessageBox.confirm(`确认删除以下域名吗?\n${domains}`, '警告', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}).then(async () => {
|
||||
try {
|
||||
try {
|
||||
await batchDeleteDomain(ids)
|
||||
ElMessage.success('批量删除成功')
|
||||
getList()
|
||||
} catch (error) {
|
||||
console.error('批量删除域名失败:', error)
|
||||
ElMessage.error('批量删除失败')
|
||||
}
|
||||
await batchDeleteDomain(ids)
|
||||
ElMessage.success('批量删除成功')
|
||||
getList()
|
||||
} catch (error) {
|
||||
console.error('批量删除域名失败:', error)
|
||||
ElMessage.error('批量删除失败')
|
||||
}
|
||||
}).catch(() => {})
|
||||
}
|
||||
|
||||
// 初始化
|
||||
onMounted(() => {
|
||||
getList()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.domain-whitelist-container {
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.filter-container {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.search-form {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.action-bar {
|
||||
display: flex;
|
||||
justify-content: flex-start;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.table-container {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.pagination {
|
||||
margin-top: 15px;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.dialog-footer {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,395 @@
|
||||
<template>
|
||||
<div class="operation-log">
|
||||
<!-- 搜索和操作栏 -->
|
||||
<el-card class="filter-container" shadow="never">
|
||||
<el-form :inline="true" :model="queryParams" class="search-form">
|
||||
<el-form-item label="操作人">
|
||||
<el-input v-model="queryParams.operator" placeholder="请输入操作人" clearable />
|
||||
</el-form-item>
|
||||
<el-form-item label="操作类型">
|
||||
<el-select v-model="queryParams.type" placeholder="请选择操作类型" clearable>
|
||||
<el-option label="登录" value="login" />
|
||||
<el-option label="新增" value="create" />
|
||||
<el-option label="修改" value="update" />
|
||||
<el-option label="删除" value="delete" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="操作时间">
|
||||
<el-date-picker
|
||||
v-model="queryParams.dateRange"
|
||||
type="daterange"
|
||||
range-separator="至"
|
||||
start-placeholder="开始日期"
|
||||
end-placeholder="结束日期"
|
||||
value-format="YYYY-MM-DD"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="handleQuery">查询</el-button>
|
||||
<el-button @click="resetQuery">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<div class="action-bar">
|
||||
<el-button type="success">
|
||||
<el-icon><upload /></el-icon>导入
|
||||
</el-button>
|
||||
<el-button type="primary" @click="handleExport">
|
||||
<el-icon><download /></el-icon>导出
|
||||
</el-button>
|
||||
</div>
|
||||
</el-card>
|
||||
|
||||
<!-- 日志列表 -->
|
||||
<el-card class="table-container" shadow="never">
|
||||
<el-table
|
||||
v-loading="loading"
|
||||
:data="logList"
|
||||
style="width: 100%"
|
||||
>
|
||||
<el-table-column prop="id" label="ID" width="80" />
|
||||
<el-table-column label="操作人" min-width="150">
|
||||
<template #default="{ row }">
|
||||
<div class="operator-info">
|
||||
<el-avatar :size="32" :src="row.avatar"></el-avatar>
|
||||
<div class="operator-detail">
|
||||
<div class="username">{{ row.operator }}</div>
|
||||
<div class="ip">{{ row.ip }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="type" label="操作类型" width="120">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="getTypeTag(row.type)">{{ getTypeText(row.type) }}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="description" label="操作描述" min-width="200" />
|
||||
<el-table-column prop="createTime" label="操作时间" width="180" />
|
||||
<el-table-column label="操作" width="120" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button type="primary" link @click="handleDetail(row)">详情</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<!-- 分页 -->
|
||||
<el-pagination
|
||||
v-model:current-page="queryParams.pageNum"
|
||||
v-model:page-size="queryParams.pageSize"
|
||||
:page-sizes="[10, 20, 50, 100]"
|
||||
layout="total, sizes, prev, pager, next, jumper"
|
||||
:total="total"
|
||||
@size-change="handleSizeChange"
|
||||
@current-change="handleCurrentChange"
|
||||
background
|
||||
class="pagination"
|
||||
/>
|
||||
</el-card>
|
||||
|
||||
<!-- 详情对话框 -->
|
||||
<el-dialog
|
||||
v-model="dialogVisible"
|
||||
title="操作日志详情"
|
||||
width="580px"
|
||||
append-to-body
|
||||
>
|
||||
<el-descriptions :column="1" border>
|
||||
<el-descriptions-item label="操作人">{{ detailData.operator }}</el-descriptions-item>
|
||||
<el-descriptions-item label="操作类型">
|
||||
<el-tag :type="getTypeTag(detailData.type)">{{ getTypeText(detailData.type) }}</el-tag>
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="操作描述">{{ detailData.description }}</el-descriptions-item>
|
||||
<el-descriptions-item label="IP地址">{{ detailData.ip }}</el-descriptions-item>
|
||||
<el-descriptions-item label="操作时间">{{ detailData.createTime }}</el-descriptions-item>
|
||||
<el-descriptions-item label="请求参数" v-if="detailData.params">
|
||||
<pre class="params">{{ JSON.stringify(detailData.params, null, 2) }}</pre>
|
||||
</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button @click="dialogVisible = false">关闭</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive, onMounted } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { Upload, Download } from '@element-plus/icons-vue'
|
||||
|
||||
// 查询参数
|
||||
const queryParams = reactive({
|
||||
operator: '',
|
||||
type: '',
|
||||
dateRange: [],
|
||||
pageNum: 1,
|
||||
pageSize: 10
|
||||
})
|
||||
|
||||
// 日志列表数据
|
||||
const logList = ref([
|
||||
{
|
||||
id: 1,
|
||||
operator: 'admin',
|
||||
avatar: 'https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png',
|
||||
type: 'login',
|
||||
description: '用户登录系统',
|
||||
ip: '127.0.0.1',
|
||||
createTime: '2024-03-20 10:00:00',
|
||||
params: {
|
||||
username: 'admin',
|
||||
loginTime: '2024-03-20 10:00:00'
|
||||
}
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
operator: 'admin',
|
||||
avatar: 'https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png',
|
||||
type: 'create',
|
||||
description: '创建新用户',
|
||||
ip: '127.0.0.1',
|
||||
createTime: '2024-03-20 11:00:00',
|
||||
params: {
|
||||
username: 'test',
|
||||
role: '测试人员'
|
||||
}
|
||||
}
|
||||
])
|
||||
|
||||
// 分页相关
|
||||
const loading = ref(false)
|
||||
const total = ref(100)
|
||||
const dialogVisible = ref(false)
|
||||
const detailData = ref({})
|
||||
|
||||
// 获取操作类型标签样式
|
||||
const getTypeTag = (type) => {
|
||||
const typeMap = {
|
||||
login: 'success',
|
||||
create: 'primary',
|
||||
update: 'warning',
|
||||
delete: 'danger'
|
||||
}
|
||||
return typeMap[type] || 'info'
|
||||
}
|
||||
|
||||
// 获取操作类型文本
|
||||
const getTypeText = (type) => {
|
||||
const typeMap = {
|
||||
login: '登录',
|
||||
create: '新增',
|
||||
update: '修改',
|
||||
delete: '删除'
|
||||
}
|
||||
return typeMap[type] || type
|
||||
}
|
||||
|
||||
// 查询日志列表
|
||||
const handleQuery = () => {
|
||||
queryParams.pageNum = 1
|
||||
getLogList()
|
||||
}
|
||||
|
||||
// 重置查询
|
||||
const resetQuery = () => {
|
||||
Object.assign(queryParams, {
|
||||
operator: '',
|
||||
type: '',
|
||||
dateRange: [],
|
||||
pageNum: 1,
|
||||
pageSize: 10
|
||||
})
|
||||
getLogList()
|
||||
}
|
||||
|
||||
// 获取日志列表
|
||||
const getLogList = () => {
|
||||
loading.value = true
|
||||
// TODO: 调用API获取数据
|
||||
setTimeout(() => {
|
||||
loading.value = false
|
||||
}, 500)
|
||||
}
|
||||
|
||||
// 导出
|
||||
const handleExport = () => {
|
||||
ElMessage.success('导出成功')
|
||||
}
|
||||
|
||||
// 查看详情
|
||||
const handleDetail = (row) => {
|
||||
detailData.value = row
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
// 分页大小改变
|
||||
const handleSizeChange = (size) => {
|
||||
queryParams.pageSize = size
|
||||
getLogList()
|
||||
}
|
||||
|
||||
// 页码改变
|
||||
const handleCurrentChange = (page) => {
|
||||
queryParams.pageNum = page
|
||||
getLogList()
|
||||
}
|
||||
|
||||
// 初始化
|
||||
onMounted(() => {
|
||||
getLogList()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.operation-log {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.filter-container {
|
||||
margin-bottom: 20px;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.search-form {
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.action-bar {
|
||||
margin-top: 10px;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.table-container {
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
/* 表格样式优化 */
|
||||
:deep(.el-table) {
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
:deep(.el-table th) {
|
||||
background-color: #f8f9fb !important;
|
||||
font-weight: 600;
|
||||
color: #1f2937;
|
||||
height: 50px;
|
||||
padding: 8px 0;
|
||||
}
|
||||
|
||||
:deep(.el-table td) {
|
||||
padding: 12px 0;
|
||||
}
|
||||
|
||||
:deep(.el-table--striped .el-table__body tr.el-table__row--striped td) {
|
||||
background: #f8fafc;
|
||||
}
|
||||
|
||||
:deep(.el-table__body tr:hover > td) {
|
||||
background-color: #f1f5f9 !important;
|
||||
}
|
||||
|
||||
:deep(.el-table__body tr) {
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.operator-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 4px 0;
|
||||
}
|
||||
|
||||
.operator-detail {
|
||||
margin-left: 12px;
|
||||
}
|
||||
|
||||
.username {
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
margin-bottom: 4px;
|
||||
color: #1f2937;
|
||||
}
|
||||
|
||||
.ip {
|
||||
font-size: 12px;
|
||||
color: #64748b;
|
||||
}
|
||||
|
||||
/* 分页样式优化 */
|
||||
.pagination {
|
||||
margin-top: 24px;
|
||||
justify-content: flex-end;
|
||||
padding: 0 16px;
|
||||
}
|
||||
|
||||
:deep(.el-pagination) {
|
||||
--el-pagination-hover-color: #1f2937;
|
||||
}
|
||||
|
||||
:deep(.el-pagination button:disabled) {
|
||||
background-color: #f1f5f9;
|
||||
}
|
||||
|
||||
:deep(.el-pagination .el-pager li) {
|
||||
border-radius: 4px;
|
||||
margin: 0 2px;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
:deep(.el-pagination .el-pager li.active) {
|
||||
background-color: #1f2937;
|
||||
color: white;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
:deep(.el-pagination .el-pager li:hover:not(.active)) {
|
||||
background-color: #f1f5f9;
|
||||
}
|
||||
|
||||
.dialog-footer {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.params {
|
||||
background-color: #f8f9fb;
|
||||
padding: 8px;
|
||||
border-radius: 4px;
|
||||
font-family: monospace;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
/* 响应式优化 */
|
||||
@media (max-width: 768px) {
|
||||
.el-form-item {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.action-bar {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
}
|
||||
|
||||
.action-bar .el-button {
|
||||
width: 100%;
|
||||
margin-left: 0 !important;
|
||||
}
|
||||
|
||||
:deep(.el-table th) {
|
||||
padding: 6px 0;
|
||||
}
|
||||
|
||||
:deep(.el-table td) {
|
||||
padding: 8px 0;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,578 @@
|
||||
<template>
|
||||
<div class="users-container">
|
||||
<!-- 搜索和操作栏 -->
|
||||
<el-card class="filter-container" shadow="never">
|
||||
<el-form :inline="true" :model="queryParams" class="search-form">
|
||||
<el-form-item label="用户名">
|
||||
<el-input v-model="queryParams.username" placeholder="请输入用户名" clearable />
|
||||
</el-form-item>
|
||||
<el-form-item label="状态">
|
||||
<el-select v-model="queryParams.status" placeholder="请选择状态" clearable>
|
||||
<el-option label="启用" value="1" />
|
||||
<el-option label="禁用" value="0" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="创建时间">
|
||||
<el-date-picker
|
||||
v-model="queryParams.dateRange"
|
||||
type="daterange"
|
||||
range-separator="至"
|
||||
start-placeholder="开始日期"
|
||||
end-placeholder="结束日期"
|
||||
value-format="YYYY-MM-DD"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="handleQuery">查询</el-button>
|
||||
<el-button @click="resetQuery">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<div class="action-bar">
|
||||
<el-button type="primary" @click="handleAdd">
|
||||
<el-icon><plus /></el-icon>新增用户
|
||||
</el-button>
|
||||
<el-button type="danger" :disabled="!selectedRows.length" @click="handleBatchDelete">
|
||||
<el-icon><delete /></el-icon>批量删除
|
||||
</el-button>
|
||||
<el-button type="success">
|
||||
<el-icon><upload /></el-icon>导入
|
||||
</el-button>
|
||||
<el-button>
|
||||
<el-icon><download /></el-icon>导出
|
||||
</el-button>
|
||||
</div>
|
||||
</el-card>
|
||||
|
||||
<!-- 用户列表 -->
|
||||
<el-card class="table-container" shadow="never">
|
||||
<el-table
|
||||
v-loading="loading"
|
||||
:data="userList"
|
||||
@selection-change="handleSelectionChange"
|
||||
style="width: 100%"
|
||||
>
|
||||
<el-table-column type="selection" width="55" />
|
||||
<el-table-column prop="id" label="ID" width="80" />
|
||||
<el-table-column label="用户信息" min-width="250">
|
||||
<template #default="{ row }">
|
||||
<div class="user-info">
|
||||
<el-avatar :size="40" :src="row.avatar"></el-avatar>
|
||||
<div class="user-detail">
|
||||
<div class="username">{{ row.username }}</div>
|
||||
<div class="email">{{ row.email }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="role" label="角色" />
|
||||
<el-table-column prop="phone" label="手机号码" />
|
||||
<el-table-column label="状态" width="100">
|
||||
<template #default="{ row }">
|
||||
<el-switch
|
||||
v-model="row.status"
|
||||
:active-value="1"
|
||||
:inactive-value="0"
|
||||
@change="(val) => handleStatusChange(row, val)"
|
||||
/>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="createTime" label="创建时间" width="180" />
|
||||
<el-table-column label="操作" width="180" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button type="primary" link @click="handleEdit(row)">编辑</el-button>
|
||||
<el-button type="primary" link @click="handleRoleAssign(row)">分配角色</el-button>
|
||||
<el-button type="danger" link @click="handleDelete(row)">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<!-- 分页 -->
|
||||
<el-pagination
|
||||
v-model:current-page="queryParams.pageNum"
|
||||
v-model:page-size="queryParams.pageSize"
|
||||
:page-sizes="[10, 20, 50, 100]"
|
||||
layout="total, sizes, prev, pager, next, jumper"
|
||||
:total="total"
|
||||
@size-change="handleSizeChange"
|
||||
@current-change="handleCurrentChange"
|
||||
background
|
||||
class="pagination"
|
||||
/>
|
||||
</el-card>
|
||||
|
||||
<!-- 用户表单对话框 -->
|
||||
<el-dialog
|
||||
v-model="dialogVisible"
|
||||
:title="dialogType === 'add' ? '新增用户' : '编辑用户'"
|
||||
width="580px"
|
||||
append-to-body
|
||||
>
|
||||
<el-form
|
||||
ref="userFormRef"
|
||||
:model="userForm"
|
||||
:rules="userRules"
|
||||
label-width="100px"
|
||||
>
|
||||
<el-form-item label="用户名" prop="username">
|
||||
<el-input v-model="userForm.username" placeholder="请输入用户名" />
|
||||
</el-form-item>
|
||||
<el-form-item label="昵称" prop="nickname">
|
||||
<el-input v-model="userForm.nickname" placeholder="请输入昵称" />
|
||||
</el-form-item>
|
||||
<el-form-item label="手机号码" prop="phone">
|
||||
<el-input v-model="userForm.phone" placeholder="请输入手机号码" />
|
||||
</el-form-item>
|
||||
<el-form-item label="邮箱" prop="email">
|
||||
<el-input v-model="userForm.email" placeholder="请输入邮箱" />
|
||||
</el-form-item>
|
||||
<el-form-item label="角色" prop="roleIds">
|
||||
<el-select
|
||||
v-model="userForm.roleIds"
|
||||
placeholder="请选择角色"
|
||||
multiple
|
||||
style="width: 100%"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in roleOptions"
|
||||
:key="item.id"
|
||||
:label="item.name"
|
||||
:value="item.id"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="状态">
|
||||
<el-radio-group v-model="userForm.status">
|
||||
<el-radio :label="1">启用</el-radio>
|
||||
<el-radio :label="0">禁用</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item label="备注" prop="remark">
|
||||
<el-input
|
||||
v-model="userForm.remark"
|
||||
type="textarea"
|
||||
placeholder="请输入备注"
|
||||
:rows="3"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button @click="dialogVisible = false">取消</el-button>
|
||||
<el-button type="primary" @click="submitForm">确定</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive, onMounted } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { Plus, Delete, Upload, Download } from '@element-plus/icons-vue'
|
||||
|
||||
// 查询参数
|
||||
const queryParams = reactive({
|
||||
username: '',
|
||||
status: '',
|
||||
dateRange: [],
|
||||
pageNum: 1,
|
||||
pageSize: 10
|
||||
})
|
||||
|
||||
// 用户表单
|
||||
const userForm = reactive({
|
||||
id: undefined,
|
||||
username: '',
|
||||
nickname: '',
|
||||
phone: '',
|
||||
email: '',
|
||||
roleIds: [],
|
||||
status: 1,
|
||||
remark: ''
|
||||
})
|
||||
|
||||
// 表单规则
|
||||
const userRules = {
|
||||
username: [
|
||||
{ required: true, message: '请输入用户名', trigger: 'blur' },
|
||||
{ min: 3, max: 20, message: '长度在 3 到 20 个字符', trigger: 'blur' }
|
||||
],
|
||||
nickname: [
|
||||
{ required: true, message: '请输入昵称', trigger: 'blur' }
|
||||
],
|
||||
phone: [
|
||||
{ required: true, message: '请输入手机号码', trigger: 'blur' },
|
||||
{ pattern: /^1[3-9]\d{9}$/, message: '请输入正确的手机号码', trigger: 'blur' }
|
||||
],
|
||||
email: [
|
||||
{ required: true, message: '请输入邮箱地址', trigger: 'blur' },
|
||||
{ type: 'email', message: '请输入正确的邮箱地址', trigger: 'blur' }
|
||||
]
|
||||
}
|
||||
|
||||
// 角色选项
|
||||
const roleOptions = ref([
|
||||
{ id: 1, name: '管理员' },
|
||||
{ id: 2, name: '测试员' },
|
||||
{ id: 3, name: '普通用户' },
|
||||
{ id: 4, name: '访客' }
|
||||
])
|
||||
|
||||
// 其他状态数据
|
||||
const loading = ref(false)
|
||||
const userList = ref([])
|
||||
const total = ref(0)
|
||||
const selectedRows = ref([])
|
||||
const dialogVisible = ref(false)
|
||||
const dialogType = ref('add') // 'add' 或 'edit'
|
||||
const userFormRef = ref(null)
|
||||
|
||||
// 模拟获取用户列表
|
||||
const getUserList = () => {
|
||||
loading.value = true
|
||||
// 模拟API请求
|
||||
setTimeout(() => {
|
||||
userList.value = [
|
||||
{
|
||||
id: 1,
|
||||
username: 'admin',
|
||||
nickname: '管理员',
|
||||
avatar: 'https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png',
|
||||
email: 'admin@example.com',
|
||||
phone: '13800138000',
|
||||
role: '超级管理员',
|
||||
status: 1,
|
||||
createTime: '2024-06-01 10:00:00'
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
username: 'test',
|
||||
nickname: '测试用户',
|
||||
avatar: 'https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png',
|
||||
email: 'test@example.com',
|
||||
phone: '13800138001',
|
||||
role: '测试人员',
|
||||
status: 1,
|
||||
createTime: '2024-06-02 14:23:10'
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
username: 'zhangsan',
|
||||
nickname: '张三',
|
||||
avatar: 'https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png',
|
||||
email: 'zhangsan@example.com',
|
||||
phone: '13800138002',
|
||||
role: '普通用户',
|
||||
status: 0,
|
||||
createTime: '2024-06-03 08:15:30'
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
username: 'lisi',
|
||||
nickname: '李四',
|
||||
avatar: 'https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png',
|
||||
email: 'lisi@example.com',
|
||||
phone: '13800138003',
|
||||
role: '普通用户',
|
||||
status: 1,
|
||||
createTime: '2024-06-03 16:42:50'
|
||||
},
|
||||
{
|
||||
id: 5,
|
||||
username: 'wangwu',
|
||||
nickname: '王五',
|
||||
avatar: 'https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png',
|
||||
email: 'wangwu@example.com',
|
||||
phone: '13800138004',
|
||||
role: '访客',
|
||||
status: 1,
|
||||
createTime: '2024-06-04 09:30:15'
|
||||
}
|
||||
]
|
||||
total.value = 5
|
||||
loading.value = false
|
||||
}, 500)
|
||||
}
|
||||
|
||||
// 查询用户列表
|
||||
const handleQuery = () => {
|
||||
queryParams.pageNum = 1
|
||||
getUserList()
|
||||
}
|
||||
|
||||
// 重置查询
|
||||
const resetQuery = () => {
|
||||
Object.assign(queryParams, {
|
||||
username: '',
|
||||
status: '',
|
||||
dateRange: [],
|
||||
pageNum: 1,
|
||||
pageSize: 10
|
||||
})
|
||||
getUserList()
|
||||
}
|
||||
|
||||
// 选择项变化
|
||||
const handleSelectionChange = (selection) => {
|
||||
selectedRows.value = selection
|
||||
}
|
||||
|
||||
// 分页大小变化
|
||||
const handleSizeChange = (size) => {
|
||||
queryParams.pageSize = size
|
||||
getUserList()
|
||||
}
|
||||
|
||||
// 分页页码变化
|
||||
const handleCurrentChange = (page) => {
|
||||
queryParams.pageNum = page
|
||||
getUserList()
|
||||
}
|
||||
|
||||
// 新增用户
|
||||
const handleAdd = () => {
|
||||
dialogType.value = 'add'
|
||||
dialogVisible.value = true
|
||||
// 重置表单
|
||||
Object.assign(userForm, {
|
||||
id: undefined,
|
||||
username: '',
|
||||
nickname: '',
|
||||
phone: '',
|
||||
email: '',
|
||||
roleIds: [],
|
||||
status: 1,
|
||||
remark: ''
|
||||
})
|
||||
// 重置表单校验结果
|
||||
if (userFormRef.value) {
|
||||
userFormRef.value.resetFields()
|
||||
}
|
||||
}
|
||||
|
||||
// 编辑用户
|
||||
const handleEdit = (row) => {
|
||||
dialogType.value = 'edit'
|
||||
dialogVisible.value = true
|
||||
// 填充表单数据
|
||||
Object.assign(userForm, {
|
||||
id: row.id,
|
||||
username: row.username,
|
||||
nickname: row.nickname,
|
||||
phone: row.phone,
|
||||
email: row.email,
|
||||
roleIds: [1], // 假设已有角色
|
||||
status: row.status,
|
||||
remark: row.remark || ''
|
||||
})
|
||||
// 重置表单校验结果
|
||||
if (userFormRef.value) {
|
||||
userFormRef.value.resetFields()
|
||||
}
|
||||
}
|
||||
|
||||
// 删除用户
|
||||
const handleDelete = (row) => {
|
||||
ElMessageBox.confirm(`确认删除用户 ${row.username} 吗?`, '警告', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}).then(() => {
|
||||
// 执行删除操作
|
||||
ElMessage.success('删除成功')
|
||||
getUserList()
|
||||
}).catch(() => {})
|
||||
}
|
||||
|
||||
// 批量删除
|
||||
const handleBatchDelete = () => {
|
||||
if (selectedRows.value.length === 0) {
|
||||
ElMessage.warning('请至少选择一条记录')
|
||||
return
|
||||
}
|
||||
ElMessageBox.confirm(`确认删除选中的 ${selectedRows.value.length} 条用户记录吗?`, '警告', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}).then(() => {
|
||||
// 执行批量删除操作
|
||||
ElMessage.success('批量删除成功')
|
||||
getUserList()
|
||||
}).catch(() => {})
|
||||
}
|
||||
|
||||
// 分配角色
|
||||
const handleRoleAssign = (row) => {
|
||||
ElMessage.info(`为用户 ${row.username} 分配角色功能待实现`)
|
||||
}
|
||||
|
||||
// 修改用户状态
|
||||
const handleStatusChange = (row, status) => {
|
||||
ElMessage.success(`修改用户 ${row.username} 状态为 ${status === 1 ? '启用' : '禁用'} 成功`)
|
||||
}
|
||||
|
||||
// 提交表单
|
||||
const submitForm = () => {
|
||||
userFormRef.value?.validate((valid) => {
|
||||
if (valid) {
|
||||
if (dialogType.value === 'add') {
|
||||
// 新增用户
|
||||
ElMessage.success('新增用户成功')
|
||||
} else {
|
||||
// 修改用户
|
||||
ElMessage.success('修改用户成功')
|
||||
}
|
||||
dialogVisible.value = false
|
||||
getUserList()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 初始化
|
||||
onMounted(() => {
|
||||
getUserList()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.users-container {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.filter-container {
|
||||
margin-bottom: 20px;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.search-form {
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.action-bar {
|
||||
margin-top: 10px;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.table-container {
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
/* 表格样式优化 */
|
||||
:deep(.el-table) {
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
:deep(.el-table th) {
|
||||
background-color: #f8f9fb !important;
|
||||
font-weight: 600;
|
||||
color: #1f2937;
|
||||
height: 50px;
|
||||
padding: 8px 0;
|
||||
}
|
||||
|
||||
:deep(.el-table td) {
|
||||
padding: 12px 0;
|
||||
}
|
||||
|
||||
:deep(.el-table--striped .el-table__body tr.el-table__row--striped td) {
|
||||
background: #f8fafc;
|
||||
}
|
||||
|
||||
:deep(.el-table__body tr:hover > td) {
|
||||
background-color: #f1f5f9 !important;
|
||||
}
|
||||
|
||||
:deep(.el-table__body tr) {
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.user-info {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 4px 0;
|
||||
}
|
||||
|
||||
.user-detail {
|
||||
margin-left: 12px;
|
||||
}
|
||||
|
||||
.username {
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
margin-bottom: 4px;
|
||||
color: #1f2937;
|
||||
}
|
||||
|
||||
.email {
|
||||
font-size: 12px;
|
||||
color: #64748b;
|
||||
}
|
||||
|
||||
/* 分页样式优化 */
|
||||
.pagination {
|
||||
margin-top: 24px;
|
||||
justify-content: flex-end;
|
||||
padding: 0 16px;
|
||||
}
|
||||
|
||||
:deep(.el-pagination) {
|
||||
--el-pagination-hover-color: #1f2937;
|
||||
}
|
||||
|
||||
:deep(.el-pagination button:disabled) {
|
||||
background-color: #f1f5f9;
|
||||
}
|
||||
|
||||
:deep(.el-pagination .el-pager li) {
|
||||
border-radius: 4px;
|
||||
margin: 0 2px;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
:deep(.el-pagination .el-pager li.active) {
|
||||
background-color: #1f2937;
|
||||
color: white;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
:deep(.el-pagination .el-pager li:hover:not(.active)) {
|
||||
background-color: #f1f5f9;
|
||||
}
|
||||
|
||||
.dialog-footer {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
/* 响应式优化 */
|
||||
@media (max-width: 768px) {
|
||||
.el-form-item {
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.action-bar {
|
||||
flex-direction: column;
|
||||
align-items: stretch;
|
||||
}
|
||||
|
||||
.action-bar .el-button {
|
||||
width: 100%;
|
||||
margin-left: 0 !important;
|
||||
}
|
||||
|
||||
:deep(.el-table th) {
|
||||
padding: 6px 0;
|
||||
}
|
||||
|
||||
:deep(.el-table td) {
|
||||
padding: 8px 0;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user