Init project

This commit is contained in:
renxiaoyin 2023-02-08 17:49:44 +08:00
parent 50c14a411b
commit 1d9b2eb6bb
9 changed files with 4419 additions and 82 deletions

3
.gitignore vendored
View File

@ -21,3 +21,6 @@ pnpm-debug.log*
*.njsproj
*.sln
*.sw?
#Electron-builder output
/dist_electron

View File

@ -5,10 +5,17 @@
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
"lint": "vue-cli-service lint",
"electron:build": "vue-cli-service electron:build",
"electron:serve": "vue-cli-service electron:serve",
"postinstall": "electron-builder install-app-deps",
"postuninstall": "electron-builder install-app-deps"
},
"main": "background.js",
"dependencies": {
"axios": "^0.26.1",
"core-js": "^3.8.3",
"element-plus": "^2.1.8",
"vue": "^3.2.13"
},
"devDependencies": {
@ -17,8 +24,11 @@
"@vue/cli-plugin-babel": "~5.0.0",
"@vue/cli-plugin-eslint": "~5.0.0",
"@vue/cli-service": "~5.0.0",
"electron": "^13.0.0",
"electron-devtools-installer": "^3.1.0",
"eslint": "^7.32.0",
"eslint-plugin-vue": "^8.0.3"
"eslint-plugin-vue": "^8.0.3",
"vue-cli-plugin-electron-builder": "~2.1.1"
},
"eslintConfig": {
"root": true,

View File

@ -1,15 +1,32 @@
<template>
<img alt="Vue logo" src="./assets/logo.png">
<HelloWorld msg="Welcome to Your Vue.js App"/>
<div id="app">
<!-- <img alt="Vue logo" src="./assets/logo.png"> -->
<!-- <HelloWorld msg="Welcome to Your Vue.js App"/> -->
<FaasReplay></FaasReplay>
</div>
</template>
<script>
import HelloWorld from './components/HelloWorld.vue'
// import HelloWorld from './components/HelloWorld.vue'
import FaasReplay from './components/FaasReplay.vue'
export default {
name: 'App',
components: {
HelloWorld
// HelloWorld,
FaasReplay
},
data(){
return {
a:100
}
},
mounted() {
// `this` refers to the component instance.
console.log(this.count) // => 1
// data can be mutated as well
this.count = 2
}
}
</script>

124
src/background.js Normal file
View File

@ -0,0 +1,124 @@
'use strict'
import { app, protocol, BrowserWindow, ipcMain } from 'electron'
import { createProtocol } from 'vue-cli-plugin-electron-builder/lib'
import installExtension, { VUEJS_DEVTOOLS } from 'electron-devtools-installer'
import axios from "axios";
// import path from "path";
const path = require("path");
// const fs = require("fs");
const isDevelopment = process.env.NODE_ENV !== 'production'
console.log("start");
// Scheme must be registered before the app is ready
protocol.registerSchemesAsPrivileged([
{ scheme: 'app', privileges: { secure: true, standard: true } }
])
async function createWindow() {
// Create the browser window.
const win = new BrowserWindow({
width: 1024,
height: 768,
webPreferences: {
// Use pluginOptions.nodeIntegration, leave this alone
// See nklayman.github.io/vue-cli-plugin-electron-builder/guide/security.html#node-integration for more info
nodeIntegration: process.env.ELECTRON_NODE_INTEGRATION,
contextIsolation: !process.env.ELECTRON_NODE_INTEGRATION,
preload: path.join(__dirname, 'preload.js')
}
})
if (process.env.WEBPACK_DEV_SERVER_URL) {
// Load the url of the dev server if in development mode
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
win.loadURL('app://./index.html')
}
}
// Quit when all windows are closed.
app.on('window-all-closed', () => {
// On macOS it is common for applications and their menu bar
// to stay active until the user quits explicitly with Cmd + Q
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('activate', () => {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', async () => {
if (isDevelopment && !process.env.IS_TEST) {
// Install Vue Devtools
try {
await installExtension(VUEJS_DEVTOOLS)
} catch (e) {
console.error('Vue Devtools failed to install:', e.toString())
}
}
createWindow()
})
// Exit cleanly on request from parent process in development mode.
if (isDevelopment) {
if (process.platform === 'win32') {
process.on('message', (data) => {
if (data === 'graceful-exit') {
app.quit()
}
})
} else {
process.on('SIGTERM', () => {
app.quit()
})
}
}
// var request =
// {
// projectId: "137F5533-B3D7-480D-9048-E23D0E3ABED7",
// yearMonth: "2022-03",
// workflows: 4,
// mobilePhone: 17705928270
// };
ipcMain.on("query-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-CalPerfReplay";
getFaasResult(event, baseFaasUrl, request);
})
ipcMain.on("query-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-CalPerfReplay";
getFaasResult(event, baseFaasUrl, request);
})
ipcMain.on("query-UAT-Sandbox", function (event, arg) {
var request = JSON.parse(arg);
var baseFaasUrl = "http://10.231.143.223:18992/hit/xrobot?intent=APIGateway&tenantid=MarketCenter_ChannelSupportTeam&appid=RuntimeCalPayProject&skill=RealtimeCalPaySkillSet-CalPerfReplay&tenant_uid=renxiaoyin";
getFaasResult(event, baseFaasUrl, request);
})
function getFaasResult(event, url, request) {
axios.post(url, request).then((res) => {
console.log(res.data);
event.sender.send("get-result", res.data);
}).catch((err) => {
console.log(err);
});
}

View File

@ -0,0 +1,274 @@
<template>
<div>
<button v-if="true" @click="testBreakPoint">TestBreakPoint</button>
</div>
<el-row>
<el-col :span="8">
<span>Env</span>
</el-col>
<el-col :span="12">
<div class="grid-content bg-purple">
<el-select v-model="env">
<el-option v-for="item in envOpts" :key="item.env" :label="item.env" :value="item.env"></el-option>
</el-select>
</div>
</el-col>
</el-row>
<el-row>
<el-col :span="8">
<span>ProjectId</span>
</el-col>
<el-col :span="12">
<div class="grid-content bg-purple">
<!-- <span>projectId</span> -->
<el-input v-model="projectId" />
</div>
</el-col>
</el-row>
<el-row>
<el-col :span="8">
<span>MobilePhone</span>
</el-col>
<el-col :span="12">
<div class="grid-content bg-purple-light">
<el-input v-model="mobilePhone" />
</div>
</el-col>
</el-row>
<el-row>
<el-col :span="8">
<span>YearMonth</span>
</el-col>
<el-col :span="12">
<div class="grid-content bg-purple-light">
<el-input v-model="yearMonth" placeholder="2022-03" />
</div>
</el-col>
</el-row>
<el-row>
<el-col :span="8">
<span>Workflows</span>
</el-col>
<el-col :span="12">
<div class="grid-content bg-purple-light">
<el-input v-model="workflows" />
</div>
</el-col>
</el-row>
<el-row>
<el-col :span="12">
<div class="grid-content bg-purple-light">
<el-button type="primary" @click="onQuerySubmit">Submit</el-button>
</div>
</el-col>
</el-row>
<el-row>
<el-col>
<el-table :data="processMsgs">
<el-table-column type="expand">
<template #default="props">
<el-table :data="props.row.data">
<!-- <el-table-column prop="groupId"></el-table-column>
<el-table-column prop="groupName"></el-table-column> -->
<el-table-column v-for="(item, key) in props.row.dataTitles" :key="key" :prop="item.value"
:label="item.label"></el-table-column>
</el-table>
</template>
</el-table-column>
<el-table-column prop="component" label="Component"></el-table-column>
<el-table-column prop="message" label="Message"></el-table-column>
</el-table>
</el-col>
</el-row>
<!-- <el-row>
<el-col :span="24">
<div class="grid-content bg-purple-light">
<el-input v-model="rawProcessMsgs" :autosize="{ minRows: 2 }" type="textarea" />
</div>
</el-col>
</el-row> -->
</template>
<script>
import axios from "axios";
// import { ipcRenderer } from "electron";
export default {
name: "FaasReplay",
data() {
return {
count: 1,
componentName: "FaasReplayComponent",
mobilePhone: 17705928270,
projectId: "137F5533-B3D7-480D-9048-E23D0E3ABED7",
yearMonth: "2022-03",
workflows: 4,
rawProcessMsgs: null,
processMsgs: null,
baseUrl: null,
env: "PROD",
envOpts: [{
env: "PROD",
baseUrl: "https://faas.longfor.com/MarketCenter_ChannelSupportTeam/hit/xrobot?intent=API&tenantid=MarketCenter_ChannelSupportTeam&appid=RuntimeCalPayProject&skill=RealtimeCalPaySkillSet-CalPerfReplay"
}, {
env: "UAT",
baseUrl: "http://10.231.143.223:18991/hit/xrobot?intent=APIGateway&tenantid=MarketCenter_ChannelSupportTeam&appid=RuntimeCalPayProject&skill=RealtimeCalPaySkillSet-CalPerfReplay"
}, {
env: "UAT-Sandbox",
baseUrl: "http://10.231.143.223:18992/hit/xrobot?intent=APIGateway&tenantid=MarketCenter_ChannelSupportTeam&appid=RuntimeCalPayProject&skill=RealtimeCalPaySkillSet-CalPerfReplay&tenant_uid=renxiaoyin"
}]
};
},
mounted() {
console.log(this.count);
},
methods: {
testBreakPoint() {
this.count++;
// console.log(this.count);
console.log(this.baseUrl);
axios.post("https://api-uat.longfor.com/mfp-pc/a/login", {}).then((res) => {
console.log(res.data);
event.sender.send("get-result", res.data);
}).catch((err) => {
console.log(err);
});
},
onQuerySubmit() {
console.log(this.mobilePhone);
console.log(this.projectId);
// var url =
// "https://faas.longfor.com/MarketCenter_ChannelSupportTeam/hit/xrobot?intent=API&tenantid=MarketCenter_ChannelSupportTeam&appid=RuntimeCalPayProject&skill=RealtimeCalPaySkillSet-CalPerfReplay";
var request = {
projectId: this.projectId,
yearMonth: this.yearMonth,
workflows: this.workflows,
mobilePhone: this.mobilePhone,
};
var ipcReceiverName = "query-" + this.env;
var encodedRequest = JSON.stringify(request);
window.ipcRenderer.send(ipcReceiverName, encodedRequest);
window.ipcRenderer.receive("get-result", (param) => {
console.log("ipc receive");
console.log(param);
this.processMsgs = JSON.parse(param.rs);
var normalizedMsgs = this.reformMsgs(this.processMsgs);
this.normalizedMsgs.forEach(item => {
if (Array.isArray(item.data)) {
// extract data title
var firstRow = item.data[0];
if (firstRow == undefined || firstRow == null) {
item.data = [];
item.dataTitles = [{
value: "Result",
label: "Result"
}]
}
else {
item.dataTitles = [];
for (var property in firstRow) {
if (Object.prototype.hasOwnProperty.call(firstRow, property)) {
item.dataTitles.push({
value: property,
label: property
})
}
}
console.log(JSON.stringify(item.dataTitles));
}
}
else {
if (typeof (item.data) == "string" || typeof (item.data) == "number" || typeof (item.data) == "bigint" || typeof (item.data) == "boolean") {
// set fixed data title
item.dataTitles = [{
value: "Result",
label: "Result"
}]
item.data = [{ Result: item.data }];
}
else {
item.dataTitles = [];
item.data = [item.data];
var firstRow2 = item.data[0];
for (var property2 in firstRow2) {
if (Object.prototype.hasOwnProperty.call(firstRow2, property2)) {
item.dataTitles.push({
value: property2,
label: property2
})
}
}
}
}
});
this.rawProcessMsgs = param.rs
});
},
reformMsgs(msgs) {
var normalizedMsgs = [];
msgs.forEach(msg => {
if (Array.isArray(msg.data) || typeof (msg.data) == "string" || typeof (msg.data) == "number" || typeof (msg.data) == "bigint" || typeof (msg.data) == "boolean") {
normalizedMsgs.push(msg);
}
else {
if (this.isMixed(msg.data)) {
if (msg.message == '业绩与模板相匹配') {
var template = msg.data.template;
var newMsg = {
message: `业绩与模板相匹配:basicTemplateId=${template.basicId},templateCode=${template.paymentCode} subTemplateId=${template.subTemplateId}` ,
data:[msg.data.performance],
component:msg.component
}
normalizedMsgs.push(newMsg);
}
else if (msg.message == '业绩与模板不匹配') {
var subTemplates = msg.data.template.subTemplates;
var templateMsg = {
message:`业绩与模板不匹配: basicTemplateId=${msg.data.template.basicId}`,
data:subTemplates,
component:msg.component
};
normalizedMsgs.push(templateMsg);
var perfMsg = {
message:`未匹配业绩`,
data:msg.data.performance,
component:msg.component
}
normalizedMsgs.push(perfMsg);
} else {
normalizedMsgs.push(msg)
}
}
else {
normalizedMsgs.push(msg);
}
}
});
},
isMixed(data) {
if (data.performance != null && data.performance != undefined && data.template != null && data.template != undefined)
return true;
return false;
}
},
};
</script>
<style scoped>
</style>

View File

@ -1,4 +1,9 @@
import { createApp } from 'vue'
import App from './App.vue'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
createApp(App).mount('#app')
const app = createApp(App);
app.use(ElementPlus);
app.mount('#app');

18
src/preload.js Normal file
View File

@ -0,0 +1,18 @@
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
if (validChannels.includes(channel)) {
ipcRenderer.send(channel, data)
}
},
receive: (channel, func) => {
let validChannels = ['get-result'] // <-- 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))
}
}
})

View File

@ -1,4 +1,8 @@
const { defineConfig } = require('@vue/cli-service')
module.exports = defineConfig({
transpileDependencies: true
})
module.exports = {
transpileDependencies: true,
pluginOptions: {
electronBuilder: {
preload: 'src/preload.js'
}
}
}

4024
yarn.lock

File diff suppressed because it is too large Load Diff