Skip to content

Commit e1841c6

Browse files
feat: resource-authorization
1 parent 6c6aa20 commit e1841c6

File tree

3 files changed

+132
-44
lines changed

3 files changed

+132
-44
lines changed

ui/src/router/modules/system.ts

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,53 @@ const systemRouter = {
140140
parentName: 'system',
141141
sameRoute: 'authorization',
142142
},
143-
component: () => import('@/views/system/resource-authorization/index.vue'),
143+
144+
children: [
145+
{
146+
path: '/system/authorization/application',
147+
name: 'authorizationApplication',
148+
meta: {
149+
title: 'views.application.title',
150+
activeMenu: '/system',
151+
parentPath: '/system',
152+
parentName: 'system',
153+
},
154+
component: () => import('@/views/system/resource-authorization/index.vue'),
155+
},
156+
{
157+
path: '/system/authorization/knowledge',
158+
name: 'authorizationKnowledge',
159+
meta: {
160+
title: 'views.knowledge.title',
161+
activeMenu: '/system',
162+
parentPath: '/system',
163+
parentName: 'system',
164+
},
165+
component: () => import('@/views/system/resource-authorization/index.vue'),
166+
},
167+
{
168+
path: '/system/authorization/tool',
169+
name: 'authorizationTool',
170+
meta: {
171+
title: 'views.tool.title',
172+
activeMenu: '/system',
173+
parentPath: '/system',
174+
parentName: 'system',
175+
},
176+
component: () => import('@/views/system/resource-authorization/index.vue'),
177+
},
178+
{
179+
path: '/system/authorization/model',
180+
name: 'authorizationModel',
181+
meta: {
182+
title: 'views.model.title',
183+
activeMenu: '/system',
184+
parentPath: '/system',
185+
parentName: 'system',
186+
},
187+
component: () => import('@/views/system/resource-authorization/index.vue'),
188+
},
189+
],
144190
},
145191
{
146192
path: '/system/shared',

ui/src/views/system/resource-authorization/component/PermissionSetting.vue

Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
<el-radio :value="true" size="large">{{
99
$t('views.resourceAuthorization.priority.role')
1010
}}</el-radio>
11-
<el-radio :value="false" size="large">{{
12-
$t('common.custom')
13-
}}</el-radio>
11+
<el-radio :value="false" size="large">{{ $t('common.custom') }}</el-radio>
1412
</el-radio-group>
1513
</div>
1614
<el-input
@@ -33,17 +31,9 @@
3331
<el-table-column class-name="folder-flex" prop="name" :label="$t('common.name')">
3432
<template #default="{ row }">
3533
<div class="flex align-center">
34+
<!-- 文件夹 icon -->
3635
<el-avatar
37-
v-if="isApplication && isAppIcon(row?.icon)"
38-
style="background: none"
39-
class="mr-12"
40-
shape="square"
41-
:size="20"
42-
>
43-
<img :src="row?.icon" alt="" />
44-
</el-avatar>
45-
<el-avatar
46-
v-else-if="row.isFolder"
36+
v-if="row.isFolder"
4737
class="mr-12"
4838
shape="square"
4939
:size="20"
@@ -55,10 +45,31 @@
5545
alt=""
5646
/>
5747
</el-avatar>
58-
<LogoIcon v-else-if="isApplication" height="32px" class="mr-12" />
59-
48+
<!--  知识库 icon -->
6049
<KnowledgeIcon class="mr-12" :size="20" v-else-if="isKnowledge" :type="row.icon" />
61-
50+
<!--  应用/工具 自定义 icon -->
51+
<el-avatar
52+
v-else-if="isAppIcon(row?.icon) && !isModel"
53+
style="background: none"
54+
class="mr-12"
55+
shape="square"
56+
:size="20"
57+
>
58+
<img :src="row?.icon" alt="" />
59+
</el-avatar>
60+
<!--  应用 icon -->
61+
<LogoIcon v-else-if="isApplication" height="20px" class="mr-12" />
62+
<!-- 工具 icon -->
63+
<el-avatar v-else-if="isTool" class="avatar-green mr-12" shape="square" :size="20">
64+
<img src="@/assets/node/icon_tool.svg" style="width: 58%" alt="" />
65+
</el-avatar>
66+
<!-- 模型 icon -->
67+
<span
68+
v-else-if="isModel"
69+
style="width: 24px; height: 24px; display: inline-block"
70+
class="mr-12"
71+
:innerHTML="getProviderIcon(row)"
72+
></span>
6273
<span :title="row?.name">
6374
{{ row?.name }}
6475
</span>
@@ -160,11 +171,13 @@
160171
</template>
161172
<script setup lang="ts">
162173
import { ref, onMounted, watch, computed } from 'vue'
174+
import type { Provider } from '@/api/type/model'
163175
import { AuthorizationEnum } from '@/enums/system'
164176
import { isAppIcon } from '@/utils/common'
165177
import { EditionConst } from '@/utils/permission/data'
166178
import { hasPermission } from '@/utils/permission/index'
167-
179+
import useStore from '@/stores'
180+
const { model } = useStore()
168181
const props = defineProps({
169182
data: {
170183
type: Array,
@@ -185,7 +198,8 @@ const radioRole = computed({
185198
})
186199
const isKnowledge = computed(() => props.type === AuthorizationEnum.KNOWLEDGE)
187200
const isApplication = computed(() => props.type === AuthorizationEnum.APPLICATION)
188-
201+
const isTool = computed(() => props.type === AuthorizationEnum.TOOL)
202+
const isModel = computed(() => props.type === AuthorizationEnum.MODEL)
189203
const dfsPermission = (arr: any = [], Name: string | number, e: boolean, idArr: any[]) => {
190204
arr.map((item: any) => {
191205
if (idArr.includes(item.id)) {
@@ -218,6 +232,24 @@ function checkedOperateChange(Name: string | number, row: any, e: boolean) {
218232
dfsPermission(props.data, Name, e, [row.id])
219233
emit('refreshData')
220234
}
235+
236+
const provider_list = ref<Array<Provider>>([])
237+
function getProvider() {
238+
model.asyncGetProvider().then((res: any) => {
239+
provider_list.value = res?.data
240+
})
241+
}
242+
243+
const getProviderIcon = computed(() => {
244+
return (row: any) => {
245+
return provider_list.value.find((p) => p.provider === row.icon)?.icon
246+
}
247+
})
248+
onMounted(() => {
249+
if (isModel.value) {
250+
getProvider()
251+
}
252+
})
221253
</script>
222254
<style lang="scss" scoped>
223255
:deep(.folder-flex) {

ui/src/views/system/resource-authorization/index.vue

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
<div class="permission-setting p-24 flex" v-loading="rLoading">
5353
<div class="resource-authorization__table">
5454
<h4 class="mb-4">{{ $t('views.resourceAuthorization.permissionSetting') }}</h4>
55-
<el-tabs
55+
<!-- <el-tabs
5656
v-model="activeName"
5757
@tab-change="handleTabChange"
5858
class="resource-authorization__tabs"
@@ -62,18 +62,17 @@
6262
:key="item.value"
6363
:label="item.label"
6464
:name="item.value"
65-
>
66-
<PermissionSetting
67-
:key="index"
68-
:data="item.data"
69-
:type="item.value"
70-
:tableHeight="tableHeight"
71-
:manage="isManage(currentType)"
72-
@refreshData="refreshData"
73-
v-model:isRole="item.isRole"
74-
></PermissionSetting>
75-
</el-tab-pane>
76-
</el-tabs>
65+
> -->
66+
<PermissionSetting
67+
:data="activeData.data"
68+
:type="activeData.type"
69+
:tableHeight="tableHeight"
70+
:manage="isManage(currentType)"
71+
@refreshData="refreshData"
72+
v-model:isRole="activeData.isRole"
73+
></PermissionSetting>
74+
<!-- </el-tab-pane> -->
75+
<!-- </el-tabs> -->
7776
</div>
7877

7978
<div class="submit-button">
@@ -87,6 +86,7 @@
8786

8887
<script lang="ts" setup>
8988
import { onMounted, ref, reactive, watch, computed } from 'vue'
89+
import { useRoute } from 'vue-router'
9090
import AuthorizationApi from '@/api/system/resource-authorization'
9191
import PermissionSetting from './component/PermissionSetting.vue'
9292
import { MsgSuccess, MsgConfirm } from '@/utils/message'
@@ -98,6 +98,7 @@ import { EditionConst } from '@/utils/permission/data'
9898
import { hasPermission } from '@/utils/permission/index'
9999
import WorkspaceApi from '@/api/workspace/workspace.ts'
100100
import type { WorkspaceItem } from '@/api/type/workspace'
101+
const route = useRoute()
101102
const { user } = useStore()
102103
const loading = ref(false)
103104
const rLoading = ref(false)
@@ -106,37 +107,46 @@ const filterMember = ref<any[]>([]) // 搜索过滤后列表
106107
const currentUser = ref<string>('')
107108
const currentType = ref<string>('')
108109
const filterText = ref('')
109-
110-
const activeName = ref(AuthorizationEnum.KNOWLEDGE)
111110
const tableHeight = ref(0)
112111
113112
const settingTags = reactive([
114113
{
115114
label: t('views.knowledge.title'),
116-
value: AuthorizationEnum.KNOWLEDGE,
115+
type: AuthorizationEnum.KNOWLEDGE,
117116
data: [] as any,
118117
isRole: false,
119118
},
120119
{
121120
label: t('views.application.title'),
122-
value: AuthorizationEnum.APPLICATION,
121+
type: AuthorizationEnum.APPLICATION,
123122
data: [] as any,
124123
isRole: false,
125124
},
126125
{
127126
label: t('views.tool.title'),
128-
value: AuthorizationEnum.TOOL,
127+
type: AuthorizationEnum.TOOL,
129128
data: [] as any,
130129
isRole: false,
131130
},
132131
{
133132
label: t('views.model.title'),
134-
value: AuthorizationEnum.MODEL,
133+
type: AuthorizationEnum.MODEL,
135134
data: [] as any,
136135
isRole: false,
137136
},
138137
])
139138
139+
// 当前激活的数据类型(应用/知识库/模型/工具)
140+
141+
const activeData = computed(() => {
142+
var lastIndex = route.path.lastIndexOf('/')
143+
const currentPathType = route.path.substring(lastIndex + 1).toUpperCase()
144+
return settingTags.filter((item) => {
145+
return item.type === currentPathType
146+
})[0]
147+
})
148+
149+
140150
watch(filterText, (val: any) => {
141151
if (val) {
142152
filterMember.value = memberList.value.filter((v: any) =>
@@ -287,7 +297,7 @@ const handleTabChange = () => {
287297
function getFolder() {
288298
return AuthorizationApi.getSystemFolder(
289299
currentWorkspaceId.value || 'default',
290-
activeName.value,
300+
activeData.value.type,
291301
{},
292302
loading,
293303
)
@@ -305,12 +315,12 @@ const getWholeTree = async (user_id: string) => {
305315
settingTags.map((item: any) => {
306316
let folderIdMap = []
307317
const folderTree = cloneDeep((parentRes as unknown as any).data)
308-
if (Object.keys(childrenRes.data).indexOf(item.value) !== -1) {
318+
if (Object.keys(childrenRes.data).indexOf(item.type) !== -1) {
309319
item.isRole =
310-
childrenRes.data[item.value].length > 0 && hasPermission([EditionConst.IS_EE], 'OR')
311-
? childrenRes.data[item.value][0].auth_type == 'ROLE'
320+
childrenRes.data[item.type].length > 0 && hasPermission([EditionConst.IS_EE], 'OR')
321+
? childrenRes.data[item.type][0].auth_type == 'ROLE'
312322
: false
313-
folderIdMap = getFolderIdMap(childrenRes.data[item.value])
323+
folderIdMap = getFolderIdMap(childrenRes.data[item.type])
314324
dfsFolder(folderTree, folderIdMap)
315325
const permissionHalf = {
316326
VIEW: [],
@@ -329,7 +339,7 @@ const getWholeTree = async (user_id: string) => {
329339
330340
const refreshData = () => {
331341
settingTags.map((item: any) => {
332-
if (activeName.value === item.value) {
342+
if (activeData.value.type === item.type) {
333343
const permissionHalf = {
334344
VIEW: [],
335345
MANAGE: [],

0 commit comments

Comments
 (0)