From a47ec2bdc8e0207b51eecef94628e22bbe00a9fc Mon Sep 17 00:00:00 2001 From: godo Date: Fri, 29 Nov 2024 23:17:32 +0800 Subject: [PATCH] change file event --- frontend/components.d.ts | 3 +- frontend/public/text/js/base.js | 1 + .../src/components/taskbar/DateTimePop.vue | 506 ------------------ frontend/src/components/window/IframeFile.vue | 2 +- .../src/components/window/WindowTemplate.vue | 2 +- frontend/src/system/core/FileOs.ts | 1 + frontend/src/system/event/EventListener.ts | 22 +- frontend/src/system/event/Eventer.ts | 4 - frontend/src/system/event/SystemEvent.ts | 89 --- .../src/{util => system/event}/eventBus.ts | 0 godo/files/pwdfile.go | 1 + 11 files changed, 23 insertions(+), 608 deletions(-) delete mode 100644 frontend/src/components/taskbar/DateTimePop.vue delete mode 100644 frontend/src/system/event/SystemEvent.ts rename frontend/src/{util => system/event}/eventBus.ts (100%) diff --git a/frontend/components.d.ts b/frontend/components.d.ts index 6dff287..d5e643f 100644 --- a/frontend/components.d.ts +++ b/frontend/components.d.ts @@ -49,7 +49,6 @@ declare module 'vue' { CustomIcon: typeof import('./src/components/taskbar/CustomIcon.vue')['default'] DateNote: typeof import('./src/components/builtin/DateNote.vue')['default'] DateTime: typeof import('./src/components/taskbar/DateTime.vue')['default'] - DateTimePop: typeof import('./src/components/taskbar/DateTimePop.vue')['default'] DateTimeShow: typeof import('./src/components/taskbar/DateTimeShow.vue')['default'] DeskItem: typeof import('./src/components/desktop/DeskItem.vue')['default'] Desktop: typeof import('./src/components/desktop/Desktop.vue')['default'] @@ -90,6 +89,8 @@ declare module 'vue' { ElSlider: typeof import('element-plus/es')['ElSlider'] ElSpace: typeof import('element-plus/es')['ElSpace'] ElSwitch: typeof import('element-plus/es')['ElSwitch'] + ElTable: typeof import('element-plus/es')['ElTable'] + ElTableColumn: typeof import('element-plus/es')['ElTableColumn'] ElTabPane: typeof import('element-plus/es')['ElTabPane'] ElTabs: typeof import('element-plus/es')['ElTabs'] ElTag: typeof import('element-plus/es')['ElTag'] diff --git a/frontend/public/text/js/base.js b/frontend/public/text/js/base.js index 8a45081..3ee9312 100644 --- a/frontend/public/text/js/base.js +++ b/frontend/public/text/js/base.js @@ -950,6 +950,7 @@ function saveData(extension) { title = Editor.query().getName("base"), //title = Editor.query().getName(), content = Editor.query().textarea.value; + //console.log(content) const save = { data: JSON.stringify({ content, title, ext }), type: 'exportText' diff --git a/frontend/src/components/taskbar/DateTimePop.vue b/frontend/src/components/taskbar/DateTimePop.vue deleted file mode 100644 index e57332d..0000000 --- a/frontend/src/components/taskbar/DateTimePop.vue +++ /dev/null @@ -1,506 +0,0 @@ - - - diff --git a/frontend/src/components/window/IframeFile.vue b/frontend/src/components/window/IframeFile.vue index 223374d..6cd4c06 100644 --- a/frontend/src/components/window/IframeFile.vue +++ b/frontend/src/components/window/IframeFile.vue @@ -11,7 +11,7 @@ import { inject, onMounted, onUnmounted, ref, toRaw } from "vue"; import { askAi } from "@/hook/useAi"; import { useChooseStore } from "@/stores/choose"; import { nanoid } from "nanoid"; -import eventBus from "@/util/eventBus"; +import eventBus from "@/system/event/eventBus"; const SP = getSplit(); const sys: any = inject("system"); diff --git a/frontend/src/components/window/WindowTemplate.vue b/frontend/src/components/window/WindowTemplate.vue index dffa57c..cdd1044 100644 --- a/frontend/src/components/window/WindowTemplate.vue +++ b/frontend/src/components/window/WindowTemplate.vue @@ -74,7 +74,7 @@ UnwrapNestedRefs, } from "vue"; import { useChooseStore } from "@/stores/choose"; - import eventBus from '@/util/eventBus' + import eventBus from '@/system/event/eventBus' const sys = useSystem(); const props = defineProps<{ diff --git a/frontend/src/system/core/FileOs.ts b/frontend/src/system/core/FileOs.ts index 41b9c03..8f8ac6a 100644 --- a/frontend/src/system/core/FileOs.ts +++ b/frontend/src/system/core/FileOs.ts @@ -218,6 +218,7 @@ export function getFormData(content: any) { return formData } export async function handleWriteFile(filePath: string, content: any, header?: { [key: string]: any }): Promise { + //console.log(content) const formData = getFormData(content); const head = header ? { ...header } : {} const url = `${API_BASE_URL}/writefile?path=${encodeURIComponent(filePath)}`; diff --git a/frontend/src/system/event/EventListener.ts b/frontend/src/system/event/EventListener.ts index bd70964..49dbe54 100644 --- a/frontend/src/system/event/EventListener.ts +++ b/frontend/src/system/event/EventListener.ts @@ -1,12 +1,22 @@ -import { mountEvent, redirectEvent } from './EventHook'; - +import { mountEvent, redirectEvent, emitEvent } from './EventHook'; +import { RootState } from '../root'; import { useSystem } from '../index.ts'; -import { initBatteryEvent, initSizeEvent, initNetworkEvent, initAlertEvent } from './SystemEvent'; + +function initSizeEvent() { + const rootState = useSystem()._rootState; + function refreshDesktopSize(rootState: RootState) { + rootState.info.screenWidth = window?.innerWidth || 0; + rootState.info.screenHeight = window?.innerHeight || 0; + } + mountEvent('system.initSize', () => { + refreshDesktopSize(rootState); + }); + window?.addEventListener('resize', () => { + emitEvent('system.resize'); + }); +} function initEventListener() { - initBatteryEvent(); initSizeEvent(); - initNetworkEvent(); - initAlertEvent(); mountEvent('system.shutdown', () => { useSystem()?.shutdown(); }); diff --git a/frontend/src/system/event/Eventer.ts b/frontend/src/system/event/Eventer.ts index 90d0263..0543781 100644 --- a/frontend/src/system/event/Eventer.ts +++ b/frontend/src/system/event/Eventer.ts @@ -1,12 +1,9 @@ interface HandlerInfo { - // eslint-disable-next-line @typescript-eslint/ban-types handler: Function; once?: boolean; } -// https://cloud.tencent.com/developer/article/1700467 class Eventer { private events: Map = new Map(); - // eslint-disable-next-line @typescript-eslint/ban-types on(type: string, handler: Function, once?: boolean) { if (!this.events.has(type)) { this.events.set(type, []); @@ -36,7 +33,6 @@ class Eventer { handler(source, ...args); // 这里 this 就交给传入的 handler 来保证了 } } - // eslint-disable-next-line @typescript-eslint/ban-types off(type?: string, handler?: Function): void { if (!type) return; // 最好不要默认全部清除,不安全 if (!handler) { diff --git a/frontend/src/system/event/SystemEvent.ts b/frontend/src/system/event/SystemEvent.ts deleted file mode 100644 index f6a41f4..0000000 --- a/frontend/src/system/event/SystemEvent.ts +++ /dev/null @@ -1,89 +0,0 @@ -import { mountEvent, emitEvent } from './EventHook'; -import { RootState } from '../root'; - -import { useSystem } from '../index'; -//import { join } from '../core/Path'; - -function initSizeEvent() { - const rootState = useSystem()._rootState; - function refreshDesktopSize(rootState: RootState) { - rootState.info.screenWidth = window?.innerWidth || 0; - rootState.info.screenHeight = window?.innerHeight || 0; - } - mountEvent('system.initSize', () => { - refreshDesktopSize(rootState); - }); - window?.addEventListener('resize', () => { - emitEvent('system.resize'); - }); -} - -function initBatteryEvent() { - const rootState = useSystem()._rootState; - const nav = navigator as any; - if (!nav || !nav.connection) { - return; - } - - nav - .getBattery?.() - .then((battery: any) => { - rootState.info.battery.isCharging = battery.charging; - rootState.info.battery.chargeLevel = battery.level; - battery.onchargingchange = () => { - rootState.info.battery.isCharging = battery.charging; - rootState.info.battery.chargeLevel = battery.level; - }; - }) - .catch(() => { - rootState.info.battery.isCharging = false; - rootState.info.battery.chargeLevel = 0; - }); -} -function initNetworkEvent() { - const rootState = useSystem()._rootState; - - const nav = navigator as any; - if (!nav || !nav.connection) { - return; - } - - const connection = nav.connection as any; - rootState.info.connection = connection; - connection.addEventListener('change', () => { - rootState.info.connection = connection; - }); -} -// function setAlertTask(time: number, callback: any) { -// const date = new Date(); //现在时刻 -// const dateIntegralPoint = new Date(time); - -// setTimeout(() => { -// callback(); -// }, dateIntegralPoint.getTime() - date.getTime()); //用户登录后的下一个整点执行。 -// } -async function initAlertEvent() { - // const sys = useSystem(); - - // const chosenDay = new Date(); - // const fileName = `${chosenDay.getFullYear()}-${chosenDay.getMonth() + 1}-${chosenDay.getDate()}.json`; - // const filePath = join(sys._rootState.options.userLocation || '', '/Schedule', fileName) - // const isExits = await sys.fs.exists(filePath); - - // if (isExits) { - // const alredyNotes = await sys.fs.readFile(filePath); - // const alertList = JSON.parse(alredyNotes); - // alertList.forEach((item: any) => { - // if (item.time < Date.now()) return; - // setAlertTask(item.time, () => { - // sys.createNotify({ - // title: '日程提醒', - // content: `今日${new Date(item.time).getHours()}时${new Date(item.time).getMinutes()}分 的提醒: ${ - // item.text - // }`, - // }); - // }); - // }); - // } -} -export { initSizeEvent, initBatteryEvent, initNetworkEvent, initAlertEvent }; diff --git a/frontend/src/util/eventBus.ts b/frontend/src/system/event/eventBus.ts similarity index 100% rename from frontend/src/util/eventBus.ts rename to frontend/src/system/event/eventBus.ts diff --git a/godo/files/pwdfile.go b/godo/files/pwdfile.go index 68651ff..b4b350d 100644 --- a/godo/files/pwdfile.go +++ b/godo/files/pwdfile.go @@ -129,6 +129,7 @@ func HandleReadFile(w http.ResponseWriter, r *http.Request) { if len(fileData)%8 == 0 { fileData = append(fileData, ' ') } + //log.Printf("fileData: %s", content) libs.SuccessMsg(w, fileData, "文件读取成功") return }