Skip to content

Commit a42a3da

Browse files
committed
:feat: add reset
1 parent 7eb9ec3 commit a42a3da

3 files changed

Lines changed: 79 additions & 26 deletions

File tree

src/view/batch-replace.css

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,23 @@ body, html, h2 {
2828
.header h2 {
2929
font-size: 28px;
3030
}
31+
.operator {
32+
float: right;
33+
}
34+
.operator.clear-his {
35+
font-size: 12px;
36+
padding: 3px 0;
37+
}
3138
.operate {
32-
width: 20px;
33-
height: 20px;
34-
min-width: 20px;
35-
min-height: 20px;
36-
vertical-align: middle;
37-
text-align: center;
38-
display: inline-block;
39-
border-radius: 50%;
39+
font-size: 18px;
40+
font-weight: bold;
4041
cursor: pointer;
4142
}
4243
.operate.add {
43-
border: 1px solid #67c23a;
4444
color: #67c23a;
4545
}
4646
.operate.del {
4747
margin-left: 5px;
48-
border: 1px solid #f56c6c;
4948
color: #f56c6c;
5049
}
5150

@@ -69,4 +68,21 @@ body, html, h2 {
6968
.empty {
7069
text-align: center;
7170
color: #ccc;
71+
}
72+
73+
.history {
74+
margin-top: 20px;
75+
}
76+
.history-list {
77+
max-height: 200px;
78+
overflow-y: auto;
79+
}
80+
.history-title {
81+
font-size: 12px;
82+
color: #333;
83+
}
84+
85+
.history-item {
86+
cursor: pointer;
87+
margin: 0 5px 5px 0;
7288
}

src/view/batch-replace.html

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,45 @@
1313
<div id="app">
1414
<div class="header">
1515
<h2>Replace Rules</h2>
16-
<span class="operate add" @click="add">+</span>
1716
</div>
18-
<div class="content">
17+
<el-card class="content">
18+
<div slot="header" class="history-title">
19+
<span>操作面板</span>
20+
<span class="operator operate add" @click="add">+</span>
21+
</div>
1922
<div class="rules">
2023
<div class="rules-item" v-for="(item, index) in replaceRule" @mouseover="item.showDel = true"
2124
@mouseout="item.showDel = false">
22-
<el-input v-model="item.find" placeholder="Search" :size="size"></el-input>
25+
<el-input size="mini" v-model="item.find" placeholder="Search"></el-input>
2326
<span class="seperate"></span>
24-
<el-input v-model="item.to" placeholder="Replace" :size="size"></el-input>
27+
<el-input size="mini" v-model="item.to" placeholder="Replace"></el-input>
2528
<span :class="{ 'hide': !item.showDel }" class="operate del" @click="del(index)">×</span>
2629
</div>
2730
</div>
2831
<div v-if="replaceRule.length > 0">
29-
<el-button @click="match" :size="size">Search</el-button>
30-
<el-button @click="replace" type="primary" :size="size">Replace All</el-button>
32+
<el-button size="mini" @click="match">Search</el-button>
33+
<el-button size="mini" @click="replace" type="primary">Replace All</el-button>
34+
<el-button size="mini" @click="reset">Reset</el-button>
3135
</div>
3236
<div v-else class="empty">
33-
点击右上角 "+" 添加匹配规则
37+
点击右上角 "+" 添加匹配规则
3438
</div>
35-
<!-- <div>{{replaceRule}}</div> -->
36-
</div>
39+
</el-card>
40+
<el-card class="history">
41+
<div slot="header" class="history-title">
42+
<span>历史记录</span>
43+
<el-button class="operator clear-his" type="text" @click=resetHistory>清空</el-button>
44+
</div>
45+
<div class="history-list">
46+
<el-tag v-for="(item, index) in histroyRules" size="mini" class="history-item"
47+
@click="reuseHistory(item)" type="info">
48+
{{item.find}} → {{item.to}}</el-tag>
49+
</div>
50+
</el-card>
3751
</div>
38-
<script src="../../lib/vue-2.5.17/vue.js"></script>
39-
<script src="../../lib/element-ui-2.7.2/index.js"></script>
40-
<script src="../../src/view/batch-replace.js"></script>
4152
</body>
4253

43-
</html>
54+
</html>
55+
<script src="../../lib/vue-2.5.17/vue.js"></script>
56+
<script src="../../lib/element-ui-2.7.2/index.js"></script>
57+
<script src="../../src/view/batch-replace.js"></script>

src/view/batch-replace.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,20 @@ new Vue({
4545
find: '输入需要替换的内容',
4646
to: '',
4747
showDel: false
48-
}]
48+
}],
49+
histroyRules: []
4950
},
5051
mounted() {
5152
callVscode('getFileContent', fileContent => this.fileContent = fileContent);
53+
console.log('window', window.localStorage);
54+
},
55+
watch: {
56+
historyRules: {
57+
deep: true,
58+
handler() {
59+
}
60+
}
5261
},
53-
watch: {},
5462
methods: {
5563
// 模拟alert
5664
alert(info) {
@@ -72,6 +80,9 @@ new Vue({
7280
item.to = '';
7381
})
7482
},
83+
resetHistory() {
84+
this.histroyRules = []
85+
},
7586
validate() {
7687
let emptyNum = 0;
7788
this.replaceRule.forEach(item => {
@@ -91,6 +102,11 @@ new Vue({
91102
if (!this.validate()) {
92103
return;
93104
}
105+
this.replaceRule.forEach(element => {
106+
this.histroyRules.push({
107+
...element
108+
})
109+
});
94110

95111
callVscode({
96112
cmd: 'match',
@@ -103,13 +119,17 @@ new Vue({
103119
if (!this.validate()) {
104120
return;
105121
}
122+
this.replaceRule.forEach(element => {
123+
this.histroyRules.push({
124+
...element
125+
})
126+
});
106127

107128
callVscode({
108129
cmd: 'replace',
109130
rules: this.replaceRule
110131
}, (data) => {
111132
this.alert(`${data.length}个匹配项已替换`);
112-
this.reset();
113133
});
114134
},
115135
add() {
@@ -121,6 +141,9 @@ new Vue({
121141
},
122142
del(index) {
123143
this.replaceRule.splice(index, 1);
144+
},
145+
reuseHistory(item) {
146+
this.replaceRule.push({...item})
124147
}
125148
}
126149
});

0 commit comments

Comments
 (0)