OfficeSystem/api/project.js

168 lines
4.4 KiB
JavaScript
Raw Normal View History

2025-11-17 11:58:49 +08:00
/**
* 项目相关 API
*/
/**
* 获取项目列表
* @param {Object} params 请求参数
* @param {number} params.pageNum 页码
* @param {number} params.pageSize 每页数量
* @param {string} params.orderByColumn 排序字段
* @param {string} params.isAsc 排序方式ascending/descending
* @param {number[]} params.statusList 项目状态列表
* @param {string} params.createId 创建人ID
* @param {string} params.ownerId 负责人ID
* @param {string[]} params.keys 搜索关键词数组
* @returns {Promise} 返回项目列表
*/
export const getProjectList = (params = {}) => {
const queryParams = [];
// 分页参数
if (params.pageNum !== undefined) {
queryParams.push(`pageNum=${params.pageNum}`);
}
if (params.pageSize !== undefined) {
queryParams.push(`pageSize=${params.pageSize}`);
}
// 排序参数
if (params.orderByColumn !== undefined && params.orderByColumn !== '') {
queryParams.push(`orderByColumn=${encodeURIComponent(params.orderByColumn)}`);
}
if (params.isAsc !== undefined && params.isAsc !== '') {
queryParams.push(`isAsc=${encodeURIComponent(params.isAsc)}`);
}
// 状态列表
if (params.statusList !== undefined && Array.isArray(params.statusList) && params.statusList.length > 0) {
params.statusList.forEach((status, index) => {
queryParams.push(`statusList=${status}`);
});
}
2025-11-22 14:14:59 +08:00
// 是否曾经逾期
if (params.overdue !== undefined && params.overdue !== '') {
queryParams.push(`devOverdue=${params.overdue}`);
}
2025-11-17 11:58:49 +08:00
// 创建人ID
if (params.createId !== undefined && params.createId !== '') {
queryParams.push(`createId=${params.createId}`);
}
// 负责人ID
if (params.ownerId !== undefined && params.ownerId !== '') {
queryParams.push(`ownerId=${params.ownerId}`);
}
// 搜索关键词
if (params.keys !== undefined && Array.isArray(params.keys) && params.keys.length > 0) {
params.keys.forEach((key, index) => {
queryParams.push(`keys[${index}]=${encodeURIComponent(key)}`);
});
}
// 项目名称搜索
if (params.projectName !== undefined && params.projectName !== '') {
2025-11-17 15:44:45 +08:00
queryParams.push(`name=${encodeURIComponent(params.projectName)}`);
2025-11-17 11:58:49 +08:00
}
// 项目编号搜索
if (params.projectId !== undefined && params.projectId !== '') {
2025-11-17 15:44:45 +08:00
queryParams.push(`no=${encodeURIComponent(params.projectId)}`);
2025-11-17 11:58:49 +08:00
}
// 客户名称搜索
if (params.customerName !== undefined && params.customerName !== '') {
queryParams.push(`customerName=${encodeURIComponent(params.customerName)}`);
}
// 成员ID搜索
2025-11-17 15:44:45 +08:00
if (params.joinUserId !== undefined && params.joinUserId !== '') {
queryParams.push(`joinUserId=${params.joinUserId}`);
2025-11-17 11:58:49 +08:00
}
const queryString = queryParams.length > 0 ? `?${queryParams.join('&')}` : '';
return uni.$uv.http.get(`bst/project/list${queryString}`, {
custom: {
auth: true // 启用 token 认证
}
});
};
/**
* 获取项目详情
* @param {string} id 项目ID
* @returns {Promise} 返回项目详情
*/
export const getProjectDetail = (id) => {
return uni.$uv.http.get(`bst/project/${id}`, {
custom: {
auth: true
}
});
};
2025-11-17 16:58:11 +08:00
/**
* 创建项目
* @param {Object} data 项目数据
* @returns {Promise} 创建结果
*/
export const createProject = (data) => {
return uni.$uv.http.post('bst/project', data, {
custom: {
2025-11-18 16:02:59 +08:00
auth: true,
catch: true // 允许在 catch 中处理错误
2025-11-17 16:58:11 +08:00
}
});
};
/**
* 更新项目
* @param {Object} data 项目数据需包含 id
* @returns {Promise} 更新结果
*/
export const updateProject = (data) => {
return uni.$uv.http.put('bst/project', data, {
custom: {
2025-11-24 16:12:22 +08:00
auth: true,
catch:true
2025-11-17 16:58:11 +08:00
}
});
};
2025-11-18 16:58:22 +08:00
/**
* 删除项目
* @param {string|string[]} ids 项目ID或ID数组
* @returns {Promise} 删除结果
*/
export const deleteProject = (ids) => {
const idsParam = Array.isArray(ids) ? ids.join(',') : ids;
return uni.$uv.http.delete(`bst/project/${idsParam}`, {}, {
custom: {
2025-11-24 16:12:22 +08:00
auth: true,
catch:true
2025-11-18 16:58:22 +08:00
}
});
};
2025-11-18 17:10:08 +08:00
/**
* 开始项目开发
* @param {Object} data
* @param {string} data.id 项目ID
* @param {string} data.expectedCompleteDate 预计完成日期YYYY-MM-DD
* @returns {Promise} 操作结果
*/
export const startProjectDevelopment = (data) => {
return uni.$uv.http.put('bst/project/start', data, {
custom: {
auth: true,
catch:true
2025-11-18 17:10:08 +08:00
}
});
};