Skip to content
This repository was archived by the owner on Jun 21, 2024. It is now read-only.

Commit 0bd5cfe

Browse files
committed
fix: 首页双击重复点击导致打开多个一样的
优化了首页,把搜索作为一个单独的组件
1 parent b0c2849 commit 0bd5cfe

File tree

4 files changed

+143
-117
lines changed

4 files changed

+143
-117
lines changed

README.md

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,25 @@
66
<img src="https://img.shields.io/badge/nedb-%5E1.8.0-orange"/>
77
</center>
88

9+
## 启动
10+
```
11+
yarn electron:serve
12+
```
13+
14+
## 打包
15+
```
16+
yarn electron:build
17+
```
18+
19+
## 教程
20+
【electron+vue3+ts实战便笺exe】一、搭建框架配置
21+
https://juejin.cn/post/6909723449246089224
22+
23+
【electron+vue3+ts实战便笺exe】二、electron+vue3开发内容
24+
https://juejin.cn/post/6909725365107687431
25+
26+
27+
928
![](https://p9-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/83e3a65a44524252af6adf0135270216~tplv-k3u1fbpfcp-watermark.image)
1029

1130
```
@@ -54,21 +73,4 @@ electron-notes
5473
- views 页面
5574
- App.vue
5675
- background.ts入口文件
57-
- main.ts vue入口文件
58-
59-
## 启动
60-
```
61-
yarn electron:serve
62-
```
63-
64-
## 打包
65-
```
66-
yarn electron:build
67-
```
68-
69-
## 教程
70-
【electron+vue3+ts实战便笺exe】一、搭建框架配置
71-
https://juejin.cn/post/6909723449246089224
72-
73-
【electron+vue3+ts实战便笺exe】二、electron+vue3开发内容
74-
https://juejin.cn/post/6909725365107687431
76+
- main.ts vue入口文件

src/router/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const routes: Array<RouteRecordRaw> = [
1111
{
1212
path: '/',
1313
name: 'index',
14-
component: () => import('../views/index.vue'),
14+
component: () => import('../views/index/index.vue'),
1515
meta: {
1616
title: 'I便笺'
1717
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<template>
2+
<div class="search-box">
3+
<div class="search flex-items">
4+
<div class="search-input flex1">
5+
<input v-model="searchWord" type="text" placeholder="搜索..." @input="searchDb" />
6+
</div>
7+
<button class="search-button" @click="searchDb">
8+
<i class="iconfont icon-search"></i>
9+
</button>
10+
</div>
11+
</div>
12+
</template>
13+
14+
<script lang="ts">
15+
import { defineComponent, ref } from 'vue';
16+
import inotedb from '@/inotedb';
17+
18+
export default defineComponent({
19+
setup(props, { emit }) {
20+
const toRegExp = (str: string) => {
21+
if (!str) return new RegExp('');
22+
const reg = '?!.\\|{}[]+-$^&*()';
23+
let regexp = '';
24+
for (const char of str) {
25+
if (reg.includes(char)) {
26+
if (char === '\\') {
27+
regexp += '\\/';
28+
continue;
29+
}
30+
regexp += `\\${char}`;
31+
} else {
32+
regexp += char;
33+
}
34+
}
35+
return new RegExp(regexp);
36+
};
37+
38+
const searchWord = ref('');
39+
const searchDb = () => {
40+
inotedb._db.find(
41+
{
42+
content: {
43+
$regex: toRegExp(searchWord.value)
44+
}
45+
},
46+
(err: Error | null, doc: DBNotes[]) => {
47+
emit('search', doc);
48+
}
49+
);
50+
};
51+
return {
52+
searchWord,
53+
searchDb
54+
};
55+
}
56+
});
57+
</script>
58+
59+
<style lang="less" scoped>
60+
.search-box {
61+
padding: 0 12px;
62+
padding-top: 10px;
63+
box-sizing: border-box;
64+
}
65+
.search {
66+
background-color: @background-sub-color;
67+
height: 34px;
68+
opacity: 0.9;
69+
.search-input {
70+
input {
71+
display: block;
72+
width: 100%;
73+
height: 100%;
74+
border: none;
75+
background-color: transparent;
76+
font-size: 14px;
77+
padding: 0 18px;
78+
}
79+
}
80+
.search-button {
81+
display: block;
82+
border: none;
83+
width: 34px;
84+
height: 100%;
85+
padding: 0;
86+
.iconfont {
87+
font-size: 20px;
88+
}
89+
&:hover {
90+
background-color: #e0e0e0;
91+
}
92+
}
93+
&:hover {
94+
opacity: 1;
95+
}
96+
&:active {
97+
opacity: 1;
98+
}
99+
}
100+
</style>

src/views/index.vue renamed to src/views/index/index.vue

Lines changed: 22 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,7 @@
11
<template>
22
<main class="page-index">
3-
<div class="search-box">
4-
<div class="search flex-items" @click="aa">
5-
<div class="search-input flex1">
6-
<input v-model="searchWord" type="text" placeholder="搜索..." @input="searchDb" />
7-
</div>
8-
<button class="search-button">
9-
<i class="iconfont icon-search"></i>
10-
</button>
11-
</div>
12-
</div>
3+
<Search @search="searchHandle" />
134
<section class="content-container" :class="fadein ? 'fadein' : ''">
14-
<!-- <button @click="getAll">getAllDBNotes</button> -->
155
<template v-if="emptyBlockState === 1">
166
<ul class="edit-list">
177
<template v-for="item in viewNotesList" :key="item.uid">
@@ -32,7 +22,7 @@
3222
<div class="index-empty-content">
3323
<div class="index-empty-content-text" style="margin-top: 0;margin-bottom: 40px;">双击此处,或</div>
3424
<div class="index-empty-content-img">
35-
<img src="../assets/empty-content.svg" />
25+
<img src="../../assets/empty-content.svg" />
3626
</div>
3727
<div class="index-empty-content-text">点击上方“+”按钮创建</div>
3828
<div class="index-empty-content-text" style="margin-top: 4px;">新的便笺内容</div>
@@ -59,6 +49,7 @@ import dayjs from 'dayjs';
5949
6050
import CreateRightClick from '@/components/rightClick';
6151
import MessageBox from '@/components/messageBox.vue';
52+
import Search from './components/search.vue';
6253
6354
import { browserWindowOption } from '@/config';
6455
import inotedb from '@/inotedb';
@@ -67,7 +58,8 @@ import { exeConfig } from '@/store/exeConfig.state';
6758
6859
export default defineComponent({
6960
components: {
70-
MessageBox
61+
MessageBox,
62+
Search
7163
},
7264
setup() {
7365
const deleteMessageShow = ref(false);
@@ -135,7 +127,15 @@ export default defineComponent({
135127
136128
const bwsWinOption = browserWindowOption('editor');
137129
const openEditorWindow = (uid: string) => {
138-
createBrowserWindow(bwsWinOption, `/editor?uid=${uid}`);
130+
let countFlag = false;
131+
ipcRenderer.send(`${uid}_toOpen`);
132+
ipcRenderer.on(`get_${uid}_toOpen`, () => {
133+
countFlag = true;
134+
return;
135+
});
136+
setTimeout(() => {
137+
if (!countFlag) createBrowserWindow(bwsWinOption, `/editor?uid=${uid}`);
138+
}, 100);
139139
};
140140
141141
const contextMenu = (event: MouseEvent, uid: string) => {
@@ -145,15 +145,7 @@ export default defineComponent({
145145
once: true,
146146
iconName: ['iconfont', 'icon-newopen'],
147147
handler: () => {
148-
let countFlag = false;
149-
ipcRenderer.send(`${uid}_toOpen`);
150-
ipcRenderer.on(`get_${uid}_toOpen`, () => {
151-
countFlag = true;
152-
return;
153-
});
154-
setTimeout(() => {
155-
if (!countFlag) openEditorWindow(uid);
156-
}, 100);
148+
openEditorWindow(uid);
157149
}
158150
},
159151
{
@@ -243,38 +235,6 @@ export default defineComponent({
243235
createBrowserWindow(editorWinOptions, '/editor', false);
244236
};
245237
246-
const toRegExp = (str: string) => {
247-
if (!str) return new RegExp('');
248-
const reg = '?!.\\|{}[]+-$^&*()';
249-
let regexp = '';
250-
for (const char of str) {
251-
if (reg.includes(char)) {
252-
if (char === '\\') {
253-
regexp += '\\/';
254-
continue;
255-
}
256-
regexp += `\\${char}`;
257-
} else {
258-
regexp += char;
259-
}
260-
}
261-
return new RegExp(regexp);
262-
};
263-
264-
const searchWord = ref('');
265-
const searchDb = () => {
266-
inotedb._db.find(
267-
{
268-
content: {
269-
$regex: toRegExp(searchWord.value)
270-
}
271-
},
272-
(err: Error | null, doc: any) => {
273-
console.log(doc);
274-
}
275-
);
276-
};
277-
278238
const onConfirm = () => {
279239
if (deleteTipChecked?.value) {
280240
exeConfig.switchStatus.deleteTip = false;
@@ -296,6 +256,12 @@ export default defineComponent({
296256
});
297257
};
298258
259+
const searchHandle = (data: DBNotes[]) => {
260+
if (data.length) {
261+
viewNotesList.value = data;
262+
}
263+
};
264+
299265
return {
300266
fadein,
301267
viewNotesList,
@@ -309,8 +275,7 @@ export default defineComponent({
309275
onConfirm,
310276
exeConfig,
311277
deleteTipChecked,
312-
searchWord,
313-
searchDb
278+
searchHandle
314279
};
315280
}
316281
});
@@ -322,47 +287,6 @@ export default defineComponent({
322287
background-color: @white-color;
323288
}
324289
325-
.search-box {
326-
padding: 0 12px;
327-
padding-top: 10px;
328-
box-sizing: border-box;
329-
}
330-
.search {
331-
background-color: @background-sub-color;
332-
height: 34px;
333-
opacity: 0.9;
334-
.search-input {
335-
input {
336-
display: block;
337-
width: 100%;
338-
height: 100%;
339-
border: none;
340-
background-color: transparent;
341-
font-size: 14px;
342-
padding: 0 18px;
343-
}
344-
}
345-
.search-button {
346-
display: block;
347-
border: none;
348-
width: 34px;
349-
height: 100%;
350-
padding: 0;
351-
.iconfont {
352-
font-size: 20px;
353-
}
354-
&:hover {
355-
background-color: #e0e0e0;
356-
}
357-
}
358-
&:hover {
359-
opacity: 1;
360-
}
361-
&:active {
362-
opacity: 1;
363-
}
364-
}
365-
366290
// 减去搜索和外边距高度
367291
.content-container {
368292
height: calc(100% - 58px);

0 commit comments

Comments
 (0)