first commit

This commit is contained in:
2026-06-03 10:09:03 +08:00
commit 81f5039458
6266 changed files with 188236 additions and 0 deletions
@@ -0,0 +1,313 @@
<template>
<div class="category-container">
<el-card shadow="never">
<template #header>
<div class="card-header">
<span>分类管理</span>
<el-button type="primary" :icon="Plus" @click="handleCategoryAdd">
新增分类
</el-button>
</div>
</template>
<el-table
:data="categoryList"
v-loading="loading"
stripe
border
>
<el-table-column prop="id" label="ID" width="80" />
<el-table-column prop="title" label="分类标题" min-width="200" show-overflow-tooltip />
<el-table-column prop="status" label="状态" width="100">
<template #default="{ row }">
<el-tag :type="getStatusType(row.status)">
{{ getStatusText(row.status) }}
</el-tag>
</template>
</el-table-column>
<el-table-column label="操作" width="200" fixed="right">
<template #default="{ row }">
<el-button
type="primary"
link
size="small"
:icon="Edit"
@click="handleEdit(row)"
>
编辑
</el-button>
<el-button
type="danger"
link
size="small"
:icon="Delete"
@click="handleDelete(row)"
>
删除
</el-button>
</template>
</el-table-column>
</el-table>
<div v-if="categoryList.length === 0 && !loading" class="empty-state">
<el-empty description="暂无分类记录" />
</div>
</el-card>
<el-dialog
v-model="categoryDialogVisible"
:title="isEdit ? '编辑分类' : '新增分类'"
width="700px"
:close-on-click-modal="false"
@close="handleCategoryClose"
>
<el-form
ref="formRef"
:model="formData"
:rules="formRules"
label-width="120px"
>
<el-form-item label="分类标题" prop="title">
<el-input
v-model="formData.title"
placeholder="请输入分类标题"
clearable
/>
</el-form-item>
<el-form-item label="状态" prop="status">
<el-radio-group v-model="formData.status">
<el-radio :value="1">启用</el-radio>
<el-radio :value="0">禁用</el-radio>
</el-radio-group>
</el-form-item>
</el-form>
<template #footer>
<el-button @click="categoryDialogVisible = false">取消</el-button>
<el-button type="primary" :loading="submitLoading" @click="handleSubmit">
确定
</el-button>
</template>
</el-dialog>
</div>
</template>
<script setup lang="ts">
import { ref, reactive, onMounted } from "vue";
import { ElMessage, ElMessageBox } from "element-plus";
import { Plus, Edit, Delete } from "@element-plus/icons-vue";
import type { FormInstance, FormRules } from "element-plus";
import { getModuleCategory,editModuleCategory } from "@/api/moduleCenter";
interface Category {
id: number;
title: string;
module_name: string;
module_id?: number;
status: number;
}
interface ModuleOption {
id: number;
name: string;
}
const loading = ref(false);
const categoryList = ref<Category[]>([]);
const categoryDialogVisible = ref(false);
const submitLoading = ref(false);
const isEdit = ref(false);
const editId = ref<number>(0);
const formRef = ref<FormInstance>();
const formData = reactive({
title: "",
module_id: null as number | null,
status: 1
});
const moduleOptions = ref<ModuleOption[]>([]);
const formRules: FormRules = {
title: [
{ required: true, message: "请输入分类标题", trigger: "blur" }
],
module_id: [
{ required: true, message: "请选择所属模块", trigger: "change" }
],
status: [
{ required: true, message: "请选择状态", trigger: "change" }
]
};
const getStatusText = (status: number) => {
const map: Record<number, string> = {
0: "禁用",
1: "启用"
};
return map[status] || "未知";
};
const getStatusType = (status: number) => {
const map: Record<number, any> = {
0: "info",
1: "success",
2: "warning"
};
return map[status] || "info";
};
const formatDate = (date: string) => {
if (!date) return "-";
const d = new Date(date);
const year = d.getFullYear();
const month = String(d.getMonth() + 1).padStart(2, "0");
const day = String(d.getDate()).padStart(2, "0");
const hours = String(d.getHours()).padStart(2, "0");
const minutes = String(d.getMinutes()).padStart(2, "0");
return `${year}-${month}-${day} ${hours}:${minutes}`;
};
const handleCategoryAdd = () => {
isEdit.value = false;
editId.value = 0;
formData.title = "";
formData.module_id = null;
formData.status = 1;
categoryDialogVisible.value = true;
fetchModuleOptions();
};
const handleEdit = (row: Category) => {
isEdit.value = true;
editId.value = row.id;
formData.title = row.title;
formData.module_id = row.module_id || null;
formData.status = row.status;
categoryDialogVisible.value = true;
fetchModuleOptions();
};
const handleView = (row: Category) => {
ElMessage.info("查看分类详情功能开发中");
};
const handleDelete = (row: Category) => {
ElMessageBox.confirm(`确定要删除分类"${row.title}"吗?`, "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(async () => {
try {
// TODO: 调用删除接口
// await deleteCategory(row.id);
ElMessage.success("删除成功");
handleRefresh();
} catch (error) {
console.error("删除失败:", error);
ElMessage.error("删除失败");
}
}).catch(() => {});
};
const handleCategoryClose = () => {
formRef.value?.resetFields();
isEdit.value = false;
editId.value = 0;
categoryDialogVisible.value = false;
};
const handleSubmit = async () => {
if (!formRef.value) return;
await formRef.value.validate(async (valid) => {
if (valid) {
submitLoading.value = true;
try {
const data = {
title: formData.title,
status: formData.status
};
if (isEdit.value) {
data.id = editId.value;
await editModuleCategory(data);
ElMessage.success("编辑成功");
} else {
await editModuleCategory(data);
ElMessage.success("添加成功");
}
handleCategoryClose();
handleRefresh();
} catch (error) {
console.error(isEdit.value ? "编辑失败:" : "添加失败:", error);
ElMessage.error(isEdit.value ? "编辑失败" : "添加失败");
} finally {
submitLoading.value = false;
}
}
});
};
const handleRefresh = () => {
fetchCategoryList();
};
const fetchCategoryList = async () => {
loading.value = true;
try {
const res = await getModuleCategory();
if (res.code === 200 && res.data) {
categoryList.value = res.data.list || [];
}
} catch (error) {
console.error("获取分类列表失败:", error);
ElMessage.error("获取分类列表失败");
} finally {
loading.value = false;
}
};
const fetchModuleOptions = async () => {
try {
// TODO: 调用获取模块列表接口
// const res = await getModules(0);
// if (res.code === 200) {
// moduleOptions.value = res.data.list.map((item: any) => ({
// id: item.id,
// name: item.title
// }));
// }
moduleOptions.value = [
{ id: 1, name: "CMS内容管理" },
{ id: 2, name: "用户管理" },
{ id: 3, name: "数据分析" },
{ id: 4, name: "系统设置" }
];
} catch (error) {
console.error("获取模块列表失败:", error);
}
};
onMounted(() => {
fetchCategoryList();
});
</script>
<style scoped lang="less">
.category-container {
.card-header {
display: flex;
justify-content: space-between;
align-items: center;
}
.empty-state {
padding: 40px 0;
}
}
</style>
@@ -0,0 +1,680 @@
<template>
<div class="modules-container">
<div class="header-section">
<div class="header-top">
<div class="category-tabs">
<div v-for="category in categories" :key="category.id" class="category-item"
:class="{ active: activeCategory === category.id }" @click="handleCategoryChange(category.id)">
{{ category.title }}
</div>
</div>
</div>
</div>
<div v-loading="loading" class="modules-grid">
<div v-for="module in moduleList" :key="module.id" class="module-card" :class="{ disabled: module.status === 0 }">
<div class="module-preview">
<img v-if="module.thumb" :src="getEnvUrl(module.thumb)" :alt="module.title" />
<div v-else class="placeholder"></div>
</div>
<div class="module-content">
<h3 class="module-name">{{ module.title }}</h3>
<p class="module-desc">{{ module.desc || '暂无描述' }}</p>
<div class="module-footer">
<div class="module-category">
<el-icon>
<OfficeBuilding />
</el-icon>
<span>{{ module.cid || '-' }}</span>
</div>
<div class="module-downloads">
<el-icon>
<Download />
</el-icon>
<span>{{ module.downloads }} 次</span>
</div>
</div>
</div>
<div class="module-actions">
<el-dropdown trigger="click" @command="(cmd) => handleCommand(cmd, module)">
<el-button type="primary" link :icon="MoreFilled" circle class="action-item" />
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item command="edit" :icon="Edit">编辑</el-dropdown-item>
<el-dropdown-item command="delete" :icon="Delete" divided>删除</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
<el-tag :type="module.status === 1 ? 'success' : 'info'" size="small">
{{ module.status === 1 ? '已启用' : '已禁用' }}
</el-tag>
</div>
</div>
</div>
<div v-if="moduleList.length === 0 && !loading" class="empty-state">
<el-empty description="暂无模块数据" :image-size="120" />
</div>
<create-modules v-model="createDialogVisible" @success="handleRefresh" />
<el-dialog v-model="editDialogVisible" title="编辑模块" width="600px" :close-on-click-modal="false"
@close="handleEditClose">
<el-form ref="editFormRef" :model="editFormData" :rules="formRules" label-width="100px">
<el-form-item label="模块名称" prop="title">
<el-input v-model="editFormData.title" placeholder="请输入模块名称" clearable />
</el-form-item>
<el-form-item label="模块描述" prop="desc">
<el-input v-model="editFormData.desc" type="textarea" :rows="3" placeholder="请输入模块描述" />
</el-form-item>
<el-form-item label="缩略图" prop="thumb">
<div class="uploads">
<el-upload v-model:file-list="fileList" :auto-upload="false" list-type="picture-card"
:limit="1" :before-upload="beforeImgUpload" :on-change="handleUploadChange">
<el-icon>
<Plus />
</el-icon>
<template #file="{ file }">
<div>
<img class="el-upload-list__item-thumbnail" :src="getEnvUrl(file.url)" alt="" />
<span class="el-upload-list__item-actions">
<span class="el-upload-list__item-preview" @click="handlePictureCardPreview(file)">
<el-icon>
<ZoomIn />
</el-icon>
</span>
<span class="el-upload-list__item-delete" @click="handleRemove(file)">
<el-icon>
<Delete />
</el-icon>
</span>
</span>
</div>
</template>
</el-upload>
<el-dialog v-model="dialogVisible">
<img w-full :src="dialogImageUrl" alt="Preview Image" />
</el-dialog>
<div class="upload-tip">
<span>建议尺寸:250px × 140px</span>
</div>
</div>
</el-form-item>
<el-form-item label="所属分类" prop="cid">
<el-select v-model="editFormData.cid" placeholder="请选择所属分类">
<el-option v-for="cat in categories.filter(c => c.id > 0)" :key="cat.id" :label="cat.title"
:value="cat.id" />
</el-select>
</el-form-item>
<el-form-item label="版本号" prop="version">
<el-input v-model="editFormData.version" placeholder="请输入版本号,如: 1.0.0" clearable />
</el-form-item>
<el-form-item label="状态" prop="status">
<el-radio-group v-model="editFormData.status">
<el-radio :value="1">启用</el-radio>
<el-radio :value="0">禁用</el-radio>
</el-radio-group>
</el-form-item>
</el-form>
<template #footer>
<el-button @click="editDialogVisible = false">取消</el-button>
<el-button type="primary" :loading="editLoading" @click="handleEditSubmit">
确定
</el-button>
</template>
</el-dialog>
</div>
</template>
<script setup lang="ts">
import { ref, reactive, onMounted } from "vue";
import { ElMessage, ElMessageBox, ElUpload } from "element-plus";
import { Plus, Edit, Delete, MoreFilled, OfficeBuilding, Download, ZoomIn } from "@element-plus/icons-vue";
import type { FormInstance, FormRules } from "element-plus";
import { getModules, getModuleCategory,editModules } from "@/api/moduleCenter";
import CreateModules from "../components/createModules.vue";
import { uploadFile } from '@/api/file.js';
interface Module {
id: number;
title: string;
desc: string;
thumb: string;
cid: number;
downloads: number;
status: number;
version: string;
create_time: string;
}
const loading = ref(false);
const moduleList = ref<Module[]>([]);
const createDialogVisible = ref(false);
const editDialogVisible = ref(false);
const editLoading = ref(false);
const activeCategory = ref(0);
const isEdit = ref(false);
const editId = ref<number>(0);
// 分类数据
const categories = ref([
{ id: 0, title: "全部" }
]);
const handleCategoryChange = (categoryId: number) => {
activeCategory.value = categoryId;
fetchModuleList(categoryId);
};
const editFormRef = ref<FormInstance>();
const editFormData = reactive({
id: 0,
title: "",
desc: "",
thumb: "",
cid: 0,
downloads: 0,
version: "",
status: 1
});
const formRules: FormRules = {
title: [
{ required: true, message: "请输入模块名称", trigger: "blur" }
],
cid: [
{ required: true, message: "请选择分类", trigger: "change" }
],
status: [
{ required: true, message: "请选择状态", trigger: "change" }
]
};
//拼接接口路径
const getEnvUrl = (path: string) => {
const API_BASE_URL = import.meta.env.VITE_API_BASE_URL;
return `${API_BASE_URL}${path}`;
};
//获取模块分类
async function getModuleCategoryList() {
try {
const res = await getModuleCategory();
if (res.code === 200 && res.data) {
categories.value = [
{ id: 0, title: "全部" },
...res.data.list || []
];
// console.log("分类数据:", categories.value);
}
} catch (error) {
console.error("获取分类失败:", error);
}
}
// 上传相关
const fileList = ref<any[]>([]);
const dialogVisible = ref(false);
const dialogImageUrl = ref('');
function beforeImgUpload(file: File) {
const isImage = file.type.startsWith('image/');
const isLt10M = file.size / 1024 / 1024 < 10;
if (!isImage) ElMessage.error('仅支持图片格式');
if (!isLt10M) ElMessage.error('图片大小不能超过10MB');
return isImage && isLt10M;
}
function handleRemove(file: any) {
fileList.value = [];
editFormData.thumb = '';
}
async function handleUploadChange(file: any) {
if (file.raw) {
const isImage = file.raw.type.startsWith('image/');
const isLt10M = file.raw.size / 1024 / 1024 < 10;
if (!isImage || !isLt10M) {
fileList.value = [];
ElMessage.error(isImage ? '图片大小不能超过10MB' : '仅支持图片格式');
return;
}
}
}
function handlePictureCardPreview(file: any) {
dialogImageUrl.value = file.url;
dialogVisible.value = true;
}
const formatDate = (date: string) => {
if (!date) return "-";
const d = new Date(date);
const year = d.getFullYear();
const month = String(d.getMonth() + 1).padStart(2, "0");
const day = String(d.getDate()).padStart(2, "0");
const hours = String(d.getHours()).padStart(2, "0");
const minutes = String(d.getMinutes()).padStart(2, "0");
return `${year}-${month}-${day} ${hours}:${minutes}`;
};
const handleCreate = () => {
createDialogVisible.value = true;
};
const handleCommand = (command: string, row: Module) => {
if (command === "edit") {
handleEdit(row);
} else if (command === "delete") {
handleDelete(row);
}
};
const handleEdit = (row: Module) => {
isEdit.value = true;
editId.value = row.id;
Object.assign(editFormData, row);
// 如果有缩略图,显示在文件列表中
if (row.thumb) {
fileList.value = [{
name: 'thumb',
url: row.thumb
}];
} else {
fileList.value = [];
}
editDialogVisible.value = true;
};
const handleEditClose = () => {
isEdit.value = false;
editId.value = 0;
fileList.value = [];
editFormRef.value?.resetFields();
editDialogVisible.value = false;
};
const handleEditSubmit = async () => {
if (!editFormRef.value) return;
await editFormRef.value.validate(async (valid) => {
if (valid) {
editLoading.value = true;
try {
let imageUrl = editFormData.thumb;
// 如果有新上传的图片,先上传图片
if (fileList.value.length > 0 && fileList.value[0].raw) {
const uploadFormData = new FormData();
uploadFormData.append('file', fileList.value[0].raw);
uploadFormData.append('cate', 'module');
const uploadRes = await uploadFile(uploadFormData);
if (uploadRes?.data?.url) {
imageUrl = uploadRes.data.url;
}
}
const data = {
title: editFormData.title,
desc: editFormData.desc,
thumb: imageUrl,
cid: editFormData.cid,
downloads: editFormData.downloads,
version: editFormData.version,
status: editFormData.status
};
if (isEdit.value) {
data.id = editId.value;
await editModules(data);
ElMessage.success("编辑成功");
} else {
await editModules(data);
ElMessage.success("添加成功");
}
handleEditClose();
handleRefresh();
} catch (error) {
console.error(isEdit.value ? "编辑失败:" : "添加失败:", error);
ElMessage.error(isEdit.value ? "编辑失败" : "添加失败");
} finally {
editLoading.value = false;
}
}
});
};
const handleStatusChange = async (row: Module) => {
try {
// TODO: 调用状态更新接口
// await updateModuleStatus(row.id, row.status);
ElMessage.success(row.status === 1 ? "已启用" : "已禁用");
} catch (error) {
console.error("状态更新失败:", error);
ElMessage.error("状态更新失败");
row.status = row.status === 1 ? 0 : 1;
}
};
const handleDelete = (row: Module) => {
ElMessageBox.confirm(`确定要删除模块"${row.title}"吗?`, "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(async () => {
try {
// TODO: 调用删除接口
// await deleteModule(row.id);
ElMessage.success("删除成功");
handleRefresh();
} catch (error) {
console.error("删除失败:", error);
ElMessage.error("删除失败");
}
}).catch(() => { });
};
const handleRefresh = () => {
fetchModuleList();
};
const fetchModuleList = async (categoryId?: number) => {
loading.value = true;
try {
// 调用获取模块列表接口
const res = await getModules(categoryId || 0);
if (res.code === 200 && res.data) {
// 转换后端数据格式为前端格式
moduleList.value = res.data.list.map((item: any) => ({
id: item.id,
title: item.title,
desc: item.desc,
thumb: item.thumb,
cid: item.cid,
downloads: item.downloads,
status: item.status,
version: item.version,
create_time: item.create_time
}));
}
} catch (error) {
console.error("获取模块列表失败:", error);
ElMessage.error("获取模块列表失败");
} finally {
loading.value = false;
}
};
onMounted(() => {
fetchModuleList();
getModuleCategoryList();
});
</script>
<style scoped lang="less">
.modules-container {
padding: 0;
margin-top: 50px;
min-height: 100vh;
.header-section {
margin-bottom: 24px;
.header-top {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 30px;
.page-title {
margin: 0;
font-size: 24px;
font-weight: 600;
color: var(--el-text-color-primary);
}
}
.category-tabs {
display: flex;
gap: 8px;
flex-wrap: wrap;
.category-item {
padding: 8px 20px;
border-radius: 20px;
font-size: 14px;
color: var(--el-text-color-regular);
background: var(--el-bg-color);
cursor: pointer;
transition: all 0.3s;
border: 1px solid transparent;
&:hover {
background: var(--el-fill-color);
color: var(--el-text-color-primary);
}
&.active {
background: var(--el-color-primary);
color: #fff;
border-color: var(--el-color-primary);
}
}
}
}
.modules-grid {
display: grid;
grid-template-columns: repeat(5, 1fr);
gap: 20px;
.module-card {
background: var(--el-bg-color);
border-radius: 12px;
border: 1px solid var(--el-border-color-lighter);
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
transition: all 0.3s;
overflow: hidden;
position: relative;
&:hover {
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
transform: translateY(-4px);
border-color: var(--el-color-primary-light-7);
}
&.disabled {
opacity: 0.6;
filter: grayscale(100%);
}
.module-preview {
width: 100%;
height: 180px;
background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
display: flex;
align-items: center;
justify-content: center;
position: relative;
overflow: hidden;
img{
width: 100%;
height: 100%;
object-fit: cover;
}
&::before {
content: '';
position: absolute;
top: -50%;
right: -50%;
width: 100%;
height: 100%;
background: linear-gradient(135deg, rgba(255, 255, 255, 0.3) 0%, transparent 100%);
transform: rotate(45deg);
}
}
.module-content {
padding: 20px;
.module-name {
margin: 0 0 12px 0;
font-size: 18px;
font-weight: 600;
color: var(--el-text-color-primary);
line-height: 1.4;
}
.module-desc {
margin: 0 0 16px 0;
font-size: 14px;
color: var(--el-text-color-regular);
line-height: 1.6;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
min-height: 44px;
}
.module-footer {
display: flex;
justify-content: space-between;
align-items: center;
padding-top: 16px;
border-top: 1px solid var(--el-border-color-lighter);
.module-category,
.module-downloads {
display: flex;
align-items: center;
gap: 6px;
font-size: 13px;
color: var(--el-text-color-placeholder);
.el-icon {
font-size: 16px;
}
}
}
}
.module-actions {
position: absolute;
top: 12px;
right: 12px;
display: flex;
align-items: center;
gap: 8px;
.action-item {
width: 16px;
height: 16px;
}
.el-button {
color: var(--el-text-color-regular);
background: rgba(255, 255, 255, 0.9);
backdrop-filter: blur(4px);
&:hover {
color: var(--el-color-primary);
}
}
.el-tag {
background: rgba(255, 255, 255, 0.9);
backdrop-filter: blur(4px);
}
}
}
}
.empty-state {
padding: 80px 20px;
text-align: center;
}
.uploads {
display: flex;
flex-direction: column;
}
.upload-tip {
font-size: 12px;
color: #999;
margin-top: 8px;
}
}
@media (max-width: 1400px) {
.modules-container {
.modules-grid {
grid-template-columns: repeat(4, 1fr);
}
}
}
@media (max-width: 1200px) {
.modules-container {
.modules-grid {
grid-template-columns: repeat(3, 1fr);
}
}
}
@media (max-width: 992px) {
.modules-container {
.modules-grid {
grid-template-columns: repeat(2, 1fr);
}
}
}
@media (max-width: 576px) {
.modules-container {
.modules-grid {
grid-template-columns: 1fr;
}
}
}
.uploads{
display: flex;
flex-direction: column;
}
.upload-tip {
font-size: 12px;
color: #999;
}
:deep(.el-upload-list__item-thumbnail) {
width: 100%;
height: 100%;
object-fit: cover;
}
</style>
@@ -0,0 +1,312 @@
<template>
<el-dialog
v-model="dialogVisible"
title="创建模块"
width="600px"
:close-on-click-modal="false"
@close="handleClose"
>
<el-form
ref="formRef"
:model="formData"
:rules="formRules"
label-width="100px"
>
<el-form-item label="模块名称" prop="name">
<el-input
v-model="formData.name"
placeholder="请输入模块名称"
clearable
/>
</el-form-item>
<el-form-item label="模块代码" prop="code">
<el-input
v-model="formData.code"
placeholder="请输入模块代码"
clearable
/>
</el-form-item>
<el-form-item label="模块图标" prop="icon">
<el-input
v-model="formData.icon"
placeholder="请输入图标类名,如: fa-solid fa-home"
clearable
>
<template #prefix>
<el-icon v-if="formData.icon" :class="formData.icon" />
</template>
</el-input>
</el-form-item>
<el-form-item label="模块描述" prop="description">
<el-input
v-model="formData.description"
type="textarea"
:rows="3"
placeholder="请输入模块描述"
/>
</el-form-item>
<el-form-item label="模块类型" prop="type">
<el-select
v-model="formData.type"
placeholder="请选择模块类型"
>
<el-option label="前端模块" :value="1" />
<el-option label="后端模块" :value="2" />
<el-option label="全栈模块" :value="3" />
</el-select>
</el-form-item>
<el-form-item label="排序" prop="sort">
<el-input-number
v-model="formData.sort"
:min="0"
:max="999"
controls-position="right"
placeholder="请输入排序"
/>
</el-form-item>
<el-form-item label="状态" prop="status">
<el-radio-group v-model="formData.status">
<el-radio :value="1">启用</el-radio>
<el-radio :value="0">禁用</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="模块包" prop="packageFile">
<el-upload
ref="uploadRef"
class="upload-demo"
drag
:auto-upload="false"
:limit="1"
:on-change="handleFileChange"
:before-upload="beforeUpload"
:on-exceed="handleExceed"
accept=".zip"
>
<el-icon class="el-icon--upload"><UploadFilled /></el-icon>
<div class="el-upload__text">
拖拽文件到此处或<em>点击上传</em>
</div>
<template #tip>
<div class="el-upload__tip">
只能上传 zip 格式的压缩包,且不超过 50MB
</div>
</template>
</el-upload>
<div v-if="formData.packageFile" class="file-info">
<el-icon><Document /></el-icon>
<span>{{ formData.packageFile.name }}</span>
<el-button
type="danger"
link
size="small"
@click="handleRemoveFile"
>
删除
</el-button>
</div>
</el-form-item>
</el-form>
<template #footer>
<el-button @click="handleClose">取消</el-button>
<el-button type="primary" :loading="submitLoading" @click="handleSubmit">
确定
</el-button>
</template>
</el-dialog>
</template>
<script setup lang="ts">
import { ref, reactive, watch } from "vue";
import { ElMessage } from "element-plus";
import { UploadFilled, Document } from "@element-plus/icons-vue";
import type { FormInstance, FormRules, UploadFile, UploadUserOptions } from "element-plus";
interface Props {
modelValue: boolean;
}
interface Emits {
(e: "update:modelValue", value: boolean): void;
(e: "success"): void;
}
const props = defineProps<Props>();
const emit = defineEmits<Emits>();
const dialogVisible = ref(false);
const formRef = ref<FormInstance>();
const uploadRef = ref();
const submitLoading = ref(false);
const formData = reactive({
name: "",
code: "",
icon: "",
description: "",
type: 3,
sort: 0,
status: 1,
packageFile: null as File | null
});
const formRules: FormRules = {
name: [
{ required: true, message: "请输入模块名称", trigger: "blur" }
],
code: [
{ required: true, message: "请输入模块代码", trigger: "blur" },
{ pattern: /^[a-zA-Z][a-zA-Z0-9]*$/, message: "代码必须以字母开头,只能包含字母和数字", trigger: "blur" }
],
type: [
{ required: true, message: "请选择模块类型", trigger: "change" }
],
status: [
{ required: true, message: "请选择状态", trigger: "change" }
]
};
watch(
() => props.modelValue,
(newVal) => {
dialogVisible.value = newVal;
},
{ immediate: true }
);
watch(dialogVisible, (newVal) => {
emit("update:modelValue", newVal);
});
const handleFileChange = (file: UploadFile) => {
formData.packageFile = file.raw;
};
const beforeUpload = (file: File) => {
const isZip = file.type === "application/zip" || file.name.endsWith(".zip");
const isLt50M = file.size / 1024 / 1024 < 50 * 1024;
if (!isZip) {
ElMessage.error("只能上传 zip 格式的文件!");
return false;
}
if (!isLt50M) {
ElMessage.error("文件大小不能超过 50MB!");
return false;
}
return true;
};
const handleExceed = () => {
ElMessage.warning("最多只能上传 1 个文件");
};
const handleRemoveFile = () => {
formData.packageFile = null;
if (uploadRef.value) {
uploadRef.value.clearFiles();
}
};
const handleSubmit = async () => {
if (!formRef.value) return;
await formRef.value.validate(async (valid) => {
if (valid) {
if (!formData.packageFile) {
ElMessage.warning("请上传模块包");
return;
}
submitLoading.value = true;
try {
// 创建 FormData 对象
const formDataObj = new FormData();
formDataObj.append("name", formData.name);
formDataObj.append("code", formData.code);
formDataObj.append("icon", formData.icon);
formDataObj.append("description", formData.description);
formDataObj.append("type", formData.type.toString());
formDataObj.append("sort", formData.sort.toString());
formDataObj.append("status", formData.status.toString());
formDataObj.append("package", formData.packageFile);
// TODO: 调用上传接口
// const res = await createModule(formDataObj);
ElMessage.success("创建成功");
handleClose();
emit("success");
} catch (error) {
console.error("创建失败:", error);
ElMessage.error("创建失败");
} finally {
submitLoading.value = false;
}
}
});
};
const handleClose = () => {
formRef.value?.resetFields();
formData.packageFile = null;
dialogVisible.value = false;
};
// 暴露重置方法
defineExpose({
reset: handleClose
});
</script>
<style scoped lang="less">
.upload-demo {
width: 100%;
:deep(.el-upload) {
width: 100%;
}
:deep(.el-upload-dragger) {
width: 100%;
height: 180px;
}
}
.file-info {
margin-top: 12px;
padding: 8px 12px;
background: var(--el-fill-color-light);
border-radius: 4px;
display: flex;
align-items: center;
gap: 8px;
.el-icon {
font-size: 20px;
color: var(--el-color-primary);
}
span {
flex: 1;
font-size: 14px;
color: var(--el-text-color-regular);
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
}
.el-upload__tip {
font-size: 12px;
color: var(--el-text-color-placeholder);
margin-top: 8px;
}
</style>
+11
View File
@@ -0,0 +1,11 @@
<script setup>
</script>
<template>
<router-view />
</template>
<style scoped>
</style>
@@ -0,0 +1,455 @@
<template>
<div class="publish-container">
<el-card shadow="never">
<template #header>
<div class="card-header">
<span>发布管理</span>
<el-button type="primary" :icon="Plus" @click="handlePublish">
新增模块
</el-button>
</div>
</template>
<el-table
:data="publishList"
v-loading="loading"
stripe
border
>
<el-table-column prop="id" label="ID" width="80" />
<el-table-column prop="title" label="模块标题" min-width="200" show-overflow-tooltip />
<el-table-column prop="version" label="版本号" width="120" />
<el-table-column prop="module_name" label="所属分类" width="150" />
<el-table-column prop="status" label="状态" width="100">
<template #default="{ row }">
<el-tag :type="getStatusType(row.status)">
{{ getStatusText(row.status) }}
</el-tag>
</template>
</el-table-column>
<el-table-column prop="author" label="作者" width="120" />
<el-table-column prop="publish_time" label="发布时间" width="180">
<template #default="{ row }">
{{ formatDate(row.publish_time) }}
</template>
</el-table-column>
<el-table-column label="操作" width="200" fixed="right">
<template #default="{ row }">
<el-button
type="primary"
link
size="small"
:icon="View"
@click="handleView(row)"
>
查看
</el-button>
<el-button
type="danger"
link
size="small"
:icon="Delete"
@click="handleDelete(row)"
>
删除
</el-button>
</template>
</el-table-column>
</el-table>
<div v-if="publishList.length === 0 && !loading" class="empty-state">
<el-empty description="暂无发布记录" />
</div>
</el-card>
<el-dialog
v-model="publishDialogVisible"
title="新增模块"
width="700px"
:close-on-click-modal="false"
@close="handlePublishClose"
>
<el-form
ref="formRef"
:model="formData"
:rules="formRules"
label-width="120px"
>
<el-form-item label="模块标题" prop="title">
<el-input
v-model="formData.title"
placeholder="请输入模块标题"
clearable
/>
</el-form-item>
<el-form-item label="版本号" prop="version">
<el-input
v-model="formData.version"
placeholder="请输入版本号,如: 1.0.0"
clearable
/>
</el-form-item>
<el-form-item label="所属分类" prop="module_id">
<el-select
v-model="formData.module_id"
placeholder="请选择所属分类"
clearable
>
<el-option
v-for="module in moduleOptions"
:key="module.id"
:label="module.name"
:value="module.id"
/>
</el-select>
</el-form-item>
<el-form-item label="状态" prop="status">
<el-radio-group v-model="formData.status">
<el-radio :value="1">发布</el-radio>
<el-radio :value="0">草稿</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="上传包" prop="packageFile">
<el-upload
ref="uploadRef"
class="upload-demo"
drag
:auto-upload="false"
:limit="1"
:on-change="handleFileChange"
:before-upload="beforeUpload"
accept=".zip"
>
<el-icon class="el-icon--upload"><UploadFilled /></el-icon>
<div class="el-upload__text">
拖拽文件到此处或<em>点击上传</em>
</div>
<template #tip>
<div class="el-upload__tip">
只能上传 zip 格式的压缩包,且不超过 100MB
</div>
</template>
</el-upload>
<div v-if="formData.packageFile" class="file-info">
<el-icon><Document /></el-icon>
<span>{{ formData.packageFile.name }}</span>
<el-button
type="danger"
link
size="small"
@click="handleRemoveFile"
>
删除
</el-button>
</div>
</el-form-item>
<el-form-item label="模块说明" prop="description">
<el-input
v-model="formData.description"
type="textarea"
:rows="4"
placeholder="请输入模块说明"
/>
</el-form-item>
</el-form>
<template #footer>
<el-button @click="publishDialogVisible = false">取消</el-button>
<el-button type="primary" :loading="submitLoading" @click="handleSubmit">
确定
</el-button>
</template>
</el-dialog>
</div>
</template>
<script setup lang="ts">
import { ref, reactive, onMounted } from "vue";
import { ElMessage, ElMessageBox } from "element-plus";
import { Plus, View, Delete, UploadFilled, Document } from "@element-plus/icons-vue";
import type { FormInstance, FormRules, UploadFile } from "element-plus";
import { getModules, getModuleCategory } from "@/api/moduleCenter";
interface Publish {
id: number;
title: string;
version: string;
author: string;
module_name: string;
status: number;
publish_time: string;
}
interface ModuleOption {
id: number;
name: string;
}
const loading = ref(false);
const publishList = ref<Publish[]>([]);
const publishDialogVisible = ref(false);
const submitLoading = ref(false);
const formRef = ref<FormInstance>();
const uploadRef = ref();
const formData = reactive({
title: "",
version: "",
author: "",
module_id: null as number | null,
status: 1,
description: "",
packageFile: null as File | null
});
const moduleOptions = ref<ModuleOption[]>([]);
const formRules: FormRules = {
title: [
{ required: true, message: "请输入模块标题", trigger: "blur" }
],
version: [
{ required: true, message: "请输入版本号", trigger: "blur" },
{ pattern: /^\d+\.\d+\.\d+$/, message: "版本号格式不正确,如: 1.0.0", trigger: "blur" }
],
module_id: [
{ required: true, message: "请选择所属分类", trigger: "change" }
],
status: [
{ required: true, message: "请选择状态", trigger: "change" }
]
};
const getStatusText = (status: number) => {
const map: Record<number, string> = {
0: "草稿",
1: "已发布",
2: "已撤回"
};
return map[status] || "未知";
};
const getStatusType = (status: number) => {
const map: Record<number, any> = {
0: "info",
1: "success",
2: "warning"
};
return map[status] || "info";
};
const formatDate = (date: string) => {
if (!date) return "-";
const d = new Date(date);
const year = d.getFullYear();
const month = String(d.getMonth() + 1).padStart(2, "0");
const day = String(d.getDate()).padStart(2, "0");
const hours = String(d.getHours()).padStart(2, "0");
const minutes = String(d.getMinutes()).padStart(2, "0");
return `${year}-${month}-${day} ${hours}:${minutes}`;
};
const handlePublish = () => {
publishDialogVisible.value = true;
fetchModuleOptions();
};
const handleView = (row: Publish) => {
ElMessage.info("查看模块详情功能开发中");
};
const handleDelete = (row: Publish) => {
ElMessageBox.confirm(`确定要删除模块"${row.title}"吗?`, "提示", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(async () => {
try {
// TODO: 调用删除接口
// await deletePublish(row.id);
ElMessage.success("删除成功");
handleRefresh();
} catch (error) {
console.error("删除失败:", error);
ElMessage.error("删除失败");
}
}).catch(() => {});
};
const handleFileChange = (file: UploadFile) => {
formData.packageFile = file.raw;
};
const beforeUpload = (file: File) => {
const isZip = file.type === "application/zip" || file.name.endsWith(".zip");
const isLt100M = file.size / 1024 / 1024 < 100 * 1024;
if (!isZip) {
ElMessage.error("只能上传 zip 格式的文件!");
return false;
}
if (!isLt100M) {
ElMessage.error("文件大小不能超过 100MB!");
return false;
}
return true;
};
const handleRemoveFile = () => {
formData.packageFile = null;
if (uploadRef.value) {
uploadRef.value.clearFiles();
}
};
const handlePublishClose = () => {
formRef.value?.resetFields();
formData.packageFile = null;
publishDialogVisible.value = false;
};
const handleSubmit = async () => {
if (!formRef.value) return;
await formRef.value.validate(async (valid) => {
if (valid) {
if (!formData.packageFile) {
ElMessage.warning("请上传模块包");
return;
}
submitLoading.value = true;
try {
// TODO: 调用模块接口
const formDataObj = new FormData();
formDataObj.append("title", formData.title);
formDataObj.append("version", formData.version);
formDataObj.append("author", formData.author);
formDataObj.append("module_id", formData.module_id.toString());
formDataObj.append("status", formData.status.toString());
formDataObj.append("description", formData.description);
formDataObj.append("package", formData.packageFile);
ElMessage.success("发布成功");
handlePublishClose();
handleRefresh();
} catch (error) {
console.error("发布失败:", error);
ElMessage.error("发布失败");
} finally {
submitLoading.value = false;
}
}
});
};
const handleRefresh = () => {
fetchPublishList();
};
const fetchPublishList = async () => {
loading.value = true;
try {
const res = await getModules(0);
if (res.code === 200 && res.data) {
publishList.value = res.data.list.map((item: any) => ({
id: item.id,
title: item.title,
version: item.version || "-",
author: item.author || "-",
module_name: item.cid || "",
status: item.status,
publish_time: item.create_time || ""
}));
}
} catch (error) {
console.error("获取模块列表失败:", error);
ElMessage.error("获取模块列表失败");
} finally {
loading.value = false;
}
};
const fetchModuleOptions = async () => {
try {
const res = await getModuleCategory();
if (res.code === 200 && res.data) {
moduleOptions.value = res.data.list.map((item: any) => ({
id: item.id,
name: item.title
}));
}
} catch (error) {
console.error("获取分类列表失败:", error);
}
};
onMounted(() => {
fetchPublishList();
});
</script>
<style scoped lang="less">
.publish-container {
.card-header {
display: flex;
justify-content: space-between;
align-items: center;
}
.upload-demo {
width: 100%;
:deep(.el-upload) {
width: 100%;
}
:deep(.el-upload-dragger) {
width: 100%;
height: 180px;
}
}
.file-info {
margin-top: 12px;
padding: 8px 12px;
background: var(--el-fill-color-light);
border-radius: 4px;
display: flex;
align-items: center;
gap: 8px;
.el-icon {
font-size: 20px;
color: var(--el-color-primary);
}
span {
flex: 1;
font-size: 14px;
color: var(--el-text-color-regular);
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
}
.el-upload__tip {
font-size: 12px;
color: var(--el-text-color-placeholder);
margin-top: 8px;
}
.empty-state {
padding: 40px 0;
}
}
</style>