删除项目

This commit is contained in:
WindowBird 2025-11-18 16:58:22 +08:00
parent 9797ca3068
commit 4bf4371fcb
2 changed files with 63 additions and 3 deletions

View File

@ -127,3 +127,18 @@ export const updateProject = (data) => {
});
};
/**
* 删除项目
* @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: {
auth: true
}
});
};

View File

@ -207,7 +207,7 @@
<script setup>
import { ref, computed, watch, onMounted, nextTick, onUnmounted } from 'vue';
import { onLoad, onReachBottom, onPullDownRefresh } from '@dcloudio/uni-app';
import { getProjectList, getUserList } from '@/api';
import { getProjectList, getUserList, deleteProject } from '@/api';
import { usePagination } from '@/composables';
import { useDictStore } from '@/store/dict';
import { useUserStore } from '@/store/user';
@ -517,6 +517,8 @@ const getAvatarText = (member) => {
return name.charAt(0);
};
const deletingProjectId = ref('');
//
const handleCardMenu = (project) => {
uni.showActionSheet({
@ -525,8 +527,7 @@ const handleCardMenu = (project) => {
if (res.tapIndex === 0) {
goToEditProject(project);
} else if (res.tapIndex === 1) {
//
uni.showToast({ title: '删除功能开发中', icon: 'none' });
handleDeleteProject(project);
} else if (res.tapIndex === 2) {
//
uni.showToast({ title: '新增任务功能开发中', icon: 'none' });
@ -538,6 +539,50 @@ const handleCardMenu = (project) => {
});
};
const handleDeleteProject = (project) => {
if (!project?.id) {
uni.showToast({
title: '缺少项目ID',
icon: 'none'
});
return;
}
if (deletingProjectId.value) {
return;
}
const projectName = project.name || project.projectName || '';
uni.showModal({
title: '删除项目',
content: projectName ? `确认删除项目「${projectName}」?` : '确认删除该项目?',
confirmColor: '#f56c6c',
success: async ({ confirm }) => {
if (!confirm) {
return;
}
try {
deletingProjectId.value = project.id;
uni.showLoading({ title: '删除中...', mask: true });
await deleteProject(project.id);
uni.showToast({ title: '删除成功', icon: 'success' });
await refresh();
} catch (err) {
console.error('删除项目失败:', err);
uni.showToast({
title: err?.message || '删除失败,请稍后重试',
icon: 'none'
});
} finally {
deletingProjectId.value = '';
uni.hideLoading();
}
}
});
};
const goToCreateProject = () => {
uni.navigateTo({
url: '/pages/project/form/index?mode=add'