From e0d3997b7fdd2b14d53759a922e3d48ce9335407 Mon Sep 17 00:00:00 2001 From: teukkk Date: Wed, 22 May 2024 11:31:06 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E7=B3=BB=E7=BB=9F=E8=AE=BE=E7=BD=AE):=20?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=88=97=E8=A1=A8=E8=BF=9B=E5=85=A5=E7=BB=84?= =?UTF-8?q?=E7=BB=87=E3=80=81=E9=A1=B9=E7=9B=AE=E7=9A=84=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../project/components/addProjectModal.vue | 7 +- .../organization/project/locale/en-US.ts | 1 + .../organization/project/locale/zh-CN.ts | 1 + .../organization/project/orgProject.vue | 29 +++++-- .../components/addProjectModal.vue | 7 +- .../components/systemProject.vue | 29 +++++-- frontend/src/views/setting/utils.ts | 79 +++++++++++++++++++ 7 files changed, 129 insertions(+), 24 deletions(-) create mode 100644 frontend/src/views/setting/utils.ts diff --git a/frontend/src/views/setting/organization/project/components/addProjectModal.vue b/frontend/src/views/setting/organization/project/components/addProjectModal.vue index 419c911d5c..c242409c0b 100644 --- a/frontend/src/views/setting/organization/project/components/addProjectModal.vue +++ b/frontend/src/views/setting/organization/project/components/addProjectModal.vue @@ -139,6 +139,7 @@ import { CreateOrUpdateSystemProjectParams, SystemOrgOption } from '@/models/setting/system/orgAndProject'; + import { showUpdateOrCreateMessage } from '@/views/setting/utils'; import type { FormInstance, ValidatedError } from '@arco-design/web-vue'; defineOptions({ @@ -246,10 +247,8 @@ } try { loading.value = true; - await createOrUpdateProjectByOrg({ id: isEdit.value ? props.currentProject?.id : '', ...form }); - Message.success( - isEdit.value ? t('system.project.updateProjectSuccess') : t('system.project.createProjectSuccess') - ); + const res = await createOrUpdateProjectByOrg({ id: isEdit.value ? props.currentProject?.id : '', ...form }); + showUpdateOrCreateMessage(isEdit.value, res.id); appStore.initProjectList(); handleCancel(true); } catch (error) { diff --git a/frontend/src/views/setting/organization/project/locale/en-US.ts b/frontend/src/views/setting/organization/project/locale/en-US.ts index f7b35eeb18..3d65beacda 100644 --- a/frontend/src/views/setting/organization/project/locale/en-US.ts +++ b/frontend/src/views/setting/organization/project/locale/en-US.ts @@ -77,4 +77,5 @@ export default { 'system.project.resourcePool': 'Resource pool', 'system.project.removeName': 'Confirm remove the {name}', 'system.project.descriptionPlaceholder': 'Please describe the project.', + 'system.project.enterProject': 'Enter project', }; diff --git a/frontend/src/views/setting/organization/project/locale/zh-CN.ts b/frontend/src/views/setting/organization/project/locale/zh-CN.ts index 6b667bc2ad..9d98f3b457 100644 --- a/frontend/src/views/setting/organization/project/locale/zh-CN.ts +++ b/frontend/src/views/setting/organization/project/locale/zh-CN.ts @@ -71,4 +71,5 @@ export default { 'system.project.resourcePool': '资源池', 'system.project.removeName': '确认移除 {name} 这个用户吗?', 'system.project.descriptionPlaceholder': '请对该项目进行描述', + 'system.project.enterProject': '进入项目', }; diff --git a/frontend/src/views/setting/organization/project/orgProject.vue b/frontend/src/views/setting/organization/project/orgProject.vue index 82d5bd1807..af982f7491 100644 --- a/frontend/src/views/setting/organization/project/orgProject.vue +++ b/frontend/src/views/setting/organization/project/orgProject.vue @@ -69,11 +69,9 @@ {{ t('system.organization.addMember') }} - {{ t('common.end') }} + {{ + t('system.project.enterProject') + }} { - if (tag.eventTag === 'delete') { - handleDelete(record); + const { eventTag } = tag; + switch (eventTag) { + case 'end': + handleEnableOrDisableProject(record, false); + break; + case 'delete': + handleDelete(record); + break; + default: + break; } }; diff --git a/frontend/src/views/setting/system/organizationAndProject/components/addProjectModal.vue b/frontend/src/views/setting/system/organizationAndProject/components/addProjectModal.vue index 5cb155338b..7ab73a1c6b 100644 --- a/frontend/src/views/setting/system/organizationAndProject/components/addProjectModal.vue +++ b/frontend/src/views/setting/system/organizationAndProject/components/addProjectModal.vue @@ -137,6 +137,7 @@ import { CreateOrUpdateSystemProjectParams, SystemOrgOption } from '@/models/setting/system/orgAndProject'; + import { showUpdateOrCreateMessage } from '@/views/setting/utils'; import type { FormInstance, ValidatedError } from '@arco-design/web-vue'; const appStore = useAppStore(); @@ -228,10 +229,8 @@ } try { loading.value = true; - await createOrUpdateProject({ id: isEdit.value ? props.currentProject?.id : '', ...form }); - Message.success( - isEdit.value ? t('system.project.updateProjectSuccess') : t('system.project.createProjectSuccess') - ); + const res = await createOrUpdateProject({ id: isEdit.value ? props.currentProject?.id : '', ...form }); + showUpdateOrCreateMessage(isEdit.value, res.id); appStore.initProjectList(); handleCancel(true); } catch (error) { diff --git a/frontend/src/views/setting/system/organizationAndProject/components/systemProject.vue b/frontend/src/views/setting/system/organizationAndProject/components/systemProject.vue index dd1fbe1a53..450a79a4ce 100644 --- a/frontend/src/views/setting/system/organizationAndProject/components/systemProject.vue +++ b/frontend/src/views/setting/system/organizationAndProject/components/systemProject.vue @@ -53,11 +53,9 @@ {{ t('system.organization.addMember') }} - {{ t('common.end') }} + {{ + t('system.project.enterProject') + }} { - if (tag.eventTag === 'delete') { - handleDelete(record); + const { eventTag } = tag; + switch (eventTag) { + case 'end': + handleEnableOrDisableProject(record, false); + break; + case 'delete': + handleDelete(record); + break; + default: + break; } }; diff --git a/frontend/src/views/setting/utils.ts b/frontend/src/views/setting/utils.ts new file mode 100644 index 0000000000..3ef0750e1d --- /dev/null +++ b/frontend/src/views/setting/utils.ts @@ -0,0 +1,79 @@ +import { Message } from '@arco-design/web-vue'; + +import MsButton from '@/components/pure/ms-button/index.vue'; + +import { switchProject } from '@/api/modules/project-management/project'; +import { switchUserOrg } from '@/api/modules/system'; +import { useI18n } from '@/hooks/useI18n'; +import router from '@/router'; +import { NO_PROJECT_ROUTE_NAME } from '@/router/constants'; +import { useUserStore } from '@/store'; +import useAppStore from '@/store/modules/app'; +import { hasAnyPermission } from '@/utils/permission'; + +import { ProjectManagementRouteEnum } from '@/enums/routeEnum'; + +const { t } = useI18n(); +const userStore = useUserStore(); +const appStore = useAppStore(); + +export async function enterProject(projectId: string, organizationId?: string) { + try { + appStore.showLoading(); + // 切换组织 + if (organizationId) { + await switchUserOrg(organizationId, userStore.id || ''); + } + // 切换项目 + await switchProject({ + projectId, + userId: userStore.id || '', + }); + await userStore.isLogin(true); + if (!appStore.currentProjectId || appStore.currentProjectId === 'no_such_project') { + // 没有项目权限(组织没有项目, 或项目全被禁用),则重定向到无项目权限页面 + router.push({ + name: NO_PROJECT_ROUTE_NAME, + }); + return; + } + // 跳转到项目页面 + router.replace({ + name: ProjectManagementRouteEnum.PROJECT_MANAGEMENT_PERMISSION, + query: { + orgId: appStore.currentOrgId, + pId: appStore.currentProjectId, + }, + }); + } catch (error) { + // eslint-disable-next-line no-console + console.log(error); + } finally { + appStore.hideLoading(); + } +} + +export function showUpdateOrCreateMessage(isEdit: boolean, id: string) { + if (isEdit) { + Message.success(t('system.project.updateProjectSuccess')); + } else if (!hasAnyPermission(['PROJECT_BASE_INFO:READ'])) { + Message.success(t('system.project.createProjectSuccess')); + } else { + Message.success({ + content: () => + h('div', { class: 'flex items-center gap-[12px]' }, [ + h('div', t('system.project.createProjectSuccess')), + h( + MsButton, + { + type: 'text', + onClick() { + enterProject(id); + }, + }, + { default: () => t('system.project.enterProject') } + ), + ]), + }); + } +}