feat(系统设置): 增加列表进入组织、项目的操作

This commit is contained in:
teukkk 2024-05-22 11:31:06 +08:00 committed by 刘瑞斌
parent d5a87f5f04
commit e0d3997b7f
7 changed files with 129 additions and 24 deletions

View File

@ -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) {

View File

@ -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',
};

View File

@ -71,4 +71,5 @@ export default {
'system.project.resourcePool': '资源池',
'system.project.removeName': '确认移除 {name} 这个用户吗?',
'system.project.descriptionPlaceholder': '请对该项目进行描述',
'system.project.enterProject': '进入项目',
};

View File

@ -69,11 +69,9 @@
<MsButton v-permission="['ORGANIZATION_PROJECT:READ+ADD_MEMBER']" @click="showAddUserModal(record)">{{
t('system.organization.addMember')
}}</MsButton>
<MsButton
v-permission="['ORGANIZATION_PROJECT:READ+UPDATE']"
@click="handleEnableOrDisableProject(record, false)"
>{{ t('common.end') }}</MsButton
>
<MsButton v-permission="['PROJECT_BASE_INFO:READ']" @click="enterProject(record.id)">{{
t('system.project.enterProject')
}}</MsButton>
<MsTableMoreAction
v-permission="['ORGANIZATION_PROJECT:READ+DELETE']"
:list="tableActions"
@ -130,6 +128,8 @@
import { CreateOrUpdateSystemProjectParams, OrgProjectTableItem } from '@/models/setting/system/orgAndProject';
import { ColumnEditTypeEnum, TableKeyEnum } from '@/enums/tableEnum';
import { enterProject } from '@/views/setting/utils';
const { t } = useI18n();
const tableStore = useTableStore();
const userVisible = ref(false);
@ -210,7 +210,7 @@
slotName: 'operation',
dataIndex: 'operation',
fixed: 'right',
width: hasOperationPermission.value ? 230 : 50,
width: hasOperationPermission.value ? 250 : 50,
},
];
@ -250,6 +250,11 @@
});
const tableActions: ActionsItem[] = [
{
label: 'common.end',
eventTag: 'end',
permission: ['ORGANIZATION_PROJECT:READ+UPDATE'],
},
{
label: 'system.user.delete',
eventTag: 'delete',
@ -388,8 +393,16 @@
};
const handleMoreAction = (tag: ActionsItem, record: TableData) => {
if (tag.eventTag === 'delete') {
const { eventTag } = tag;
switch (eventTag) {
case 'end':
handleEnableOrDisableProject(record, false);
break;
case 'delete':
handleDelete(record);
break;
default:
break;
}
};

View File

@ -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) {

View File

@ -53,11 +53,9 @@
<MsButton v-permission="['SYSTEM_ORGANIZATION_PROJECT:READ+ADD_MEMBER']" @click="showAddUserModal(record)">{{
t('system.organization.addMember')
}}</MsButton>
<MsButton
v-permission="['SYSTEM_ORGANIZATION_PROJECT:READ+UPDATE']"
@click="handleEnableOrDisableProject(record, false)"
>{{ t('common.end') }}</MsButton
>
<MsButton v-permission="['PROJECT_BASE_INFO:READ']" @click="enterProject(record.id, record.organizationId)">{{
t('system.project.enterProject')
}}</MsButton>
<MsTableMoreAction
v-permission="['SYSTEM_ORGANIZATION_PROJECT:READ+DELETE']"
:list="tableActions"
@ -113,6 +111,8 @@
import { CreateOrUpdateSystemProjectParams, OrgProjectTableItem } from '@/models/setting/system/orgAndProject';
import { ColumnEditTypeEnum, TableKeyEnum } from '@/enums/tableEnum';
import { enterProject } from '@/views/setting/utils';
export interface SystemOrganizationProps {
keyword: string;
}
@ -188,7 +188,7 @@
slotName: 'operation',
dataIndex: 'operation',
fixed: 'right',
width: hasOperationPermission.value ? 230 : 50,
width: hasOperationPermission.value ? 250 : 50,
},
];
@ -229,6 +229,11 @@
});
const tableActions: ActionsItem[] = [
{
label: 'common.end',
eventTag: 'end',
permission: ['SYSTEM_ORGANIZATION_PROJECT:READ+UPDATE'],
},
{
label: 'system.user.delete',
eventTag: 'delete',
@ -360,8 +365,16 @@
});
};
const handleMoreAction = (tag: ActionsItem, record: TableData) => {
if (tag.eventTag === 'delete') {
const { eventTag } = tag;
switch (eventTag) {
case 'end':
handleEnableOrDisableProject(record, false);
break;
case 'delete':
handleDelete(record);
break;
default:
break;
}
};

View File

@ -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') }
),
]),
});
}
}