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. 14
      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 // @ts-nocheck
// noinspection JSUnusedGlobalSymbols // noinspection JSUnusedGlobalSymbols
// Generated by unplugin-auto-import // Generated by unplugin-auto-import
// biome-ignore lint: disable
export {} export {}
declare global { declare global {
const EffectScope: typeof import('vue')['EffectScope'] const EffectScope: typeof import('vue')['EffectScope']
@ -71,6 +70,6 @@ declare global {
// for type re-export // for type re-export
declare global { declare global {
// @ts-ignore // @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') import('vue')
} }

3
frontend/components.d.ts

@ -44,8 +44,6 @@ declare module 'vue' {
DeskItem: typeof import('./src/components/desktop/DeskItem.vue')['default'] DeskItem: typeof import('./src/components/desktop/DeskItem.vue')['default']
Desktop: typeof import('./src/components/desktop/Desktop.vue')['default'] Desktop: typeof import('./src/components/desktop/Desktop.vue')['default']
DesktopBackground: typeof import('./src/components/desktop/DesktopBackground.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'] DialogProcess: typeof import('./src/components/window/DialogProcess.vue')['default']
DialogTemp: typeof import('./src/components/window/DialogTemp.vue')['default'] DialogTemp: typeof import('./src/components/window/DialogTemp.vue')['default']
EditFileName: typeof import('./src/components/builtin/EditFileName.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'] ElTooltip: typeof import('element-plus/es')['ElTooltip']
ElTransfer: typeof import('element-plus/es')['ElTransfer'] ElTransfer: typeof import('element-plus/es')['ElTransfer']
Error: typeof import('./src/components/taskbar/Error.vue')['default'] 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'] FileIcon: typeof import('./src/components/builtin/FileIcon.vue')['default']
FileIconImg: typeof import('./src/components/builtin/FileIconImg.vue')['default'] FileIconImg: typeof import('./src/components/builtin/FileIconImg.vue')['default']
FileIconIs: typeof import('./src/components/builtin/FileIconIs.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 filePwd = ref('')
const setPwd = ref(false) const setPwd = ref(false)
const params = { const params = {
ispwd: true, isPwd: 1,
pwd: md5(filePwd.value), pwd: '',
salt: getSystemConfig().file.salt salt: getSystemConfig().file.salt
} }
//
async function toSetFilePwd() { async function toSetFilePwd() {
// console.log(':',filePwd.value, md5(filePwd.value)); //console.log('aaa:',filePwd.value);
params.ispwd = filePwd.value === '' ? false : true params.pwd = filePwd.value === '' ? '' : md5(filePwd.value)
params.isPwd = filePwd.value === '' ? 0 : 1
const url = getApiUrl() + '/file/setfilepwd' const url = getApiUrl() + '/file/setfilepwd'
const header = { const header = {
'Salt': params.salt, 'Salt': params.salt ? params.salt : 'vIf_wIUedciAd0nTm6qjJA==',
'FilePwd': params.pwd '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) const res = await fetchGet(url, header)
if (res.ok){ if (res.ok){
notifySuccess("设置文件密码成功"); notifySuccess("设置文件密码成功");
} else { } else {
params.ispwd = false params.isPwd = 0
params.pwd = '' params.pwd = ''
notifyError("设置文件密码失败") notifyError("设置文件密码失败")
} }
//console.log('',params);
setSystemKey('file',params) setSystemKey('file',params)
} }
function clearPwd() { function clearPwd() {
@ -56,7 +60,7 @@ function clearPwd() {
toSetFilePwd() toSetFilePwd()
} }
onMounted(()=>{ onMounted(()=>{
setPwd.value = params.ispwd setPwd.value = params.isPwd ? true : false
}) })
</script> </script>

14
frontend/src/components/window/IframeFile.vue

@ -6,7 +6,7 @@
import { BrowserWindow, Notify, System, Dialog } from "@/system"; import { BrowserWindow, Notify, System, Dialog } from "@/system";
import { ref, onMounted, inject, onUnmounted, toRaw } from "vue"; import { ref, onMounted, inject, onUnmounted, toRaw } from "vue";
import { isBase64, base64ToBuffer } from "@/util/file"; import { isBase64, base64ToBuffer } from "@/util/file";
import { getSplit } from "@/system/config"; import { getSplit, getSystemConfig } from "@/system/config";
const SP = getSplit(); const SP = getSplit();
const sys: any = inject<System>("system"); const sys: any = inject<System>("system");
@ -25,14 +25,15 @@ const props = defineProps({
default: "md", default: "md",
}, },
}); });
//console.log('iframe: ', props);
//console.log(props); //console.log(props);
//let path = win?.config?.path; //let path = win?.config?.path;
const storeRef = ref<HTMLIFrameElement | null>(null); const storeRef = ref<HTMLIFrameElement | null>(null);
let hasInit = false; let hasInit = false;
const eventHandler = async (e: MessageEvent) => { const eventHandler = async (e: MessageEvent) => {
const eventData = e.data; const eventData = e.data;
// console.log(path)
//console.log(eventData);
if (eventData.type == props.eventType) { if (eventData.type == props.eventType) {
let data = JSON.parse(eventData.data); let data = JSON.parse(eventData.data);
let title = data.title; let title = data.title;
@ -102,7 +103,12 @@ const eventHandler = async (e: MessageEvent) => {
title = title.split(SP).pop(); title = title.split(SP).pop();
//console.log(title); //console.log(title);
if (!content && win?.config.path) { 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); content = toRaw(content);
// console.log(content); // console.log(content);

2
frontend/src/system/config.ts

@ -31,7 +31,7 @@ export const getSystemConfig = (ifset = false) => {
} }
if (!config.file) { if (!config.file) {
config.file = { config.file = {
ispwd: false, isPwd: 0,
pwd: '', pwd: '',
salt: 'vIf_wIUedciAd0nTm6qjJA==' 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(); return await res.json();
} }
export async function handleReadFile(path: string): Promise<any> { export async function handleReadFile(path: string , header?: {[key: string]: string}): Promise<any> {
const res = await fetchGet(`${API_BASE_URL}/readfile?path=${encodeURIComponent(path)}`); // console.log('请求头:', header);
const res = await fetchGet(`${API_BASE_URL}/readfile?path=${encodeURIComponent(path)}`, header);
if (!res.ok) { if (!res.ok) {
return false; return false;
} }
@ -295,9 +296,9 @@ export const useOsFile = () => {
} }
return false; return false;
}, },
async readFile(path: string) { async readFile(path: string, header?: {[key: string]: string}) {
// 注意:handleReadFile返回的是JSON,但通常readFile期望返回Buffer或字符串 // 注意:handleReadFile返回的是JSON,但通常readFile期望返回Buffer或字符串
const response = await handleReadFile(path); const response = await handleReadFile(path, header);
if (response && response.data) { if (response && response.data) {
return 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, ''); this._flieOpenerMap.get('dir')?.func.call(this, path, '');
return; return;
} else { } 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中获取文件扩展名对应的函数并调用 // 从_fileOpenerMap中获取文件扩展名对应的函数并调用
const fileName = extname(fileStat?.name || '') || 'link' const fileName = extname(fileStat?.name || '') || 'link'
//console.log(fileName) //console.log(fileName)
@ -460,7 +473,6 @@ export class System {
?.func.call(this, path, fileContent || ''); ?.func.call(this, path, fileContent || '');
} }
} }
} }
// 插件系统 // 插件系统
use(func: OsPlugin): void { use(func: OsPlugin): void {

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

@ -1,5 +1,7 @@
import { ElMessageBox } from 'element-plus' import { ElMessageBox } from 'element-plus'
import {BrowserWindow} from "./BrowserWindow" import {BrowserWindow} from "./BrowserWindow"
import { md5 } from "js-md5"
import { notifyError } from "@/util/msg"
class Dialog { class Dialog {
constructor() { constructor() {
// static class // static class
@ -10,7 +12,7 @@ class Dialog {
title?: string; title?: string;
buttons?: string[]; buttons?: string[];
}) { }) {
console.log(option) console.log('弹窗',option)
const opt = Object.assign( const opt = Object.assign(
{ {
message: '', message: '',
@ -101,6 +103,37 @@ class Dialog {
return porm; 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 }; export { Dialog };

Loading…
Cancel
Save