This commit is contained in:
xue jiahao
2024-12-16 16:58:57 +08:00
parent 736c722eb7
commit fef9e74ba1
3 changed files with 30 additions and 15 deletions

View File

@@ -1,11 +1,15 @@
<template>
<q-badge v-if="isOwner" color="purple">所有者</q-badge>
<q-badge v-else-if="isManager" color="primary">管理者</q-badge>
<q-badge class="q-mr-xs" v-if="isOwner" color="secondary">所有者</q-badge>
<!-- <q-badge v-else-if="isManager" color="primary">管理者</q-badge> -->
<q-badge v-if="isSelf" color="purple">自分</q-badge>
</template>
<script setup lang="ts">
import { computed } from 'vue';
import { IDomainOwnerDisplay } from '../../types/DomainTypes';
import { useAuthStore } from 'stores/useAuthStore';
const authStore = useAuthStore();
interface Props {
user: { id: number };
@@ -14,6 +18,7 @@ interface Props {
const props = defineProps<Props>();
const isSelf = computed(() => props.user.id === (Number)(authStore.userId));
const isOwner = computed(() => props.user.id === props.domain.owner.id);
const isManager = computed(() => props.user.id === props.domain.owner.id); // TODO
</script>

View File

@@ -37,7 +37,7 @@
<q-item-section>{{scope.opt.fullName}}</q-item-section>
<q-item-section>{{scope.opt.email}}</q-item-section>
<q-item-section side>
<div style="width: 4em;">
<div style="width: 6.5em;">
<role-label :domain="domain" :user="scope.opt"></role-label>
</div>
</q-item-section>
@@ -47,7 +47,7 @@
<sharing-user-list class="q-mt-md" style="height: 330px" :users="sharedUsers" :loading="loading" :title="userListTitle">
<template v-slot:body-cell-role="{ row }">
<q-td>
<q-td auto-width>
<role-label :domain="domain" :user="row"></role-label>
</q-td>
</template>
@@ -84,6 +84,7 @@ interface Props {
domain: IDomainOwnerDisplay;
dialogTitle: string;
userListTitle: string;
hideSelf: boolean;
shareApi: (user: IUserDisplay, domain: IDomainOwnerDisplay) => Promise<any>;
removeSharedApi: (user: IUserDisplay, domain: IDomainOwnerDisplay) => Promise<any>;
getSharedApi: (domain: IDomainOwnerDisplay) => Promise<any>;
@@ -204,20 +205,28 @@ const loadShared = async () => {
loading.value = true;
sharedUsersIdSet.clear();
if(props.hideSelf) {
sharedUsersIdSet.add((Number)(authStore.userId));
}
const { data } = await props.getSharedApi(props.domain);
sharedUsers.value = data.data.map((item: IUser) => {
sharedUsers.value = data.data.reduce((arr: IUserDisplayWithShareRole[], item: IUser) => {
const val = itemToDisplay(item);
sharedUsersIdSet.add(val.id);
// for sort
if (isOwner(item.id)) {
val.role = 2;
} else if (isManager(item.id)) {
val.role = 1;
} else {
val.role = 0;
if(!sharedUsersIdSet.has(val.id)) {
sharedUsersIdSet.add(val.id);
// for sort
if (isOwner(val.id)) {
val.role = 2;
} else if (isManager(val.id)) {
val.role = 1;
} else {
val.role = 0;
}
arr.push(val);
}
return val;
}).reverse().sort((a: IUserDisplayWithShareRole, b: IUserDisplayWithShareRole) => b.role - a.role);
return arr;
}, []).sort((a: IUserDisplayWithShareRole, b: IUserDisplayWithShareRole) => b.role - a.role);
canSharedUsers.value = allUsers.value.filter((item) => !sharedUsersIdSet.has(item.id));
canSharedUserFilteredOptions.value = canSharedUsers.value;

View File

@@ -7,6 +7,7 @@
:remove-shared-api="removeSharedApi"
:get-shared-api="getSharedApi"
:model-value="modelValue"
hide-self
@update:modelValue="updateModelValue"
@close="close"
/>