From 30ffd8cd1a474c0e0c44017146754130aae4a8b7 Mon Sep 17 00:00:00 2001 From: prr <3099672575@qq.com> Date: Thu, 31 Oct 2024 19:00:08 +0800 Subject: [PATCH] =?UTF-8?q?add:=E5=88=86=E4=BA=AB=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=A4=B9=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/components.d.ts | 2 -- frontend/src/components/computer/Computer.vue | 7 +++++-- .../src/components/setting/SetFilePwd.vue | 5 +---- frontend/src/hook/useComputer.ts | 9 +++++++-- frontend/src/system/core/FileOs.ts | 19 +++++++++++++++++-- frontend/src/system/index.ts | 13 ++++++++----- frontend/src/system/window/Dialog.ts | 19 +++++++------------ frontend/src/util/sharePath.ts | 7 +++++++ 8 files changed, 52 insertions(+), 29 deletions(-) diff --git a/frontend/components.d.ts b/frontend/components.d.ts index 3d33306..522afce 100644 --- a/frontend/components.d.ts +++ b/frontend/components.d.ts @@ -57,8 +57,6 @@ declare module 'vue' { ElCarouselItem: typeof import('element-plus/es')['ElCarouselItem'] ElCheckbox: typeof import('element-plus/es')['ElCheckbox'] ElCol: typeof import('element-plus/es')['ElCol'] - ElCollapse: typeof import('element-plus/es')['ElCollapse'] - ElCollapseItem: typeof import('element-plus/es')['ElCollapseItem'] ElColorPicker: typeof import('element-plus/es')['ElColorPicker'] ElContainer: typeof import('element-plus/es')['ElContainer'] ElDialog: typeof import('element-plus/es')['ElDialog'] diff --git a/frontend/src/components/computer/Computer.vue b/frontend/src/components/computer/Computer.vue index 557e257..55ecd7b 100644 --- a/frontend/src/components/computer/Computer.vue +++ b/frontend/src/components/computer/Computer.vue @@ -165,8 +165,7 @@ const { refersh, createFolder, backFolder, openFolder, onComputerMount } = useCo return system.fs.readdir(path); }, sharedir(path) { - const val:number = getSystemConfig().userInfo.id - return system.fs.sharedir(val,path) + return system.fs.sharedir(getSystemConfig().userInfo.id,path) }, exists(path) { return system.fs.exists(path); @@ -174,6 +173,10 @@ const { refersh, createFolder, backFolder, openFolder, onComputerMount } = useCo isDirectory(file) { return file.isDirectory; }, + // 读取分享文件夹 + readShareDir(path){ + return system.fs.readShareFileDir(getSystemConfig().userInfo.id, path) + }, notify(title, content) { new Notify({ title, diff --git a/frontend/src/components/setting/SetFilePwd.vue b/frontend/src/components/setting/SetFilePwd.vue index 7b9759b..5ea9843 100644 --- a/frontend/src/components/setting/SetFilePwd.vue +++ b/frontend/src/components/setting/SetFilePwd.vue @@ -33,8 +33,7 @@ const params = { } // 设置文件密码 async function toSetFilePwd() { - //console.log('密码aaa:',filePwd.value); - params.pwd = filePwd.value === '' ? '' : md5(filePwd.value) + params.pwd = filePwd.value || md5(filePwd.value) params.isPwd = filePwd.value === '' ? 0 : 1 const url = getApiUrl() + '/file/setfilepwd' const header = { @@ -50,8 +49,6 @@ async function toSetFilePwd() { params.pwd = '' notifyError("设置文件密码失败") } - //console.log('密码:',params); - setSystemKey('file',params) } function clearPwd() { diff --git a/frontend/src/hook/useComputer.ts b/frontend/src/hook/useComputer.ts index 1eef71e..f8af8cd 100644 --- a/frontend/src/hook/useComputer.ts +++ b/frontend/src/hook/useComputer.ts @@ -1,5 +1,6 @@ import * as fspath from '../system/core/Path'; import { OsFileWithoutContent } from '../system/core/FileSystem'; +import { turnFilePath } from "@/util/sharePath.ts"; export type RouterPath = string; export const useComputer = (adpater: { @@ -15,6 +16,7 @@ export const useComputer = (adpater: { isDirectory: (file: OsFileWithoutContent) => boolean; notify: (title: string, content: string) => void; search: (keyword: string) => Promise; + readShareDir: (path: RouterPath) => Promise; }) => { const isVia = async (path: RouterPath) => { if (path === '') path = '/'; @@ -42,8 +44,10 @@ export const useComputer = (adpater: { if (!(await isVia(currentPath))) return; // console.log('use computer refresh:', currentPath); let result - if (currentPath.substring(0,2) == '/F') { + if (currentPath === '/F/myshare' || currentPath === '/F/othershare') { result = await adpater.sharedir(currentPath) + } else if (currentPath.indexOf('/F') === 0) { + result = await adpater.readShareDir(currentPath) } else { result = await adpater.readdir(currentPath); } @@ -68,7 +72,8 @@ export const useComputer = (adpater: { }; const openFolder = (file: OsFileWithoutContent) => { if (adpater.isDirectory(file)) { - adpater.setRouter(file.path); + const path = file?.isShare ? turnFilePath(file) : file.path + adpater.setRouter(path); refersh(); } else { adpater.openFile(file.path); diff --git a/frontend/src/system/core/FileOs.ts b/frontend/src/system/core/FileOs.ts index 960a6dd..a990c04 100644 --- a/frontend/src/system/core/FileOs.ts +++ b/frontend/src/system/core/FileOs.ts @@ -21,6 +21,15 @@ export async function handleReadShareDir(id: number,path: string): Promise } return await res.json(); } +// 查看分享文件夹 +export async function handleShareDir(id: number,path: string): Promise { + path = turnServePath(path) + const res = await fetchGet(`${API_BASE_URL}/sharedir?id=${id}&dirPath=${path}`); + if (!res.ok) { + return false; + } + return await res.json(); +} // 读文件 export async function handleReadShareFile(path: string): Promise { path = turnServePath(path) @@ -95,7 +104,6 @@ export async function handleExists(path: string): Promise { } export async function handleReadFile(path: string , header?: {[key: string]: string}): Promise { - // console.log('请求头:', header); const res = await fetchGet(`${API_BASE_URL}/readfile?path=${encodeURIComponent(path)}`, header); if (!res.ok) { return false; @@ -248,7 +256,7 @@ export const useOsFile = () => { }, async readShareFile(path: string) { const file = await handleShareDetail(path,getSystemConfig()?.userInfo.id) - console.log('文件信息:',file, file.data.fs.is_write); + // console.log('文件信息:',file, file.data.fs.is_write); if(!file.data.fs.is_write) { alert('该文件不能编辑') console.log('该文件不能编辑'); @@ -260,6 +268,13 @@ export const useOsFile = () => { } return []; }, + async readShareFileDir(id: number, path: string) { + const response = await handleShareDir(id,path); + if (response && response.data) { + return response.data; + } + return []; + }, async getShareInfo(path: string) { const response = await handleShareDetail(path, getSystemConfig().userInfo.id); if (response && response.data) { diff --git a/frontend/src/system/index.ts b/frontend/src/system/index.ts index 208bb3e..62657ce 100644 --- a/frontend/src/system/index.ts +++ b/frontend/src/system/index.ts @@ -432,7 +432,6 @@ export class System { if (isShareFile(path)) { const arr = path.split('/') const fileContent = await this.fs.readShareFile(path) - // console.log('阅读:', fileContent); if (fileContent !== false) { const fileName = extname(arr[arr.length - 1] || '') || 'link' this._flieOpenerMap @@ -455,19 +454,23 @@ export class System { salt: '', filePwd: '' } - header.salt = filePwd.file.salt ? filePwd.file.salt : 'vIf_wIUedciAd0nTm6qjJA==' - header.filePwd = filePwd.file.pwd + //判断文件是否需要输入密码 if(fileStat.isPwd && path.indexOf('.exe') === -1) { - const temp = await Dialog.showInputBox(filePwd.file.pwd) + const temp = await Dialog.showInputBox() if (temp.response !== 1) { return } + header.salt = filePwd.file.salt || 'vIf_wIUedciAd0nTm6qjJA==' + header.filePwd = temp?.inputPwd || '' } // 读取文件内容 const fileContent = await this.fs.readFile(path, header); + if (!fileContent && fileStat.isPwd){ + notifyError('密码错误') + return + } // 从_fileOpenerMap中获取文件扩展名对应的函数并调用 const fileName = extname(fileStat?.name || '') || 'link' - //console.log(fileName) this._flieOpenerMap .get(fileName) ?.func.call(this, path, fileContent || ''); diff --git a/frontend/src/system/window/Dialog.ts b/frontend/src/system/window/Dialog.ts index 1b3afcc..5ec7ed1 100644 --- a/frontend/src/system/window/Dialog.ts +++ b/frontend/src/system/window/Dialog.ts @@ -1,7 +1,6 @@ import { ElMessageBox } from 'element-plus' import {BrowserWindow} from "./BrowserWindow" import { md5 } from "js-md5" -import { notifyError } from "@/util/msg" class Dialog { constructor() { // static class @@ -103,31 +102,27 @@ class Dialog { return porm; } - public static showInputBox(correctPwd: string): Promise<{response: number}>{ - let promres: (value: { response: number }) => void = () => { + public static showInputBox(): Promise<{response: number, inputPwd?: string}>{ + let promres: (value: { response: number, inputPwd?: string }) => void = () => { // do nothing }; const porm = new Promise<{ - response: number; + response: number, + inputPwd?: string }>((resolve) => { promres = resolve; }); ElMessageBox.prompt('请输入文件加密密码' , '提示', { + inputType: 'password', confirmButtonText: '确定', cancelButtonText: '取消', }).then(({value}) => { - // console.log('正确否:', correctPwd === md5(value)); - // console.log('正确密码:', correctPwd); - const isCorrect = md5(value) === correctPwd ? 1 : 0 - if(!isCorrect) { - notifyError('密码错误') - } promres({ - response: isCorrect, + response: 1, + inputPwd: md5(value) }); }).catch(()=>{ - console.log('取消'); promres({ response: -1, }); diff --git a/frontend/src/util/sharePath.ts b/frontend/src/util/sharePath.ts index 6e4ad79..0975b49 100644 --- a/frontend/src/util/sharePath.ts +++ b/frontend/src/util/sharePath.ts @@ -1,3 +1,4 @@ +import { OsFileWithoutContent } from '../system/core/FileSystem'; export function turnServePath(path: string): string { const replaceUrl = path.indexOf('/F/myshare') === 0 ? '/F/myshare' : '/F/othershare' return path.replace(replaceUrl, 'data/userData') @@ -8,4 +9,10 @@ export function turnLocalPath(path: string, newTemp: string): string { export function isShareFile(path: string) : boolean { // console.log('是否是共享文件:',path,path.indexOf('/F/myshare') === 0 || path.indexOf('/F/othershare') === 0); return path.indexOf('/F/myshare') === 0 || path.indexOf('/F/othershare') === 0 +} +//返回路径 +export function turnFilePath(file: OsFileWithoutContent) : string { + // console.log('是否是共享文件:',path,path.indexOf('/F/myshare') === 0 || path.indexOf('/F/othershare') === 0); + const arr = file.path.split('/') + return `/${arr[1]}/${arr[2]}/${arr[arr.length - 1]}` } \ No newline at end of file