Skip to content
This repository was archived by the owner on Dec 22, 2024. It is now read-only.

Commit 99acb78

Browse files
committed
打开文件夹功能
1 parent a6ce3f8 commit 99acb78

File tree

10 files changed

+126
-16
lines changed

10 files changed

+126
-16
lines changed

backend/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ EXPOSE 8000
3838

3939
# 运行应用
4040
#CMD ["uvicorn", "src.main:app", "--host", "0.0.0.0", "--port", "8000"]
41-
CMD ["gunicorn", "-k", "uvicorn.workers.UvicornWorker", "-w","4", "-b", "0.0.0.0:8000", "src.main:app"]
41+
CMD ["gunicorn", "-k", "uvicorn.workers.UvicornWorker", "-w","1", "-b", "0.0.0.0:8000", "src.main:app"]
0 Bytes
Binary file not shown.
340 Bytes
Binary file not shown.

backend/src/api/file.py

-4
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@
1919
def mkdir(
2020
success: bool = Depends(create_folder_dp),
2121
):
22-
"""user_root_path = get_root_path(user)
23-
if not os.path.exists(f"{user_root_path}"):
24-
return {"error": "path not exists"}
25-
os.mkdir(f"{user_root_path}/{path}")"""
2622
return {"success": success}
2723

2824

backend/src/api/users.py

+15-1
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,18 @@ async def register(user: UserCreate, db: Session = Depends(get_db)):
9696
db_user = get_user_by_email(db, email=user.email)
9797
if db_user:
9898
raise HTTPException(status_code=400, detail="邮箱已存在")
99-
return create_user(db=db, user=user)
99+
user = create_user(db=db, user=user)
100+
access_token, expires_access = create_access_token(user.id)
101+
refresh_token, expire_refresh = create_refresh_token(user.id)
102+
response = LoginResponse(
103+
success=True,
104+
data=LoginData(
105+
username=user.username,
106+
roles=["admin"],
107+
access_Token=access_token,
108+
refresh_Token=refresh_token,
109+
expires=expires_access, # TODO
110+
),
111+
access_token=access_token,
112+
)
113+
return response

backend/src/dependencies.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,4 @@ def create_folder_dp(
9191
db: Session = Depends(get_db),
9292
):
9393
create_folder(path, user, db)
94-
return {"success": True}
94+
return True

frontend/src/api/user.ts

+11
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ export const getLogin = (data?: object) => {
3636
//return http.request<UserResult>("post", "login", { data, headers: { "Content-Type": "application/x-www-form-urlencoded" } });
3737
};
3838

