This commit is contained in:
@@ -68,44 +68,6 @@
|
||||
>
|
||||
<ElOption label="超级管理员" :value="1" />
|
||||
<ElOption label="平台用户" :value="2" />
|
||||
<ElOption label="代理账号" :value="3" />
|
||||
<ElOption label="企业账号" :value="4" />
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
<ElFormItem v-if="dialogType === 'add' && formData.user_type === 3" label="关联店铺" prop="shop_id">
|
||||
<ElSelect
|
||||
v-model="formData.shop_id"
|
||||
placeholder="请输入店铺名称搜索"
|
||||
style="width: 100%"
|
||||
filterable
|
||||
remote
|
||||
:remote-method="handleShopSearch"
|
||||
clearable
|
||||
>
|
||||
<ElOption
|
||||
v-for="shop in shopList"
|
||||
:key="shop.id"
|
||||
:label="shop.shop_name"
|
||||
:value="shop.id"
|
||||
/>
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
<ElFormItem v-if="dialogType === 'add' && formData.user_type === 4" label="关联企业" prop="enterprise_id">
|
||||
<ElSelect
|
||||
v-model="formData.enterprise_id"
|
||||
placeholder="请输入企业名称搜索"
|
||||
style="width: 100%"
|
||||
filterable
|
||||
remote
|
||||
:remote-method="handleEnterpriseSearch"
|
||||
clearable
|
||||
>
|
||||
<ElOption
|
||||
v-for="enterprise in enterpriseList"
|
||||
:key="enterprise.id"
|
||||
:label="enterprise.enterprise_name"
|
||||
:value="enterprise.id"
|
||||
/>
|
||||
</ElSelect>
|
||||
</ElFormItem>
|
||||
</ElForm>
|
||||
@@ -124,6 +86,9 @@
|
||||
<span class="dialog-title">分配角色</span>
|
||||
<div class="account-info">
|
||||
<span class="account-name">{{ currentAccountName }}</span>
|
||||
<ElTag v-if="currentAccountType === 3" type="warning" size="small" style="margin-left: 8px">
|
||||
代理账号只能分配一个客户角色
|
||||
</ElTag>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -142,18 +107,11 @@
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<ElCheckboxGroup v-model="rolesToAdd" class="role-list">
|
||||
<div
|
||||
v-for="role in filteredAvailableRoles"
|
||||
:key="role.ID"
|
||||
class="role-item"
|
||||
>
|
||||
<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"
|
||||
>
|
||||
<ElTag :type="role.role_type === 1 ? 'primary' : 'success'" size="small">
|
||||
{{ role.role_type === 1 ? '平台角色' : '客户角色' }}
|
||||
</ElTag>
|
||||
</span>
|
||||
@@ -196,19 +154,11 @@
|
||||
>
|
||||
<span class="role-info">
|
||||
<span>{{ role.role_name }}</span>
|
||||
<ElTag
|
||||
:type="role.role_type === 1 ? 'primary' : 'success'"
|
||||
size="small"
|
||||
>
|
||||
<ElTag :type="role.role_type === 1 ? 'primary' : 'success'" size="small">
|
||||
{{ role.role_type === 1 ? '平台角色' : '客户角色' }}
|
||||
</ElTag>
|
||||
</span>
|
||||
<ElButton
|
||||
type="danger"
|
||||
size="small"
|
||||
link
|
||||
@click="removeSingleRole(role.ID)"
|
||||
>
|
||||
<ElButton type="danger" size="small" link @click="removeSingleRole(role.ID)">
|
||||
移除
|
||||
</ElButton>
|
||||
</div>
|
||||
@@ -256,6 +206,7 @@
|
||||
const roleSubmitLoading = ref(false)
|
||||
const currentAccountId = ref<number>(0)
|
||||
const currentAccountName = ref<string>('')
|
||||
const currentAccountType = ref<number>(0)
|
||||
const selectedRoles = ref<number[]>([])
|
||||
const allRoles = ref<PlatformRole[]>([])
|
||||
const rolesToAdd = ref<number[]>([])
|
||||
@@ -517,7 +468,7 @@
|
||||
{
|
||||
prop: 'operation',
|
||||
label: '操作',
|
||||
width: 200,
|
||||
width: 240,
|
||||
fixed: 'right',
|
||||
formatter: (row: any) => {
|
||||
const buttons = []
|
||||
@@ -525,7 +476,7 @@
|
||||
if (hasAuth('account:patch_role')) {
|
||||
buttons.push(
|
||||
h(ArtButtonTable, {
|
||||
icon: '',
|
||||
text: '分配角色',
|
||||
onClick: () => showRoleDialog(row)
|
||||
})
|
||||
)
|
||||
@@ -534,7 +485,7 @@
|
||||
if (hasAuth('account:edit')) {
|
||||
buttons.push(
|
||||
h(ArtButtonTable, {
|
||||
type: 'edit',
|
||||
text: '编辑',
|
||||
onClick: () => showDialog('edit', row)
|
||||
})
|
||||
)
|
||||
@@ -543,7 +494,7 @@
|
||||
if (hasAuth('account:delete')) {
|
||||
buttons.push(
|
||||
h(ArtButtonTable, {
|
||||
type: 'delete',
|
||||
text: '删除',
|
||||
onClick: () => deleteAccount(row)
|
||||
})
|
||||
)
|
||||
@@ -593,11 +544,23 @@
|
||||
}
|
||||
}
|
||||
|
||||
// 计算属性:过滤后的可分配角色
|
||||
// 计算属性:过滤后的可分配角色(根据账号类型过滤)
|
||||
const filteredAvailableRoles = computed(() => {
|
||||
if (!leftRoleFilter.value) return allRoles.value
|
||||
let roles = allRoles.value
|
||||
|
||||
// 根据账号类型过滤角色
|
||||
if (currentAccountType.value === 3) {
|
||||
// 代理账号:只显示客户角色
|
||||
roles = roles.filter((role) => role.role_type === 2)
|
||||
} else if (currentAccountType.value === 2) {
|
||||
// 平台用户:只显示平台角色
|
||||
roles = roles.filter((role) => role.role_type === 1)
|
||||
}
|
||||
|
||||
// 根据搜索关键词过滤
|
||||
if (!leftRoleFilter.value) return roles
|
||||
const keyword = leftRoleFilter.value.toLowerCase()
|
||||
return allRoles.value.filter((role) => role.role_name.toLowerCase().includes(keyword))
|
||||
return roles.filter((role) => role.role_name.toLowerCase().includes(keyword))
|
||||
})
|
||||
|
||||
// 计算属性:过滤后的已分配角色
|
||||
@@ -612,6 +575,7 @@
|
||||
const showRoleDialog = async (row: any) => {
|
||||
currentAccountId.value = row.id
|
||||
currentAccountName.value = row.username
|
||||
currentAccountType.value = row.user_type
|
||||
selectedRoles.value = []
|
||||
rolesToAdd.value = []
|
||||
leftRoleFilter.value = ''
|
||||
@@ -641,18 +605,31 @@
|
||||
if (rolesToAdd.value.length === 0) return
|
||||
|
||||
try {
|
||||
// 将选中的角色添加到已分配列表
|
||||
const newRoles = [...new Set([...selectedRoles.value, ...rolesToAdd.value])]
|
||||
let newRoles: number[]
|
||||
|
||||
// 代理账号只能分配一个角色,会覆盖之前的角色
|
||||
if (currentAccountType.value === 3) {
|
||||
if (rolesToAdd.value.length > 1) {
|
||||
ElMessage.warning('代理账号只能分配一个角色')
|
||||
return
|
||||
}
|
||||
// 只保留新选择的一个角色
|
||||
newRoles = rolesToAdd.value
|
||||
} else {
|
||||
// 其他账号类型可以分配多个角色
|
||||
newRoles = [...new Set([...selectedRoles.value, ...rolesToAdd.value])]
|
||||
}
|
||||
|
||||
await AccountService.assignRolesToAccount(currentAccountId.value, newRoles)
|
||||
|
||||
selectedRoles.value = newRoles
|
||||
rolesToAdd.value = []
|
||||
|
||||
ElMessage.success('角色添加成功')
|
||||
ElMessage.success('角色分配成功')
|
||||
// 刷新列表以更新角色显示
|
||||
await getAccountList()
|
||||
} catch (error) {
|
||||
console.error('添加角色失败:', error)
|
||||
console.error('分配角色失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user