generated from template/astro-template
temp
This commit is contained in:
parent
56e3d08869
commit
14b2faaa4d
@ -91,12 +91,19 @@ const FileItem: React.FC<FileItemProps> = ({ item, level, prefix }) => {
|
||||
</div>
|
||||
);
|
||||
};
|
||||
export const getFolder = () => {
|
||||
const url = new URL(window.location.href);
|
||||
|
||||
const searchParams = url.searchParams;
|
||||
const folder = searchParams.get('folder') || '';
|
||||
return folder;
|
||||
};
|
||||
export const Sidebar: React.FC = () => {
|
||||
const { menu, isLoading } = useMenuStore();
|
||||
useEffect(() => {
|
||||
// 初始化菜单数据
|
||||
init();
|
||||
const folder = getFolder();
|
||||
init('', folder);
|
||||
}, []);
|
||||
// 获取顶层项(根目录下的文件和文件夹)
|
||||
const rootItems = useMemo(() => {
|
||||
|
@ -2,6 +2,7 @@ import { create } from 'zustand';
|
||||
import { query } from '@/modules/query';
|
||||
import { QueryLoginBrowser } from '@/query/query-login/query-login-browser';
|
||||
import { QueryResources } from '@/query/query-resources/index';
|
||||
import { toast } from 'react-toastify';
|
||||
|
||||
export const queryLogin = new QueryLoginBrowser({ query });
|
||||
export const queryResources = new QueryResources({
|
||||
@ -46,7 +47,7 @@ class Status {
|
||||
}
|
||||
const status = new Status();
|
||||
|
||||
export const init = async (prefix: string = '') => {
|
||||
export const init = async (resource: string = '', prefix: string = '') => {
|
||||
const { setMenu, setCurrentPath, setLoading } = useMenuStore.getState();
|
||||
let me = await queryLogin.checkLocalUser();
|
||||
const isInitialized = status.isInitialized;
|
||||
@ -60,7 +61,15 @@ export const init = async (prefix: string = '') => {
|
||||
if (recursive) {
|
||||
data['recursive'] = recursive;
|
||||
}
|
||||
const res = await queryResources.getList(prefix, data);
|
||||
if (prefix) {
|
||||
queryResources.setPrefix(prefix);
|
||||
}
|
||||
const res = await queryResources.getList(resource, data);
|
||||
// @ts-ignore
|
||||
if (res?.status === 404) {
|
||||
toast.error('资源不存在,请检查路径是否正确');
|
||||
return;
|
||||
}
|
||||
if (res.code === 200) {
|
||||
const menu = res.data!.map((item: any) => {
|
||||
if (item.prefix) {
|
||||
|
@ -7,7 +7,7 @@ type QueryResourcesOptions = {
|
||||
[key: string]: any;
|
||||
};
|
||||
export class QueryResources {
|
||||
prefix: string; // root/resources
|
||||
prefix: string; // /root/resources
|
||||
storage: Storage;
|
||||
constructor(opts: QueryResourcesOptions) {
|
||||
if (opts.username) {
|
||||
@ -18,7 +18,11 @@ export class QueryResources {
|
||||
this.storage = opts.storage || localStorage;
|
||||
}
|
||||
setUsername(username: string) {
|
||||
this.prefix = `/${username}/resources/`;
|
||||
const prefix = `/${username}/resources/`;
|
||||
return prefix;
|
||||
}
|
||||
setPrefix(prefix: string) {
|
||||
this.prefix = prefix;
|
||||
}
|
||||
header(headers?: Record<string, string>, json = true): Record<string, string> {
|
||||
const token = this.storage.getItem('token');
|
||||
|
Loading…
x
Reference in New Issue
Block a user