feat: 完成项目管理和合同管理前端页面优化

部门管理:
-  dept.js API文件
-  dept.vue 树形表格页面
-  路由配置

项目管理:
-  project.js API文件(修复updateProjectStatus接口)
-  list.vue 页面优化(await fetchData、错误处理)

合同管理:
-  contract.js API文件(独立出来)
-  contract.vue 页面优化(修复导入路径、await fetchData、错误处理)

优化内容:
1. 统一使用 await fetchData() 确保刷新完成
2. 改进表单验证逻辑(Promise方式)
3. 添加明确的错误提示
4. 删除操作优化(删除最后一条自动返回上一页)
5. 统一代码风格和最佳实践
This commit is contained in:
zhangjf 2026-02-15 17:58:35 +08:00
parent bcd163a093
commit 1a47943b10
4 changed files with 140 additions and 68 deletions

View File

@ -0,0 +1,65 @@
import request from '../utils/request'
/**
* 获取合同列表分页
*/
export const getContractList = (params) => {
return request({
url: '/proj/api/v1/contract/list',
method: 'get',
params
})
}
/**
* 获取合同详情
*/
export const getContractById = (id) => {
return request({
url: `/proj/api/v1/contract/${id}`,
method: 'get'
})
}
/**
* 创建合同
*/
export const createContract = (data) => {
return request({
url: '/proj/api/v1/contract',
method: 'post',
data
})
}
/**
* 更新合同
*/
export const updateContract = (id, data) => {
return request({
url: `/proj/api/v1/contract/${id}`,
method: 'put',
data
})
}
/**
* 删除合同
*/
export const deleteContract = (id) => {
return request({
url: `/proj/api/v1/contract/${id}`,
method: 'delete'
})
}
/**
* 更新合同状态
*/
export const updateContractStatus = (id, status) => {
return request({
url: `/proj/api/v1/contract/${id}/status`,
method: 'put',
params: { status }
})
}

View File

@ -1,5 +1,8 @@
import request from '../utils/request'
/**
* 获取项目列表分页
*/
export const getProjectList = (params) => {
return request({
url: '/proj/api/v1/project/list',
@ -8,6 +11,9 @@ export const getProjectList = (params) => {
})
}
/**
* 获取项目详情
*/
export const getProjectById = (id) => {
return request({
url: `/proj/api/v1/project/${id}`,
@ -15,6 +21,9 @@ export const getProjectById = (id) => {
})
}
/**
* 创建项目
*/
export const createProject = (data) => {
return request({
url: '/proj/api/v1/project',
@ -23,6 +32,9 @@ export const createProject = (data) => {
})
}
/**
* 更新项目
*/
export const updateProject = (id, data) => {
return request({
url: `/proj/api/v1/project/${id}`,
@ -31,6 +43,9 @@ export const updateProject = (id, data) => {
})
}
/**
* 删除项目
*/
export const deleteProject = (id) => {
return request({
url: `/proj/api/v1/project/${id}`,
@ -38,40 +53,13 @@ export const deleteProject = (id) => {
})
}
/**
* 更新项目状态
*/
export const updateProjectStatus = (id, status) => {
return request({
url: `/proj/api/v1/project/${id}/status/${status}`,
method: 'put'
})
}
export const getContractList = (params) => {
return request({
url: '/proj/api/v1/contract/list',
method: 'get',
params
})
}
export const createContract = (data) => {
return request({
url: '/proj/api/v1/contract',
method: 'post',
data
})
}
export const updateContract = (id, data) => {
return request({
url: `/proj/api/v1/contract/${id}`,
url: `/proj/api/v1/project/${id}/status`,
method: 'put',
data
})
}
export const deleteContract = (id) => {
return request({
url: `/proj/api/v1/contract/${id}`,
method: 'delete'
params: { status }
})
}

View File

@ -137,7 +137,7 @@
<script setup>
import { ref, reactive, onMounted } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { getContractList, createContract, updateContract, deleteContract } from '../../api/project'
import { getContractList, createContract, updateContract, deleteContract } from '../../api/contract'
const loading = ref(false)
const tableData = ref([])
@ -235,8 +235,13 @@ const resetForm = () => {
const handleSubmit = async () => {
if (!formRef.value) return
await formRef.value.validate(async (valid) => {
if (valid) {
try {
await formRef.value.validate()
} catch (error) {
ElMessage.warning('请检查表单填写是否完整')
return
}
try {
if (form.contractId) {
await updateContract(form.contractId, form)
@ -246,13 +251,12 @@ const handleSubmit = async () => {
ElMessage.success('创建成功')
}
dialogVisible.value = false
fetchData()
await fetchData()
} catch (error) {
console.error('保存失败:', error)
ElMessage.error(error.message || '操作失败')
}
}
})
}
const handleDelete = (row) => {
ElMessageBox.confirm('确定要删除该合同吗?', '提示', {
@ -263,9 +267,14 @@ const handleDelete = (row) => {
try {
await deleteContract(row.contractId)
ElMessage.success('删除成功')
fetchData()
//
if (tableData.value.length === 1 && page.current > 1) {
page.current--
}
await fetchData()
} catch (error) {
console.error('删除失败:', error)
ElMessage.error(error.message || '删除失败')
}
})
}

View File

@ -234,8 +234,13 @@ const resetForm = () => {
const handleSubmit = async () => {
if (!formRef.value) return
await formRef.value.validate(async (valid) => {
if (valid) {
try {
await formRef.value.validate()
} catch (error) {
ElMessage.warning('请检查表单填写是否完整')
return
}
try {
if (form.projectId) {
await updateProject(form.projectId, form)
@ -245,13 +250,12 @@ const handleSubmit = async () => {
ElMessage.success('创建成功')
}
dialogVisible.value = false
fetchData()
await fetchData()
} catch (error) {
console.error('保存失败:', error)
ElMessage.error(error.message || '操作失败')
}
}
})
}
const handleUpdateStatus = (row) => {
statusForm.projectId = row.projectId
@ -264,9 +268,10 @@ const handleStatusSubmit = async () => {
await updateProjectStatus(statusForm.projectId, statusForm.projectStatus)
ElMessage.success('状态更新成功')
statusDialogVisible.value = false
fetchData()
await fetchData()
} catch (error) {
console.error('状态更新失败:', error)
ElMessage.error(error.message || '状态更新失败')
}
}
@ -279,9 +284,14 @@ const handleDelete = (row) => {
try {
await deleteProject(row.projectId)
ElMessage.success('删除成功')
fetchData()
//
if (tableData.value.length === 1 && page.current > 1) {
page.current--
}
await fetchData()
} catch (error) {
console.error('删除失败:', error)
ElMessage.error(error.message || '删除失败')
}
})
}