Browse Source

test:get share file

master
prr 7 months ago
parent
commit
9964e9e549
  1. 2
      frontend/src/components/builtin/FileList.vue
  2. 5
      frontend/src/components/builtin/FileTree.vue
  3. 37
      frontend/src/components/computer/Computer.vue
  4. 7
      frontend/src/hook/useComputer.ts
  5. 3
      frontend/src/i18n/index.ts
  6. 1
      frontend/src/i18n/lang/zh.json
  7. 39
      frontend/src/system/core/FileOs.ts

2
frontend/src/components/builtin/FileList.vue

@ -196,6 +196,8 @@ function handleClick(index: number) {
chosenIndexs.value = [index]; chosenIndexs.value = [index];
} }
onMounted(() => { onMounted(() => {
console.log('filelist:',props.fileList)
chosenIndexs.value = []; chosenIndexs.value = [];
props.onChosen( props.onChosen(
throttle((rect: Rect) => { throttle((rect: Rect) => {

5
frontend/src/components/builtin/FileTree.vue

@ -51,6 +51,10 @@
import { useSystem,OsFileWithoutContent,basename } from '@/system/index.ts'; import { useSystem,OsFileWithoutContent,basename } from '@/system/index.ts';
import { onMounted, ref } from 'vue'; import { onMounted, ref } from 'vue';
import { dealSystemName } from '@/i18n'; import { dealSystemName } from '@/i18n';
//
import { getSystemConfig } from "@/system/config";
const config = ref(getSystemConfig())
const sys = useSystem(); const sys = useSystem();
type FileWithOpen = OsFileWithoutContent & { type FileWithOpen = OsFileWithoutContent & {
isOpen?: boolean; isOpen?: boolean;
@ -119,7 +123,6 @@ async function onOpenArrow(item: FileWithOpen) {
return; return;
} }
item.isOpen = !item.isOpen; item.isOpen = !item.isOpen;
item.subFileList = (await sys.fs.readdir(item.path)).filter((file:any) => { item.subFileList = (await sys.fs.readdir(item.path)).filter((file:any) => {
return file.isDirectory; return file.isDirectory;
}); });

37
frontend/src/components/computer/Computer.vue

@ -42,6 +42,16 @@
:key="random" :key="random"
> >
</FileTree> </FileTree>
<div class="showName">{{ t("share") }}</div>
<FileTree
:chosen-path="chosenTreePath"
mode="list"
:on-open="onTreeOpen"
:on-refresh="onListRefresh"
:file-list="shareFileList"
:key="random"
>
</FileTree>
<QuickLink :on-open="onTreeOpen"></QuickLink> <QuickLink :on-open="onTreeOpen"></QuickLink>
<div class="left-handle" @mousedown="leftHandleDown"></div> <div class="left-handle" @mousedown="leftHandleDown"></div>
</div> </div>
@ -125,7 +135,7 @@ const { refersh, createFolder, backFolder, openFolder, onComputerMount } = useCo
return router_url.value; return router_url.value;
}, },
setFileList(list) { setFileList(list) {
//console.log(list) console.log('list:',list)
//currentList.value = list; //currentList.value = list;
if(config.ext && config.ext instanceof Array && config.ext.length > 0) { if(config.ext && config.ext instanceof Array && config.ext.length > 0) {
const res:any = [] const res:any = []
@ -196,6 +206,7 @@ function leftHandleDown(e: MouseEvent) {
} }
const rootFileList = ref<Array<OsFileWithoutContent>>([]); const rootFileList = ref<Array<OsFileWithoutContent>>([]);
const shareFileList = ref<Array<OsFileWithoutContent>>([]);
const random = ref(0); const random = ref(0);
onMounted(() => { onMounted(() => {
if (config) { if (config) {
@ -216,6 +227,24 @@ onMounted(() => {
random.value = random.value + 1; 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() { function handleOuterClick() {
@ -245,8 +274,12 @@ async function onTreeOpen(path: string) {
chosenTreePath.value = path; chosenTreePath.value = path;
const file = await system.fs.stat(path); const file = await system.fs.stat(path);
if (file) { 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) //console.log(path)
router_url.value = path; router_url.value = path;

7
frontend/src/hook/useComputer.ts

@ -37,9 +37,8 @@ export const useComputer = (adpater: {
} }
if (!(await isVia(currentPath))) return; if (!(await isVia(currentPath))) return;
//console.log(currentPath)
const result = await adpater.readdir(currentPath); const result = await adpater.readdir(currentPath);
//console.log(result) console.log('refersh result:',result)
if (result) adpater.setFileList(result); if (result) adpater.setFileList(result);
}; };
const createFolder = (path: RouterPath) => { const createFolder = (path: RouterPath) => {
@ -60,7 +59,11 @@ export const useComputer = (adpater: {
refersh(); refersh();
}; };
const openFolder = (file: OsFileWithoutContent) => { const openFolder = (file: OsFileWithoutContent) => {
console.log('打开:', file);
if (adpater.isDirectory(file)) { if (adpater.isDirectory(file)) {
console.log('走refresh');
adpater.setRouter(file.path); adpater.setRouter(file.path);
refersh(); refersh();
} else { } else {

3
frontend/src/i18n/index.ts

@ -58,7 +58,8 @@ export function dealSystemName(name: string) {
"C": t('system'), "C": t('system'),
"D": t('document'), "D": t('document'),
"E": t('office'), "E": t('office'),
"B": t('recycle') "B": t('recycle'),
"F": t('share')
} }
if (sysNames[name]) { if (sysNames[name]) {
return sysNames[name]; return sysNames[name];

1
frontend/src/i18n/lang/zh.json

@ -7,6 +7,7 @@
"system": "系统", "system": "系统",
"office": "办公", "office": "办公",
"recycle": "回收站", "recycle": "回收站",
"share": "分享",
"favorite": "我的收藏", "favorite": "我的收藏",
"desktop": "桌面", "desktop": "桌面",
"personalization": "个性化", "personalization": "个性化",

39
frontend/src/system/core/FileOs.ts

@ -1,6 +1,8 @@
import { getFileUrl,fetchGet,fetchPost } from "../config.ts"; import { getFileUrl,fetchGet,fetchPost } from "../config.ts";
const API_BASE_URL = getFileUrl() const API_BASE_URL = getFileUrl()
import { OsFileMode } from '../core/FileMode'; import { OsFileMode } from '../core/FileMode';
import { getSystemConfig } from "@/system/config";
export async function handleReadDir(path: string): Promise<any> { export async function handleReadDir(path: string): Promise<any> {
const res = await fetchGet(`${API_BASE_URL}/read?path=${encodeURIComponent(path)}`); const res = await fetchGet(`${API_BASE_URL}/read?path=${encodeURIComponent(path)}`);
if (!res.ok) { if (!res.ok) {
@ -8,6 +10,15 @@ export async function handleReadDir(path: string): Promise<any> {
} }
return await res.json(); return await res.json();
} }
// 查看分享文件
export async function handleReadShareDir(val: number): Promise<any> {
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<any> { export async function handleStat(path: string): Promise<any> {
const res = await fetchGet(`${API_BASE_URL}/stat?path=${encodeURIComponent(path)}`); const res = await fetchGet(`${API_BASE_URL}/stat?path=${encodeURIComponent(path)}`);
@ -16,6 +27,7 @@ export async function handleStat(path: string): Promise<any> {
} }
return await res.json(); return await res.json();
} }
export async function handleChmod(path: string, mode: string): Promise<any> { export async function handleChmod(path: string, mode: string): Promise<any> {
const res = await fetchPost(`${API_BASE_URL}/chmod`, JSON.stringify({ path, mode })); const res = await fetchPost(`${API_BASE_URL}/chmod`, JSON.stringify({ path, mode }));
if (!res.ok) { if (!res.ok) {
@ -191,15 +203,30 @@ export async function handleUnZip(path: string): Promise<any> {
} }
export const useOsFile = () => { export const useOsFile = () => {
return { 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) { if (response && response.data) {
return response.data; return response.data;
} }
return []; return [];
}, },
async stat(path: string) { 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) { if (response && response.data) {
return response.data; return response.data;
} }
@ -218,7 +245,9 @@ export const useOsFile = () => {
if (response && response.data) { if (response && response.data) {
return response.data; return response.data;
} }
return false; // return false;
//分享
return true
}, },
async readFile(path: string) { async readFile(path: string) {
// 注意:handleReadFile返回的是JSON,但通常readFile期望返回Buffer或字符串 // 注意:handleReadFile返回的是JSON,但通常readFile期望返回Buffer或字符串
@ -278,7 +307,7 @@ export const useOsFile = () => {
return false; return false;
}, },
async search(path: string, options: any) { async search(path: string, options: any) {
console.log(path, options) console.log('search:',path, options)
return true; return true;
}, },
async zip(path: string, ext: string) { async zip(path: string, ext: string) {

Loading…
Cancel
Save