11<script setup lang="ts">
2- import { computed , ref } from ' vue'
2+ import { computed , onMounted , ref } from ' vue'
33import { useRoute } from ' vue-router'
44import { cloneDeep } from ' lodash'
55import ApplicationApi from ' @/api/admin/workspace/application/application'
66import SharedApi from ' @/api/admin/workspace/shared'
77import ToolApi from ' @/api/admin/workspace/tool/tool'
8- import { APPLICATION_TYPE , RESOURCE_TYPE , TOOL_SCOPE , TOOL_TYPE } from ' @/api/enums'
8+ import { APPLICATION_TYPE , RESOURCE_TYPE , TOOL_TYPE } from ' @/api/enums'
99import type { ApplicationDetail , ApplicationType , FolderItem , ToolItem , ToolType } from ' @/api/types'
1010import FolderTree from ' @/components/business/folder-tree/index.vue'
1111import { FOLDER_ENTRY_ID } from ' @/constants'
@@ -30,10 +30,9 @@ interface ResourceMenuItem {
3030 toolType? : ToolType
3131}
3232
33- const RESOURCE_PAGE = { currentPage: 1 , pageSize: 1_000 }
3433const SUPPORTED_TOOL_TYPES: ToolType [] = [TOOL_TYPE .CUSTOM , TOOL_TYPE .WORKFLOW ]
3534const route = useRoute ()
36- const currentFolderId = ref (' ' )
35+ const currentFolderId = ref (FOLDER_ENTRY_ID . ALL )
3736const loading = ref (false )
3837const resourceItems = ref <ResourceMenuItem []>([])
3938const searchKeyword = ref (' ' )
@@ -71,13 +70,17 @@ function createApplicationNode(application: ApplicationDetail): NodeMenuItem {
7170 return node
7271}
7372
74- function loadTools(folder : FolderItem ) {
75- const requestApi = folder .id === FOLDER_ENTRY_ID .SHARED ? SharedApi : ToolApi
76- const folderQuery = folder .id === FOLDER_ENTRY_ID .SHARED ? {} : { folder_id: folder .id }
73+ function loadTools(folder ? : FolderItem ) {
74+ const isSharedFolder = folder ?.id === FOLDER_ENTRY_ID .SHARED
75+ const requestApi = isSharedFolder ? SharedApi : ToolApi
76+ const folderQuery = {
77+ tool_type_list: SUPPORTED_TOOL_TYPES ,
78+ ... (! isSharedFolder ? { folder_id: folder ?.id || FOLDER_ENTRY_ID .ALL } : {}),
79+ }
7780
78- return requestApi .getToolPage ( RESOURCE_PAGE , { ... folderQuery , scope: TOOL_SCOPE . WORKSPACE } ).then ((page ) => {
79- resourceItems .value = page . records
80- .filter ((tool ) => tool .is_active && SUPPORTED_TOOL_TYPES . includes ( tool . tool_type ) )
81+ return requestApi .getAllTool ( folderQuery ).then ((tools ) => {
82+ resourceItems .value = tools
83+ .filter ((tool ) => tool .is_active )
8184 .map ((tool ) => ({
8285 desc: tool .desc ,
8386 icon: tool .icon ,
@@ -89,10 +92,12 @@ function loadTools(folder: FolderItem) {
8992 })
9093}
9194
92- function loadApplications(folder : FolderItem ) {
93- return ApplicationApi .getApplicationPage (RESOURCE_PAGE , { folder_id: folder .id , publish_status: ' published' }).then ((page ) => {
94- resourceItems .value = page .records
95- .filter ((application ) => application .resource_type === ' application' && application .is_publish && application .id !== currentApplicationId .value )
95+ function loadApplications(folder ? : FolderItem ) {
96+ const folderQuery = { folder_id: folder ?.id || FOLDER_ENTRY_ID .ALL }
97+
98+ return ApplicationApi .getAllApplication ({ ... folderQuery , publish_status: ' published' }).then ((res ) => {
99+ resourceItems .value = res
100+ .filter ((application ) => application .id !== currentApplicationId .value )
96101 .map ((application ) => ({
97102 applicationType: application .type ,
98103 desc: application .desc ,
@@ -104,12 +109,7 @@ function loadApplications(folder: FolderItem) {
104109 })
105110}
106111
107- function handleFolderChange(folder ? : FolderItem ) {
108- if (! folder ) {
109- resourceItems .value = []
110- return
111- }
112-
112+ function loadResources(folder ? : FolderItem ) {
113113 loading .value = true
114114 const request = isToolMenu .value ? loadTools (folder ) : loadApplications (folder )
115115 return request .finally (() => {
@@ -120,19 +120,16 @@ function handleFolderChange(folder?: FolderItem) {
120120function handleNodeDragStart(event : PointerEvent , node : NodeMenuItem ) {
121121 if (event .button === 0 ) emit (' dragstart' , node , event )
122122}
123+
124+ onMounted (() => {
125+ void loadResources ()
126+ })
123127 </script >
124128
125129<template >
126130 <div class =" flex h-[450px] min-h-0" >
127131 <aside class =" flex w-60 shrink-0 border-r pt-3" >
128- <FolderTree
129- v-model =" currentFolderId "
130- :can-edit =" false "
131- :show-shared =" isToolMenu "
132- :source =" source "
133- @loaded =" handleFolderChange "
134- @select =" handleFolderChange "
135- />
132+ <FolderTree v-model =" currentFolderId " :can-edit =" false " :show-shared =" isToolMenu " :source =" source " @select =" loadResources " />
136133 </aside >
137134
138135 <section v-loading =" loading" class =" flex min-w-0 flex-1 flex-col" >
0 commit comments