feat: Support folder authorization(#3853)
parent
0bc635a802
commit
6485d12646
|
|
@ -122,22 +122,29 @@
|
||||||
<!-- 单个资源授权提示框 -->
|
<!-- 单个资源授权提示框 -->
|
||||||
<el-dialog
|
<el-dialog
|
||||||
v-model="singleSelectDialogVisible"
|
v-model="singleSelectDialogVisible"
|
||||||
:title="$t('views.system.resourceAuthorization.setting.configure')"
|
:title="$t('views.system.resourceAuthorization.setting.effectiveResource')"
|
||||||
destroy-on-close
|
destroy-on-close
|
||||||
@close="closeSingleSelectDialog"
|
@close="closeSingleSelectDialog"
|
||||||
|
width="500px"
|
||||||
>
|
>
|
||||||
<el-radio-group v-model="authAllChildren" class="radio-block">
|
<el-radio-group v-model="authAllChildren" class="radio-block">
|
||||||
<el-radio :value="false">
|
<el-radio :value="false">
|
||||||
<p class="color-text-primary lighter">{{ $t('views.system.resourceAuthorization.setting.currentOnly') }}</p>
|
<p class="color-text-primary lighter">
|
||||||
</el-radio>
|
{{ $t('views.system.resourceAuthorization.setting.currentOnly') }}
|
||||||
<el-radio :value="true">
|
</p>
|
||||||
<p class="color-text-primary lighter">{{ $t('views.system.resourceAuthorization.setting.includeAll') }}</p>
|
</el-radio>
|
||||||
</el-radio>
|
<el-radio :value="true">
|
||||||
|
<p class="color-text-primary lighter">
|
||||||
|
{{ $t('views.system.resourceAuthorization.setting.includeAll') }}
|
||||||
|
</p>
|
||||||
|
</el-radio>
|
||||||
</el-radio-group>
|
</el-radio-group>
|
||||||
<template #footer>
|
<template #footer>
|
||||||
<div class="dialog-footer mt-24">
|
<div class="dialog-footer mt-24">
|
||||||
<el-button @click="closeSingleSelectDialog">{{ $t('common.cancel') }}</el-button>
|
<el-button @click="closeSingleSelectDialog">{{ $t('common.cancel') }}</el-button>
|
||||||
<el-button type="primary" @click="confirmSinglePermission">{{ $t('common.confirm') }}</el-button>
|
<el-button type="primary" @click="confirmSinglePermission">{{
|
||||||
|
$t('common.confirm')
|
||||||
|
}}</el-button>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</el-dialog>
|
</el-dialog>
|
||||||
|
|
@ -148,6 +155,7 @@
|
||||||
:title="$t('views.system.resourceAuthorization.setting.configure')"
|
:title="$t('views.system.resourceAuthorization.setting.configure')"
|
||||||
destroy-on-close
|
destroy-on-close
|
||||||
@close="closeDialog"
|
@close="closeDialog"
|
||||||
|
width="500px"
|
||||||
>
|
>
|
||||||
<el-radio-group v-model="radioPermission" class="radio-block">
|
<el-radio-group v-model="radioPermission" class="radio-block">
|
||||||
<template v-for="(item, index) in getFolderPermissionOptions()" :key="index">
|
<template v-for="(item, index) in getFolderPermissionOptions()" :key="index">
|
||||||
|
|
@ -160,15 +168,21 @@
|
||||||
<!-- 如果是文件夹,显示子资源选项 -->
|
<!-- 如果是文件夹,显示子资源选项 -->
|
||||||
<div v-if="isFolder" class="mt-16">
|
<div v-if="isFolder" class="mt-16">
|
||||||
<el-divider />
|
<el-divider />
|
||||||
<div class="color-text-primary mb-8">{{ $t('views.system.resourceAuthorization.setting.effectiveResource') }}</div>
|
<div class="color-text-primary mb-8">
|
||||||
<el-radio-group v-model="batchAuthAllChildren" class="radio-block">
|
{{ $t('views.system.resourceAuthorization.setting.effectiveResource') }}
|
||||||
<el-radio :value="false">
|
</div>
|
||||||
<p class="color-text-primary lighter">{{ $t('views.system.resourceAuthorization.setting.currentOnly') }}</p>
|
<el-radio-group v-model="batchAuthAllChildren" class="radio-block">
|
||||||
</el-radio>
|
<el-radio :value="false">
|
||||||
<el-radio :value="true">
|
<p class="color-text-primary lighter">
|
||||||
<p class="color-text-primary lighter">{{ $t('views.system.resourceAuthorization.setting.includeAll') }}</p>
|
{{ $t('views.system.resourceAuthorization.setting.currentOnly') }}
|
||||||
</el-radio>
|
</p>
|
||||||
</el-radio-group>
|
</el-radio>
|
||||||
|
<el-radio :value="true">
|
||||||
|
<p class="color-text-primary lighter">
|
||||||
|
{{ $t('views.system.resourceAuthorization.setting.includeAll') }}
|
||||||
|
</p>
|
||||||
|
</el-radio>
|
||||||
|
</el-radio-group>
|
||||||
</div>
|
</div>
|
||||||
<template #footer>
|
<template #footer>
|
||||||
<div class="dialog-footer mt-24">
|
<div class="dialog-footer mt-24">
|
||||||
|
|
@ -211,14 +225,13 @@ const apiType = computed(() => {
|
||||||
const folderType = computed(() => {
|
const folderType = computed(() => {
|
||||||
if (route.path.includes('application')) {
|
if (route.path.includes('application')) {
|
||||||
return 'application'
|
return 'application'
|
||||||
}
|
} else if (route.path.includes('knowledge')) {
|
||||||
else if (route.path.includes('knowledge')) {
|
|
||||||
return 'knowledge'
|
return 'knowledge'
|
||||||
}
|
} else if (route.path.includes('tool')) {
|
||||||
else if (route.path.includes('tool')) {
|
|
||||||
return 'tool'
|
return 'tool'
|
||||||
|
} else {
|
||||||
|
return 'application'
|
||||||
}
|
}
|
||||||
else {return 'application'}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
const permissionPrecise = computed(() => {
|
const permissionPrecise = computed(() => {
|
||||||
|
|
@ -228,12 +241,14 @@ const permissionPrecise = computed(() => {
|
||||||
// 取出文件夹id
|
// 取出文件夹id
|
||||||
function getAllFolderIds(data: any) {
|
function getAllFolderIds(data: any) {
|
||||||
if (!data) return []
|
if (!data) return []
|
||||||
return [data.id,...(data.children?.flatMap((child: any) => getAllFolderIds(child)) || [])]
|
return [data.id, ...(data.children?.flatMap((child: any) => getAllFolderIds(child)) || [])]
|
||||||
}
|
}
|
||||||
|
|
||||||
const RESOURCE_PERMISSION_MAP = {
|
const RESOURCE_PERMISSION_MAP = {
|
||||||
application: PermissionConst.APPLICATION_RESOURCE_AUTHORIZATION.getWorkspacePermissionWorkspaceManageRole,
|
application:
|
||||||
knowledge: PermissionConst.KNOWLEDGE_RESOURCE_AUTHORIZATION.getWorkspacePermissionWorkspaceManageRole,
|
PermissionConst.APPLICATION_RESOURCE_AUTHORIZATION.getWorkspacePermissionWorkspaceManageRole,
|
||||||
|
knowledge:
|
||||||
|
PermissionConst.KNOWLEDGE_RESOURCE_AUTHORIZATION.getWorkspacePermissionWorkspaceManageRole,
|
||||||
tool: PermissionConst.TOOL_RESOURCE_AUTHORIZATION.getWorkspacePermissionWorkspaceManageRole,
|
tool: PermissionConst.TOOL_RESOURCE_AUTHORIZATION.getWorkspacePermissionWorkspaceManageRole,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -243,18 +258,16 @@ const resourceAuthorizationOfManager = computed(() => {
|
||||||
|
|
||||||
// 过滤没有Manage权限的文件夹ID
|
// 过滤没有Manage权限的文件夹ID
|
||||||
function filterHasPermissionFolderIds(folderIds: string[]) {
|
function filterHasPermissionFolderIds(folderIds: string[]) {
|
||||||
if (hasPermission(
|
if (
|
||||||
[
|
hasPermission(
|
||||||
RoleConst.WORKSPACE_MANAGE.getWorkspaceRole,
|
[RoleConst.WORKSPACE_MANAGE.getWorkspaceRole, resourceAuthorizationOfManager.value],
|
||||||
resourceAuthorizationOfManager.value
|
'OR',
|
||||||
],'OR'
|
)
|
||||||
)) {
|
) {
|
||||||
return folderIds
|
return folderIds
|
||||||
|
} else {
|
||||||
|
return folderIds.filter((id) => permissionPrecise.value.folderManage(id))
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
return folderIds.filter(id => permissionPrecise.value.folderManage(id))
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function confirmSinglePermission() {
|
function confirmSinglePermission() {
|
||||||
|
|
@ -270,7 +283,7 @@ function confirmSinglePermission() {
|
||||||
user_id: row.id,
|
user_id: row.id,
|
||||||
permission: val,
|
permission: val,
|
||||||
include_children: authAllChildren.value,
|
include_children: authAllChildren.value,
|
||||||
...(folderIds.length > 0 && {folder_ids: folderIds})
|
...(folderIds.length > 0 && { folder_ids: folderIds }),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
submitPermissions(obj)
|
submitPermissions(obj)
|
||||||
|
|
@ -354,7 +367,7 @@ const handleSelectionChange = (val: any[]) => {
|
||||||
|
|
||||||
const dialogVisible = ref(false)
|
const dialogVisible = ref(false)
|
||||||
const singleSelectDialogVisible = ref(false)
|
const singleSelectDialogVisible = ref(false)
|
||||||
const pendingPermissionChange = ref<{ val: any; row: any; } | null>(null)
|
const pendingPermissionChange = ref<{ val: any; row: any } | null>(null)
|
||||||
const radioPermission = ref('')
|
const radioPermission = ref('')
|
||||||
const authAllChildren = ref(false)
|
const authAllChildren = ref(false)
|
||||||
function openMulConfigureDialog() {
|
function openMulConfigureDialog() {
|
||||||
|
|
@ -379,7 +392,7 @@ function submitDialog() {
|
||||||
user_id: item.id,
|
user_id: item.id,
|
||||||
permission: radioPermission.value,
|
permission: radioPermission.value,
|
||||||
include_children: batchAuthAllChildren.value,
|
include_children: batchAuthAllChildren.value,
|
||||||
...(folderIds.length > 0 && { folder_ids: folderIds })
|
...(folderIds.length > 0 && { folder_ids: folderIds }),
|
||||||
}))
|
}))
|
||||||
submitPermissions(obj)
|
submitPermissions(obj)
|
||||||
closeDialog()
|
closeDialog()
|
||||||
|
|
@ -403,7 +416,7 @@ function closeDialog() {
|
||||||
function permissionsHandle(val: any, row: any) {
|
function permissionsHandle(val: any, row: any) {
|
||||||
if (props.isFolder) {
|
if (props.isFolder) {
|
||||||
singleSelectDialogVisible.value = true
|
singleSelectDialogVisible.value = true
|
||||||
pendingPermissionChange.value = {val, row}
|
pendingPermissionChange.value = { val, row }
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const obj = [
|
const obj = [
|
||||||
|
|
@ -415,7 +428,7 @@ function permissionsHandle(val: any, row: any) {
|
||||||
submitPermissions(obj)
|
submitPermissions(obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
function submitPermissions( obj: any) {
|
function submitPermissions(obj: any) {
|
||||||
const workspaceId = user.getWorkspaceId() || 'default'
|
const workspaceId = user.getWorkspaceId() || 'default'
|
||||||
loadSharedApi({ type: 'resourceAuthorization', systemType: apiType.value })
|
loadSharedApi({ type: 'resourceAuthorization', systemType: apiType.value })
|
||||||
.putResourceAuthorization(workspaceId, targetId.value, props.type, obj, loading)
|
.putResourceAuthorization(workspaceId, targetId.value, props.type, obj, loading)
|
||||||
|
|
@ -440,12 +453,13 @@ const getPermissionList = () => {
|
||||||
loading,
|
loading,
|
||||||
)
|
)
|
||||||
.then((res: any) => {
|
.then((res: any) => {
|
||||||
permissionData.value = res.data.records.map((item: any) => {
|
permissionData.value =
|
||||||
if (props.isRootFolder && item.permission === 'NOT_AUTH') {
|
res.data.records.map((item: any) => {
|
||||||
return {...item, permission: 'VIEW'}
|
if (props.isRootFolder && item.permission === 'NOT_AUTH') {
|
||||||
}
|
return { ...item, permission: 'VIEW' }
|
||||||
return item
|
}
|
||||||
}) || []
|
return item
|
||||||
|
}) || []
|
||||||
paginationConfig.total = res.data.total || 0
|
paginationConfig.total = res.data.total || 0
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,288 +0,0 @@
|
||||||
<template>
|
|
||||||
<div class="w-full">
|
|
||||||
<div class="flex-between mb-16">
|
|
||||||
<div
|
|
||||||
class="flex align-center"
|
|
||||||
v-if="hasPermission([EditionConst.IS_EE, EditionConst.IS_PE], 'OR')"
|
|
||||||
>
|
|
||||||
<!-- 企业版: 选优先级-->
|
|
||||||
<span class="lighter mr-16">{{
|
|
||||||
$t('views.system.resourceAuthorization.priority.label')
|
|
||||||
}}</span>
|
|
||||||
<el-radio-group v-model="radioRole">
|
|
||||||
<el-radio :value="true" size="large"
|
|
||||||
>{{ $t('views.system.resourceAuthorization.priority.role') }}
|
|
||||||
</el-radio>
|
|
||||||
<el-radio :value="false" size="large">{{ $t('common.custom') }}</el-radio>
|
|
||||||
</el-radio-group>
|
|
||||||
</div>
|
|
||||||
<el-input
|
|
||||||
v-model="filterText"
|
|
||||||
:placeholder="$t('common.search')"
|
|
||||||
prefix-icon="Search"
|
|
||||||
class="mt-4"
|
|
||||||
:class="hasPermission([EditionConst.IS_EE, EditionConst.IS_PE], 'OR') ? 'w-240' : ''"
|
|
||||||
clearable
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<el-table
|
|
||||||
row-key="id"
|
|
||||||
:data="filterData"
|
|
||||||
:max-height="tableHeight"
|
|
||||||
:expand-row-keys="defaultExpandKeys"
|
|
||||||
style="width: 100%"
|
|
||||||
>
|
|
||||||
<el-table-column class-name="folder-flex" prop="name" :label="$t('common.name')">
|
|
||||||
<template #default="{ row }">
|
|
||||||
<div class="flex align-center">
|
|
||||||
<!-- 文件夹 icon -->
|
|
||||||
<el-avatar
|
|
||||||
v-if="row.isFolder"
|
|
||||||
class="mr-12"
|
|
||||||
shape="square"
|
|
||||||
:size="20"
|
|
||||||
style="background: none"
|
|
||||||
>
|
|
||||||
<img
|
|
||||||
src="@/assets/knowledge/icon_file-folder_colorful.svg"
|
|
||||||
style="width: 100%"
|
|
||||||
alt=""
|
|
||||||
/>
|
|
||||||
</el-avatar>
|
|
||||||
<!-- 知识库 icon -->
|
|
||||||
<KnowledgeIcon class="mr-12" :size="20" v-else-if="isKnowledge" :type="row.icon" />
|
|
||||||
<!-- 应用/工具 自定义 icon -->
|
|
||||||
<el-avatar
|
|
||||||
v-else-if="isAppIcon(row?.icon) && !isModel"
|
|
||||||
style="background: none"
|
|
||||||
class="mr-12"
|
|
||||||
shape="square"
|
|
||||||
:size="20"
|
|
||||||
>
|
|
||||||
<img :src="resetUrl(row?.icon)" alt="" />
|
|
||||||
</el-avatar>
|
|
||||||
<!-- 应用 icon -->
|
|
||||||
<LogoIcon v-else-if="isApplication" height="20px" class="mr-12" />
|
|
||||||
<!-- 工具 icon -->
|
|
||||||
<el-avatar v-else-if="isTool" class="avatar-green mr-12" shape="square" :size="20">
|
|
||||||
<img src="@/assets/workflow/icon_tool.svg" style="width: 58%" alt="" />
|
|
||||||
</el-avatar>
|
|
||||||
<!-- 模型 icon -->
|
|
||||||
<span
|
|
||||||
v-else-if="isModel"
|
|
||||||
style="width: 24px; height: 24px; display: inline-block"
|
|
||||||
class="mr-12"
|
|
||||||
:innerHTML="getProviderIcon(row)"
|
|
||||||
></span>
|
|
||||||
<span :title="row?.name">
|
|
||||||
{{ row?.name }}
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
<el-table-column
|
|
||||||
v-if="isRole"
|
|
||||||
:label="$t('views.system.resourceAuthorization.setting.authorization')"
|
|
||||||
align="center"
|
|
||||||
width="100"
|
|
||||||
>
|
|
||||||
<!-- <template #header>
|
|
||||||
<el-checkbox
|
|
||||||
:disabled="props.manage"
|
|
||||||
v-model="allChecked[AuthorizationEnum.MANAGE]"
|
|
||||||
:indeterminate="allIndeterminate[AuthorizationEnum.MANAGE]"
|
|
||||||
:label="$t('views.system.resourceAuthorization.setting.management')"
|
|
||||||
/>
|
|
||||||
</template> -->
|
|
||||||
<template #default="{ row }">
|
|
||||||
<el-checkbox
|
|
||||||
v-if="row.isFolder"
|
|
||||||
:disabled="props.manage"
|
|
||||||
v-model="row.permission[AuthorizationEnum.ROLE]"
|
|
||||||
:indeterminate="row.permissionHalf[AuthorizationEnum.ROLE]"
|
|
||||||
@change="(e: boolean) => checkedOperateChange(AuthorizationEnum.ROLE, row, e)"
|
|
||||||
/>
|
|
||||||
<el-checkbox
|
|
||||||
v-else
|
|
||||||
:disabled="props.manage"
|
|
||||||
v-model="row.permission[AuthorizationEnum.ROLE]"
|
|
||||||
@change="(e: boolean) => checkedOperateChange(AuthorizationEnum.ROLE, row, e)"
|
|
||||||
/>
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
<el-table-column
|
|
||||||
v-if="!isRole"
|
|
||||||
:label="$t('views.system.resourceAuthorization.setting.management')"
|
|
||||||
align="center"
|
|
||||||
width="100"
|
|
||||||
>
|
|
||||||
<!-- <template #header>
|
|
||||||
<el-checkbox
|
|
||||||
:disabled="props.manage"
|
|
||||||
v-model="allChecked[AuthorizationEnum.MANAGE]"
|
|
||||||
:indeterminate="allIndeterminate[AuthorizationEnum.MANAGE]"
|
|
||||||
:label="$t('views.system.resourceAuthorization.setting.management')"
|
|
||||||
/>
|
|
||||||
</template> -->
|
|
||||||
<template #default="{ row }">
|
|
||||||
<el-checkbox
|
|
||||||
v-if="row.isFolder"
|
|
||||||
:disabled="props.manage"
|
|
||||||
v-model="row.permission[AuthorizationEnum.MANAGE]"
|
|
||||||
:indeterminate="row.permissionHalf[AuthorizationEnum.MANAGE]"
|
|
||||||
@change="(e: boolean) => checkedOperateChange(AuthorizationEnum.MANAGE, row, e)"
|
|
||||||
/>
|
|
||||||
<el-checkbox
|
|
||||||
v-else
|
|
||||||
:disabled="props.manage"
|
|
||||||
v-model="row.permission[AuthorizationEnum.MANAGE]"
|
|
||||||
@change="(e: boolean) => checkedOperateChange(AuthorizationEnum.MANAGE, row, e)"
|
|
||||||
/>
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
<el-table-column
|
|
||||||
v-if="!isRole"
|
|
||||||
:label="$t('views.system.resourceAuthorization.setting.check')"
|
|
||||||
align="center"
|
|
||||||
width="100"
|
|
||||||
>
|
|
||||||
<!-- <template #header>
|
|
||||||
<el-checkbox
|
|
||||||
:disabled="props.manage"
|
|
||||||
v-model="allChecked[AuthorizationEnum.VIEW]"
|
|
||||||
:indeterminate="allIndeterminate[AuthorizationEnum.VIEW]"
|
|
||||||
:label="$t('views.system.resourceAuthorization.setting.check')"
|
|
||||||
/>
|
|
||||||
</template> -->
|
|
||||||
<template #default="{ row }">
|
|
||||||
<el-checkbox
|
|
||||||
v-if="row.isFolder"
|
|
||||||
:disabled="props.manage"
|
|
||||||
v-model="row.permission[AuthorizationEnum.VIEW]"
|
|
||||||
:indeterminate="row.permissionHalf[AuthorizationEnum.VIEW]"
|
|
||||||
@change="(e: boolean) => checkedOperateChange(AuthorizationEnum.VIEW, row, e)"
|
|
||||||
/>
|
|
||||||
<el-checkbox
|
|
||||||
v-else
|
|
||||||
:disabled="props.manage"
|
|
||||||
v-model="row.permission[AuthorizationEnum.VIEW]"
|
|
||||||
@change="(e: boolean) => checkedOperateChange(AuthorizationEnum.VIEW, row, e)"
|
|
||||||
/>
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
</el-table>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
<script setup lang="ts">
|
|
||||||
import { ref, onMounted, watch, computed } from 'vue'
|
|
||||||
import type { Provider } from '@/api/type/model'
|
|
||||||
import { AuthorizationEnum } from '@/enums/system'
|
|
||||||
import { SourceTypeEnum } from '@/enums/common'
|
|
||||||
import { isAppIcon, resetUrl } from '@/utils/common'
|
|
||||||
import { EditionConst } from '@/utils/permission/data'
|
|
||||||
import { hasPermission } from '@/utils/permission/index'
|
|
||||||
import useStore from '@/stores'
|
|
||||||
|
|
||||||
const { model } = useStore()
|
|
||||||
const props = defineProps({
|
|
||||||
data: {
|
|
||||||
type: Array<any>,
|
|
||||||
default: () => [],
|
|
||||||
},
|
|
||||||
id: String,
|
|
||||||
type: String,
|
|
||||||
tableHeight: Number,
|
|
||||||
manage: Boolean,
|
|
||||||
isRole: Boolean,
|
|
||||||
})
|
|
||||||
const emit = defineEmits(['update:data', 'refreshData', 'update:isRole'])
|
|
||||||
const radioRole = computed({
|
|
||||||
get: () => props.isRole,
|
|
||||||
set: (v: boolean) => {
|
|
||||||
emit('update:isRole', v)
|
|
||||||
},
|
|
||||||
})
|
|
||||||
const isKnowledge = computed(() => props.type === SourceTypeEnum.KNOWLEDGE)
|
|
||||||
const isApplication = computed(() => props.type === SourceTypeEnum.APPLICATION)
|
|
||||||
const isTool = computed(() => props.type === SourceTypeEnum.TOOL)
|
|
||||||
const isModel = computed(() => props.type === SourceTypeEnum.MODEL)
|
|
||||||
const defaultExpandKeys = computed(() => (props.data?.length > 0 ? [props.data[0]?.id] : []))
|
|
||||||
const dfsPermission = (arr: any = [], Name: string | number, e: boolean, idArr: any[]) => {
|
|
||||||
arr.map((item: any) => {
|
|
||||||
if (idArr.includes(item.id)) {
|
|
||||||
item.permission[Name] = e
|
|
||||||
if (Name === AuthorizationEnum.MANAGE && e) {
|
|
||||||
item.permission[AuthorizationEnum.VIEW] = true
|
|
||||||
} else if (Name === AuthorizationEnum.VIEW && !e) {
|
|
||||||
item.permission[AuthorizationEnum.MANAGE] = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (item.children?.length) {
|
|
||||||
dfsPermission(
|
|
||||||
item.children,
|
|
||||||
Name,
|
|
||||||
e,
|
|
||||||
idArr.includes(item.id) ? item.children.map((ele: any) => ele.id) : idArr,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const filterText = ref('')
|
|
||||||
|
|
||||||
const filterData = computed(() => {
|
|
||||||
function filterTree(data: any[]): any[] {
|
|
||||||
return data
|
|
||||||
.map((item) => {
|
|
||||||
// 递归过滤 children
|
|
||||||
const children = item.children ? filterTree(item.children) : []
|
|
||||||
// 判断当前节点或其子节点是否匹配
|
|
||||||
const isMatch = item.name.toLowerCase().includes(filterText.value.toLowerCase())
|
|
||||||
if (isMatch || children.length) {
|
|
||||||
return {
|
|
||||||
...item,
|
|
||||||
children: children.length ? children : undefined,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null
|
|
||||||
})
|
|
||||||
.filter(Boolean)
|
|
||||||
}
|
|
||||||
|
|
||||||
return filterTree(props.data)
|
|
||||||
})
|
|
||||||
|
|
||||||
function checkedOperateChange(Name: string | number, row: any, e: boolean) {
|
|
||||||
dfsPermission(props.data, Name, e, [row.id])
|
|
||||||
emit('refreshData')
|
|
||||||
}
|
|
||||||
|
|
||||||
const provider_list = ref<Array<Provider>>([])
|
|
||||||
|
|
||||||
function getProvider() {
|
|
||||||
model.asyncGetProvider().then((res: any) => {
|
|
||||||
provider_list.value = res?.data
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
const getProviderIcon = computed(() => {
|
|
||||||
return (row: any) => {
|
|
||||||
return provider_list.value.find((p) => p.provider === row.icon)?.icon
|
|
||||||
}
|
|
||||||
})
|
|
||||||
onMounted(() => {
|
|
||||||
if (isModel.value) {
|
|
||||||
getProvider()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
</script>
|
|
||||||
<style lang="scss" scoped>
|
|
||||||
:deep(.folder-flex) {
|
|
||||||
.cell {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|
@ -43,7 +43,7 @@
|
||||||
collapse-tags-tooltip
|
collapse-tags-tooltip
|
||||||
style="width: 220px"
|
style="width: 220px"
|
||||||
>
|
>
|
||||||
<template v-for="(item, index) in permissionOptions" :key="index">
|
<template v-for="(item, index) in getPermissionOptions()" :key="index">
|
||||||
<el-option :label="item.label" :value="item.value" />
|
<el-option :label="item.label" :value="item.value" />
|
||||||
</template>
|
</template>
|
||||||
</el-select>
|
</el-select>
|
||||||
|
|
@ -58,11 +58,13 @@
|
||||||
:maxTableHeight="260"
|
:maxTableHeight="260"
|
||||||
:row-key="(row: any) => row.id"
|
:row-key="(row: any) => row.id"
|
||||||
:expand-row-keys="defaultExpandKeys"
|
:expand-row-keys="defaultExpandKeys"
|
||||||
|
style="min-width: 600px"
|
||||||
|
show-overflow-tooltip
|
||||||
>
|
>
|
||||||
<el-table-column type="selection" width="55" :reserve-selection="true" />
|
<el-table-column type="selection" width="55" :reserve-selection="true" />
|
||||||
<el-table-column prop="name" :label="$t('common.name')">
|
<el-table-column prop="name" :label="$t('common.name')">
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
<el-space :size="8">
|
<span style="vertical-align: sub">
|
||||||
<!-- 文件夹 icon -->
|
<!-- 文件夹 icon -->
|
||||||
<AppIcon
|
<AppIcon
|
||||||
v-if="row.resource_type === 'folder'"
|
v-if="row.resource_type === 'folder'"
|
||||||
|
|
@ -90,10 +92,8 @@
|
||||||
style="width: 20px; height: 20px; display: inline-block"
|
style="width: 20px; height: 20px; display: inline-block"
|
||||||
:innerHTML="getProviderIcon(row)"
|
:innerHTML="getProviderIcon(row)"
|
||||||
></span>
|
></span>
|
||||||
<span :title="row?.name" class="ellipsis-1">
|
</span>
|
||||||
{{ row?.name }}
|
{{ row?.name }}
|
||||||
</span>
|
|
||||||
</el-space>
|
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column :label="$t('views.model.modelForm.permissionType.label')" align="left">
|
<el-table-column :label="$t('views.model.modelForm.permissionType.label')" align="left">
|
||||||
|
|
@ -157,26 +157,24 @@ const props = defineProps<{
|
||||||
const emit = defineEmits(['submitPermissions'])
|
const emit = defineEmits(['submitPermissions'])
|
||||||
|
|
||||||
const defaultExpandKeys = computed(() => {
|
const defaultExpandKeys = computed(() => {
|
||||||
const searchName = searchForm.value.name || ''
|
const searchName = searchForm.value.name || ''
|
||||||
const searchPermissions = searchForm.value.permission ?? []
|
const searchPermissions = searchForm.value.permission ?? []
|
||||||
if (!searchName && (!searchPermissions || searchPermissions.length === 0)) {
|
if (!searchName && (!searchPermissions || searchPermissions.length === 0)) {
|
||||||
return (props.data?.length > 0 ? [props.data[0]?.id] : [])
|
return props.data?.length > 0 ? [props.data[0]?.id] : []
|
||||||
}
|
}
|
||||||
const expandIds: string[] = []
|
const expandIds: string[] = []
|
||||||
// 传入过滤后的数据
|
// 传入过滤后的数据
|
||||||
const collectExpandIds = (nodes: any[]) => {
|
const collectExpandIds = (nodes: any[]) => {
|
||||||
nodes.forEach(
|
nodes.forEach((node) => {
|
||||||
node => {
|
if (node.children && node.children.length > 0) {
|
||||||
if (node.children && node.children.length > 0) {
|
expandIds.push(node.id)
|
||||||
expandIds.push(node.id)
|
collectExpandIds(node.children)
|
||||||
collectExpandIds(node.children)
|
}
|
||||||
}
|
})
|
||||||
})
|
|
||||||
}
|
}
|
||||||
collectExpandIds(filteredData.value)
|
collectExpandIds(filteredData.value)
|
||||||
return expandIds
|
return expandIds
|
||||||
}
|
})
|
||||||
)
|
|
||||||
|
|
||||||
const permissionOptionMap = computed(() => {
|
const permissionOptionMap = computed(() => {
|
||||||
return {
|
return {
|
||||||
|
|
@ -199,7 +197,17 @@ const getRowPermissionOptions = (row: any) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const permissionOptions = computed(() => {
|
const permissionOptions = computed(() => {
|
||||||
return getPermissionOptions()
|
if (
|
||||||
|
multipleSelection.value.some(
|
||||||
|
(item) => item.resource_type === 'folder' && item.folder_id == null,
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
return permissionOptionMap.value.rootFolder
|
||||||
|
} else if (multipleSelection.value.some((item) => item.resource_type === 'folder')) {
|
||||||
|
return permissionOptionMap.value.folder
|
||||||
|
} else {
|
||||||
|
return permissionOptionMap.value.resource
|
||||||
|
}
|
||||||
})
|
})
|
||||||
const permissionObj = ref<any>({
|
const permissionObj = ref<any>({
|
||||||
APPLICATION: new ComplexPermission(
|
APPLICATION: new ComplexPermission(
|
||||||
|
|
@ -259,19 +267,6 @@ const search_type_change = () => {
|
||||||
searchForm.value = { name: '', permission: undefined }
|
searchForm.value = { name: '', permission: undefined }
|
||||||
}
|
}
|
||||||
|
|
||||||
const paginationConfig = reactive({
|
|
||||||
current_page: 1,
|
|
||||||
page_size: 20,
|
|
||||||
total: 0,
|
|
||||||
})
|
|
||||||
|
|
||||||
function handleSizeChange() {
|
|
||||||
paginationConfig.current_page = 1
|
|
||||||
if (props.getData) {
|
|
||||||
props.getData()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const filterTreeData = () => {
|
const filterTreeData = () => {
|
||||||
const searchName = searchForm.value.name || ''
|
const searchName = searchForm.value.name || ''
|
||||||
const searchPermissions = searchForm.value.permission ?? []
|
const searchPermissions = searchForm.value.permission ?? []
|
||||||
|
|
@ -313,7 +308,6 @@ const filteredData = computed(() => {
|
||||||
return filterTreeData()
|
return filterTreeData()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
const multipleSelection = ref<any[]>([])
|
const multipleSelection = ref<any[]>([])
|
||||||
|
|
||||||
const handleSelectionChange = (val: any[]) => {
|
const handleSelectionChange = (val: any[]) => {
|
||||||
|
|
@ -375,7 +369,6 @@ onMounted(() => {
|
||||||
})
|
})
|
||||||
|
|
||||||
defineExpose({
|
defineExpose({
|
||||||
// paginationConfig,
|
|
||||||
searchForm,
|
searchForm,
|
||||||
searchType,
|
searchType,
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue