Skip to content

Commit 7519956

Browse files
feature: 新增 MockInput 组件,目的是为了 内容搜索功能 能够搜索到输入框中的内容。
1 parent 67c7e39 commit 7519956

File tree

6 files changed

+93
-10
lines changed

6 files changed

+93
-10
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+
white-space: nowrap;
42+
overflow: hidden;
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+
.fine-tuning .fake-input {
66+
margin-top: -2px;
67+
}
68+
</style>

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

Lines changed: 4 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: 'Git',
7+
components: { MockInput },
68
mixins: [Plugin],
79
data () {
810
return {
@@ -107,8 +109,8 @@ export default {
107109
</a-col>
108110
</a-row>
109111
<a-row v-for="(item, index) of noProxyUrls" :key="index" :gutter="10">
110-
<a-col :span="22">
111-
<a-input v-model="item.key" />
112+
<a-col :span="22" class="fine-tuning">
113+
<MockInput v-model="item.key" />
112114
</a-col>
113115
<a-col :span="2">
114116
<a-button type="danger" icon="minus" @click="delNoProxyUrl(item, index)" />

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

Lines changed: 4 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: 'Overwall',
7+
components: { MockInput },
68
mixins: [Plugin],
79
data () {
810
return {
@@ -168,8 +170,8 @@ export default {
168170
</a-col>
169171
</a-row>
170172
<a-row v-for="(item, index) of targets" :key="index" :gutter="10">
171-
<a-col :span="18">
172-
<a-input v-model="item.key" />
173+
<a-col :span="18" class="fine-tuning">
174+
<MockInput v-model="item.key" />
173175
</a-col>
174176
<a-col :span="4">
175177
<a-select v-model="item.value" style="width:100%">

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

Lines changed: 11 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 {
@@ -164,9 +166,9 @@ export default {
164166
<a-button type="primary" icon="plus" @click="addExcludeIp()" />
165167
</a-col>
166168
</a-row>
167-
<a-row v-for="(item, index) of excludeIpList" :key="index" :gutter="10">
169+
<a-row v-for="(item, index) of excludeIpList" :key="index" :gutter="10" class="fine-tuning">
168170
<a-col :span="17">
169-
<a-input v-model="item.key" />
171+
<MockInput v-model="item.key" />
170172
</a-col>
171173
<a-col :span="5">
172174
<a-select v-model="item.value" style="width:100%">
@@ -216,3 +218,10 @@ export default {
216218
</a-drawer>
217219
</ds-container>
218220
</template>
221+
222+
<style lang="scss">
223+
/*样式微调*/
224+
.fine-tuning .ant-btn-danger {
225+
margin-top: 3px;
226+
}
227+
</style>

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

Lines changed: 5 additions & 3 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 () {
@@ -316,7 +318,7 @@ export default {
316318
</a-row>
317319
<a-row v-for="(item, index) of whiteList" :key="index" :gutter="10" style="margin-top: 5px">
318320
<a-col :span="16">
319-
<a-input v-model="item.key" />
321+
<MockInput v-model="item.key" />
320322
</a-col>
321323
<a-col :span="5">
322324
<a-select v-model="item.value" style="width:100%">
@@ -374,7 +376,7 @@ export default {
374376
</a-row>
375377
<a-row v-for="(item, index) of dnsMappings" :key="index" :gutter="10" style="margin-top: 5px">
376378
<a-col :span="15">
377-
<a-input v-model="item.key" />
379+
<MockInput v-model="item.key" />
378380
</a-col>
379381
<a-col :span="6">
380382
<a-select v-model="item.value" :disabled="item.value === false" style="width: 100%">
@@ -422,7 +424,7 @@ export default {
422424
</a-row>
423425
<a-row v-for="(item, index) of getSpeedTestConfig().hostnameList" :key="index" :gutter="10" style="margin-top: 5px">
424426
<a-col :span="21">
425-
<a-input v-model="getSpeedTestConfig().hostnameList[index]" />
427+
<MockInput v-model="getSpeedTestConfig().hostnameList[index]" />
426428
</a-col>
427429
<a-col :span="2">
428430
<a-button style="margin-left:10px" type="danger" icon="minus" @click="delSpeedHostname(item, index)" />

packages/gui/src/view/style/theme/dark.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ $dark-input: #777; //输入框:背景色
9999
}
100100

101101
/* 输入框、下拉框 */
102-
.ant-input,
102+
.ant-input, .fake-input,
103103
.ant-input-number-input,
104104
.ant-input-number,
105105
.ant-select-selection,

0 commit comments

Comments
 (0)