Skip to content

Commit bd185c3

Browse files
feature: 新增 MockInput 组件,用于部分列表配置页面,目的是为了SearchBar能够搜索到输入框中的内容。
1 parent aaf6ca8 commit bd185c3

File tree

11 files changed

+191
-66
lines changed

11 files changed

+191
-66
lines changed

packages/gui/src/view/App.vue

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
<script>
22
import { ipcRenderer } from 'electron'
3-
import { SearchBar } from 'search-bar-vue2'
43
import createMenus from '@/view/router/menu'
54
import zhCN from 'ant-design-vue/lib/locale-provider/zh_CN'
65
import { colorTheme } from './composables/theme'
76
87
export default {
98
name: 'App',
10-
components: {
11-
SearchBar,
12-
},
139
data () {
1410
return {
1511
locale: zhCN,

packages/gui/src/view/components/container.vue

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ export default {
2323
<style lang="scss">
2424
.ds-container {
2525
height: 100%;
26-
background: #fff;
26+
background-color: #fff;
2727
display: flex;
2828
position: relative;
2929
3030
.body-wrapper {
3131
position: absolute;
32-
top: 0px;
33-
right: 0px;
34-
bottom: 0px;
35-
left: 0px;
32+
top: 0;
33+
right: 0;
34+
bottom: 0;
35+
left: 0;
3636
display: flex;
3737
flex-direction: column;
3838
overflow: hidden;
@@ -41,7 +41,7 @@ export default {
4141
.container-header {
4242
padding: 15px;
4343
border-bottom: 1px solid #eee;
44-
background: #fff;
44+
background-color: #fff;
4545
height: 60px;
4646
display: flex;
4747
align-items: center;
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<!--
2+
组件:模拟输入框(当前为简易版本,只添加了value属性)
3+
作用:全文检索(SearchBar)组件,无法检索 `<a-input/>` 的内容,所以使用 `<span contenteditable="true"></span>` 代替。
4+
-->
5+
<script>
6+
export default {
7+
name: 'MockInput',
8+
props: {
9+
value: {
10+
type: String,
11+
default: '',
12+
required: false,
13+
},
14+
},
15+
methods: {
16+
onKeydown (event) {
17+
// 不允许输入换行符
18+
if (event.key === 'Enter' || event.keyCode === 13) {
19+
event.preventDefault()
20+
}
21+
},
22+
onChange () {
23+
if (this.$refs.input.textContent !== this.value) {
24+
this.$emit('input', this.$refs.input.textContent)
25+
}
26+
},
27+
},
28+
}
29+
</script>
30+
31+
<template>
32+
<span ref="input" class="fake-input" contenteditable="true" :title="value" @focus="onChange" @blur="onChange" @keydown="onKeydown" v-html="value" />
33+
</template>
34+
35+
<style lang="scss">
36+
.fake-input {
37+
/* 鼠标样式 */
38+
cursor: text;
39+
40+
/* 内容不换行 */
41+
overflow-y: auto;
42+
/*white-space: nowrap;
43+
vertical-align: middle;*/
44+
45+
/* 复制 ant-input 样式 */
46+
box-sizing: border-box;
47+
margin: 0;
48+
padding: 4px 11px;
49+
font-variant: tabular-nums;
50+
list-style: none;
51+
font-feature-settings: 'tnum';
52+
position: relative;
53+
display: inline-block;
54+
width: 100%;
55+
height: 32px;
56+
color: rgba(0, 0, 0, 0.65);
57+
font-size: 14px;
58+
line-height: 1.5;
59+
background-color: #fff;
60+
background-image: none;
61+
border: 1px solid #d9d9d9;
62+
border-radius: 4px;
63+
transition: all 0.3s;
64+
}
65+
</style>

packages/gui/src/view/mixins/plugin.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,5 +142,17 @@ export default {
142142
const dir = await this.$api.info.getLogDir()
143143
this.$api.ipc.openPath(dir)
144144
},
145+
handleHostname (hostname) {
146+
if (this.isNotHostname(hostname)) {
147+
return ''
148+
}
149+
150+
// 移除所有空白符
151+
return hostname.replaceAll(/\s+/g, '')
152+
},
153+
isNotHostname (hostname) {
154+
// 暂时只判断数字
155+
return !hostname || /^[\d\s]+$/.test(hostname)
156+
},
145157
},
146158
}

packages/gui/src/view/pages/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ export default {
319319
</div>
320320
<div :span="12">
321321
<a-form style="margin-top:20px" :label-col="{ span: 15 }" :wrapper-col="{ span: 9 }">
322-
<a-form-item v-for=" (item, key) in switchBtns" :key="key" :label="item.label">
322+
<a-form-item v-for="(item, key) in switchBtns" :key="key" :label="item.label">
323323
<a-tooltip placement="topLeft">
324324
<a-switch
325325
style="margin-left:10px" :loading="item.loading" :checked="item.status()" default-checked

packages/gui/src/view/pages/plugin/git.vue

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<script>
22
import Plugin from '../../mixins/plugin'
3+
import MockInput from '@/view/components/mock-input.vue'
34
45
export default {
56
name: 'Git',
7+
components: { MockInput },
68
mixins: [Plugin],
79
data () {
810
return {
@@ -45,7 +47,7 @@ export default {
4547
}
4648
},
4749
addNoProxyUrl () {
48-
this.noProxyUrls.unshift({ key: '', value: true })
50+
this.noProxyUrls.unshift({ key: '' })
4951
},
5052
delNoProxyUrl (item, index) {
5153
this.noProxyUrls.splice(index, 1)
@@ -54,7 +56,10 @@ export default {
5456
const noProxyUrls = {}
5557
for (const item of this.noProxyUrls) {
5658
if (item.key) {
57-
noProxyUrls[item.key] = item.value
59+
const hostname = this.handleHostname(item.key)
60+
if (hostname) {
61+
noProxyUrls[hostname] = true
62+
}
5863
}
5964
}
6065
this.config.plugin.git.setting.noProxyUrls = noProxyUrls
@@ -103,7 +108,7 @@ export default {
103108
</a-row>
104109
<a-row v-for="(item, index) of noProxyUrls" :key="index" :gutter="10">
105110
<a-col :span="22">
106-
<a-input v-model="item.key" :disabled="item.value === false" />
111+
<MockInput v-model="item.key" />
107112
</a-col>
108113
<a-col :span="2">
109114
<a-button type="danger" icon="minus" @click="delNoProxyUrl(item, index)" />

packages/gui/src/view/pages/plugin/overwall.vue

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<script>
22
import Plugin from '../../mixins/plugin'
3+
import MockInput from '@/view/components/mock-input.vue'
34
45
export default {
56
name: 'Overwall',
7+
components: { MockInput },
68
mixins: [Plugin],
79
data () {
810
return {
@@ -40,8 +42,8 @@ export default {
4042
this.initServer()
4143
},
4244
async applyBefore () {
43-
this.saveTarget()
44-
this.saveServer()
45+
this.submitTarget()
46+
this.submitServer()
4547
},
4648
initTarget () {
4749
this.targets = []
@@ -60,11 +62,14 @@ export default {
6062
deleteTarget (item, index) {
6163
this.targets.splice(index, 1)
6264
},
63-
saveTarget () {
65+
submitTarget () {
6466
const map = {}
6567
for (const item of this.targets) {
6668
if (item.key) {
67-
map[item.key] = item.value === 'true'
69+
const hostname = this.handleHostname(item.key)
70+
if (hostname) {
71+
map[hostname] = (item.value === 'true')
72+
}
6873
}
6974
}
7075
this.config.plugin.overwall.targets = map
@@ -90,11 +95,14 @@ export default {
9095
addServer () {
9196
this.servers.unshift({ key: '', value: { type: 'path' } })
9297
},
93-
saveServer () {
98+
submitServer () {
9499
const map = {}
95100
for (const item of this.servers) {
96101
if (item.key) {
97-
map[item.key] = item.value
102+
const hostname = this.handleHostname(item.key)
103+
if (hostname) {
104+
map[hostname] = item.value
105+
}
98106
}
99107
}
100108
this.config.plugin.overwall.server = map
@@ -161,7 +169,7 @@ export default {
161169
</a-row>
162170
<a-row v-for="(item, index) of targets" :key="index" :gutter="10">
163171
<a-col :span="18">
164-
<a-input v-model="item.key" />
172+
<MockInput v-model="item.key" />
165173
</a-col>
166174
<a-col :span="4">
167175
<a-select v-model="item.value" style="width:100%">

packages/gui/src/view/pages/proxy.vue

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<script>
22
import Plugin from '../mixins/plugin'
3+
import MockInput from '@/view/components/mock-input.vue'
34
45
export default {
56
name: 'Proxy',
7+
components: { MockInput },
68
mixins: [Plugin],
79
data () {
810
return {
@@ -68,7 +70,10 @@ export default {
6870
const excludeIpList = {}
6971
for (const item of this.excludeIpList) {
7072
if (item.key) {
71-
excludeIpList[item.key] = item.value === 'true'
73+
const hostname = this.handleHostname(item.key)
74+
if (hostname) {
75+
excludeIpList[hostname] = (item.value === 'true')
76+
}
7277
}
7378
}
7479
this.config.proxy.excludeIpList = excludeIpList
@@ -163,7 +168,7 @@ export default {
163168
</a-row>
164169
<a-row v-for="(item, index) of excludeIpList" :key="index" :gutter="10">
165170
<a-col :span="17">
166-
<a-input v-model="item.key" />
171+
<MockInput v-model="item.key" />
167172
</a-col>
168173
<a-col :span="5">
169174
<a-select v-model="item.value" style="width:100%">

packages/gui/src/view/pages/server.vue

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
import _ from 'lodash'
33
import VueJsonEditor from 'vue-json-editor-fix-cn'
44
import Plugin from '../mixins/plugin'
5+
import MockInput from '@/view/components/mock-input.vue'
56
67
export default {
78
name: 'Server',
89
components: {
910
VueJsonEditor,
11+
MockInput,
1012
},
1113
mixins: [Plugin],
1214
data () {
@@ -68,8 +70,9 @@ export default {
6870
}
6971
},
7072
async applyBefore () {
71-
this.submitDnsMapping()
73+
this.submitDnsMappings()
7274
this.submitWhiteList()
75+
this.delEmptySpeedHostname()
7376
},
7477
async applyAfter () {
7578
if (this.status.server.enabled) {
@@ -87,11 +90,14 @@ export default {
8790
})
8891
}
8992
},
90-
submitDnsMapping () {
93+
submitDnsMappings () {
9194
const dnsMapping = {}
9295
for (const item of this.dnsMappings) {
9396
if (item.key) {
94-
dnsMapping[item.key] = item.value
97+
const hostname = this.handleHostname(item.key)
98+
if (hostname) {
99+
dnsMapping[hostname] = item.value
100+
}
95101
}
96102
}
97103
this.config.server.dns.mapping = dnsMapping
@@ -127,7 +133,10 @@ export default {
127133
const whiteList = {}
128134
for (const item of this.whiteList) {
129135
if (item.key) {
130-
whiteList[item.key] = item.value === 'true'
136+
const hostname = this.handleHostname(item.key)
137+
if (hostname) {
138+
whiteList[hostname] = (item.value === 'true')
139+
}
131140
}
132141
}
133142
this.config.server.whiteList = whiteList
@@ -141,6 +150,14 @@ export default {
141150
delSpeedHostname (item, index) {
142151
this.getSpeedTestConfig().hostnameList.splice(index, 1)
143152
},
153+
delEmptySpeedHostname () {
154+
for (let i = this.getSpeedTestConfig().hostnameList.length - 1; i >= 0; i--) {
155+
const hostname = this.handleHostname(this.getSpeedTestConfig().hostnameList[i])
156+
if (hostname) {
157+
this.getSpeedTestConfig().hostnameList.splice(i, 1)
158+
}
159+
}
160+
},
144161
reSpeedTest () {
145162
this.$api.server.reSpeedTest()
146163
},
@@ -305,7 +322,7 @@ export default {
305322
</a-row>
306323
<a-row v-for="(item, index) of whiteList" :key="index" :gutter="10" style="margin-top: 5px">
307324
<a-col :span="16">
308-
<a-input v-model="item.key" />
325+
<MockInput v-model="item.key" />
309326
</a-col>
310327
<a-col :span="5">
311328
<a-select v-model="item.value" style="width:100%">
@@ -360,7 +377,7 @@ export default {
360377
</a-row>
361378
<a-row v-for="(item, index) of dnsMappings" :key="index" :gutter="10" style="margin-top: 5px">
362379
<a-col :span="15">
363-
<a-input v-model="item.key" :disabled="item.value === false" />
380+
<MockInput v-model="item.key" />
364381
</a-col>
365382
<a-col :span="6">
366383
<a-select v-model="item.value" :disabled="item.value === false" style="width: 100%">
@@ -407,12 +424,9 @@ export default {
407424
<a-button style="margin-left:10px" type="primary" icon="plus" @click="addSpeedHostname()" />
408425
</a-col>
409426
</a-row>
410-
<a-row
411-
v-for="(item, index) of getSpeedTestConfig().hostnameList" :key="index" :gutter="10"
412-
style="margin-top: 5px"
413-
>
427+
<a-row v-for="(item, index) of getSpeedTestConfig().hostnameList" :key="index" :gutter="10" style="margin-top: 5px">
414428
<a-col :span="21">
415-
<a-input v-model="getSpeedTestConfig().hostnameList[index]" />
429+
<MockInput v-model="getSpeedTestConfig().hostnameList[index]" />
416430
</a-col>
417431
<a-col :span="2">
418432
<a-button style="margin-left:10px" type="danger" icon="minus" @click="delSpeedHostname(item, index)" />
@@ -493,5 +507,8 @@ export default {
493507
overflow-y: auto;
494508
overflow-x: hidden;
495509
}
510+
.ant-input-group-addon:first-child {
511+
width: 50px;
512+
}
496513
}
497514
</style>

0 commit comments

Comments
 (0)