(instanceId: string = "", daemonId: string = "")
| 67 | const MAX_FOLDER_SIZE = 250 * 1024 * 1024; // 250MB |
| 68 | |
| 69 | export const useFileManager = (instanceId: string = "", daemonId: string = "") => { |
| 70 | const tabList = useLocalStorage<TabsMap>(TAB_LIST_KEY, {}); |
| 71 | const dataSource = ref<DataType[]>(); |
| 72 | const fileStatus = ref<FileStatus>(); |
| 73 | const selectedRowKeys = ref<Key[]>([]); |
| 74 | const selectionData = ref<DataType[]>(); |
| 75 | const isMultiple = computed(() => selectionData.value && selectionData.value.length > 1); |
| 76 | const operationForm = ref<OperationForm>({ |
| 77 | name: "", |
| 78 | current: 1, |
| 79 | pageSize: 100, |
| 80 | total: 0 |
| 81 | }); |
| 82 | |
| 83 | const breadcrumbs = reactive<Breadcrumb[]>([]); |
| 84 | breadcrumbs.push({ |
| 85 | path: "/", |
| 86 | name: "/", |
| 87 | disabled: false |
| 88 | }); |
| 89 | const currentPath = computed( |
| 90 | () => removeTrail(breadcrumbs[breadcrumbs.length - 1].path, "/") + "/" |
| 91 | ); |
| 92 | |
| 93 | const currentTabKey = instanceId + daemonId; |
| 94 | const currentTabs = computed(() => tabList.value[currentTabKey] ?? []); |
| 95 | const activeTab = ref<string>(""); |
| 96 | |
| 97 | const initDefaultTab = (path = "/") => { |
| 98 | const key = v4(); |
| 99 | tabList.value[currentTabKey] ||= []; |
| 100 | tabList.value[currentTabKey].push({ |
| 101 | key, |
| 102 | path, |
| 103 | name: path, |
| 104 | pushedTime: 0, |
| 105 | closable: false |
| 106 | }); |
| 107 | activeTab.value = key; |
| 108 | currentDisk.value = t("TXT_CODE_28124988"); |
| 109 | handleChangeTab(key); |
| 110 | }; |
| 111 | |
| 112 | // clear old tabs |
| 113 | onMounted(() => { |
| 114 | const oneDayInMs = 1000 * 60 * 60 * 24; |
| 115 | const now = Date.now(); |
| 116 | |
| 117 | Object.keys(tabList.value).forEach((key) => { |
| 118 | const tabs = tabList.value[key]; |
| 119 | if (tabs && tabs.length > 0) { |
| 120 | tabList.value[key] = tabs.filter((tab) => { |
| 121 | if (!tab.pushedTime) return true; |
| 122 | return now - tab.pushedTime < oneDayInMs; |
| 123 | }); |
| 124 | |
| 125 | if (tabList.value[key].length === 0) { |
| 126 | delete tabList.value[key]; |
no test coverage detected