Skip to content

Commit 40a3e1d

Browse files
committed
init flexsearch
1 parent 4226757 commit 40a3e1d

File tree

8 files changed

+188
-14
lines changed

8 files changed

+188
-14
lines changed

package-lock.json

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

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"electron-log": "^4.3.0",
1818
"electron-pdf-window": "^1.0.12",
1919
"element-ui": "^2.4.5",
20+
"flexsearch": "^0.6.32",
2021
"mysql": "^2.18.1",
2122
"sqlite3": "^5.0.0",
2223
"typeorm": "^0.2.29",

src/App.vue

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,44 @@
11
<template>
22
<div id="app">
3-
<router-view></router-view>
3+
<el-menu
4+
:default-active="activeIndex"
5+
class="el-menu-demo"
6+
mode="horizontal"
7+
@select="handleSelect"
8+
>
9+
<el-menu-item index="1">Table</el-menu-item>
10+
<el-menu-item index="2">SearchBuild</el-menu-item>
11+
12+
</el-menu>
13+
<router-view></router-view>
414
</div>
515
</template>
616

717
<script>
8-
918
export default {
10-
name: 'app',
11-
}
19+
name: "app",
20+
data(){
21+
return {
22+
activeIndex:'',
23+
24+
}
25+
},
26+
methods:{
27+
handleSelect(val){
28+
console.log(val)
29+
if(val=='1'){
30+
this.$router.push('/')
31+
}else{
32+
this.$router.push('/searchBuild')
33+
}
34+
}
35+
}
36+
};
1237
</script>
1338

1439
<style>
1540
#app {
16-
font-family: "Helvetica Neue",Helvetica,"PingFang SC","Hiragino Sans GB","Microsoft YaHei","微软雅黑",Arial,sans-serif;
41+
font-family: "Helvetica Neue", Helvetica, "PingFang SC", "Hiragino Sans GB",
42+
"Microsoft YaHei", "微软雅黑", Arial, sans-serif;
1743
}
1844
</style>

src/components/buildSearch.vue

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
<template>
2+
<div>
3+
<el-pagination
4+
layout="prev, pager, next"
5+
:total="pageTotalNum * 10"
6+
:current-page.sync="pageNum"
7+
@current-change="handleCurrentChange"
8+
background
9+
>
10+
</el-pagination>
11+
{{rightCnt}}/{{totalCnt}}
12+
13+
</div>
14+
</template>
15+
16+
<script>
17+
import { ipcRenderer } from "electron";
18+
import products from "./products.js";
19+
import flexSearch from 'flexsearch';
20+
export default {
21+
data() {
22+
return {
23+
index:'',
24+
db: "jlc",
25+
table: "cap",
26+
type: "贴片电容",
27+
rightCnt:0,
28+
totalCnt: 0,
29+
pageNum: 1,
30+
eachCnt: 500,
31+
loading: true,
32+
productValue: ["cap", "贴片电容"],
33+
productList: products,
34+
};
35+
},
36+
computed: {
37+
pageTotalNum: function () {
38+
return Math.ceil(this.totalCnt / this.eachCnt);
39+
},
40+
},
41+
mounted() {
42+
this.index=flexSearch.create()
43+
ipcRenderer.on("getDataRet", (evt, data) => {
44+
for(let i in data.data){
45+
let val=data.data[i]
46+
this.index.add(val.pn, val.value+val.footprint+val.desc+val.vendorPn+val.type);
47+
this.rightCnt+=1
48+
}
49+
this.pageNum+=1;
50+
if(this.pageNum<=this.pageTotalNum)
51+
this.handleCurrentChange(this.pageNum)
52+
else{
53+
console.log(this.index.export());
54+
}
55+
});
56+
ipcRenderer.on("dbGetCountRet", (evt, data) => {
57+
this.totalCnt = data.count;
58+
ipcRenderer.send("getData", {
59+
db: this.db,
60+
column: this.table,
61+
start: 0,
62+
end: this.eachCnt,
63+
where: {
64+
type_: this.type,
65+
},
66+
});
67+
});
68+
this.loading = true;
69+
ipcRenderer.send("dbGetCount", {
70+
db: this.db,
71+
column: this.table,
72+
option: `type_="${this.type}"`,
73+
});
74+
// ipcRenderer.send("getData",{db:'jlc',column:'cap',start:0,end:30});
75+
},
76+
destroyed() {
77+
ipcRenderer.removeAllListeners("getDataRet");
78+
ipcRenderer.removeAllListeners("dbGetCountRet");
79+
80+
},
81+
methods: {
82+
productChange(val) {
83+
this.pageNum = 1;
84+
this.table = val[0];
85+
this.type = val[1];
86+
this.loading = true;
87+
ipcRenderer.send("dbGetCount", {
88+
db: this.db,
89+
column: this.table,
90+
option: `type_="${this.type}"`,
91+
});
92+
},
93+
handleCurrentChange(val) {
94+
this.loading = true;
95+
ipcRenderer.send("getData", {
96+
db: this.db,
97+
column: this.table,
98+
start: (val - 1) * this.eachCnt,
99+
end: val * this.eachCnt,
100+
where: {
101+
type_: this.type,
102+
},
103+
});
104+
},
105+
},
106+
};
107+
</script>
108+
109+
<!-- Add "scoped" attribute to limit CSS to this component only -->
110+
<style scoped>
111+
.page {
112+
position: fixed;
113+
bottom: 50px;
114+
left: 50%;
115+
transform: translate(-50%, -50%);
116+
z-index: 1000;
117+
opacity: 0.5;
118+
}
119+
.page:hover {
120+
position: fixed;
121+
bottom: 50px;
122+
left: 50%;
123+
transform: translate(-50%, -50%);
124+
z-index: 1000;
125+
opacity: 1;
126+
}
127+
.table{
128+
overflow-y: scroll;
129+
height: 200px;
130+
}
131+
</style>

src/components/table.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ export default {
175175
db: this.db,
176176
column: this.table,
177177
start: 0,
178-
end: 30,
178+
end: this.eachCnt,
179179
where: {
180180
type_: this.type,
181181
},

src/router/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ const routes = [
1111
component: Home
1212
},
1313
{
14-
path: '/about',
15-
name: 'About',
14+
path: '/searchBuild',
15+
name: 'SearchBuild',
1616
// route level code-splitting
1717
// this generates a separate chunk (about.[hash].js) for this route
1818
// which is lazy-loaded when the route is visited.
19-
component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
19+
component: () => import(/* webpackChunkName: "about" */ '../views/SearchBuild.vue')
2020
}
2121
]
2222

src/views/About.vue

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/views/SearchBuild.vue

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<template>
2+
<div class="home">
3+
<BuildSearch />
4+
</div>
5+
</template>
6+
7+
<script>
8+
// @ is an alias to /src
9+
import BuildSearch from "@/components/buildSearch.vue";
10+
11+
export default {
12+
components: {
13+
BuildSearch,
14+
},
15+
};
16+
</script>

0 commit comments

Comments
 (0)