<template>
|
<div class="app-container">
|
<!-- 顶部搜索和操作栏 -->
|
<el-form :model="queryParams" ref="queryRef" :inline="true" label-width="80px">
|
<el-form-item label="项目名称" prop="projectName">
|
<el-input
|
v-model="queryParams.projectName"
|
placeholder="请输入项目名称"
|
clearable
|
style="width: 240px"
|
@keyup.enter="handleQuery"
|
/>
|
</el-form-item>
|
<el-form-item label="负责人" prop="managerName">
|
<el-input
|
v-model="queryParams.managerName"
|
placeholder="请输入负责人姓名"
|
clearable
|
style="width: 240px"
|
@keyup.enter="handleQuery"
|
/>
|
</el-form-item>
|
<el-form-item label="状态" prop="status">
|
<el-select
|
v-model="queryParams.status"
|
placeholder="项目状态"
|
clearable
|
style="width: 150px"
|
>
|
<el-option label="规划中" value="planning" />
|
<el-option label="进行中" value="inProgress" />
|
<el-option label="已完成" value="completed" />
|
<el-option label="已暂停" value="paused" />
|
</el-select>
|
</el-form-item>
|
<el-form-item>
|
<el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
|
<el-button icon="Refresh" @click="resetQuery">重置</el-button>
|
</el-form-item>
|
</el-form>
|
|
<!-- 工具栏 -->
|
<el-row :gutter="10" class="mb8">
|
<el-col :span="1.5">
|
<el-button
|
type="primary"
|
plain
|
icon="Plus"
|
@click="handleAdd"
|
v-hasPermi="['oaSystem:project:add']"
|
>新增项目</el-button>
|
</el-col>
|
<!-- <el-col :span="1.5">
|
<el-button
|
type="success"
|
plain
|
icon="Edit"
|
:disabled="single"
|
@click="handleUpdate"
|
v-hasPermi="['oaSystem:project:edit']"
|
>编辑项目</el-button>
|
</el-col>
|
<el-col :span="1.5">
|
<el-button
|
type="danger"
|
plain
|
icon="Delete"
|
:disabled="multiple"
|
@click="handleDelete"
|
v-hasPermi="['oaSystem:project:remove']"
|
>删除项目</el-button>
|
</el-col> -->
|
<el-col :span="1.5">
|
<el-button
|
type="warning"
|
plain
|
icon="Download"
|
@click="handleExport"
|
v-hasPermi="['oaSystem:project:export']"
|
>导出项目</el-button>
|
</el-col>
|
</el-row>
|
|
<!-- 项目列表表格 -->
|
<el-table
|
v-loading="loading"
|
:data="projectList"
|
@selection-change="handleSelectionChange"
|
>
|
<el-table-column type="selection" width="50" align="center" />
|
<el-table-column
|
label="项目编号"
|
align="center"
|
prop="projectId"
|
width="100"
|
/>
|
<el-table-column
|
label="项目名称"
|
align="center"
|
prop="projectName"
|
:show-overflow-tooltip="true"
|
/>
|
<el-table-column
|
label="负责人"
|
align="center"
|
prop="managerName"
|
/>
|
<el-table-column
|
label="开始日期"
|
align="center"
|
prop="startDate"
|
width="120"
|
/>
|
<el-table-column
|
label="结束日期"
|
align="center"
|
prop="endDate"
|
width="120"
|
/>
|
<el-table-column
|
label="状态"
|
align="center"
|
prop="status"
|
width="90"
|
>
|
<template #default="scope">
|
<el-tag :type="getStatusType(scope.row.status)">{{ getStatusText(scope.row.status) }}</el-tag>
|
</template>
|
</el-table-column>
|
<el-table-column
|
label="完成度"
|
align="center"
|
prop="completionRate"
|
width="100"
|
>
|
<template #default="scope">
|
<el-progress :percentage="scope.row.completionRate" :stroke-width="6" />
|
</template>
|
</el-table-column>
|
<el-table-column
|
label="操作"
|
align="center"
|
width="180"
|
class-name="small-padding fixed-width"
|
>
|
<template #default="scope">
|
<el-button
|
link
|
type="primary"
|
icon="Search"
|
@click="handleView(scope.row)"
|
v-hasPermi="['oaSystem:project:query']"
|
>详情</el-button>
|
<el-button
|
link
|
type="primary"
|
icon="Edit"
|
@click="handleUpdate(scope.row)"
|
v-hasPermi="['oaSystem:project:edit']"
|
>编辑</el-button>
|
<el-button
|
link
|
type="danger"
|
icon="Delete"
|
@click="handleDelete(scope.row)"
|
v-hasPermi="['oaSystem:project:remove']"
|
>删除</el-button>
|
</template>
|
</el-table-column>
|
</el-table>
|
|
<!-- 分页组件 -->
|
<pagination
|
v-show="total > 0"
|
:total="total"
|
v-model:page="queryParams.pageNum"
|
v-model:limit="queryParams.pageSize"
|
@pagination="getList"
|
/>
|
|
<!-- 项目表单对话框 -->
|
<el-dialog :title="title" v-model="open" width="600px" append-to-body>
|
<project-form
|
ref="projectFormRef"
|
:form="form"
|
:rules="rules"
|
:visible="open"
|
/>
|
<template #footer>
|
<div class="dialog-footer">
|
<el-button @click="cancel">取消</el-button>
|
<el-button type="primary" @click="submitForm">确定</el-button>
|
</div>
|
</template>
|
</el-dialog>
|
</div>
|
</template>
|
|
<script setup>
|
import { ref, reactive, computed, onMounted } from 'vue';
|
import { ElMessage, ElMessageBox } from 'element-plus';
|
import Pagination from '@/components/Pagination';
|
import ProjectForm from './components/projectForm.vue';
|
import { useRouter } from 'vue-router';
|
const { proxy } = getCurrentInstance();
|
// 导入项目管理API接口
|
import { listProject, addProject, updateProject, delProject, exportProject } from '@/api/oaSystem/projectManagement';
|
// import { listUser } from '@/api/system/user'; // 导入用户列表API接口
|
|
// 创建router实例
|
const router = useRouter();
|
|
// 表格数据
|
const projectList = ref([]);
|
const loading = ref(true);
|
const total = ref(0);
|
const queryParams = reactive({
|
pageNum: 1,
|
pageSize: 10,
|
projectName: '',
|
managerName: '',
|
status: ''
|
});
|
|
// 表单数据
|
const form = reactive({
|
projectId: undefined,
|
projectName: '',
|
description: '',
|
startDate: '',
|
endDate: '',
|
managerId: '',
|
managerName: '',
|
status: 'planning',
|
completionRate: 0
|
});
|
|
// 表单校验规则
|
const rules = {
|
projectName: [
|
{ required: true, message: '项目名称不能为空', trigger: 'blur' },
|
{ min: 2, max: 50, message: '项目名称长度在 2 到 50 个字符', trigger: 'blur' }
|
],
|
startDate: [
|
{ required: true, message: '开始日期不能为空', trigger: 'change' }
|
],
|
endDate: [
|
{ required: true, message: '结束日期不能为空', trigger: 'change' }
|
],
|
managerId: [
|
{ required: true, message: '负责人不能为空', trigger: 'blur' }
|
]
|
};
|
|
// 对话框状态
|
const open = ref(false);
|
const title = ref('');
|
const projectFormRef = ref();
|
const queryRef = ref();
|
|
// 选中状态
|
const multiple = computed(() => {
|
return selectedRowKeys.value.length === 0;
|
});
|
const single = computed(() => {
|
return selectedRowKeys.value.length !== 1;
|
});
|
const selectedRowKeys = ref([]);
|
|
// 获取项目列表
|
const getList = async () => {
|
loading.value = true;
|
try {
|
const { data } = await listProject(queryParams);
|
projectList.value = data.records;
|
total.value = data.total;
|
} catch (error) {
|
ElMessage.error('获取项目列表失败');
|
console.error('获取项目列表失败:', error);
|
} finally {
|
loading.value = false;
|
}
|
};
|
|
// 搜索
|
const handleQuery = () => {
|
queryParams.pageNum = 1;
|
getList();
|
};
|
|
// 重置
|
const resetQuery = () => {
|
if (queryRef.value) {
|
queryRef.value.resetFields();
|
}
|
handleQuery();
|
};
|
|
// 选中行变化
|
const handleSelectionChange = (selection) => {
|
selectedRowKeys.value = selection.map(item => item.projectId);
|
};
|
|
// 新增项目
|
const handleAdd = () => {
|
resetForm();
|
open.value = true;
|
title.value = '新增项目';
|
};
|
|
// 编辑项目
|
const handleUpdate = async (row) => {
|
resetForm();
|
const projectId = row.projectId || selectedRowKeys.value[0];
|
try {
|
// const { data } = await getProject(projectId);
|
Object.assign(form, row);
|
open.value = true;
|
title.value = '编辑项目';
|
} catch (error) {
|
ElMessage.error('获取项目详情失败');
|
console.error('获取项目详情失败:', error);
|
}
|
};
|
|
// 删除项目
|
const handleDelete = async (row) => {
|
// const projectIds = row.projectId ? [row.projectId] : selectedRowKeys.value;
|
const projectNames = row.projectName ? [row.projectName] :
|
projectList.value.filter(item => projectIds.includes(item.projectId)).map(item => item.projectName);
|
|
const confirmMessage = `确定要删除项目 "${projectNames.join('、')}" 吗?`;
|
await ElMessageBox.confirm(confirmMessage, '确认操作', {
|
confirmButtonText: '确定',
|
cancelButtonText: '取消',
|
type: 'warning'
|
}).catch(() => {
|
throw new Error('取消删除');
|
});
|
|
try {
|
// if (projectIds.length === 1) {
|
await delProject(row.projectId);
|
// } else {
|
// await delProjectBatch(projectIds);
|
// }
|
ElMessage.success('删除成功');
|
getList();
|
} catch (error) {
|
if (error.message !== '取消删除') {
|
ElMessage.error('删除失败');
|
console.error('删除项目失败:', error);
|
}
|
}
|
// try {
|
// await ElMessageBox.confirm(confirmMessage, '确认操作', {
|
// confirmButtonText: '确定',
|
// cancelButtonText: '取消',
|
// type: 'warning'
|
// });
|
|
// // 模拟网络延迟
|
// await new Promise(resolve => setTimeout(resolve, 300));
|
|
|
// ElMessage.success('删除成功');
|
// getList();
|
// } catch (error) {
|
// if (error !== 'cancel') {
|
// console.error('删除项目失败:', error);
|
// }
|
// }
|
};
|
|
// 查看项目详情
|
const handleView = (row) => {
|
const projectId = row.projectId;
|
// 跳转到项目详情页面
|
router.push({
|
path: `/oaSystem/projectManagement/projectDetail/${projectId}`,
|
query: { projectName: row.projectName }
|
});
|
};
|
|
// 导出项目
|
const handleExport = async () => {
|
let ids = [];
|
if (selectedRowKeys.value.length > 0) {
|
ids = selectedRowKeys.value; // 导出选中的项目
|
} else {
|
ids = projectList.value.map(item => item.projectId); // 导出所有项目
|
}
|
ElMessageBox.confirm("选中的内容将被导出,是否确认导出?", "导出", {
|
confirmButtonText: "确认",
|
cancelButtonText: "取消",
|
type: "warning",
|
})
|
.then(() => {
|
proxy.download(`/oA/project/export/${ids.join(',')}`, {}, "项目数据.xlsx");
|
ElMessage.success("导出成功");
|
ids = [];
|
})
|
.catch(() => {
|
proxy.$modal.msg("已取消");
|
});
|
};
|
// 提交表单
|
const submitForm = async () => {
|
try {
|
await projectFormRef.value.validate();
|
|
if (form.projectId) {
|
await updateProject(form);
|
ElMessage.success('修改项目成功');
|
} else {
|
console.log("form",form);
|
await addProject(form);
|
ElMessage.success('新增项目成功');
|
}
|
open.value = false;
|
getList();
|
} catch (error) {
|
console.error('提交表单失败:', error);
|
}
|
};
|
|
// 取消
|
const cancel = () => {
|
open.value = false;
|
resetForm();
|
};
|
|
// 重置表单
|
const resetForm = () => {
|
form.projectId = undefined;
|
form.projectName = '';
|
form.description = '';
|
form.startDate = '';
|
form.endDate = '';
|
form.managerId = '';
|
form.managerName = '';
|
form.status = 'planning';
|
form.completionRate = 0;
|
if (projectFormRef.value) {
|
projectFormRef.value.resetFields();
|
}
|
};
|
|
// 获取状态标签类型
|
const getStatusType = (status) => {
|
const statusTypeMap = {
|
planning: 'info',
|
inProgress: 'primary',
|
completed: 'success',
|
paused: 'warning'
|
};
|
return statusTypeMap[status] || 'default';
|
};
|
|
// 获取状态文本
|
const getStatusText = (status) => {
|
const statusTextMap = {
|
planning: '规划中',
|
inProgress: '进行中',
|
completed: '已完成',
|
paused: '已暂停'
|
};
|
return statusTextMap[status] || status;
|
};
|
|
// 初始化
|
onMounted(() => {
|
getList();
|
});
|
</script>
|
|
<style scoped>
|
.app-container {
|
padding: 20px;
|
}
|
</style>
|