Add role label when sharing

This commit is contained in:
xue jiahao
2024-12-16 11:12:50 +08:00
parent 35270e32f5
commit 78e7f1c840
2 changed files with 46 additions and 15 deletions

View File

@@ -18,11 +18,17 @@
:options="canSharedUserFilteredOptions" :options="canSharedUserFilteredOptions"
clearable clearable
:placeholder="canSharedUserFilter ? '' : domain.domainActive ? '権限を付与するユーザーを選択' : 'ドメインが無効なため、権限を付与できません'" :placeholder="canSharedUserFilter ? '' : domain.domainActive ? '権限を付与するユーザーを選択' : 'ドメインが無効なため、権限を付与できません'"
@filter="filterFn" @filter="filterFn">
:display-value="canSharedUserFilter?`${canSharedUserFilter.fullName} ${canSharedUserFilter.email}`:''">
<template v-slot:selected-item="scope">
<span v-if="canSharedUserFilter">
{{ canSharedUserFilter.fullName }} {{ canSharedUserFilter.email }}
<q-badge v-if="isOwner(scope.opt.id)" color="purple">所有者</q-badge>
</span>
</template>
<template v-slot:after> <template v-slot:after>
<q-btn :disable="!canSharedUserFilter" :loading="addLoading" label="付与" color="primary" @click="shareTo(canSharedUserFilter as IUserDisplay)" /> <q-btn :disable="!canSharedUserFilter" :loading="addLoading" label="付与" color="primary" @click="shareTo(canSharedUserFilter as IUserDisplayWithShareRole)" />
</template> </template>
<template v-slot:option="scope"> <template v-slot:option="scope">
@@ -30,14 +36,28 @@
<q-item-section avatar>{{scope.opt.id}}</q-item-section> <q-item-section avatar>{{scope.opt.id}}</q-item-section>
<q-item-section>{{scope.opt.fullName}}</q-item-section> <q-item-section>{{scope.opt.fullName}}</q-item-section>
<q-item-section>{{scope.opt.email}}</q-item-section> <q-item-section>{{scope.opt.email}}</q-item-section>
<q-item-section side>
<div style="width: 4em;">
<q-badge v-if="isOwner(scope.opt.id)" color="purple">所有者</q-badge>
</div>
</q-item-section>
</q-item> </q-item>
</template> </template>
</q-select> </q-select>
<sharing-user-list class="q-mt-md" style="height: 330px" :users="sharedUsers" :loading="loading" title="ドメイン利用権限を持つユーザー"> <sharing-user-list class="q-mt-md" style="height: 330px" :users="sharedUsers" :loading="loading" title="ドメイン利用権限を持つユーザー">
<template v-slot:body-cell-role="{ row }">
<q-td>
<q-badge v-if="row.role == 2" color="purple">所有者</q-badge>
<!-- <q-badge v-else-if="row.id === domain.owner.id" color="primary">管理者</q-badge> -->
</q-td>
</template>
<template v-slot:actions="{ row }"> <template v-slot:actions="{ row }">
<q-btn title="解除" flat color="primary" padding="xs" size="1em" :loading="row.id == removingUser?.id" icon="person_off" @click="removeShareTo(row)" /> <q-btn round title="解除" flat color="primary" padding="xs" size="1em" :loading="row.isRemoving" icon="person_off" @click="removeShareTo(row)" />
</template> </template>
</sharing-user-list> </sharing-user-list>
</q-card-section> </q-card-section>
<q-card-actions align="right" class="text-primary"> <q-card-actions align="right" class="text-primary">
@@ -62,7 +82,8 @@ interface Props {
} }
interface IUserDisplayWithShareRole extends IUserDisplay { interface IUserDisplayWithShareRole extends IUserDisplay {
role: number; isRemoving: boolean;
role: number; // 2: 所有者1: 管理者, 0: 利用者
} }
const props = defineProps<Props>(); const props = defineProps<Props>();
@@ -73,7 +94,6 @@ const emit = defineEmits<{
}>(); }>();
const addLoading = ref(false); const addLoading = ref(false);
const removingUser = ref<IUserDisplayWithShareRole>();
const loading = ref(true); const loading = ref(true);
const visible = ref(props.modelValue); const visible = ref(props.modelValue);
@@ -158,12 +178,11 @@ const shareTo = async (user: IUserDisplayWithShareRole) => {
} }
const removeShareTo = async (user: IUserDisplayWithShareRole) => { const removeShareTo = async (user: IUserDisplayWithShareRole) => {
removingUser.value = user;
loading.value = true; loading.value = true;
user.isRemoving = true;
await api.delete(`api/domain/${props.domain.id}/${user.id}`) await api.delete(`api/domain/${props.domain.id}/${user.id}`)
await loadShared(); await loadShared();
loading.value = false; loading.value = false;
removingUser.value = undefined;
}; };
const loadShared = async () => { const loadShared = async () => {
@@ -175,7 +194,7 @@ const loadShared = async () => {
const val = itemToDisplay(item); const val = itemToDisplay(item);
sharedUsersIdSet.add(val.id); sharedUsersIdSet.add(val.id);
return val; return val;
}); }).reverse().sort((a: IUserDisplayWithShareRole, b: IUserDisplayWithShareRole) => b.role - a.role);
canSharedUsers.value = allUsers.value.filter((item) => !sharedUsersIdSet.has(item.id)); canSharedUsers.value = allUsers.value.filter((item) => !sharedUsersIdSet.has(item.id));
canSharedUserFilteredOptions.value = canSharedUsers.value; canSharedUserFilteredOptions.value = canSharedUsers.value;
@@ -197,6 +216,10 @@ const getUsers = async () => {
loading.value = false; loading.value = false;
} }
function isOwner(userId: number) {
return userId === props.domain.owner.id
}
const itemToDisplay = (item: IUser) => { const itemToDisplay = (item: IUser) => {
return { return {
id: item.id, id: item.id,
@@ -207,7 +230,7 @@ const itemToDisplay = (item: IUser) => {
email: item.email, email: item.email,
isSuperuser: item.is_superuser, isSuperuser: item.is_superuser,
isActive: item.is_active, isActive: item.is_active,
role: 0, // TODO role: isOwner(item.id) ? 2 : 0, // TODO
} as IUserDisplayWithShareRole } as IUserDisplayWithShareRole
} }
</script> </script>

View File

@@ -10,10 +10,17 @@
</q-input> </q-input>
</template> </template>
<template v-slot:body-cell-actions="props"> <template v-for="col in columns" :key="col.name" v-slot:[`body-cell-${col.name}`]="props">
<q-td auto-width :props="props"> <slot :name="`body-cell-${col.name}`" :row="props.row" :column="props.col">
<slot name="actions" :row="props.row"></slot> <!-- 默认内容 -->
</q-td> <q-td v-if="col.name !== 'actions'" :props="props" >
<span>{{ props.row[col.name] }}</span>
</q-td>
<!-- actions -->
<q-td v-else auto-width :props="props">
<slot name="actions" :row="props.row"></slot>
</q-td>
</slot>
</template> </template>
</q-table> </q-table>
</template> </template>
@@ -37,9 +44,10 @@ const columns = [
{ name: 'id', label: 'ID', field: 'id', align: 'left', sortable: true }, { name: 'id', label: 'ID', field: 'id', align: 'left', sortable: true },
{ name: 'fullName', label: '名前', field: 'fullName', align: 'left', sortable: true }, { name: 'fullName', label: '名前', field: 'fullName', align: 'left', sortable: true },
{ name: 'email', label: '電子メール', field: 'email', align: 'left', sortable: true }, { name: 'email', label: '電子メール', field: 'email', align: 'left', sortable: true },
{ name: 'role', label: '権限', field: 'role', align: 'left', sortable: true },
{ name: 'actions', label: '', field: 'actions', sortable: false }, { name: 'actions', label: '', field: 'actions', sortable: false },
]; ];
const filter = ref(''); const filter = ref('');
const pagination = ref({ sortBy: 'id', descending: true, rowsPerPage: 10 }); const pagination = ref({ rowsPerPage: 10 });
</script> </script>