From b9c94a1930902c7d965db237fb15a4f08edd9d4f Mon Sep 17 00:00:00 2001 From: renxiaoyin Date: Mon, 20 Feb 2023 16:12:46 +0800 Subject: [PATCH] make two pages switchable --- package.json | 3 +- src/App.vue | 23 +- src/background.js | 59 +++- src/components/FaasAttendReplay.vue | 313 ++++++++++++++++++ .../{FaasReplay.vue => FaasPerfReplay.vue} | 11 +- src/main.js | 5 +- src/preload.js | 4 +- src/router/index.js | 22 ++ yarn.lock | 12 + 9 files changed, 436 insertions(+), 16 deletions(-) create mode 100644 src/components/FaasAttendReplay.vue rename src/components/{FaasReplay.vue => FaasPerfReplay.vue} (96%) create mode 100644 src/router/index.js diff --git a/package.json b/package.json index 8985425..b1904c0 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,8 @@ "axios": "^0.26.1", "core-js": "^3.8.3", "element-plus": "^2.1.8", - "vue": "^3.2.13" + "vue": "^3.2.13", + "vue-router": "^4.1.6" }, "devDependencies": { "@babel/core": "^7.12.16", diff --git a/src/App.vue b/src/App.vue index 72bad35..9000e68 100644 --- a/src/App.vue +++ b/src/App.vue @@ -2,32 +2,41 @@
- + + +
diff --git a/src/background.js b/src/background.js index 70c229e..e47ed21 100644 --- a/src/background.js +++ b/src/background.js @@ -1,6 +1,6 @@ 'use strict' -import { app, protocol, BrowserWindow, ipcMain } from 'electron' +import { app, protocol, BrowserWindow, ipcMain, Menu } from 'electron' import { createProtocol } from 'vue-cli-plugin-electron-builder/lib' import installExtension, { VUEJS_DEVTOOLS } from 'electron-devtools-installer' import axios from "axios"; @@ -15,10 +15,11 @@ protocol.registerSchemesAsPrivileged([ { scheme: 'app', privileges: { secure: true, standard: true } } ]) +let win; async function createWindow() { // Create the browser window. - const win = new BrowserWindow({ + win = new BrowserWindow({ width: 1024, height: 768, webPreferences: { @@ -31,15 +32,44 @@ async function createWindow() { } }) + const template = [ + { + label: 'Pages', + submenu: [ + { + label: 'Attendance', + click() { + console.log("pages-attendance") + win.webContents.postMessage('navigate', 'Attendance') + } + }, + { + label: 'Performance', + click() { + console.log("pages-performance") + win.webContents.postMessage('navigate', 'Performance') + + } + } + ] + } + ]; + + if (process.env.WEBPACK_DEV_SERVER_URL) { // Load the url of the dev server if in development mode + console.log("webpack env: "+process.env.WEBPACK_DEV_SERVER_URL ); await win.loadURL(process.env.WEBPACK_DEV_SERVER_URL) if (!process.env.IS_TEST) win.webContents.openDevTools() } else { createProtocol('app') // Load the index.html when not in development + console.log("appurl: app://./index.html") win.loadURL('app://./index.html') } + const menu = Menu.buildFromTemplate(template); + Menu.setApplicationMenu(menu); + } // Quit when all windows are closed. @@ -114,6 +144,31 @@ ipcMain.on("query-UAT-Sandbox", function (event, arg) { getFaasResult(event, baseFaasUrl, request); }) +ipcMain.on("query-attend-PROD", function (event, arg) { + var request = JSON.parse(arg); + var baseFaasUrl = "https://faas.longfor.com/MarketCenter_ChannelSupportTeam/hit/xrobot?intent=API&tenantid=MarketCenter_ChannelSupportTeam&appid=RuntimeCalPayProject&skill=RealtimeCalPaySkillSet-ReplaySalaryAttendanceServiceSkillV2"; + getFaasResult(event, baseFaasUrl, request); +}) + +ipcMain.on("query-attend-UAT", function (event, arg) { + var request = JSON.parse(arg); + var baseFaasUrl = "http://10.231.143.223:18991/hit/xrobot?intent=APIGateway&tenantid=MarketCenter_ChannelSupportTeam&appid=RuntimeCalPayProject&skill=RealtimeCalPaySkillSet-ReplaySalaryAttendanceServiceSkillV2"; + getFaasResult(event, baseFaasUrl, request); + +}) + +ipcMain.on("query-attend-UAT-Sandbox", function (event, arg) { + var request = JSON.parse(arg); + console.log("query-attend-UAT-Sandbox ") + var baseFaasUrl = "http://10.231.143.223:18992/hit/xrobot?tenantid=MarketCenter_ChannelSupportTeam&appid=sandbox&skill=RuntimeCalPaySkillSet-ReplaySalaryAttendanceServiceSkillV2&intent=APIGateway&tenant_uid=renxiaoyin"; + getFaasResult(event, baseFaasUrl, request); +}) + +ipcMain.on('navigate', (event, route) => { + win.webContents.send('navigate', route) +}) + + function getFaasResult(event, url, request) { axios.post(url, request).then((res) => { console.log(res.data); diff --git a/src/components/FaasAttendReplay.vue b/src/components/FaasAttendReplay.vue new file mode 100644 index 0000000..c4cca6f --- /dev/null +++ b/src/components/FaasAttendReplay.vue @@ -0,0 +1,313 @@ + + + + + \ No newline at end of file diff --git a/src/components/FaasReplay.vue b/src/components/FaasPerfReplay.vue similarity index 96% rename from src/components/FaasReplay.vue rename to src/components/FaasPerfReplay.vue index 001520d..9de1f02 100644 --- a/src/components/FaasReplay.vue +++ b/src/components/FaasPerfReplay.vue @@ -102,11 +102,11 @@ import axios from "axios"; // import { ipcRenderer } from "electron"; export default { - name: "FaasReplay", + name: "FaasPerfReplay", data() { return { count: 1, - componentName: "FaasReplayComponent", + componentName: "FaasPerfReplayComponent", mobilePhone: 17705928270, projectId: "137F5533-B3D7-480D-9048-E23D0E3ABED7", yearMonth: "2022-03", @@ -129,6 +129,13 @@ export default { }, mounted() { console.log(this.count); + window.ipcRenderer.receive("navigate", (param) => { + console.log(param) + if (param == "Attendance") { + console.log(" Go Attendance") + this.$router.push('/attendance'); + } + }); }, methods: { diff --git a/src/main.js b/src/main.js index 0a3a5c5..e6e9319 100644 --- a/src/main.js +++ b/src/main.js @@ -1,9 +1,10 @@ -import { createApp } from 'vue' +import { createApp} from 'vue' import App from './App.vue' +import router from './router' import ElementPlus from 'element-plus' import 'element-plus/dist/index.css' - const app = createApp(App); app.use(ElementPlus); +app.use(router); app.mount('#app'); diff --git a/src/preload.js b/src/preload.js index dbceb09..60d5a58 100644 --- a/src/preload.js +++ b/src/preload.js @@ -3,13 +3,13 @@ import { contextBridge, ipcRenderer } from 'electron' // Expose ipcRenderer to the client contextBridge.exposeInMainWorld('ipcRenderer', { send: (channel, data) => { - let validChannels = ['query','query-PROD', 'query-UAT', 'query-UAT-Sandbox'] // <-- Array of all ipcRenderer Channels used in the client + let validChannels = ['query','query-PROD', 'query-UAT', 'query-UAT-Sandbox', 'query-attend-PROD', 'query-attend-UAT', 'query-attend-UAT-Sandbox','navigate'] // <-- Array of all ipcRenderer Channels used in the client if (validChannels.includes(channel)) { ipcRenderer.send(channel, data) } }, receive: (channel, func) => { - let validChannels = ['get-result'] // <-- Array of all ipcMain Channels used in the electron + let validChannels = ['get-result','navigate'] // <-- Array of all ipcMain Channels used in the electron if (validChannels.includes(channel)) { // Deliberately strip event as it includes `sender` ipcRenderer.on(channel, (event, ...args) => func(...args)) diff --git a/src/router/index.js b/src/router/index.js new file mode 100644 index 0000000..bc43b79 --- /dev/null +++ b/src/router/index.js @@ -0,0 +1,22 @@ +import {createRouter,createWebHashHistory} from 'vue-router' +import FaasPerfReplay from '../components/FaasPerfReplay.vue' +import FaasAttendReplay from '../components/FaasAttendReplay.vue' + +var routes = [ + { + path: '/attendance', + name: 'Attendance', + component: FaasAttendReplay + }, + { + path: '/perf', + name: 'Performance', + component: FaasPerfReplay + } + ]; +var router = createRouter({ + history: createWebHashHistory(), + routes: routes + }); + +export default router \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index a3bdd00..08b5897 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1781,6 +1781,11 @@ optionalDependencies: prettier "^1.18.2 || ^2.0.0" +"@vue/devtools-api@^6.4.5": + version "6.5.0" + resolved "https://registry.yarnpkg.com/@vue/devtools-api/-/devtools-api-6.5.0.tgz#98b99425edee70b4c992692628fa1ea2c1e57d07" + integrity sha512-o9KfBeaBmCKl10usN4crU53fYtC1r7jJwdGKjPT24t348rHxgfpZ0xL3Xm/gLUYnc0oTp8LAmrxOeLyu6tbk2Q== + "@vue/reactivity-transform@3.2.31": version "3.2.31" resolved "https://registry.npmmirror.com/@vue/reactivity-transform/-/reactivity-transform-3.2.31.tgz#0f5b25c24e70edab2b613d5305c465b50fc00911" @@ -9406,6 +9411,13 @@ vue-loader@^17.0.0: hash-sum "^2.0.0" loader-utils "^2.0.0" +vue-router@^4.1.6: + version "4.1.6" + resolved "https://registry.yarnpkg.com/vue-router/-/vue-router-4.1.6.tgz#b70303737e12b4814578d21d68d21618469375a1" + integrity sha512-DYWYwsG6xNPmLq/FmZn8Ip+qrhFEzA14EI12MsMgVxvHFDYvlr4NXpVF5hrRH1wVcDP8fGi5F4rxuJSl8/r+EQ== + dependencies: + "@vue/devtools-api" "^6.4.5" + vue-style-loader@^4.1.0, vue-style-loader@^4.1.3: version "4.1.3" resolved "https://registry.npmmirror.com/vue-style-loader/-/vue-style-loader-4.1.3.tgz#6d55863a51fa757ab24e89d9371465072aa7bc35"