Browse Source

add:分享文件夹展示

master
prr 8 months ago
parent
commit
30ffd8cd1a
  1. 2
      frontend/components.d.ts
  2. 7
      frontend/src/components/computer/Computer.vue
  3. 5
      frontend/src/components/setting/SetFilePwd.vue
  4. 9
      frontend/src/hook/useComputer.ts
  5. 19
      frontend/src/system/core/FileOs.ts
  6. 13
      frontend/src/system/index.ts
  7. 19
      frontend/src/system/window/Dialog.ts
  8. 7
      frontend/src/util/sharePath.ts

2
frontend/components.d.ts

@ -57,8 +57,6 @@ declare module 'vue' {
ElCarouselItem: typeof import('element-plus/es')['ElCarouselItem'] ElCarouselItem: typeof import('element-plus/es')['ElCarouselItem']
ElCheckbox: typeof import('element-plus/es')['ElCheckbox'] ElCheckbox: typeof import('element-plus/es')['ElCheckbox']
ElCol: typeof import('element-plus/es')['ElCol'] 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'] ElColorPicker: typeof import('element-plus/es')['ElColorPicker']
ElContainer: typeof import('element-plus/es')['ElContainer'] ElContainer: typeof import('element-plus/es')['ElContainer']
ElDialog: typeof import('element-plus/es')['ElDialog'] ElDialog: typeof import('element-plus/es')['ElDialog']

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

@ -165,8 +165,7 @@ const { refersh, createFolder, backFolder, openFolder, onComputerMount } = useCo
return system.fs.readdir(path); return system.fs.readdir(path);
}, },
sharedir(path) { sharedir(path) {
const val:number = getSystemConfig().userInfo.id return system.fs.sharedir(getSystemConfig().userInfo.id,path)
return system.fs.sharedir(val,path)
}, },
exists(path) { exists(path) {
return system.fs.exists(path); return system.fs.exists(path);
@ -174,6 +173,10 @@ const { refersh, createFolder, backFolder, openFolder, onComputerMount } = useCo
isDirectory(file) { isDirectory(file) {
return file.isDirectory; return file.isDirectory;
}, },
//
readShareDir(path){
return system.fs.readShareFileDir(getSystemConfig().userInfo.id, path)
},
notify(title, content) { notify(title, content) {
new Notify({ new Notify({
title, title,

5
frontend/src/components/setting/SetFilePwd.vue

@ -33,8 +33,7 @@ const params = {
} }
// //
async function toSetFilePwd() { 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 params.isPwd = filePwd.value === '' ? 0 : 1
const url = getApiUrl() + '/file/setfilepwd' const url = getApiUrl() + '/file/setfilepwd'
const header = { const header = {
@ -50,8 +49,6 @@ async function toSetFilePwd() {
params.pwd = '' params.pwd = ''
notifyError("设置文件密码失败") notifyError("设置文件密码失败")
} }
//console.log('',params);
setSystemKey('file',params) setSystemKey('file',params)
} }
function clearPwd() { function clearPwd() {

9
frontend/src/hook/useComputer.ts

@ -1,5 +1,6 @@
import * as fspath from '../system/core/Path'; import * as fspath from '../system/core/Path';
import { OsFileWithoutContent } from '../system/core/FileSystem'; import { OsFileWithoutContent } from '../system/core/FileSystem';
import { turnFilePath } from "@/util/sharePath.ts";
export type RouterPath = string; export type RouterPath = string;
export const useComputer = (adpater: { export const useComputer = (adpater: {
@ -15,6 +16,7 @@ export const useComputer = (adpater: {
isDirectory: (file: OsFileWithoutContent) => boolean; isDirectory: (file: OsFileWithoutContent) => boolean;
notify: (title: string, content: string) => void; notify: (title: string, content: string) => void;
search: (keyword: string) => Promise<OsFileWithoutContent[]>; search: (keyword: string) => Promise<OsFileWithoutContent[]>;
readShareDir: (path: RouterPath) => Promise<OsFileWithoutContent[]>;
}) => { }) => {
const isVia = async (path: RouterPath) => { const isVia = async (path: RouterPath) => {
if (path === '') path = '/'; if (path === '') path = '/';
@ -42,8 +44,10 @@ export const useComputer = (adpater: {
if (!(await isVia(currentPath))) return; if (!(await isVia(currentPath))) return;
// console.log('use computer refresh:', currentPath); // console.log('use computer refresh:', currentPath);
let result let result
if (currentPath.substring(0,2) == '/F') { if (currentPath === '/F/myshare' || currentPath === '/F/othershare') {
result = await adpater.sharedir(currentPath) result = await adpater.sharedir(currentPath)
} else if (currentPath.indexOf('/F') === 0) {
result = await adpater.readShareDir(currentPath)
} else { } else {
result = await adpater.readdir(currentPath); result = await adpater.readdir(currentPath);
} }
@ -68,7 +72,8 @@ export const useComputer = (adpater: {
}; };
const openFolder = (file: OsFileWithoutContent) => { const openFolder = (file: OsFileWithoutContent) => {
if (adpater.isDirectory(file)) { if (adpater.isDirectory(file)) {
adpater.setRouter(file.path); const path = file?.isShare ? turnFilePath(file) : file.path
adpater.setRouter(path);
refersh(); refersh();
} else { } else {
adpater.openFile(file.path); adpater.openFile(file.path);

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

@ -21,6 +21,15 @@ export async function handleReadShareDir(id: number,path: string): Promise<any>
} }
return await res.json(); return await res.json();
} }
// 查看分享文件夹
export async function handleShareDir(id: number,path: string): Promise<any> {
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<any> { export async function handleReadShareFile(path: string): Promise<any> {
path = turnServePath(path) path = turnServePath(path)
@ -95,7 +104,6 @@ export async function handleExists(path: string): Promise<any> {
} }
export async function handleReadFile(path: string , header?: {[key: string]: string}): Promise<any> { export async function handleReadFile(path: string , header?: {[key: string]: string}): Promise<any> {
// console.log('请求头:', header);
const res = await fetchGet(`${API_BASE_URL}/readfile?path=${encodeURIComponent(path)}`, header); const res = await fetchGet(`${API_BASE_URL}/readfile?path=${encodeURIComponent(path)}`, header);
if (!res.ok) { if (!res.ok) {
return false; return false;
@ -248,7 +256,7 @@ export const useOsFile = () => {
}, },
async readShareFile(path: string) { async readShareFile(path: string) {
const file = await handleShareDetail(path,getSystemConfig()?.userInfo.id) 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) { if(!file.data.fs.is_write) {
alert('该文件不能编辑') alert('该文件不能编辑')
console.log('该文件不能编辑'); console.log('该文件不能编辑');
@ -260,6 +268,13 @@ export const useOsFile = () => {
} }
return []; 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) { async getShareInfo(path: string) {
const response = await handleShareDetail(path, getSystemConfig().userInfo.id); const response = await handleShareDetail(path, getSystemConfig().userInfo.id);
if (response && response.data) { if (response && response.data) {

13
frontend/src/system/index.ts

@ -432,7 +432,6 @@ export class System {
if (isShareFile(path)) { if (isShareFile(path)) {
const arr = path.split('/') const arr = path.split('/')
const fileContent = await this.fs.readShareFile(path) const fileContent = await this.fs.readShareFile(path)
// console.log('阅读:', fileContent);
if (fileContent !== false) { if (fileContent !== false) {
const fileName = extname(arr[arr.length - 1] || '') || 'link' const fileName = extname(arr[arr.length - 1] || '') || 'link'
this._flieOpenerMap this._flieOpenerMap
@ -455,19 +454,23 @@ export class System {
salt: '', salt: '',
filePwd: '' filePwd: ''
} }
header.salt = filePwd.file.salt ? filePwd.file.salt : 'vIf_wIUedciAd0nTm6qjJA==' //判断文件是否需要输入密码
header.filePwd = filePwd.file.pwd
if(fileStat.isPwd && path.indexOf('.exe') === -1) { if(fileStat.isPwd && path.indexOf('.exe') === -1) {
const temp = await Dialog.showInputBox(filePwd.file.pwd) const temp = await Dialog.showInputBox()
if (temp.response !== 1) { if (temp.response !== 1) {
return return
} }
header.salt = filePwd.file.salt || 'vIf_wIUedciAd0nTm6qjJA=='
header.filePwd = temp?.inputPwd || ''
} }
// 读取文件内容 // 读取文件内容
const fileContent = await this.fs.readFile(path, header); const fileContent = await this.fs.readFile(path, header);
if (!fileContent && fileStat.isPwd){
notifyError('密码错误')
return
}
// 从_fileOpenerMap中获取文件扩展名对应的函数并调用 // 从_fileOpenerMap中获取文件扩展名对应的函数并调用
const fileName = extname(fileStat?.name || '') || 'link' const fileName = extname(fileStat?.name || '') || 'link'
//console.log(fileName)
this._flieOpenerMap this._flieOpenerMap
.get(fileName) .get(fileName)
?.func.call(this, path, fileContent || ''); ?.func.call(this, path, fileContent || '');

19
frontend/src/system/window/Dialog.ts

@ -1,7 +1,6 @@
import { ElMessageBox } from 'element-plus' import { ElMessageBox } from 'element-plus'
import {BrowserWindow} from "./BrowserWindow" import {BrowserWindow} from "./BrowserWindow"
import { md5 } from "js-md5" import { md5 } from "js-md5"
import { notifyError } from "@/util/msg"
class Dialog { class Dialog {
constructor() { constructor() {
// static class // static class
@ -103,31 +102,27 @@ class Dialog {
return porm; return porm;
} }
public static showInputBox(correctPwd: string): Promise<{response: number}>{ public static showInputBox(): Promise<{response: number, inputPwd?: string}>{
let promres: (value: { response: number }) => void = () => { let promres: (value: { response: number, inputPwd?: string }) => void = () => {
// do nothing // do nothing
}; };
const porm = new Promise<{ const porm = new Promise<{
response: number; response: number,
inputPwd?: string
}>((resolve) => { }>((resolve) => {
promres = resolve; promres = resolve;
}); });
ElMessageBox.prompt('请输入文件加密密码' , '提示', { ElMessageBox.prompt('请输入文件加密密码' , '提示', {
inputType: 'password',
confirmButtonText: '确定', confirmButtonText: '确定',
cancelButtonText: '取消', cancelButtonText: '取消',
}).then(({value}) => { }).then(({value}) => {
// console.log('正确否:', correctPwd === md5(value));
// console.log('正确密码:', correctPwd);
const isCorrect = md5(value) === correctPwd ? 1 : 0
if(!isCorrect) {
notifyError('密码错误')
}
promres({ promres({
response: isCorrect, response: 1,
inputPwd: md5(value)
}); });
}).catch(()=>{ }).catch(()=>{
console.log('取消');
promres({ promres({
response: -1, response: -1,
}); });

7
frontend/src/util/sharePath.ts

@ -1,3 +1,4 @@
import { OsFileWithoutContent } from '../system/core/FileSystem';
export function turnServePath(path: string): string { export function turnServePath(path: string): string {
const replaceUrl = path.indexOf('/F/myshare') === 0 ? '/F/myshare' : '/F/othershare' const replaceUrl = path.indexOf('/F/myshare') === 0 ? '/F/myshare' : '/F/othershare'
return path.replace(replaceUrl, 'data/userData') return path.replace(replaceUrl, 'data/userData')
@ -9,3 +10,9 @@ export function isShareFile(path: string) : boolean {
// console.log('是否是共享文件:',path,path.indexOf('/F/myshare') === 0 || path.indexOf('/F/othershare') === 0); // console.log('是否是共享文件:',path,path.indexOf('/F/myshare') === 0 || path.indexOf('/F/othershare') === 0);
return 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]}`
}
Loading…
Cancel
Save