feat: resource-authorization
This commit is contained in:
parent
1287da6ed0
commit
687fd6cb84
@ -4,22 +4,22 @@ import type { pageRequest } from '@/api/type/common'
|
|||||||
import type { Ref } from 'vue'
|
import type { Ref } from 'vue'
|
||||||
|
|
||||||
import useStore from '@/stores'
|
import useStore from '@/stores'
|
||||||
const prefix: any = { _value: '/workspace/' }
|
const prefix = '/workspace'
|
||||||
Object.defineProperty(prefix, 'value', {
|
|
||||||
get: function () {
|
|
||||||
const { user } = useStore()
|
|
||||||
return this._value + user.getWorkspaceId()
|
|
||||||
},
|
|
||||||
})
|
|
||||||
/**
|
/**
|
||||||
* 获取资源权限
|
* 获取资源权限
|
||||||
* @query 参数
|
* @query 参数
|
||||||
*/
|
*/
|
||||||
const getResourceAuthorization: (
|
const getResourceAuthorization: (
|
||||||
|
workspace_id: string,
|
||||||
user_id: string,
|
user_id: string,
|
||||||
loading?: Ref<boolean>,
|
loading?: Ref<boolean>,
|
||||||
) => Promise<Result<any>> = (user_id, loading) => {
|
) => Promise<Result<any>> = (workspace_id, user_id, loading) => {
|
||||||
return get(`${prefix.value}/user_resource_permission/user/${user_id}`, undefined, loading)
|
return get(
|
||||||
|
`${prefix}/${workspace_id}/user_resource_permission/user/${user_id}`,
|
||||||
|
undefined,
|
||||||
|
loading,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -41,24 +41,45 @@ const getResourceAuthorization: (
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
const putResourceAuthorization: (
|
const putResourceAuthorization: (
|
||||||
|
workspace_id: string,
|
||||||
user_id: string,
|
user_id: string,
|
||||||
body: any,
|
body: any,
|
||||||
loading?: Ref<boolean>,
|
loading?: Ref<boolean>,
|
||||||
) => Promise<Result<any>> = (user_id, body, loading) => {
|
) => Promise<Result<any>> = (workspace_id, user_id, body, loading) => {
|
||||||
return put(`${prefix.value}/user_resource_permission/user/${user_id}`, body, loading)
|
return put(`${prefix}/${workspace_id}/user_resource_permission/user/${user_id}`, body, loading)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取成员列表
|
* 获取成员列表
|
||||||
* @query 参数
|
* @query 参数
|
||||||
*/
|
*/
|
||||||
const getUserList: (loading?: Ref<boolean>) => Promise<Result<any>> = (loading) => {
|
const getUserList: (workspace_id: string, loading?: Ref<boolean>) => Promise<Result<any>> = (
|
||||||
return get(`${prefix.value}/user_list`, undefined, loading)
|
workspace_id,
|
||||||
|
loading,
|
||||||
|
) => {
|
||||||
|
return get(`${prefix}/${workspace_id}/user_list`, undefined, loading)
|
||||||
}
|
}
|
||||||
|
|
||||||
const getUserMember: (loading?: Ref<boolean>) => Promise<Result<any>> = (loading) => {
|
const getUserMember: (workspace_id: string, loading?: Ref<boolean>) => Promise<Result<any>> = (
|
||||||
return get(`${prefix.value}/user_member`, undefined, loading)
|
workspace_id,
|
||||||
|
loading,
|
||||||
|
) => {
|
||||||
|
return get(`${prefix}/${workspace_id}/user_member`, undefined, loading)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得系统文件夹列表
|
||||||
|
* @params 参数
|
||||||
|
* source : APPLICATION, KNOWLEDGE, TOOL
|
||||||
|
* data : {name: string}
|
||||||
|
*/
|
||||||
|
const getSystemFolder: (
|
||||||
|
workspace_id: string,
|
||||||
|
source: string,
|
||||||
|
data?: any,
|
||||||
|
loading?: Ref<boolean>,
|
||||||
|
) => Promise<Result<Array<any>>> = (workspace_id, source, data, loading) => {
|
||||||
|
return get(`${prefix}/${workspace_id}/${source}/folder`, data, loading)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@ -66,4 +87,5 @@ export default {
|
|||||||
putResourceAuthorization,
|
putResourceAuthorization,
|
||||||
getUserList,
|
getUserList,
|
||||||
getUserMember,
|
getUserMember,
|
||||||
|
getSystemFolder,
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,7 +12,7 @@
|
|||||||
<template #dropdown>
|
<template #dropdown>
|
||||||
<el-dropdown-menu v-loading="loading">
|
<el-dropdown-menu v-loading="loading">
|
||||||
<el-dropdown-item
|
<el-dropdown-item
|
||||||
v-for="item in user.workspace_list"
|
v-for="item in data"
|
||||||
:key="item.id"
|
:key="item.id"
|
||||||
:class="item.id === currentWorkspace?.id ? 'active' : ''"
|
:class="item.id === currentWorkspace?.id ? 'active' : ''"
|
||||||
@click="changeWorkspace(item)"
|
@click="changeWorkspace(item)"
|
||||||
@ -37,19 +37,21 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, ref } from 'vue'
|
import { computed, ref } from 'vue'
|
||||||
import type { WorkspaceItem } from '@/api/type/workspace'
|
import type { WorkspaceItem } from '@/api/type/workspace'
|
||||||
import useStore from '@/stores'
|
|
||||||
|
|
||||||
const { user } = useStore()
|
const props = defineProps({
|
||||||
const loading = ref(false)
|
data: {
|
||||||
|
type: Array,
|
||||||
const currentWorkspace = computed(() => {
|
default: () => [],
|
||||||
return user.workspace_list.find((w) => w.id == user.workspace_id)
|
},
|
||||||
|
currentWorkspace: {
|
||||||
|
type: Object,
|
||||||
|
default: () => {},
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
const loading = ref(false)
|
||||||
|
const emit = defineEmits(['changeWorkspace'])
|
||||||
function changeWorkspace(item: WorkspaceItem) {
|
function changeWorkspace(item: WorkspaceItem) {
|
||||||
if (item.id === user.workspace_id) return
|
emit('changeWorkspace', item)
|
||||||
user.setWorkspaceId(item.id || 'default')
|
|
||||||
window.location.reload()
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
|||||||
@ -13,7 +13,12 @@
|
|||||||
direction="vertical"
|
direction="vertical"
|
||||||
v-if="hasPermission(EditionConst.IS_EE, 'OR')"
|
v-if="hasPermission(EditionConst.IS_EE, 'OR')"
|
||||||
/>
|
/>
|
||||||
<WorkspaceDropdown v-if="hasPermission(EditionConst.IS_EE, 'OR')" />
|
<WorkspaceDropdown
|
||||||
|
v-if="hasPermission(EditionConst.IS_EE, 'OR')"
|
||||||
|
:data="user.workspace_list"
|
||||||
|
:currentWorkspace="currentWorkspace"
|
||||||
|
@changeWorkspace="changeWorkspace"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<TopMenu></TopMenu>
|
<TopMenu></TopMenu>
|
||||||
<TopAbout></TopAbout>
|
<TopAbout></TopAbout>
|
||||||
@ -22,11 +27,24 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
import { computed, ref } from 'vue'
|
||||||
import TopMenu from './top-menu/index.vue'
|
import TopMenu from './top-menu/index.vue'
|
||||||
import Avatar from './avatar/index.vue'
|
import Avatar from './avatar/index.vue'
|
||||||
import TopAbout from './top-about/index.vue'
|
import TopAbout from './top-about/index.vue'
|
||||||
import { EditionConst } from '@/utils/permission/data'
|
import { EditionConst } from '@/utils/permission/data'
|
||||||
import { hasPermission } from '@/utils/permission/index'
|
import { hasPermission } from '@/utils/permission/index'
|
||||||
|
import type { WorkspaceItem } from '@/api/type/workspace'
|
||||||
|
import useStore from '@/stores'
|
||||||
|
const { user } = useStore()
|
||||||
|
const currentWorkspace = computed(() => {
|
||||||
|
return user.workspace_list.find((w) => w.id == user.workspace_id)
|
||||||
|
})
|
||||||
|
|
||||||
|
function changeWorkspace(item: WorkspaceItem) {
|
||||||
|
if (item.id === user.workspace_id) return
|
||||||
|
user.setWorkspaceId(item.id || 'default')
|
||||||
|
window.location.reload()
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
.app-top-bar-container {
|
.app-top-bar-container {
|
||||||
|
|||||||
@ -8,7 +8,12 @@
|
|||||||
direction="vertical"
|
direction="vertical"
|
||||||
v-if="hasPermission(EditionConst.IS_EE, 'OR')"
|
v-if="hasPermission(EditionConst.IS_EE, 'OR')"
|
||||||
/>
|
/>
|
||||||
<WorkspaceDropdown v-if="hasPermission(EditionConst.IS_EE, 'OR')" />
|
<WorkspaceDropdown
|
||||||
|
v-if="hasPermission(EditionConst.IS_EE, 'OR')"
|
||||||
|
:data="workspaceList"
|
||||||
|
:currentWorkspace="currentWorkspace"
|
||||||
|
@changeWorkspace="changeWorkspace"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<el-card style="--el-card-padding: 0">
|
<el-card style="--el-card-padding: 0">
|
||||||
@ -76,7 +81,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { onMounted, ref, reactive, watch } from 'vue'
|
import { onMounted, ref, reactive, watch, computed } from 'vue'
|
||||||
import AuthorizationApi from '@/api/user/resource-authorization'
|
import AuthorizationApi from '@/api/user/resource-authorization'
|
||||||
import PermissionSetting from './component/PermissionSetting.vue'
|
import PermissionSetting from './component/PermissionSetting.vue'
|
||||||
import { MsgSuccess, MsgConfirm } from '@/utils/message'
|
import { MsgSuccess, MsgConfirm } from '@/utils/message'
|
||||||
@ -86,6 +91,8 @@ import useStore from '@/stores'
|
|||||||
import { cloneDeep } from 'lodash'
|
import { cloneDeep } from 'lodash'
|
||||||
import { EditionConst } from '@/utils/permission/data'
|
import { EditionConst } from '@/utils/permission/data'
|
||||||
import { hasPermission } from '@/utils/permission/index'
|
import { hasPermission } from '@/utils/permission/index'
|
||||||
|
import WorkspaceApi from '@/api/workspace/workspace.ts'
|
||||||
|
import type { WorkspaceItem } from '@/api/type/workspace'
|
||||||
|
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const rLoading = ref(false)
|
const rLoading = ref(false)
|
||||||
@ -97,7 +104,7 @@ const filterText = ref('')
|
|||||||
|
|
||||||
const activeName = ref(AuthorizationEnum.KNOWLEDGE)
|
const activeName = ref(AuthorizationEnum.KNOWLEDGE)
|
||||||
const tableHeight = ref(0)
|
const tableHeight = ref(0)
|
||||||
const { folder } = useStore()
|
const { user } = useStore()
|
||||||
|
|
||||||
const settingTags = reactive([
|
const settingTags = reactive([
|
||||||
{
|
{
|
||||||
@ -153,6 +160,7 @@ function submitPermissions() {
|
|||||||
return [...pre, ...next]
|
return [...pre, ...next]
|
||||||
}, [])
|
}, [])
|
||||||
AuthorizationApi.putResourceAuthorization(
|
AuthorizationApi.putResourceAuthorization(
|
||||||
|
currentWorkspaceId.value || 'default',
|
||||||
currentUser.value,
|
currentUser.value,
|
||||||
{ user_resource_permission_list: user_resource_permission_list },
|
{ user_resource_permission_list: user_resource_permission_list },
|
||||||
rLoading,
|
rLoading,
|
||||||
@ -169,7 +177,7 @@ function clickMemberHandle(item: any) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getMember(id?: string) {
|
function getMember(id?: string) {
|
||||||
AuthorizationApi.getUserMember(loading).then((res) => {
|
AuthorizationApi.getUserMember(currentWorkspaceId.value || 'default', loading).then((res) => {
|
||||||
memberList.value = res.data
|
memberList.value = res.data
|
||||||
filterMember.value = res.data
|
filterMember.value = res.data
|
||||||
|
|
||||||
@ -256,13 +264,20 @@ const dfsFolder = (arr: any[] = [], folderIdMap: any) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getFolder() {
|
function getFolder() {
|
||||||
return folder.asyncGetFolder('KNOWLEDGE', {}, loading)
|
return AuthorizationApi.getSystemFolder(
|
||||||
|
currentWorkspaceId.value || 'default',
|
||||||
|
'KNOWLEDGE',
|
||||||
|
{},
|
||||||
|
loading,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function getResourcePermissions(user_id: string) {
|
function getResourcePermissions(user_id: string) {
|
||||||
return AuthorizationApi.getResourceAuthorization(user_id, rLoading)
|
return AuthorizationApi.getResourceAuthorization(
|
||||||
|
currentWorkspaceId.value || 'default',
|
||||||
|
user_id,
|
||||||
|
rLoading,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
const getWholeTree = async (user_id: string) => {
|
const getWholeTree = async (user_id: string) => {
|
||||||
const [parentRes, childrenRes] = await Promise.all([getFolder(), getResourcePermissions(user_id)])
|
const [parentRes, childrenRes] = await Promise.all([getFolder(), getResourcePermissions(user_id)])
|
||||||
if (!childrenRes.data || Object.keys(childrenRes.data).length > 0) {
|
if (!childrenRes.data || Object.keys(childrenRes.data).length > 0) {
|
||||||
@ -313,7 +328,11 @@ const getFolderIdMap = (arr: any = []) => {
|
|||||||
}, {})
|
}, {})
|
||||||
}
|
}
|
||||||
function ResourcePermissions(user_id: string) {
|
function ResourcePermissions(user_id: string) {
|
||||||
AuthorizationApi.getResourceAuthorization(user_id, rLoading).then((res) => {
|
AuthorizationApi.getResourceAuthorization(
|
||||||
|
currentWorkspaceId.value || 'default',
|
||||||
|
user_id,
|
||||||
|
rLoading,
|
||||||
|
).then((res) => {
|
||||||
if (!res.data || Object.keys(res.data).length > 0) {
|
if (!res.data || Object.keys(res.data).length > 0) {
|
||||||
settingTags.map((item: any) => {
|
settingTags.map((item: any) => {
|
||||||
if (Object.keys(res.data).indexOf(item.value) !== -1) {
|
if (Object.keys(res.data).indexOf(item.value) !== -1) {
|
||||||
@ -325,6 +344,23 @@ function ResourcePermissions(user_id: string) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const workspaceList = ref<WorkspaceItem[]>([])
|
||||||
|
const currentWorkspaceId = ref<string | undefined>('')
|
||||||
|
const currentWorkspace = computed(() => {
|
||||||
|
return workspaceList.value.find((w) => w.id == currentWorkspaceId.value)
|
||||||
|
})
|
||||||
|
async function getWorkspaceList() {
|
||||||
|
if (user.isEE()) {
|
||||||
|
const res = await WorkspaceApi.getSystemWorkspaceList(loading)
|
||||||
|
workspaceList.value = res.data
|
||||||
|
currentWorkspaceId.value = 'default'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function changeWorkspace(item: WorkspaceItem) {
|
||||||
|
currentWorkspaceId.value = item.id
|
||||||
|
getMember()
|
||||||
|
}
|
||||||
function refresh(data?: string[]) {}
|
function refresh(data?: string[]) {}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
@ -334,6 +370,7 @@ onMounted(() => {
|
|||||||
tableHeight.value = window.innerHeight - 330
|
tableHeight.value = window.innerHeight - 330
|
||||||
})()
|
})()
|
||||||
}
|
}
|
||||||
|
getWorkspaceList()
|
||||||
getMember()
|
getMember()
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@ -17,8 +17,8 @@ export default defineConfig(({ mode }) => {
|
|||||||
const prefix = process.env.VITE_DYNAMIC_PREFIX || ENV.VITE_BASE_PATH
|
const prefix = process.env.VITE_DYNAMIC_PREFIX || ENV.VITE_BASE_PATH
|
||||||
const proxyConf: Record<string, string | ProxyOptions> = {}
|
const proxyConf: Record<string, string | ProxyOptions> = {}
|
||||||
proxyConf['/api'] = {
|
proxyConf['/api'] = {
|
||||||
// target: 'http://43.166.1.146:8080',
|
target: 'http://43.166.1.146:8080',
|
||||||
target: 'http://127.0.0.1:8080',
|
// target: 'http://127.0.0.1:8080',
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
rewrite: (path: string) => path.replace(ENV.VITE_BASE_PATH, '/'),
|
rewrite: (path: string) => path.replace(ENV.VITE_BASE_PATH, '/'),
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user