mirror of
https://github.com/1Panel-dev/MaxKB.git
synced 2025-12-30 09:42:48 +00:00
feat: resource-authorization
This commit is contained in:
parent
6c6aa20ff6
commit
e1841c6189
|
|
@ -140,7 +140,53 @@ const systemRouter = {
|
|||
parentName: 'system',
|
||||
sameRoute: 'authorization',
|
||||
},
|
||||
component: () => import('@/views/system/resource-authorization/index.vue'),
|
||||
|
||||
children: [
|
||||
{
|
||||
path: '/system/authorization/application',
|
||||
name: 'authorizationApplication',
|
||||
meta: {
|
||||
title: 'views.application.title',
|
||||
activeMenu: '/system',
|
||||
parentPath: '/system',
|
||||
parentName: 'system',
|
||||
},
|
||||
component: () => import('@/views/system/resource-authorization/index.vue'),
|
||||
},
|
||||
{
|
||||
path: '/system/authorization/knowledge',
|
||||
name: 'authorizationKnowledge',
|
||||
meta: {
|
||||
title: 'views.knowledge.title',
|
||||
activeMenu: '/system',
|
||||
parentPath: '/system',
|
||||
parentName: 'system',
|
||||
},
|
||||
component: () => import('@/views/system/resource-authorization/index.vue'),
|
||||
},
|
||||
{
|
||||
path: '/system/authorization/tool',
|
||||
name: 'authorizationTool',
|
||||
meta: {
|
||||
title: 'views.tool.title',
|
||||
activeMenu: '/system',
|
||||
parentPath: '/system',
|
||||
parentName: 'system',
|
||||
},
|
||||
component: () => import('@/views/system/resource-authorization/index.vue'),
|
||||
},
|
||||
{
|
||||
path: '/system/authorization/model',
|
||||
name: 'authorizationModel',
|
||||
meta: {
|
||||
title: 'views.model.title',
|
||||
activeMenu: '/system',
|
||||
parentPath: '/system',
|
||||
parentName: 'system',
|
||||
},
|
||||
component: () => import('@/views/system/resource-authorization/index.vue'),
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
path: '/system/shared',
|
||||
|
|
|
|||
|
|
@ -8,9 +8,7 @@
|
|||
<el-radio :value="true" size="large">{{
|
||||
$t('views.resourceAuthorization.priority.role')
|
||||
}}</el-radio>
|
||||
<el-radio :value="false" size="large">{{
|
||||
$t('common.custom')
|
||||
}}</el-radio>
|
||||
<el-radio :value="false" size="large">{{ $t('common.custom') }}</el-radio>
|
||||
</el-radio-group>
|
||||
</div>
|
||||
<el-input
|
||||
|
|
@ -33,17 +31,9 @@
|
|||
<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="isApplication && isAppIcon(row?.icon)"
|
||||
style="background: none"
|
||||
class="mr-12"
|
||||
shape="square"
|
||||
:size="20"
|
||||
>
|
||||
<img :src="row?.icon" alt="" />
|
||||
</el-avatar>
|
||||
<el-avatar
|
||||
v-else-if="row.isFolder"
|
||||
v-if="row.isFolder"
|
||||
class="mr-12"
|
||||
shape="square"
|
||||
:size="20"
|
||||
|
|
@ -55,10 +45,31 @@
|
|||
alt=""
|
||||
/>
|
||||
</el-avatar>
|
||||
<LogoIcon v-else-if="isApplication" height="32px" class="mr-12" />
|
||||
|
||||
<!-- 知识库 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="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/node/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>
|
||||
|
|
@ -160,11 +171,13 @@
|
|||
</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 { isAppIcon } 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,
|
||||
|
|
@ -185,7 +198,8 @@ const radioRole = computed({
|
|||
})
|
||||
const isKnowledge = computed(() => props.type === AuthorizationEnum.KNOWLEDGE)
|
||||
const isApplication = computed(() => props.type === AuthorizationEnum.APPLICATION)
|
||||
|
||||
const isTool = computed(() => props.type === AuthorizationEnum.TOOL)
|
||||
const isModel = computed(() => props.type === AuthorizationEnum.MODEL)
|
||||
const dfsPermission = (arr: any = [], Name: string | number, e: boolean, idArr: any[]) => {
|
||||
arr.map((item: any) => {
|
||||
if (idArr.includes(item.id)) {
|
||||
|
|
@ -218,6 +232,24 @@ 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) {
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@
|
|||
<div class="permission-setting p-24 flex" v-loading="rLoading">
|
||||
<div class="resource-authorization__table">
|
||||
<h4 class="mb-4">{{ $t('views.resourceAuthorization.permissionSetting') }}</h4>
|
||||
<el-tabs
|
||||
<!-- <el-tabs
|
||||
v-model="activeName"
|
||||
@tab-change="handleTabChange"
|
||||
class="resource-authorization__tabs"
|
||||
|
|
@ -62,18 +62,17 @@
|
|||
:key="item.value"
|
||||
:label="item.label"
|
||||
:name="item.value"
|
||||
>
|
||||
<PermissionSetting
|
||||
:key="index"
|
||||
:data="item.data"
|
||||
:type="item.value"
|
||||
:tableHeight="tableHeight"
|
||||
:manage="isManage(currentType)"
|
||||
@refreshData="refreshData"
|
||||
v-model:isRole="item.isRole"
|
||||
></PermissionSetting>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
> -->
|
||||
<PermissionSetting
|
||||
:data="activeData.data"
|
||||
:type="activeData.type"
|
||||
:tableHeight="tableHeight"
|
||||
:manage="isManage(currentType)"
|
||||
@refreshData="refreshData"
|
||||
v-model:isRole="activeData.isRole"
|
||||
></PermissionSetting>
|
||||
<!-- </el-tab-pane> -->
|
||||
<!-- </el-tabs> -->
|
||||
</div>
|
||||
|
||||
<div class="submit-button">
|
||||
|
|
@ -87,6 +86,7 @@
|
|||
|
||||
<script lang="ts" setup>
|
||||
import { onMounted, ref, reactive, watch, computed } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import AuthorizationApi from '@/api/system/resource-authorization'
|
||||
import PermissionSetting from './component/PermissionSetting.vue'
|
||||
import { MsgSuccess, MsgConfirm } from '@/utils/message'
|
||||
|
|
@ -98,6 +98,7 @@ import { EditionConst } from '@/utils/permission/data'
|
|||
import { hasPermission } from '@/utils/permission/index'
|
||||
import WorkspaceApi from '@/api/workspace/workspace.ts'
|
||||
import type { WorkspaceItem } from '@/api/type/workspace'
|
||||
const route = useRoute()
|
||||
const { user } = useStore()
|
||||
const loading = ref(false)
|
||||
const rLoading = ref(false)
|
||||
|
|
@ -106,37 +107,46 @@ const filterMember = ref<any[]>([]) // 搜索过滤后列表
|
|||
const currentUser = ref<string>('')
|
||||
const currentType = ref<string>('')
|
||||
const filterText = ref('')
|
||||
|
||||
const activeName = ref(AuthorizationEnum.KNOWLEDGE)
|
||||
const tableHeight = ref(0)
|
||||
|
||||
const settingTags = reactive([
|
||||
{
|
||||
label: t('views.knowledge.title'),
|
||||
value: AuthorizationEnum.KNOWLEDGE,
|
||||
type: AuthorizationEnum.KNOWLEDGE,
|
||||
data: [] as any,
|
||||
isRole: false,
|
||||
},
|
||||
{
|
||||
label: t('views.application.title'),
|
||||
value: AuthorizationEnum.APPLICATION,
|
||||
type: AuthorizationEnum.APPLICATION,
|
||||
data: [] as any,
|
||||
isRole: false,
|
||||
},
|
||||
{
|
||||
label: t('views.tool.title'),
|
||||
value: AuthorizationEnum.TOOL,
|
||||
type: AuthorizationEnum.TOOL,
|
||||
data: [] as any,
|
||||
isRole: false,
|
||||
},
|
||||
{
|
||||
label: t('views.model.title'),
|
||||
value: AuthorizationEnum.MODEL,
|
||||
type: AuthorizationEnum.MODEL,
|
||||
data: [] as any,
|
||||
isRole: false,
|
||||
},
|
||||
])
|
||||
|
||||
// 当前激活的数据类型(应用/知识库/模型/工具)
|
||||
|
||||
const activeData = computed(() => {
|
||||
var lastIndex = route.path.lastIndexOf('/')
|
||||
const currentPathType = route.path.substring(lastIndex + 1).toUpperCase()
|
||||
return settingTags.filter((item) => {
|
||||
return item.type === currentPathType
|
||||
})[0]
|
||||
})
|
||||
|
||||
|
||||
watch(filterText, (val: any) => {
|
||||
if (val) {
|
||||
filterMember.value = memberList.value.filter((v: any) =>
|
||||
|
|
@ -287,7 +297,7 @@ const handleTabChange = () => {
|
|||
function getFolder() {
|
||||
return AuthorizationApi.getSystemFolder(
|
||||
currentWorkspaceId.value || 'default',
|
||||
activeName.value,
|
||||
activeData.value.type,
|
||||
{},
|
||||
loading,
|
||||
)
|
||||
|
|
@ -305,12 +315,12 @@ const getWholeTree = async (user_id: string) => {
|
|||
settingTags.map((item: any) => {
|
||||
let folderIdMap = []
|
||||
const folderTree = cloneDeep((parentRes as unknown as any).data)
|
||||
if (Object.keys(childrenRes.data).indexOf(item.value) !== -1) {
|
||||
if (Object.keys(childrenRes.data).indexOf(item.type) !== -1) {
|
||||
item.isRole =
|
||||
childrenRes.data[item.value].length > 0 && hasPermission([EditionConst.IS_EE], 'OR')
|
||||
? childrenRes.data[item.value][0].auth_type == 'ROLE'
|
||||
childrenRes.data[item.type].length > 0 && hasPermission([EditionConst.IS_EE], 'OR')
|
||||
? childrenRes.data[item.type][0].auth_type == 'ROLE'
|
||||
: false
|
||||
folderIdMap = getFolderIdMap(childrenRes.data[item.value])
|
||||
folderIdMap = getFolderIdMap(childrenRes.data[item.type])
|
||||
dfsFolder(folderTree, folderIdMap)
|
||||
const permissionHalf = {
|
||||
VIEW: [],
|
||||
|
|
@ -329,7 +339,7 @@ const getWholeTree = async (user_id: string) => {
|
|||
|
||||
const refreshData = () => {
|
||||
settingTags.map((item: any) => {
|
||||
if (activeName.value === item.value) {
|
||||
if (activeData.value.type === item.type) {
|
||||
const permissionHalf = {
|
||||
VIEW: [],
|
||||
MANAGE: [],
|
||||
|
|
|
|||
Loading…
Reference in New Issue