This commit is contained in:
@@ -131,18 +131,34 @@
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<ElEmpty v-if="filteredAvailableRoles.length === 0" description="暂无角色" />
|
||||
<ElRadioGroup v-else v-model="roleToAdd" class="role-list">
|
||||
<div v-for="role in filteredAvailableRoles" :key="role.ID" class="role-item">
|
||||
<ElRadio :label="role.ID" :disabled="selectedRoles.includes(role.ID)">
|
||||
<span class="role-info">
|
||||
<span>{{ role.role_name }}</span>
|
||||
<ElTag :type="role.role_type === 1 ? 'primary' : 'success'" size="small">
|
||||
{{ role.role_type === 1 ? '平台角色' : '客户角色' }}
|
||||
</ElTag>
|
||||
</span>
|
||||
</ElRadio>
|
||||
</div>
|
||||
</ElRadioGroup>
|
||||
<template v-else-if="isPlatformUser">
|
||||
<ElCheckboxGroup v-model="rolesToAdd" class="role-list">
|
||||
<div v-for="role in filteredAvailableRoles" :key="role.ID" class="role-item">
|
||||
<ElCheckbox :label="role.ID" :disabled="selectedRoles.includes(role.ID)">
|
||||
<span class="role-info">
|
||||
<span>{{ role.role_name }}</span>
|
||||
<ElTag :type="role.role_type === 1 ? 'primary' : 'success'" size="small">
|
||||
{{ role.role_type === 1 ? '平台角色' : '客户角色' }}
|
||||
</ElTag>
|
||||
</span>
|
||||
</ElCheckbox>
|
||||
</div>
|
||||
</ElCheckboxGroup>
|
||||
</template>
|
||||
<template v-else>
|
||||
<ElRadioGroup v-model="roleToAdd" class="role-list">
|
||||
<div v-for="role in filteredAvailableRoles" :key="role.ID" class="role-item">
|
||||
<ElRadio :label="role.ID" :disabled="selectedRoles.includes(role.ID)">
|
||||
<span class="role-info">
|
||||
<span>{{ role.role_name }}</span>
|
||||
<ElTag :type="role.role_type === 1 ? 'primary' : 'success'" size="small">
|
||||
{{ role.role_type === 1 ? '平台角色' : '客户角色' }}
|
||||
</ElTag>
|
||||
</span>
|
||||
</ElRadio>
|
||||
</div>
|
||||
</ElRadioGroup>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -152,7 +168,7 @@
|
||||
type="primary"
|
||||
:icon="'ArrowRight'"
|
||||
@click="addRoles"
|
||||
:disabled="!roleToAdd"
|
||||
:disabled="isPlatformUser ? rolesToAdd.length === 0 : !roleToAdd"
|
||||
>
|
||||
分配
|
||||
</ElButton>
|
||||
@@ -205,7 +221,16 @@
|
||||
<script setup lang="ts">
|
||||
import { h } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { FormInstance, ElSwitch, ElCheckbox, ElCheckboxGroup, ElTag, ElEmpty } from 'element-plus'
|
||||
import {
|
||||
FormInstance,
|
||||
ElSwitch,
|
||||
ElCheckbox,
|
||||
ElCheckboxGroup,
|
||||
ElTag,
|
||||
ElEmpty,
|
||||
ElRadioGroup,
|
||||
ElRadio
|
||||
} from 'element-plus'
|
||||
import { ElMessageBox, ElMessage } from 'element-plus'
|
||||
import type { FormRules } from 'element-plus'
|
||||
import { useCheckedColumns } from '@/composables/useCheckedColumns'
|
||||
@@ -232,10 +257,14 @@
|
||||
const currentAccountType = ref<number>(0)
|
||||
const selectedRoles = ref<number[]>([])
|
||||
const allRoles = ref<PlatformRole[]>([])
|
||||
const roleToAdd = ref<number | undefined>(undefined)
|
||||
const rolesToAdd = ref<number[]>([]) // 多选时使用
|
||||
const roleToAdd = ref<number | undefined>(undefined) // 单选时使用
|
||||
const leftRoleFilter = ref('')
|
||||
const rightRoleFilter = ref('')
|
||||
|
||||
// 是否为平台用户(平台用户可多选,其他单选)
|
||||
const isPlatformUser = computed(() => currentAccountType.value === 2)
|
||||
|
||||
// 定义表单搜索初始值
|
||||
const initialSearchState = {
|
||||
name: '',
|
||||
@@ -648,6 +677,7 @@
|
||||
currentAccountName.value = row.username
|
||||
currentAccountType.value = row.user_type
|
||||
selectedRoles.value = []
|
||||
rolesToAdd.value = []
|
||||
roleToAdd.value = undefined
|
||||
leftRoleFilter.value = ''
|
||||
rightRoleFilter.value = ''
|
||||
@@ -671,17 +701,26 @@
|
||||
}
|
||||
}
|
||||
|
||||
// 添加角色(单选)
|
||||
// 添加角色
|
||||
const addRoles = async () => {
|
||||
if (!roleToAdd.value) return
|
||||
|
||||
try {
|
||||
// 新角色会替换之前的角色
|
||||
const newRoles = [roleToAdd.value]
|
||||
let newRoles: number[]
|
||||
|
||||
// 平台用户可以分配多个角色,其他用户只能分配一个角色
|
||||
if (isPlatformUser.value) {
|
||||
if (rolesToAdd.value.length === 0) return
|
||||
// 平台用户可以分配多个角色
|
||||
newRoles = [...new Set([...selectedRoles.value, ...rolesToAdd.value])]
|
||||
} else {
|
||||
// 其他用户只能分配一个角色(单选)
|
||||
if (!roleToAdd.value) return
|
||||
newRoles = [...selectedRoles.value, roleToAdd.value]
|
||||
}
|
||||
|
||||
await AccountService.assignRolesToAccount(currentAccountId.value, newRoles)
|
||||
|
||||
selectedRoles.value = newRoles
|
||||
rolesToAdd.value = []
|
||||
roleToAdd.value = undefined
|
||||
|
||||
ElMessage.success('角色分配成功')
|
||||
|
||||
Reference in New Issue
Block a user