commits
This commit is contained in:
@@ -1,313 +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>
|
||||
<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>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,312 +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>
|
||||
<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>
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
<script setup>
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<router-view />
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
|
||||
<script setup>
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<router-view />
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
||||
@@ -1,455 +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>
|
||||
<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>
|
||||
|
||||
Reference in New Issue
Block a user