39+
/** 注册 */
40+
export const getRegister = (data?: object) => {
41+
const reg_data = {
42+
username: data["username"],
43+
nickname: data["username"],
44+
password: data["password"],
45+
email: "test@test",
46+
};
47+
return http.request<UserResult>("post", baseUrlApi("api/register"), { data:reg_data, headers: { "Content-Type": "application/json" } });
48+
};
49+
3950
/** 刷新token */
4051
export const refreshTokenApi = (data?: object) => {
4152
return http.request<RefreshTokenResult>("post", baseUrlApi("api/refreshToken"), { data });

frontend/src/store/modules/user.ts

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { RefreshTokenResult, UserResult, getLogin, refreshTokenApi } from "@/api/user";
1+
import { RefreshTokenResult, UserResult, getLogin, getRegister, refreshTokenApi } from "@/api/user";
22
import { routerArrays } from "@/layout/types";
33
import { resetRouter, router } from "@/router";
44
import { store } from "@/store";
@@ -41,6 +41,20 @@ export const useUserStore = defineStore({
4141
});
4242
});
4343
},
44+
async registerByUsername(data) {
45+
return new Promise<UserResult>((resolve, reject) => {
46+
getRegister(data)
47+
.then(data => {
48+
if (data) {
49+
setToken(data.data);
50+
resolve(data);
51+
}
52+
})
53+
.catch(error => {
54+
reject(error);
55+
});
56+
});
57+
},
4458
/** 前端登出(不调用接口) */
4559
logOut() {
4660
this.username = "";

frontend/src/views/login/index.vue

+30
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,30 @@ const onLogin = async (formEl: FormInstance | undefined) => {
6262
});
6363
};
6464
65+
const onRegister = async (formEl: FormInstance | undefined) => {
66+
loading.value = true;
67+
if (!formEl) return;
68+
await formEl.validate((valid, fields) => {
69+
if (valid) {
70+
const formData = { grant_type: 'password', username: ruleForm.username, password: ruleForm.password }
71+
useUserStoreHook()
72+
.registerByUsername(formData)
73+
.then(res => {
74+
if (res.success) {
75+
// 获取后端路由
76+
initRouter().then(() => {
77+
router.push(getTopMenu(true).path);
78+
message("注册成功", { type: "success" });
79+
});
80+
}
81+
});
82+
} else {
83+
loading.value = false;
84+
return fields;
85+
}
86+
});
87+
};
88+
6589
/** 使用公共函数,避免`removeEventListener`失效 */
6690
function onkeypress({ code }: KeyboardEvent) {
6791
if (code === "Enter") {
@@ -124,6 +148,12 @@ onBeforeUnmount(() => {
124148
登录
125149
</el-button>
126150
</Motion>
151+
<Motion :delay="300">
152+
<el-button class="w-full mt-4" size="default" type="primary" :loading="loading"
153+
@click="onRegister(ruleFormRef)">
154+
注册
155+
</el-button>
156+
</Motion>
127157
</el-form>
128158
</div>
129159
</div>

frontend/src/views/welcome/index.vue

+53-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<script setup lang="ts">
22
import { baseUrlApi } from "@/api/utils";
33
import { http } from "@/utils/http";
4-
import data from "@iconify-icons/ri/fullscreen-fill";
54
import PureTable from "@pureadmin/table";
65
import qs from "qs";
76
import { onMounted, ref } from "vue";
@@ -25,7 +24,11 @@ const tableData = ref([]);
2524
// 在 'onMounted' 钩子中发起 HTTP 请求
2625
onMounted(async () => {
2726
try {
28-
const response = await http.request<FilesResult>("get", baseUrlApi("/api/list/"));
27+
const response = await http.request<FilesResult>("get", baseUrlApi("/api/list/"));
28+
const items = response.items;
29+
items.forEach(item => {
30+
item.type = item.type === 0 ? '文件夹' : '文件';
31+
});
2932
tableData.value = response.items;
3033
} catch (error) {
3134
console.error('There was an error fetching the data:', error);
@@ -47,6 +50,22 @@ const toggleSelection = (rows?: any) => {
4750
const handleSelectionChange = val => {
4851
multipleSelection.value = val;
4952
};
53+
const handleRowClick = async row => {
54+
if (row.type === '文件夹') {
55+
try {
56+
const response = await http.request<FilesResult>("get", baseUrlApi("/api/list/") + row.name);
57+
const items = response.items;
58+
items.forEach(item => {
59+
item.type = item.type === 0 ? '文件夹' : '文件';
60+
});
61+
tableData.value = response.items;
62+
} catch (error) {
63+
console.error('There was an error fetching the data:', error);
64+
}
65+
} else {
66+
alert('这是一个文件,无法打开!');
67+
}
68+
};
5069
const handleDownload = async () => {
5170
if (multipleSelection.value.length === 0) {
5271
alert('请至少选择一项进行下载!');
@@ -101,7 +120,7 @@ const handleDownload = async () => {
101120
}
102121
103122
};
104-
const handleUpload = async (uploadPath) => {
123+
const handleUpload = async () => {
105124
// 创建一个文件输入控件
106125
const input = document.createElement('input');
107126
input.type = 'file';
@@ -125,6 +144,8 @@ const handleUpload = async (uploadPath) => {
125144
126145
if (response.success === true) {
127146
alert('上传成功!');
147+
// 刷新页面
148+
window.location.reload();
128149
} else {
129150
console.error('上传失败:', response);
130151
}
@@ -134,6 +155,27 @@ const handleUpload = async (uploadPath) => {
134155
};
135156
};
136157
158+
const handleNewFolder = async () => {
159+
const folderName = prompt('请输入文件夹名称:');
160+
if (!folderName) {
161+
return;
162+
}
163+
164+
try {
165+
const response = await http.request<FilesResult>("post",baseUrlApi("api/mkdir/"+ folderName) , {
166+
});
167+
168+
if (response.success === true) {
169+
alert('创建成功!');
170+
// 刷新页面
171+
window.location.reload();
172+
} else {
173+
console.error('创建失败:', response);
174+
}
175+
} catch (error) {
176+
console.error('创建文件夹时出错:', error);
177+
}
178+
};
137179
138180
const columns: TableColumnList = [
139181
{
@@ -148,22 +190,25 @@ const columns: TableColumnList = [
148190
label: "大小",
149191
prop: "size"
150192
},
151-
{
152-
label: "日期",
153-
prop: "date"
193+
{
194+
label: "类型",
195+
prop: "type"
154196
}
155197
];
156198
</script>
157199

158200
<template>
159-
<pure-table ref="tableRef" :data="tableData" :columns="columns"
160-
@selection-change="handleSelectionChange" height="360" />
201+
<pure-table ref="tableRef" :data="tableData" :columns="columns"
202+
@selection-change="handleSelectionChange"
203+
@row-click="handleRowClick" height="360"> </pure-table>
161204
<div style="display: flex; justify-content: space-between; align-items: center; margin-top: 20px;">
162205
<div>
163206
<el-button @click="toggleSelection(tableData)">全选</el-button>
164207
<el-button @click="toggleSelection()">清除</el-button>
165208
</div>
166209
<div>
210+
211+
<el-button type="primary" icon="el-icon-download" @click="handleNewFolder">新建文件夹</el-button>
167212
<el-button type="primary" icon="el-icon-download" @click="handleDownload">下载</el-button>
168213
<el-button type="primary" icon="el-icon-download" @click="handleUpload">上传</el-button>
169214
</div>

0 commit comments

Comments
 (0)