Skip to content

Commit b36d187

Browse files
committed
init typeorm
1 parent 74997c4 commit b36d187

File tree

9 files changed

+1008
-241
lines changed

9 files changed

+1008
-241
lines changed

package-lock.json

Lines changed: 745 additions & 222 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
"main": "background.js",
1515
"dependencies": {
1616
"core-js": "^3.6.5",
17+
"electron-log": "^4.3.0",
18+
"element-ui": "^2.4.5",
19+
"mysql": "^2.18.1",
20+
"sqlite3": "^5.0.0",
21+
"typeorm": "^0.2.29",
1722
"vue": "^2.6.11",
1823
"vue-router": "^3.2.0",
1924
"vuex": "^3.4.0"
@@ -30,6 +35,7 @@
3035
"eslint": "^6.7.2",
3136
"eslint-plugin-vue": "^6.2.2",
3237
"vue-cli-plugin-electron-builder": "~2.0.0-rc.5",
38+
"vue-cli-plugin-element": "~1.0.1",
3339
"vue-template-compiler": "^2.6.11"
3440
}
3541
}

src/App.vue

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,36 @@
11
<template>
22
<div id="app">
3-
<div id="nav">
4-
<router-link to="/">Home</router-link> |
5-
<router-link to="/about">About</router-link>
3+
<img src="./assets/logo.png">
4+
<div>
5+
<p>
6+
If Element is successfully added to this project, you'll see an
7+
<code v-text="'<el-button>'"></code>
8+
below
9+
</p>
10+
<el-button>el-button</el-button>
611
</div>
7-
<router-view/>
12+
<HelloWorld msg="Welcome to Your Vue.js App"/>
813
</div>
914
</template>
1015

16+
<script>
17+
import HelloWorld from './components/HelloWorld.vue'
18+
19+
export default {
20+
name: 'app',
21+
components: {
22+
HelloWorld
23+
}
24+
}
25+
</script>
26+
1127
<style>
1228
#app {
13-
font-family: Avenir, Helvetica, Arial, sans-serif;
29+
font-family: 'Avenir', Helvetica, Arial, sans-serif;
1430
-webkit-font-smoothing: antialiased;
1531
-moz-osx-font-smoothing: grayscale;
1632
text-align: center;
1733
color: #2c3e50;
18-
}
19-
20-
#nav {
21-
padding: 30px;
22-
}
23-
24-
#nav a {
25-
font-weight: bold;
26-
color: #2c3e50;
27-
}
28-
29-
#nav a.router-link-exact-active {
30-
color: #42b983;
34+
margin-top: 60px;
3135
}
3236
</style>

src/background.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { app, protocol, BrowserWindow } from 'electron'
44
import { createProtocol } from 'vue-cli-plugin-electron-builder/lib'
55
import installExtension, { VUEJS_DEVTOOLS } from 'electron-devtools-installer'
6+
import db from './db/db'
67
const isDevelopment = process.env.NODE_ENV !== 'production'
78

