2024-10-05 19:19:35 +08:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { onMounted, ref } from 'vue';
|
|
|
|
import { useRoleStore } from '@/store/system/role';
|
|
|
|
import { userMenuStore } from '@/store/system/menu';
|
2024-10-17 15:07:45 +08:00
|
|
|
import { $t } from '@/plugins/i18n';
|
2024-10-05 19:19:35 +08:00
|
|
|
|
|
|
|
const props = defineProps({
|
|
|
|
routerId: { type: String as PropType<String> },
|
|
|
|
});
|
|
|
|
|
|
|
|
const roleStore = useRoleStore();
|
|
|
|
const menuStore = userMenuStore();
|
|
|
|
// 分配的角色
|
|
|
|
const assignRoles = ref([]);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* * 根据用户id获取当前用户角色
|
|
|
|
*/
|
|
|
|
const getRoleListByRouterId = async () => {
|
|
|
|
// 初始化值为空数组
|
|
|
|
assignRoles.value = [];
|
|
|
|
|
|
|
|
// 根据用户id查询角色信息
|
|
|
|
const routerId = props.routerId;
|
|
|
|
assignRoles.value = await menuStore.getRoleListByRouterId({ routerId });
|
|
|
|
};
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
roleStore.getAllRoles();
|
|
|
|
getRoleListByRouterId();
|
|
|
|
});
|
|
|
|
|
|
|
|
defineExpose({ assignRoles });
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div class="flex justify-center">
|
|
|
|
<el-transfer
|
|
|
|
v-model="assignRoles"
|
2024-10-17 15:07:45 +08:00
|
|
|
:button-texts="[$t('take_back'), $t('add')]"
|
2024-10-05 19:19:35 +08:00
|
|
|
:data="roleStore.allRoleList"
|
2024-10-17 15:07:45 +08:00
|
|
|
:filter-placeholder="$t('Searching_for_router')"
|
|
|
|
:format="{ noChecked: `${$t('total')} $\{total}`, hasChecked: '${checked}/${total}' }"
|
|
|
|
:titles="[$t('not_added'), $t('added')]"
|
2024-10-05 19:19:35 +08:00
|
|
|
class="m-3"
|
|
|
|
filterable
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</template>
|