Skip to content

Commit

Permalink
feat(user): add organization preview to user page
Browse files Browse the repository at this point in the history
  • Loading branch information
colinin committed May 31, 2024
1 parent 945a486 commit 96f5ce2
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 6 deletions.
15 changes: 15 additions & 0 deletions apps/vue/src/api/identity/users/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import {
UpdateUser,
GetUserPagedRequest,
UserClaim,
IdentityUserOrganizationUnitUpdateDto,
} from './model';
import { CreateIdentityClaim, UpdateIdentityClaim } from '../claims/model';
import { Role } from '../roles/model';
import { OrganizationUnit } from '../organization-units/model';

export const create = (input: CreateUser) => {
return defHttp.post<User>({
Expand Down Expand Up @@ -106,6 +108,19 @@ export const unlock = (id: string) => {
});
};

export const getOrganizationUnits = (id: string) => {
return defHttp.get<ListResultDto<OrganizationUnit>>({
url: `/api/identity/users/${id}/organization-units`,
});
};

export const setOrganizationUnits = (id: string, input: IdentityUserOrganizationUnitUpdateDto) => {
return defHttp.put<ListResultDto<OrganizationUnit>>({
url: `/api/identity/users/${id}/organization-units`,
data: input,
});
};

export const removeOrganizationUnit = (id: string, ouId: string) => {
return defHttp.delete<void>({
url: `/api/identity/users/${id}/organization-units/${ouId}`,
Expand Down
4 changes: 4 additions & 0 deletions apps/vue/src/api/identity/users/model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export interface SetPassword {
password: string;
}

export interface IdentityUserOrganizationUnitUpdateDto {
organizationUnitIds: string[]
}

/** 用户对象 */
export interface User extends FullAuditedEntityDto<string>, IUser, IHasConcurrencyStamp {
/** 租户标识 */
Expand Down
19 changes: 18 additions & 1 deletion apps/vue/src/views/identity/user/components/UserModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
</TabPane>
<TabPane key="role" :tab="L('Roles')">
<Transfer
:disabled="hasPermission('AbpIdentity.Users.ManageRoles')"
class="tree-transfer"
:dataSource="roleDataSource"
:targetKeys="userRef.roleNames"
Expand All @@ -57,6 +58,18 @@
@change="handleRoleChange"
/>
</TabPane>
<TabPane key="organization-unit" :tab="L('OrganizationUnit')">
<Tree
checkable
disabled
:tree-data="getOrganizationUnitsTree"
:checked-keys="hasInOrganizationUnitKeys"
:field-names="{
title: 'displayName',
key: 'code',
}"
/>
</TabPane>
</Tabs>
</Form>
</BasicModal>
Expand All @@ -65,12 +78,14 @@
<script lang="ts" setup>
import { ref } from 'vue';
import { useMessage } from '/@/hooks/web/useMessage';
import { usePermission } from '/@/hooks/web/usePermission';
import { useLocalization } from '/@/hooks/abp/useLocalization';
import { Checkbox, Input, Form, Tabs, Transfer } from 'ant-design-vue';
import { Checkbox, Input, Form, Tabs, Transfer, Tree } from 'ant-design-vue';
import { Input as BInput } from '/@/components/Input';
import { FormActionType } from '/@/components/Form';
import { BasicModal, useModalInner } from '/@/components/Modal';
import { useUserForm } from '../hooks/useUserForm';
import { useOrganizationUnit } from '../hooks/useOrganizationUnit';
const FormItem = Form.Item;
const TabPane = Tabs.TabPane;
Expand All @@ -79,6 +94,7 @@
const emits = defineEmits(['register', 'change']);
const { createMessage } = useMessage();
const { hasPermission } = usePermission();
const { L } = useLocalization(['AbpIdentity', 'AbpIdentityServer']);
const activedTab = ref('info');
const userRef = ref<Recordable>({});
Expand All @@ -88,6 +104,7 @@
userRef,
formElRef,
});
const { getOrganizationUnitsTree, hasInOrganizationUnitKeys } = useOrganizationUnit({ userRef });
const [registerModal, { closeModal, changeOkLoading }] = useModalInner(async (val) => {
activedTab.value = 'info';
getUser(val.id);
Expand Down
44 changes: 44 additions & 0 deletions apps/vue/src/views/identity/user/hooks/useOrganizationUnit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import type { Ref } from 'vue';
import { computed, ref, onMounted, watchEffect } from 'vue';
import { getAll as getAllOrganizationUnits } from '/@/api/identity/organization-units';
import { OrganizationUnit } from '/@/api/identity/organization-units/model';
import { getOrganizationUnits } from '/@/api/identity/users';
import { listToTree } from '/@/utils/helper/treeHelper';

interface UseOrganizationUnit {
userRef: Ref<Recordable | undefined>;
}

export function useOrganizationUnit({ userRef }: UseOrganizationUnit) {
const organizationUnits = ref<OrganizationUnit[]>([]);
const hasInOrganizationUnitKeys = ref<string[]>([]);

const getOrganizationUnitsTree = computed(() => {
const ouTree = listToTree(organizationUnits.value, {
id: 'id',
pid: 'parentId',
children: 'children',
});
return ouTree;
});

async function fetchOrganizationUnits() {
const { items } = await getAllOrganizationUnits();
organizationUnits.value = items;
}

async function fetchUserOrganizationUnits(userId: string) {
const { items } = await getOrganizationUnits(userId);
hasInOrganizationUnitKeys.value = items.map((item) => item.code);
}

onMounted(fetchOrganizationUnits);
watchEffect(() => {
userRef.value?.id && fetchUserOrganizationUnits(userRef.value.id);
});

return {
getOrganizationUnitsTree,
hasInOrganizationUnitKeys,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<TargetFramework>net8.0</TargetFramework> <!-- 或其他适合的框架 -->
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageId>LINGYUN.Abp.MicroService.Templates</PackageId>
<Version>8.1.1.1</Version>
<Version>8.1.3</Version>
<Authors>[email protected]</Authors>
<Description>Abp framework micro-service template</Description>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
Expand Down
4 changes: 2 additions & 2 deletions aspnet-core/templates/content/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<PropertyGroup>
<DotNetCoreCAPPackageVersion>8.1.1</DotNetCoreCAPPackageVersion>
<ElsaPackageVersion>2.14.1</ElsaPackageVersion>
<VoloAbpPackageVersion>8.1.2</VoloAbpPackageVersion>
<LINGYUNAbpPackageVersion>8.1.2</LINGYUNAbpPackageVersion>
<VoloAbpPackageVersion>8.1.3</VoloAbpPackageVersion>
<LINGYUNAbpPackageVersion>8.1.3</LINGYUNAbpPackageVersion>
<MicrosoftExtensionsPackageVersion>8.0.0</MicrosoftExtensionsPackageVersion>
<MicrosoftAspNetCorePackageVersion>8.0.0</MicrosoftAspNetCorePackageVersion>
<MicrosoftEntityFrameworkCorePackageVersion>8.0.0</MicrosoftEntityFrameworkCorePackageVersion>
Expand Down
4 changes: 2 additions & 2 deletions aspnet-core/templates/content/common.props
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Project>
<PropertyGroup>
<LangVersion>latest</LangVersion>
<Version>8.1.2</Version>
<Version>8.1.3</Version>
<Authors>colin</Authors>
<NoWarn>$(NoWarn);CS1591;CS0436;CS8618;NU1803</NoWarn>
<PackageProjectUrl>https://github.com/colinin/abp-next-admin</PackageProjectUrl>
<PackageOutputPath>$(SolutionDir)LocalNuget</PackageOutputPath>
<PackageVersion>8.1.2</PackageVersion>
<PackageVersion>8.1.3</PackageVersion>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/colinin/abp-next-admin</RepositoryUrl>
Expand Down

0 comments on commit 96f5ce2

Please sign in to comment.