89
// Scheme must be registered before the app is ready
@@ -21,7 +22,8 @@ async function createWindow() {
2122
nodeIntegration: process.env.ELECTRON_NODE_INTEGRATION
2223
}
2324
})
24-
25+
const database= new db(win)
26+
database.connect(false)
2527
if (process.env.WEBPACK_DEV_SERVER_URL) {
2628
// Load the url of the dev server if in development mode
2729
await win.loadURL(process.env.WEBPACK_DEV_SERVER_URL)

src/db/db.js

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
'use strict';
2+
import {createConnections,getConnection,getRepository} from "typeorm";
3+
import { Cap } from './entity/jlc/Cap';
4+
import path from 'path';
5+
import {app,ipcMain} from 'electron';
6+
import log from 'electron-log';
7+
8+
export default class Db {
9+
constructor(win) {
10+
this.win = win;
11+
this.connected = false;
12+
}
13+
14+
parseJlc(val,g) {
15+
16+
var a = {
17+
pn: '',
18+
vendor: '',
19+
vendorPn: '',
20+
vendorUrl: '',
21+
value: '',
22+
prices: [],
23+
imgs: [],
24+
symbolUrl: '',
25+
footprint: '',
26+
fpUrl: '',
27+
desc: '',
28+
datasheet: '',
29+
g: 'cap',
30+
type: '',
31+
}
32+
if (val != null) {
33+
let svgs = [];
34+
if (val.svgs != null)
35+
svgs = val.svgs.split(',');
36+
a.g = g
37+
a.pn = val.pn;
38+
if (val.imgs != null)
39+
a.imgs = val.imgs.split(',');
40+
a.vendorPn = val.jlcpn;
41+
a.vendorUrl = val.jlcurl;
42+
a.vendor = 'jlc';
43+
a.desc = val.desc;
44+
a.footprint = val.footprint;
45+
if (svgs.length > 0) {
46+
a.symbolUrl = svgs[0];
47+
}
48+
if (svgs.length > 1) {
49+
a.fpUrl = svgs[1];
50+
}
51+
if (val.datasheet != null)
52+
a.datasheet = val.datasheet;
53+
a.value = val.value;
54+
if (val.type_ != null)
55+
a.type = val.type_;
56+
if (val.prices != null) {
57+
const prices = val.prices.split(',');
58+
a.prices=[]
59+
for (const i in prices) {
60+
const m = prices[i].split(':');
61+
a.prices.push({
62+
num: m[0],
63+
price: m[1]
64+
});
65+
}
66+
}
67+
}
68+
log.info(a)
69+
this.win.webContents.send('data',a)
70+
return a;
71+
72+
73+
74+
}
75+
connect(sync) {
76+
createConnections([{
77+
name: "jlc",
78+
type: "mysql",
79+
host: "www.whyengineer.com",
80+
port: 3306,
81+
username: "jlc",
82+
password: "71451085a",
83+
database: "jlc",
84+
entities: [Cap],
85+
logging: true,
86+
synchronize: sync
87+
}, {
88+
name: "bom",
89+
type: "sqlite",
90+
database: path.join(app.getPath('userData'), 'db', 'bom.sqlite'),
91+
entities: [],
92+
logging: true,
93+
synchronize: sync
94+
}]).then(() => {
95+
log.info("connect database ok")
96+
this.connected = true;
97+
this.jlc = getConnection('jlc');
98+
this.bom = getConnection('bom');
99+
// ipcMain.on('getData',()=>{
100+
// this.jlc.manager.findOne(Cap).then((val) => {
101+
// this.parseJlc(val, 'cap')
102+
// })
103+
// })
104+
this.jlc.manager.findOne(Cap).then((val) => {
105+
this.parseJlc(val, 'cap')
106+
})
107+
108+
109+
}).catch((err) => {
110+
this.connected = false;
111+
log.error(err);
112+
})
113+
}
114+
115+
}

src/db/entity/jlc/Cap.js

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import {EntitySchema} from "typeorm";
2+
3+
export const Cap = new EntitySchema({
4+
name: "cap",
5+
columns: {
6+
pn: {
7+
primary: true,
8+
type: String,
9+
nullable: false
10+
},
11+
value: {
12+
type: String,
13+
nullable: false
14+
},
15+
footprint: {
16+
type: String,
17+
nullable: false
18+
},
19+
jlcpn: {
20+
type: String,
21+
nullable: false
22+
},
23+
jlcurl: {
24+
type: String,
25+
nullable: false
26+
},
27+
prices: {
28+
type: String,
29+
nullable: true
30+
},
31+
imgs: {
32+
type: String,
33+
nullable: true
34+
},
35+
datasheet: {
36+
type: String,
37+
nullable: true
38+
},
39+
desc: {
40+
type: String,
41+
nullable: false
42+
},
43+
svgs: {
44+
type: String,
45+
nullable: true
46+
},
47+
type_: {
48+
type: String,
49+
nullable: true
50+
},
51+
},
52+
indices: [
53+
{
54+
name: "cap_value",
55+
unique: false,
56+
columns: [
57+
"value",
58+
]
59+
},
60+
{
61+
name: "cap_footprint",
62+
unique: false,
63+
columns: [
64+
"footprint",
65+
]
66+
},
67+
{
68+
name: "cap_jlcpn",
69+
unique: true,
70+
columns: [
71+
"jlcpn",
72+
]
73+
},
74+
{
75+
name: "cap_jlcurl",
76+
unique: true,
77+
columns: [
78+
"jlcurl",
79+
]
80+
},
81+
{
82+
name: "cap_type_",
83+
unique: false,
84+
columns: [
85+
"type_",
86+
]
87+
},
88+
],
89+
});

src/main.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Vue from 'vue'
22
import App from './App.vue'
33
import router from './router'
44
import store from './store'
5+
import './plugins/element.js'
56

67
Vue.config.productionTip = false
78

src/plugins/element.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import Vue from 'vue'
2+
import Element from 'element-ui'
3+
import 'element-ui/lib/theme-chalk/index.css'
4+
5+
Vue.use(Element)

vue.config.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
module.exports = {
2+
configureWebpack: {
3+
// Webpack configuration applied to web builds and the electron renderer process
4+
},
5+
pluginOptions: {
6+
electronBuilder: {
7+
nodeIntegration: true,
8+
chainWebpackMainProcess: (config) => {
9+
// Chain webpack config for electron main process only
10+
},
11+
chainWebpackRendererProcess: (config) => {
12+
// Chain webpack config for electron renderer process only (won't be applied to web builds)
13+
},
14+
mainProcessWatch: ['src/**/**.js'],
15+
// Provide a list of arguments that Electron will be launched with during "electron:serve",
16+
// which can be accessed from the main process (src/background.js).
17+
// Note that it is ignored when --debug flag is used with "electron:serve", as you must launch Electron yourself
18+
// Command line args (excluding --debug, --dashboard, and --headless) are passed to Electron as well
19+
mainProcessArgs: ['--arg-name', 'arg-value']
20+
}
21+
}
22+
}

0 commit comments

Comments
 (0)