From 9964e9e5491341d4c4a779d28bce5452e7027dec Mon Sep 17 00:00:00 2001
From: prr <3099672575@qq.com>
Date: Mon, 28 Oct 2024 08:54:40 +0800
Subject: [PATCH] test:get share file
---
frontend/src/components/builtin/FileList.vue | 2 +
frontend/src/components/builtin/FileTree.vue | 5 ++-
frontend/src/components/computer/Computer.vue | 37 +++++++++++++++++-
frontend/src/hook/useComputer.ts | 7 +++-
frontend/src/i18n/index.ts | 3 +-
frontend/src/i18n/lang/zh.json | 1 +
frontend/src/system/core/FileOs.ts | 39 ++++++++++++++++---
7 files changed, 83 insertions(+), 11 deletions(-)
diff --git a/frontend/src/components/builtin/FileList.vue b/frontend/src/components/builtin/FileList.vue
index 94e02a5..8220aff 100644
--- a/frontend/src/components/builtin/FileList.vue
+++ b/frontend/src/components/builtin/FileList.vue
@@ -196,6 +196,8 @@ function handleClick(index: number) {
chosenIndexs.value = [index];
}
onMounted(() => {
+ console.log('filelist:',props.fileList)
+
chosenIndexs.value = [];
props.onChosen(
throttle((rect: Rect) => {
diff --git a/frontend/src/components/builtin/FileTree.vue b/frontend/src/components/builtin/FileTree.vue
index db4c6fa..3b89ddf 100644
--- a/frontend/src/components/builtin/FileTree.vue
+++ b/frontend/src/components/builtin/FileTree.vue
@@ -51,6 +51,10 @@
import { useSystem,OsFileWithoutContent,basename } from '@/system/index.ts';
import { onMounted, ref } from 'vue';
import { dealSystemName } from '@/i18n';
+// 分享
+import { getSystemConfig } from "@/system/config";
+const config = ref(getSystemConfig())
+
const sys = useSystem();
type FileWithOpen = OsFileWithoutContent & {
isOpen?: boolean;
@@ -119,7 +123,6 @@ async function onOpenArrow(item: FileWithOpen) {
return;
}
item.isOpen = !item.isOpen;
-
item.subFileList = (await sys.fs.readdir(item.path)).filter((file:any) => {
return file.isDirectory;
});
diff --git a/frontend/src/components/computer/Computer.vue b/frontend/src/components/computer/Computer.vue
index 3957ba2..be5b83b 100644
--- a/frontend/src/components/computer/Computer.vue
+++ b/frontend/src/components/computer/Computer.vue
@@ -42,6 +42,16 @@
:key="random"
>
+
{{ t("share") }}
+
+
@@ -125,7 +135,7 @@ const { refersh, createFolder, backFolder, openFolder, onComputerMount } = useCo
return router_url.value;
},
setFileList(list) {
- //console.log(list)
+ console.log('list:',list)
//currentList.value = list;
if(config.ext && config.ext instanceof Array && config.ext.length > 0) {
const res:any = []
@@ -196,6 +206,7 @@ function leftHandleDown(e: MouseEvent) {
}
const rootFileList = ref>([]);
+const shareFileList = ref>([]);
const random = ref(0);
onMounted(() => {
if (config) {
@@ -216,6 +227,24 @@ onMounted(() => {
random.value = random.value + 1;
}
});
+ shareFileList.value = [{
+ atime: "2024-10-21T18:25:12.936228381+08:00",
+ birthtime: "2024-10-21T18:25:12.936228381+08:00",
+ content: "",
+ ext: "",
+ isDirectory: true,
+ isFile: false,
+ isOpen: false,
+ isSymlink: false,
+ modTime: "2024-10-21T18:25:12.936228381+08:00",
+ mode: 2147484141,
+ name: "F",
+ oldPath: "/F",
+ parentPath: "/",
+ path: "/F",
+ size: 64,
+ title: "F"
+ }]
});
function handleOuterClick() {
@@ -245,8 +274,12 @@ async function onTreeOpen(path: string) {
chosenTreePath.value = path;
const file = await system.fs.stat(path);
+
if (file) {
- openFolder(file);
+ console.log('此电脑:',file,path);
+ const temp = path.substr(0,2) == '/F' ? shareFileList.value[0] : file
+ openFolder(temp)
+ // openFolder(file);
}
//console.log(path)
router_url.value = path;
diff --git a/frontend/src/hook/useComputer.ts b/frontend/src/hook/useComputer.ts
index bdff2dd..d7b5e54 100644
--- a/frontend/src/hook/useComputer.ts
+++ b/frontend/src/hook/useComputer.ts
@@ -37,9 +37,8 @@ export const useComputer = (adpater: {
}
if (!(await isVia(currentPath))) return;
- //console.log(currentPath)
const result = await adpater.readdir(currentPath);
- //console.log(result)
+ console.log('refersh result:',result)
if (result) adpater.setFileList(result);
};
const createFolder = (path: RouterPath) => {
@@ -60,7 +59,11 @@ export const useComputer = (adpater: {
refersh();
};
const openFolder = (file: OsFileWithoutContent) => {
+ console.log('打开:', file);
+
if (adpater.isDirectory(file)) {
+ console.log('走refresh');
+
adpater.setRouter(file.path);
refersh();
} else {
diff --git a/frontend/src/i18n/index.ts b/frontend/src/i18n/index.ts
index 0df6325..e07f68a 100644
--- a/frontend/src/i18n/index.ts
+++ b/frontend/src/i18n/index.ts
@@ -58,7 +58,8 @@ export function dealSystemName(name: string) {
"C": t('system'),
"D": t('document'),
"E": t('office'),
- "B": t('recycle')
+ "B": t('recycle'),
+ "F": t('share')
}
if (sysNames[name]) {
return sysNames[name];
diff --git a/frontend/src/i18n/lang/zh.json b/frontend/src/i18n/lang/zh.json
index 8a81c74..26a9c7c 100644
--- a/frontend/src/i18n/lang/zh.json
+++ b/frontend/src/i18n/lang/zh.json
@@ -7,6 +7,7 @@
"system": "系统",
"office": "办公",
"recycle": "回收站",
+ "share": "分享",
"favorite": "我的收藏",
"desktop": "桌面",
"personalization": "个性化",
diff --git a/frontend/src/system/core/FileOs.ts b/frontend/src/system/core/FileOs.ts
index 88ccc6b..dc9595b 100644
--- a/frontend/src/system/core/FileOs.ts
+++ b/frontend/src/system/core/FileOs.ts
@@ -1,6 +1,8 @@
import { getFileUrl,fetchGet,fetchPost } from "../config.ts";
const API_BASE_URL = getFileUrl()
import { OsFileMode } from '../core/FileMode';
+import { getSystemConfig } from "@/system/config";
+
export async function handleReadDir(path: string): Promise {
const res = await fetchGet(`${API_BASE_URL}/read?path=${encodeURIComponent(path)}`);
if (!res.ok) {
@@ -8,6 +10,15 @@ export async function handleReadDir(path: string): Promise {
}
return await res.json();
}
+// 查看分享文件
+export async function handleReadShareDir(val: number): Promise {
+ console.log('共享-用户ID:', val)
+ const res = await fetchGet(`${API_BASE_URL}/sharelist?id=${val}`);
+ if (!res.ok) {
+ return false;
+ }
+ return await res.json();
+}
export async function handleStat(path: string): Promise {
const res = await fetchGet(`${API_BASE_URL}/stat?path=${encodeURIComponent(path)}`);
@@ -16,6 +27,7 @@ export async function handleStat(path: string): Promise {
}
return await res.json();
}
+
export async function handleChmod(path: string, mode: string): Promise {
const res = await fetchPost(`${API_BASE_URL}/chmod`, JSON.stringify({ path, mode }));
if (!res.ok) {
@@ -191,15 +203,30 @@ export async function handleUnZip(path: string): Promise {
}
export const useOsFile = () => {
return {
- async readdir(path: string) {
- const response = await handleReadDir(path);
+ // 分享
+ async sharedir(val: number) {
+ const response = await handleReadShareDir(val);
+ if (response && response.data) {
+ return response.data;
+ }
+ return [];
+ },
+ async readdir(path: string) {console.log('raeddir path:',path,path.substring(0,2))
+ const api = path.substring(0,2) == '/F' ? handleReadShareDir : handleReadDir
+ const temp = path.substring(0,2) == '/F' ? getSystemConfig().userInfo.id : path
+ const response = await api(temp);
+ // const response = await handleReadDir(path);
if (response && response.data) {
return response.data;
}
return [];
},
async stat(path: string) {
- const response = await handleStat(path);
+ console.log('stat path:',path,path.substring(0,2))
+ const api = path.substring(0,2) == '/F' ? handleReadShareDir : handleStat
+ const temp = path.substring(0,2) == '/F' ? getSystemConfig().userInfo.id : path
+ const response = await api(temp);
+ // const response = await handleStat(path);
if (response && response.data) {
return response.data;
}
@@ -218,7 +245,9 @@ export const useOsFile = () => {
if (response && response.data) {
return response.data;
}
- return false;
+ // return false;
+ //分享
+ return true
},
async readFile(path: string) {
// 注意:handleReadFile返回的是JSON,但通常readFile期望返回Buffer或字符串
@@ -278,7 +307,7 @@ export const useOsFile = () => {
return false;
},
async search(path: string, options: any) {
- console.log(path, options)
+ console.log('search:',path, options)
return true;
},
async zip(path: string, ext: string) {