diff --git a/frontend/auto-imports.d.ts b/frontend/auto-imports.d.ts index d0c217f..eab6be6 100644 --- a/frontend/auto-imports.d.ts +++ b/frontend/auto-imports.d.ts @@ -3,7 +3,6 @@ // @ts-nocheck // noinspection JSUnusedGlobalSymbols // Generated by unplugin-auto-import -// biome-ignore lint: disable export {} declare global { const EffectScope: typeof import('vue')['EffectScope'] @@ -71,6 +70,6 @@ declare global { // for type re-export declare global { // @ts-ignore - export type { Component, ComponentPublicInstance, ComputedRef, DirectiveBinding, ExtractDefaultPropTypes, ExtractPropTypes, ExtractPublicPropTypes, InjectionKey, PropType, Ref, MaybeRef, MaybeRefOrGetter, VNode, WritableComputedRef } from 'vue' + export type { Component, ComponentPublicInstance, ComputedRef, ExtractDefaultPropTypes, ExtractPropTypes, ExtractPublicPropTypes, InjectionKey, PropType, Ref, VNode, WritableComputedRef } from 'vue' import('vue') } diff --git a/frontend/components.d.ts b/frontend/components.d.ts index 0623253..d46e001 100644 --- a/frontend/components.d.ts +++ b/frontend/components.d.ts @@ -44,8 +44,6 @@ declare module 'vue' { DeskItem: typeof import('./src/components/desktop/DeskItem.vue')['default'] Desktop: typeof import('./src/components/desktop/Desktop.vue')['default'] DesktopBackground: typeof import('./src/components/desktop/DesktopBackground.vue')['default'] - Dialog: typeof import('./src/components/builtin/Dialog.vue')['default'] - DialogFilePwd: typeof import('./src/components/window/DialogFilePwd.vue')['default'] DialogProcess: typeof import('./src/components/window/DialogProcess.vue')['default'] DialogTemp: typeof import('./src/components/window/DialogTemp.vue')['default'] EditFileName: typeof import('./src/components/builtin/EditFileName.vue')['default'] @@ -88,7 +86,6 @@ declare module 'vue' { ElTooltip: typeof import('element-plus/es')['ElTooltip'] ElTransfer: typeof import('element-plus/es')['ElTransfer'] Error: typeof import('./src/components/taskbar/Error.vue')['default'] - FileDialogPwd: typeof import('./src/components/builtin/FileDialogPwd.vue')['default'] FileIcon: typeof import('./src/components/builtin/FileIcon.vue')['default'] FileIconImg: typeof import('./src/components/builtin/FileIconImg.vue')['default'] FileIconIs: typeof import('./src/components/builtin/FileIconIs.vue')['default'] diff --git a/frontend/src/components/setting/SetFilePwd.vue b/frontend/src/components/setting/SetFilePwd.vue index 281eae9..7b9759b 100644 --- a/frontend/src/components/setting/SetFilePwd.vue +++ b/frontend/src/components/setting/SetFilePwd.vue @@ -27,27 +27,31 @@ import { notifySuccess, notifyError } from "@/util/msg"; const filePwd = ref('') const setPwd = ref(false) const params = { - ispwd: true, - pwd: md5(filePwd.value), + isPwd: 1, + pwd: '', salt: getSystemConfig().file.salt } +// 设置文件密码 async function toSetFilePwd() { - // console.log('密码:',filePwd.value, md5(filePwd.value)); - params.ispwd = filePwd.value === '' ? false : true + //console.log('密码aaa:',filePwd.value); + params.pwd = filePwd.value === '' ? '' : md5(filePwd.value) + params.isPwd = filePwd.value === '' ? 0 : 1 const url = getApiUrl() + '/file/setfilepwd' const header = { - 'Salt': params.salt, + 'Salt': params.salt ? params.salt : 'vIf_wIUedciAd0nTm6qjJA==', 'FilePwd': params.pwd } - await fetchGet(`${getApiUrl()}/file/ispwd?ispwd=${params.ispwd}`) + await fetchGet(`${getApiUrl()}/file/changeispwd?ispwd=${params.isPwd}`) const res = await fetchGet(url, header) if (res.ok){ notifySuccess("设置文件密码成功"); } else { - params.ispwd = false + params.isPwd = 0 params.pwd = '' notifyError("设置文件密码失败") } + //console.log('密码:',params); + setSystemKey('file',params) } function clearPwd() { @@ -56,7 +60,7 @@ function clearPwd() { toSetFilePwd() } onMounted(()=>{ - setPwd.value = params.ispwd + setPwd.value = params.isPwd ? true : false }) diff --git a/frontend/src/components/window/IframeFile.vue b/frontend/src/components/window/IframeFile.vue index 40abe8b..5eccd3f 100644 --- a/frontend/src/components/window/IframeFile.vue +++ b/frontend/src/components/window/IframeFile.vue @@ -6,7 +6,7 @@ import { BrowserWindow, Notify, System, Dialog } from "@/system"; import { ref, onMounted, inject, onUnmounted, toRaw } from "vue"; import { isBase64, base64ToBuffer } from "@/util/file"; -import { getSplit } from "@/system/config"; +import { getSplit, getSystemConfig } from "@/system/config"; const SP = getSplit(); const sys: any = inject("system"); @@ -25,14 +25,15 @@ const props = defineProps({ default: "md", }, }); +//console.log('iframe: ', props); + //console.log(props); //let path = win?.config?.path; const storeRef = ref(null); let hasInit = false; const eventHandler = async (e: MessageEvent) => { const eventData = e.data; - // console.log(path) - //console.log(eventData); + if (eventData.type == props.eventType) { let data = JSON.parse(eventData.data); let title = data.title; @@ -102,7 +103,12 @@ const eventHandler = async (e: MessageEvent) => { title = title.split(SP).pop(); //console.log(title); if (!content && win?.config.path) { - content = await sys?.fs.readFile(win?.config.path); + const file = getSystemConfig().file + const header = { + salt: file.salt, + filePwd: file.pwd + } + content = await sys?.fs.readFile(win?.config.path, header); } content = toRaw(content); // console.log(content); @@ -126,7 +132,7 @@ const eventHandler = async (e: MessageEvent) => { } }; onMounted(() => { - window.addEventListener("message", eventHandler); + window.addEventListener("message", eventHandler); }); onUnmounted(() => { diff --git a/frontend/src/system/config.ts b/frontend/src/system/config.ts index f27880b..b55b575 100644 --- a/frontend/src/system/config.ts +++ b/frontend/src/system/config.ts @@ -31,7 +31,7 @@ export const getSystemConfig = (ifset = false) => { } if (!config.file) { config.file = { - ispwd: false, + isPwd: 0, pwd: '', salt: 'vIf_wIUedciAd0nTm6qjJA==' } diff --git a/frontend/src/system/core/FileOs.ts b/frontend/src/system/core/FileOs.ts index 2775a6f..960a6dd 100644 --- a/frontend/src/system/core/FileOs.ts +++ b/frontend/src/system/core/FileOs.ts @@ -94,8 +94,9 @@ export async function handleExists(path: string): Promise { return await res.json(); } -export async function handleReadFile(path: string): Promise { - const res = await fetchGet(`${API_BASE_URL}/readfile?path=${encodeURIComponent(path)}`); +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; } @@ -295,9 +296,9 @@ export const useOsFile = () => { } return false; }, - async readFile(path: string) { + async readFile(path: string, header?: {[key: string]: string}) { // 注意:handleReadFile返回的是JSON,但通常readFile期望返回Buffer或字符串 - const response = await handleReadFile(path); + const response = await handleReadFile(path, header); if (response && response.data) { return response.data; } diff --git a/frontend/src/system/index.ts b/frontend/src/system/index.ts index efa3241..208bb3e 100644 --- a/frontend/src/system/index.ts +++ b/frontend/src/system/index.ts @@ -450,8 +450,21 @@ export class System { this._flieOpenerMap.get('dir')?.func.call(this, path, ''); return; } else { + const filePwd = getSystemConfig() + const header = { + 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) + if (temp.response !== 1) { + return + } + } // 读取文件内容 - const fileContent = await this.fs.readFile(path); + const fileContent = await this.fs.readFile(path, header); // 从_fileOpenerMap中获取文件扩展名对应的函数并调用 const fileName = extname(fileStat?.name || '') || 'link' //console.log(fileName) @@ -460,7 +473,6 @@ export class System { ?.func.call(this, path, fileContent || ''); } } - } // 插件系统 use(func: OsPlugin): void { diff --git a/frontend/src/system/window/Dialog.ts b/frontend/src/system/window/Dialog.ts index f2c6f28..1b3afcc 100644 --- a/frontend/src/system/window/Dialog.ts +++ b/frontend/src/system/window/Dialog.ts @@ -1,5 +1,7 @@ import { ElMessageBox } from 'element-plus' import {BrowserWindow} from "./BrowserWindow" +import { md5 } from "js-md5" +import { notifyError } from "@/util/msg" class Dialog { constructor() { // static class @@ -10,7 +12,7 @@ class Dialog { title?: string; buttons?: string[]; }) { - console.log(option) + console.log('弹窗',option) const opt = Object.assign( { message: '', @@ -101,6 +103,37 @@ class Dialog { return porm; } + public static showInputBox(correctPwd: string): Promise<{response: number}>{ + let promres: (value: { response: number }) => void = () => { + // do nothing + }; + + const porm = new Promise<{ + response: number; + }>((resolve) => { + promres = resolve; + }); + ElMessageBox.prompt('请输入文件加密密码' , '提示', { + 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, + }); + }).catch(()=>{ + console.log('取消'); + promres({ + response: -1, + }); + }) + return porm; + } } export { Dialog };