Browse Source

test:文件加密弹窗

master
prr 7 months ago
parent
commit
3535733cf2
  1. 3
      frontend/auto-imports.d.ts
  2. 3
      frontend/components.d.ts
  3. 20
      frontend/src/components/setting/SetFilePwd.vue
  4. 16
      frontend/src/components/window/IframeFile.vue
  5. 2
      frontend/src/system/config.ts
  6. 9
      frontend/src/system/core/FileOs.ts
  7. 16
      frontend/src/system/index.ts
  8. 35
      frontend/src/system/window/Dialog.ts

3
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')
}

3
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']

20
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
})
</script>

16
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>("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<HTMLIFrameElement | null>(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(() => {

2
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=='
}

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

@ -94,8 +94,9 @@ export async function handleExists(path: string): Promise<any> {
return await res.json();
}
export async function handleReadFile(path: string): Promise<any> {
const res = await fetchGet(`${API_BASE_URL}/readfile?path=${encodeURIComponent(path)}`);
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);
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;
}

16
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 {

35
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 };

Loading…
Cancel
Save