From 13f6d1659885b61e7f22b39f104e02be2ffcfd56 Mon Sep 17 00:00:00 2001 From: gaoshuaixing <530353222@qq.com> Date: Sat, 11 Jan 2025 15:47:15 +0800 Subject: [PATCH] chore: add frontend types --- frontend/src/views/cross/go/Index.vue | 10 ++++---- frontend/src/views/cross/java/Index.vue | 10 ++++---- frontend/src/views/cross/python/Index.vue | 10 ++++---- frontend/src/views/framework/jobs/Index.vue | 12 +++++----- .../src/views/framework/socket/HttpServer.vue | 14 +++++------ frontend/src/views/framework/socket/Ipc.vue | 8 +++---- .../views/framework/socket/SocketServer.vue | 6 ++--- .../src/views/framework/software/Index.vue | 2 +- .../src/views/framework/sqlitedb/Index.vue | 24 +++++++++---------- .../src/views/framework/updater/Index.vue | 10 ++++---- frontend/src/views/os/file/Index.vue | 16 ++++++------- frontend/src/views/os/file/Pic.vue | 6 ++--- frontend/src/views/os/notification/Index.vue | 4 ++-- frontend/src/views/os/subwindow/Ipc.vue | 10 ++++---- frontend/src/views/os/window/Index.vue | 2 +- frontend/tsconfig.json | 4 ++-- 16 files changed, 73 insertions(+), 75 deletions(-) diff --git a/frontend/src/views/cross/go/Index.vue b/frontend/src/views/cross/go/Index.vue index 69bc8bf..9474bf7 100644 --- a/frontend/src/views/cross/go/Index.vue +++ b/frontend/src/views/cross/go/Index.vue @@ -36,13 +36,13 @@ import { message } from 'ant-design-vue'; const serverUrl = ref(''); function info() { - ipc.invoke(ipcApiRoute.cross.crossInfo, {}).then(res => { + ipc.invoke(ipcApiRoute.cross.crossInfo, {}).then((res: any) => { console.log('res:', res); }) } function getUrl() { - ipc.invoke(ipcApiRoute.cross.getCrossUrl, {name: 'goapp'}).then(url => { + ipc.invoke(ipcApiRoute.cross.getCrossUrl, {name: 'goapp'}).then((url: string) => { serverUrl.value = url; message.info(`服务地址: ${url}`); }) @@ -57,14 +57,14 @@ function create() { ipc.invoke(ipcApiRoute.cross.createCrossServer, { program: 'go' }) } -function request(type) { +function request(type: number) { if (type == 1 && serverUrl.value == "") { message.info("请先获取服务地址"); return } if (type == 1) { const testApi = serverUrl.value + '/api/hello'; - const cfg = { + const cfg: Record = { method: 'get', url: testApi, params: { id: '111'}, @@ -76,7 +76,7 @@ function request(type) { message.info(`服务返回: ${data}`); }) } else { - ipc.invoke(ipcApiRoute.cross.requestApi, {name: 'goapp', urlPath: '/api/hello'}).then(res => { + ipc.invoke(ipcApiRoute.cross.requestApi, {name: 'goapp', urlPath: '/api/hello'}).then((res: any) => { console.log('res:', res); if (res) { const { data} = res; diff --git a/frontend/src/views/cross/java/Index.vue b/frontend/src/views/cross/java/Index.vue index 47060ea..904681c 100644 --- a/frontend/src/views/cross/java/Index.vue +++ b/frontend/src/views/cross/java/Index.vue @@ -36,13 +36,13 @@ import { message } from 'ant-design-vue'; const serverUrl = ref(''); function info() { - ipc.invoke(ipcApiRoute.cross.crossInfo, {}).then(res => { + ipc.invoke(ipcApiRoute.cross.crossInfo, {}).then((res: any) => { console.log('res:', res); }) } function getUrl() { - ipc.invoke(ipcApiRoute.cross.getCrossUrl, {name: 'javaapp'}).then(url => { + ipc.invoke(ipcApiRoute.cross.getCrossUrl, {name: 'javaapp'}).then((url: string) => { serverUrl.value = url; message.info(`服务地址: ${url}`); }) @@ -57,7 +57,7 @@ function create() { ipc.invoke(ipcApiRoute.cross.createCrossServer, { program: 'java' }) } -function request(type) { +function request(type: number) { if (type == 1 && serverUrl.value == "") { message.info("请先获取服务地址"); return @@ -65,7 +65,7 @@ function request(type) { if (type == 1) { const testApi = serverUrl.value + '/test1/get'; - const cfg = { + const cfg: Record = { method: 'get', url: testApi, params: { id: '1111111'}, @@ -77,7 +77,7 @@ function request(type) { message.info(`服务返回: ${data}`); }) } else { - ipc.invoke(ipcApiRoute.cross.requestApi, {name: 'javaapp', urlPath: '/test1/get', params: { id: '1111111'}}).then(res => { + ipc.invoke(ipcApiRoute.cross.requestApi, {name: 'javaapp', urlPath: '/test1/get', params: { id: '1111111'}}).then((res: any) => { console.log('res:', res); const data = res || null; message.info(`服务返回: ${data}`); diff --git a/frontend/src/views/cross/python/Index.vue b/frontend/src/views/cross/python/Index.vue index 2ebb60a..d160ad7 100644 --- a/frontend/src/views/cross/python/Index.vue +++ b/frontend/src/views/cross/python/Index.vue @@ -36,13 +36,13 @@ import { message } from 'ant-design-vue'; const serverUrl = ref(''); function info() { - ipc.invoke(ipcApiRoute.cross.crossInfo, {}).then(res => { + ipc.invoke(ipcApiRoute.cross.crossInfo, {}).then((res: any) => { console.log('res:', res); }) } function getUrl() { - ipc.invoke(ipcApiRoute.cross.getCrossUrl, {name: 'pyapp'}).then(url => { + ipc.invoke(ipcApiRoute.cross.getCrossUrl, {name: 'pyapp'}).then((url: string) => { serverUrl.value = url; message.info(`服务地址: ${url}`); }) @@ -57,14 +57,14 @@ function create() { ipc.invoke(ipcApiRoute.cross.createCrossServer, { program: 'python' }) } -function request(type) { +function request(type: number) { if (type == 1 && serverUrl.value == "") { message.info("请先获取服务地址"); return } if (type == 1) { const testApi = serverUrl.value + '/api/hello'; - const cfg = { + const cfg: Record = { method: 'get', url: testApi, params: { id: '111'}, @@ -76,7 +76,7 @@ function request(type) { message.info(`服务返回: ${JSON.stringify(data)}`); }) } else { - ipc.invoke(ipcApiRoute.cross.requestApi, {name: 'pyapp', urlPath: '/api/hello'}).then(res => { + ipc.invoke(ipcApiRoute.cross.requestApi, {name: 'pyapp', urlPath: '/api/hello'}).then((res: any) => { console.log('res:', res); const data = res || null; message.info(`服务返回: ${JSON.stringify(data)}`); diff --git a/frontend/src/views/framework/jobs/Index.vue b/frontend/src/views/framework/jobs/Index.vue index 6144bbd..14d747b 100644 --- a/frontend/src/views/framework/jobs/Index.vue +++ b/frontend/src/views/framework/jobs/Index.vue @@ -84,7 +84,7 @@ function init() { ipc.removeAllListeners(ipcApiRoute.framework.createPoolNotice); // 监听任务进度 - ipc.on(ipcApiRoute.framework.timerJobProgress, (event, result) => { + ipc.on(ipcApiRoute.framework.timerJobProgress, (event: any, result: Record) => { const { jobId, pid, number} = result; switch (jobId) { case 1: @@ -115,18 +115,18 @@ function init() { }) // 监听pool - ipc.on(ipcApiRoute.framework.createPoolNotice, (event, result) => { + ipc.on(ipcApiRoute.framework.createPoolNotice, (event: any, result: any) => { processPids.value = JSON.stringify(result); }) } -function runJob(jobId, operation) { +function runJob(jobId: number, operation: string) { const params = { jobId, type: 'timer', action: operation } - ipc.invoke(ipcApiRoute.framework.someJob, params).then(data => { + ipc.invoke(ipcApiRoute.framework.someJob, params).then((data: any) => { if (operation != 'create') return; switch (data.jobId) { case 1: @@ -146,13 +146,13 @@ function createPool() { ipc.send(ipcApiRoute.framework.createPool, params); } -function runJobByPool(jobId, operation) { +function runJobByPool(jobId: number, operation: string) { const params = { jobId, type: 'timer', action: operation } - ipc.invoke(ipcApiRoute.framework.someJobByPool, params).then(data => { + ipc.invoke(ipcApiRoute.framework.someJobByPool, params).then((data: any) => { const { jobId, result} = data; switch (jobId) { case 3: diff --git a/frontend/src/views/framework/socket/HttpServer.vue b/frontend/src/views/framework/socket/HttpServer.vue index 92c9255..40b7002 100644 --- a/frontend/src/views/framework/socket/HttpServer.vue +++ b/frontend/src/views/framework/socket/HttpServer.vue @@ -41,7 +41,7 @@ onMounted(() => { }) function init() { - ipc.invoke(ipcApiRoute.framework.checkHttpServer, {}).then(r => { + ipc.invoke(ipcApiRoute.framework.checkHttpServer, {}).then((r: any) => { if (r.enable) { currentStatus.value = '开启'; servicAddress.value = r.server; @@ -50,21 +50,19 @@ function init() { }) } -function sendRequest(id) { +function sendRequest(id: string) { if (currentStatus.value == '关闭') { message.error('http服务未开启'); return; } - requestHttp(ipcApiRoute.framework.doHttpRequest, {id}).then(res => { - //console.log('res:', res) - }) + requestHttp(ipcApiRoute.framework.doHttpRequest, {id}) } /** * Accessing built-in HTTP services */ -function requestHttp(uri, parameter) { +function requestHttp(uri: string, parameter: any) { // URL conversion const config = storage.get('httpServiceConfig'); const host = config.server || 'http://localhost:7071'; @@ -84,7 +82,7 @@ function requestHttp(uri, parameter) { */ function backendRequest() { console.log('GO_URL:', import.meta.env.VITE_GO_URL); - const cfg = { + const cfg: Record = { baseURL: import.meta.env.VITE_GO_URL, method: 'get', url: '/hello', @@ -93,7 +91,7 @@ function backendRequest() { axios(cfg).then(res => { console.log('res:', res); const data = res.data || null; - this.$message.info(`go服务返回: ${data}`, ); + message.info(`go服务返回: ${data}`, ); }) } diff --git a/frontend/src/views/framework/socket/Ipc.vue b/frontend/src/views/framework/socket/Ipc.vue index b9cde5c..ac46234 100644 --- a/frontend/src/views/framework/socket/Ipc.vue +++ b/frontend/src/views/framework/socket/Ipc.vue @@ -78,7 +78,7 @@ onMounted(() => { function init() { // 避免重复监听,或者将 on 功能写到一个统一的地方,只加载一次 ipc.removeAllListeners(ipcApiRoute.framework.ipcSendMsg); - ipc.on(ipcApiRoute.framework.ipcSendMsg, (event, result) => { + ipc.on(ipcApiRoute.framework.ipcSendMsg, (event: any, result: string) => { console.log('[ipcRenderer] [socketMsgStart] result:', result); messageString.value = result; @@ -88,7 +88,7 @@ function init() { // 监听 窗口2 发来的消息 ipc.removeAllListeners(ipcApiRoute.os.window2ToWindow1); - ipc.on(ipcApiRoute.os.window2ToWindow1, (event, arg) => { + ipc.on(ipcApiRoute.os.window2ToWindow1, (event: any, arg: any) => { message.info(arg); }) } @@ -110,7 +110,7 @@ function sendMsgStop() { } function handleInvoke() { - ipc.invoke(ipcApiRoute.framework.ipcInvokeMsg, '异步-回调').then(r => { + ipc.invoke(ipcApiRoute.framework.ipcInvokeMsg, '异步-回调').then((r: any) => { console.log('r:', r); message1.value = r; }); @@ -128,7 +128,7 @@ function handleSendSync() { } function createWindow() { - ipc.invoke(ipcApiRoute.os.createWindow, vueItem).then(wcid => { + ipc.invoke(ipcApiRoute.os.createWindow, vueItem).then((wcid: number | string) => { console.log('[createWindow] wcid:', wcid); }) } diff --git a/frontend/src/views/framework/socket/SocketServer.vue b/frontend/src/views/framework/socket/SocketServer.vue index afce6f7..288b85a 100644 --- a/frontend/src/views/framework/socket/SocketServer.vue +++ b/frontend/src/views/framework/socket/SocketServer.vue @@ -32,7 +32,7 @@ import { message } from 'ant-design-vue'; const currentStatus = ref('关闭'); const servicAddress = ref('ws://localhost:7070'); const client = { - socket: null + socket: null as any, }; onMounted(() => { @@ -47,14 +47,14 @@ function init() { }); } -function sendRequest(id) { +function sendRequest(id: string) { if (currentStatus.value == '关闭') { message.error('socketio服务未开启'); return; } const method = ipcApiRoute.framework.doSocketRequest; - client.socket.emit('c1', { cmd: method, args: {id} }, (response) => { + client.socket.emit('c1', { cmd: method, args: {id} }, (response: any) => { // response为返回值 console.log('response:', response) }); diff --git a/frontend/src/views/framework/software/Index.vue b/frontend/src/views/framework/software/Index.vue index 8d877e1..99321fc 100644 --- a/frontend/src/views/framework/software/Index.vue +++ b/frontend/src/views/framework/software/Index.vue @@ -26,7 +26,7 @@ import { message } from 'ant-design-vue'; const soft = ref('powershell.exe'); function openSoft() { - ipc.invoke(ipcApiRoute.framework.openSoftware, {softName: soft.value}).then(result => { + ipc.invoke(ipcApiRoute.framework.openSoftware, {softName: soft.value}).then((result: any) => { if (!result) { message.error('程序不存在'); } diff --git a/frontend/src/views/framework/sqlitedb/Index.vue b/frontend/src/views/framework/sqlitedb/Index.vue index 270086e..9490294 100644 --- a/frontend/src/views/framework/sqlitedb/Index.vue +++ b/frontend/src/views/framework/sqlitedb/Index.vue @@ -183,7 +183,7 @@ function init() { const params = { action: 'getDataDir', } - ipc.invoke(ipcApiRoute.framework.sqlitedbOperation, params).then(res => { + ipc.invoke(ipcApiRoute.framework.sqlitedbOperation, params).then((res: any) => { if (res.code == -1) { message.error('请检查sqlite是否正确安装', 5); return @@ -198,7 +198,7 @@ function getAllTestData () { const params = { action: 'all', } - ipc.invoke(ipcApiRoute.framework.sqlitedbOperation, params).then(res => { + ipc.invoke(ipcApiRoute.framework.sqlitedbOperation, params).then((res: any) => { if (res.all_list.length == 0) { return false; } @@ -207,10 +207,10 @@ function getAllTestData () { } function selectDir() { - ipc.invoke(ipcApiRoute.os.selectFolder, '').then(r => { - data_dir.value = r; + ipc.invoke(ipcApiRoute.os.selectFolder, '').then((res: any) => { + data_dir.value = res; // 修改数据目录 - modifyDataDir(r); + modifyDataDir(res); }) } @@ -219,32 +219,32 @@ function openDir() { ipc.invoke(ipcApiRoute.os.openDirectory, {id: data_dir.value}) } -function modifyDataDir(dir) { +function modifyDataDir(dir: string) { const params = { action: 'setDataDir', data_dir: dir } - ipc.invoke(ipcApiRoute.framework.sqlitedbOperation, params).then(res => { + ipc.invoke(ipcApiRoute.framework.sqlitedbOperation, params).then((res: any) => { all_list.value = res.all_list; }) } -function sqlitedbOperation (ac) { +function sqlitedbOperation (ac: string) { const params = { action: ac, info: { name: name.value, - age: parseInt(age.value) + age: age.value }, - search_age: parseInt(search_age.value), + search_age: search_age.value, update_name: update_name.value, - update_age: parseInt(update_age.value), + update_age: update_age.value, delete_name: delete_name.value, } if (ac == 'add' && name.value.length == 0) { message.error(`请填写数据`); } - ipc.invoke(ipcApiRoute.framework.sqlitedbOperation, params).then(res => { + ipc.invoke(ipcApiRoute.framework.sqlitedbOperation, params).then((res: any) => { console.log('res:', res); if (ac == 'get') { if (res.result.length == 0) { diff --git a/frontend/src/views/framework/updater/Index.vue b/frontend/src/views/framework/updater/Index.vue index 4214bd2..21817e4 100644 --- a/frontend/src/views/framework/updater/Index.vue +++ b/frontend/src/views/framework/updater/Index.vue @@ -40,7 +40,7 @@ onMounted(() => { function init() { ipc.removeAllListeners(specialIpcRoute.appUpdater); - ipc.on(specialIpcRoute.appUpdater, (event, result) => { + ipc.on(specialIpcRoute.appUpdater, (event: any, result: any) => { result = JSON.parse(result); status.value = result.status; if (result.status == 3) { @@ -53,8 +53,8 @@ function init() { } function checkForUpdater () { - ipc.invoke(ipcApiRoute.framework.checkForUpdater).then(r => { - console.log(r); + ipc.invoke(ipcApiRoute.framework.checkForUpdater).then((res: any) => { + console.log(res); }) } @@ -63,8 +63,8 @@ function download () { message.info('没有可用版本'); return } - ipc.invoke(ipcApiRoute.framework.downloadApp).then(r => { - console.log(r); + ipc.invoke(ipcApiRoute.framework.downloadApp).then((res: any) => { + console.log(res); }) } diff --git a/frontend/src/views/os/file/Index.vue b/frontend/src/views/os/file/Index.vue index 0053bae..e9accae 100644 --- a/frontend/src/views/os/file/Index.vue +++ b/frontend/src/views/os/file/Index.vue @@ -78,26 +78,26 @@ const fileList = [ const dir_path = ref('D:\\www\\ee'); -function openDirectry (id) { +function openDirectry (id: string) { ipc.invoke(ipcApiRoute.os.openDirectory, {id: id}) } function selectDir() { - ipc.invoke(ipcApiRoute.os.selectFolder).then(r => { - dir_path.value = r; - message.info(r); + ipc.invoke(ipcApiRoute.os.selectFolder).then((res: any) => { + dir_path.value = res; + message.info(res); }) } function messageShow() { - ipc.invoke(ipcApiRoute.os.messageShow).then(r => { - message.info(r); + ipc.invoke(ipcApiRoute.os.messageShow).then((res: any) => { + message.info(res); }) } function messageShowConfirm() { - ipc.invoke(ipcApiRoute.os.messageShowConfirm).then(r => { - message.info(r); + ipc.invoke(ipcApiRoute.os.messageShowConfirm).then((res: any) => { + message.info(res); }) } diff --git a/frontend/src/views/os/file/Pic.vue b/frontend/src/views/os/file/Pic.vue index b573060..e1233d4 100644 --- a/frontend/src/views/os/file/Pic.vue +++ b/frontend/src/views/os/file/Pic.vue @@ -7,7 +7,7 @@
- 选择图片 + 选择图片

{ - picPath.value = r; + ipc.invoke(ipcApiRoute.os.selectPic).then((res: any) => { + picPath.value = res; }) } diff --git a/frontend/src/views/os/notification/Index.vue b/frontend/src/views/os/notification/Index.vue index 9ef8449..3191a7a 100644 --- a/frontend/src/views/os/notification/Index.vue +++ b/frontend/src/views/os/notification/Index.vue @@ -59,14 +59,14 @@ onMounted(() => { function init() { // Avoid duplicate monitoring, or write the on function to a unified place and load it only once ipc.removeAllListeners(ipcApiRoute.os.sendNotification); - ipc.on(ipcApiRoute.os.sendNotification, (event, result) => { + ipc.on(ipcApiRoute.os.sendNotification, (event: any, result: any) => { if (Object.prototype.toString.call(result) == '[object Object]') { message.info(result.msg); } }) } -function sendNotification (index) { +function sendNotification (index: number) { ipc.send(ipcApiRoute.os.sendNotification, views[index]); } diff --git a/frontend/src/views/os/subwindow/Ipc.vue b/frontend/src/views/os/subwindow/Ipc.vue index 3ee0e14..ba163f4 100644 --- a/frontend/src/views/os/subwindow/Ipc.vue +++ b/frontend/src/views/os/subwindow/Ipc.vue @@ -68,7 +68,7 @@ onMounted(() => { }) function init() { - ipc.on(ipcApiRoute.framework.ipcSendMsg, (event, result) => { + ipc.on(ipcApiRoute.framework.ipcSendMsg, (event: any, result: any) => { console.log('[ipcRenderer] [socketMsgStart] result:', result); messageString.value = result; @@ -78,7 +78,7 @@ function init() { // 监听主窗口发来的消息 ipc.removeAllListeners(ipcApiRoute.os.window1ToWindow2); - ipc.on(ipcApiRoute.os.window1ToWindow2, (event, arg) => { + ipc.on(ipcApiRoute.os.window1ToWindow2, (event: any, arg: any) => { message.info(arg); }) } @@ -100,9 +100,9 @@ function sendMsgStop() { } function handleInvoke () { - ipc.invoke(ipcApiRoute.framework.ipcInvokeMsg, '异步-回调').then(r => { - console.log('r:', r); - message1.value = r; + ipc.invoke(ipcApiRoute.framework.ipcInvokeMsg, '异步-回调').then((res: any) => { + console.log('r:', res); + message1.value = res; }); } diff --git a/frontend/src/views/os/window/Index.vue b/frontend/src/views/os/window/Index.vue index 6116058..929293c 100644 --- a/frontend/src/views/os/window/Index.vue +++ b/frontend/src/views/os/window/Index.vue @@ -57,7 +57,7 @@ const views = [ }, ]; -function createWindow(index) { +function createWindow(index: number) { ipc.invoke(ipcApiRoute.os.createWindow, views[index]) } diff --git a/frontend/tsconfig.json b/frontend/tsconfig.json index 7d6abf9..aa697e4 100644 --- a/frontend/tsconfig.json +++ b/frontend/tsconfig.json @@ -23,11 +23,11 @@ "baseUrl": "./", "paths": { "@/*": [ - "src/*" + "./src/*" ], } }, - "include":["src/**/*.ts", "src/**/*.vue", "src/**/*.tsx", "src/**/*.d.ts", "*.d.ts"], + "include":["./src/**/*.ts", "./src/**/*.vue", "./src/**/*.tsx", "./src/**/*.d.ts", "*.d.ts"], "exclude": [ "node_modules", "dist"