From 37fe90457db080f8d72e522030c1339c0d5dfe5a Mon Sep 17 00:00:00 2001 From: RubyLiu Date: Wed, 25 Oct 2023 18:11:11 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=A1=A8=E6=A0=BC=E8=A1=8C=E5=86=85?= =?UTF-8?q?=E7=BC=96=E8=BE=91=E4=BF=AE=E6=94=B9=E5=A4=B1=E8=B4=A5=E6=81=A2?= =?UTF-8?q?=E5=A4=8D=E5=8E=9F=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/modules/setting/organizationAndProject.ts | 14 ++++++++++++++ .../api/requrls/setting/organizationAndProject.ts | 6 ++++++ .../src/components/pure/ms-table/base-table.vue | 13 +++++++++---- frontend/src/components/pure/ms-table/useTable.ts | 9 +++++---- .../setting/organization/project/orgProject.vue | 7 ++++--- .../components/systemOrganization.vue | 7 ++++--- .../components/systemProject.vue | 7 ++++--- 7 files changed, 46 insertions(+), 17 deletions(-) diff --git a/frontend/src/api/modules/setting/organizationAndProject.ts b/frontend/src/api/modules/setting/organizationAndProject.ts index d9e56fdeb8..e146d3ec42 100644 --- a/frontend/src/api/modules/setting/organizationAndProject.ts +++ b/frontend/src/api/modules/setting/organizationAndProject.ts @@ -29,6 +29,11 @@ export function createOrUpdateOrg(data: CreateOrUpdateSystemOrgParams | CreateOr return MSR.post({ url: data.id ? orgUrl.postModifyOrgUrl : orgUrl.postAddOrgUrl, data }); } +// 修改组织名称 +export function modifyOrgName(data: { id: string; name: string }) { + return MSR.post({ url: orgUrl.postModifyOrgNameUrl, data }); +} + // 删除组织 export function deleteOrg(id: string) { return MSR.get({ url: `${orgUrl.getDeleteOrgUrl}${id}` }); @@ -104,6 +109,10 @@ export function getSystemOrgOption() { export function createOrUpdateProject(data: Partial) { return MSR.post({ url: data.id ? orgUrl.postModifyProjectUrl : orgUrl.postAddProjectUrl, data }); } +// 修改项目名称 +export function renameProject(data: { id: string; name: string; organizationId: string }) { + return MSR.post({ url: orgUrl.postModifyProjectNameUrl, data }); +} // 创建项目或组织时获取所有用户 export function getAllUser() { @@ -141,6 +150,11 @@ export function createOrUpdateProjectByOrg(data: CreateOrUpdateOrgProjectParams) return MSR.post({ url: data.id ? orgUrl.postModifyProjectByOrgUrl : orgUrl.postAddProjectByOrgUrl, data }); } +// 修改项目名称 +export function renameProjectByOrg(data: { id: string; name: string; organizationId: string }) { + return MSR.post({ url: orgUrl.postModifyProjectNameByOrgUrl, data }); +} + // 组织-获取项目下的成员列表 export function postProjectMemberByProjectId(data: TableQueryParams) { return MSR.post({ url: orgUrl.postProjectMemberByOrgIdUrl, data }); diff --git a/frontend/src/api/requrls/setting/organizationAndProject.ts b/frontend/src/api/requrls/setting/organizationAndProject.ts index b611c96011..23bb951f28 100644 --- a/frontend/src/api/requrls/setting/organizationAndProject.ts +++ b/frontend/src/api/requrls/setting/organizationAndProject.ts @@ -1,6 +1,8 @@ // 系统-组织 // 修改组织 export const postModifyOrgUrl = '/system/organization/update'; +// 修改组织名称 +export const postModifyOrgNameUrl = '/system/organization/rename'; // 获取系统下所有组织-下拉选项 export const postOrgOptionsUrl = '/system/organization/option/all'; // 获取系统下所有组织-Table @@ -35,6 +37,8 @@ export const postProjectTableUrl = '/system/project/page'; export const postProjectMemberUrl = '/system/project/member-list'; // 添加项目 export const postAddProjectUrl = '/system/project/add'; +// 修改项目名称 +export const postModifyProjectNameUrl = '/system/project/rename'; // 添加项目成员 export const postAddProjectMemberUrl = '/system/project/add-member'; // 撤销项目 @@ -67,6 +71,8 @@ export const postProjectTableByOrgIdUrl = '/organization/project/page'; // 获取项目下的成员列表 export const postProjectMemberByOrgIdUrl = '/organization/project/member-list'; // 添加项目 +// 修改项目名称 +export const postModifyProjectNameByOrgUrl = '/organization/project/rename'; export const postAddProjectByOrgUrl = '/organization/project/add'; // 添加项目成员 export const postAddProjectMemberByOrgUrl = '/organization/project/add-members'; diff --git a/frontend/src/components/pure/ms-table/base-table.vue b/frontend/src/components/pure/ms-table/base-table.vue index 0cbf73c62c..f0cf5ea043 100644 --- a/frontend/src/components/pure/ms-table/base-table.vue +++ b/frontend/src/components/pure/ms-table/base-table.vue @@ -224,7 +224,7 @@ (e: 'batchAction', value: BatchActionParams, queryParams: BatchActionQueryParams): void; (e: 'pageChange', value: number): void; (e: 'pageSizeChange', value: number): void; - (e: 'rowNameChange', value: TableData): void; + (e: 'rowNameChange', value: TableData, cb: (v: boolean) => void): void; (e: 'rowSelectChange', key: string): void; (e: 'selectAllChange', value: SelectAllEnum): void; (e: 'sorterChange', value: { [key: string]: string }): void; @@ -349,9 +349,14 @@ currentEditValue.value = ''; } else { // 触发的是Enter - emit('rowNameChange', record); - isEnter.value = true; - editActiveKey.value = ''; + emit('rowNameChange', record, (v: boolean) => { + if (!v) { + // 如果接口报错,没有成功的修改,恢复旧值 + record[dataIndex] = currentEditValue.value; + } + isEnter.value = true; + editActiveKey.value = ''; + }); } }; diff --git a/frontend/src/components/pure/ms-table/useTable.ts b/frontend/src/components/pure/ms-table/useTable.ts index eacf226353..ef0ea59d1f 100644 --- a/frontend/src/components/pure/ms-table/useTable.ts +++ b/frontend/src/components/pure/ms-table/useTable.ts @@ -199,6 +199,7 @@ export default function useTableProps( } } catch (err) { setTableErrorStatus('error'); + propsRes.value.data = []; } finally { setLoading(false); // debug 模式下打印属性 @@ -233,9 +234,8 @@ export default function useTableProps( return data; } } catch (err) { - // eslint-disable-next-line no-console - console.log(err); setTableErrorStatus('error'); + propsRes.value.data = []; } finally { setLoading(false); } @@ -311,9 +311,10 @@ export default function useTableProps( } }, // 编辑触发 - rowNameChange: (record: T) => { + rowNameChange: async (record: T, cb: (v: boolean) => void) => { if (saveCallBack) { - saveCallBack(record); + const res = await saveCallBack(record); + cb(res); } }, // 重置排序 diff --git a/frontend/src/views/setting/organization/project/orgProject.vue b/frontend/src/views/setting/organization/project/orgProject.vue index 72d9d4dc2c..b8d525a02a 100644 --- a/frontend/src/views/setting/organization/project/orgProject.vue +++ b/frontend/src/views/setting/organization/project/orgProject.vue @@ -76,10 +76,10 @@ import UserDrawer from './components/userDrawer.vue'; import { - createOrUpdateProjectByOrg, deleteProjectByOrg, enableOrDisableProjectByOrg, postProjectTableByOrg, + renameProjectByOrg, revokeDeleteProjectByOrg, } from '@/api/modules/setting/organizationAndProject'; import { useI18n } from '@/hooks/useI18n'; @@ -163,10 +163,11 @@ const handleNameChange = async (record: OrgProjectTableItem) => { try { - await createOrUpdateProjectByOrg(record); + await renameProjectByOrg({ id: record.id, name: record.name, organizationId: record.organizationId }); Message.success(t('common.updateSuccess')); + return true; } catch (error) { - Message.error(t('common.updateFailed')); + return false; } }; diff --git a/frontend/src/views/setting/system/organizationAndProject/components/systemOrganization.vue b/frontend/src/views/setting/system/organizationAndProject/components/systemOrganization.vue index bf21e9c868..cabea4f5f4 100644 --- a/frontend/src/views/setting/system/organizationAndProject/components/systemOrganization.vue +++ b/frontend/src/views/setting/system/organizationAndProject/components/systemOrganization.vue @@ -68,9 +68,9 @@ import UserDrawer from './userDrawer.vue'; import { - createOrUpdateOrg, deleteOrg, enableOrDisableOrg, + modifyOrgName, postOrgTable, revokeDeleteOrg, } from '@/api/modules/setting/organizationAndProject'; @@ -150,10 +150,11 @@ const handleNameChange = async (record: OrgProjectTableItem) => { try { - await createOrUpdateOrg(record); + await modifyOrgName({ id: record.id, name: record.name }); Message.success(t('common.updateSuccess')); + return true; } catch (error) { - Message.error(t('common.updateFailed')); + return false; } }; diff --git a/frontend/src/views/setting/system/organizationAndProject/components/systemProject.vue b/frontend/src/views/setting/system/organizationAndProject/components/systemProject.vue index 76c196b543..d10fe93a98 100644 --- a/frontend/src/views/setting/system/organizationAndProject/components/systemProject.vue +++ b/frontend/src/views/setting/system/organizationAndProject/components/systemProject.vue @@ -62,10 +62,10 @@ import UserDrawer from './userDrawer.vue'; import { - createOrUpdateProject, deleteProject, enableOrDisableProject, postProjectTable, + renameProject, revokeDeleteProject, } from '@/api/modules/setting/organizationAndProject'; import { useI18n } from '@/hooks/useI18n'; @@ -148,10 +148,11 @@ const handleNameChange = async (record: OrgProjectTableItem) => { try { - await createOrUpdateProject(record); + await renameProject({ id: record.id, name: record.name, organizationId: record.organizationId }); Message.success(t('common.updateSuccess')); + return true; } catch (error) { - Message.error(t('common.updateFailed')); + return false; } };