Skip to content

Commit df4f300

Browse files
committed
优化terminal的显示
1 parent c05314c commit df4f300

File tree

4 files changed

+43
-29
lines changed

4 files changed

+43
-29
lines changed

README.md

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,11 @@ export default {
8686
</script>
8787
8888
<style>
89-
body, html {
89+
body, html, #app {
9090
margin: 0;
9191
padding: 0;
92+
width: 100%;
93+
height: 100%;
9294
}
9395
</style>
9496
```
@@ -99,32 +101,34 @@ body, html {
99101

100102
terminal标签支持属性参数表
101103

102-
| 参数 | 说明 | 类型 | 默认值 |
103-
|--------------------|-----------------------------------------|---------|--------------------|
104-
| name | Terminal实例名称,同一页面的name必须唯一,Api中使用也需用到此值 | string | terminal |
105-
| context | 初始化上下文文本 | string | /vue-web-terminal |
106-
| title | header中显示的标题 | string | vue-web-terminal |
107-
| show-header | 是否显示header | boolean | true |
108-
| init-log | Terminal初始化时显示的日志,是由[消息对象](#消息对象)组成的数组 | array ||
109-
| init-log-delay | 初始化显示日志时每条日志之间的间隔时间,单位毫秒 ms | number | 150 |
110-
| show-log-time | 当消息**type**`normal`时是否显示时间 | boolean | true |
111-
| warnLogByteLimit | 当前Terminal日志占用内存大小超出此限制会发出警告,单位`byte` | number | 1024 * 1024 * 10 |
112-
| warnLogCountLimit | 当前Terminal日志条数超出此限制会发出警告 | number | 200 |
113-
| warnLogLimitEnable | 是否开启日志限制警告 | boolean | true |
114-
| auto-help | 是否打开命令行自动搜索提示功能 | boolean | true |
115-
| command-store | 自定义的命令行库,见[命令行定义格式](#命令行定义) | array | [内置命令行](#内置命令行) |
104+
| 参数 | 说明 | 类型 | 默认值 |
105+
|---------------------|-----------------------------------------|----------|-------------------|
106+
| name | Terminal实例名称,同一页面的name必须唯一,Api中使用也需用到此值 | string | terminal |
107+
| context | 初始化上下文文本 | string | /vue-web-terminal |
108+
| title | header中显示的标题 | string | vue-web-terminal |
109+
| show-header | 是否显示header | boolean | true |
110+
| init-log | Terminal初始化时显示的日志,是由[消息对象](#消息对象)组成的数组 | array ||
111+
| init-log-delay | 初始化显示日志时每条日志之间的间隔时间,单位毫秒 ms | number | 150 |
112+
| show-log-time | 当消息**type**`normal`时是否显示时间 | boolean | true |
113+
| warnLogByteLimit | 当前Terminal日志占用内存大小超出此限制会发出警告,单位`byte` | number | 1024 * 1024 * 10 |
114+
| warnLogCountLimit | 当前Terminal日志条数超出此限制会发出警告 | number | 200 |
115+
| warnLogLimitEnable | 是否开启日志限制警告 | boolean | true |
116+
| auto-help | 是否打开命令行自动搜索提示功能 | boolean | true |
117+
| help-style | help自定义样式 | string | |
118+
| command-store | 自定义的命令行库,见[命令行定义格式](#命令行定义) | array | [内置命令行](#内置命令行) |
119+
| command-store-sort | 命令行库排序 | function | function(a,b) {} |
116120

117121
## Select Events
118122

119123
terminal标签支持事件表
120124

121-
| 事件名称 | 说明 | 回调参数 |
122-
|---------------|----------------------------------------------------------------------------------------------------------------|--------------------------------------|
123-
| execCmd | 执行自定义命令时触发。`success``failed`为回调函数,**
124-
必须调用两个回调其中之一才会回显!**,其中`success`回调参数为一个[消息对象](#消息对象)`failed`回调参数为一个string | `(cmdKey, command, success, failed)` |
125-
| beforeExecCmd | 执行任意命令之前触发 | `(cmdKey, command)` |
126-
| onKeydown | 当获取光标焦点时,按下任意键盘触发 | `(event)` |
127-
| onClick | 用户点击按钮时触发,参数`key`为按钮唯一识别,已有按钮:close、minScreen、fullScreen、title | `(key)` |
125+
| 事件名称 | 说明 | 回调参数 |
126+
|---------------------------------------------------------------------------|----------------------------------------------------------------|---------------------|
127+
| execCmd | 执行自定义命令时触发。`success``failed`为回调函数,** | |
128+
| 必须调用两个回调其中之一才会回显!**,其中`success`回调参数为一个[消息对象](#消息对象)`failed`回调参数为一个string | `(cmdKey, command, success, failed)` | |
129+
| beforeExecCmd | 执行任意命令之前触发 | `(cmdKey, command)` |
130+
| onKeydown | 当获取光标焦点时,按下任意键盘触发 | `(event)` |
131+
| onClick | 用户点击按钮时触发,参数`key`为按钮唯一识别,已有按钮:close、minScreen、fullScreen、title | `(key)` |
128132

129133
## Api
130134

@@ -196,7 +200,7 @@ export default {
196200

197201
### normal 普通文本
198202

199-
content为字符串格式,支持html标签,time字段会在push时自动填充,class、content、type必填,其他选填
203+
content为字符串格式,支持html标签,time字段会在push时自动填充,content、type必填,其他选填
200204

201205
```json
202206
{
@@ -321,7 +325,7 @@ type为`table`时content为表格配置,`head`为表头,`rows`为每行的
321325
type为`html`时可自定义内容格式,content为html标签构成
322326

323327
```js
324-
execCmd(key, command, success)
328+
execCmd(key, command, success)
325329
{
326330
// ...
327331
success({

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-web-terminal",
3-
"version": "1.2.4",
3+
"version": "1.2.5",
44
"private": false,
55
"scripts": {
66
"serve": "vue-cli-service serve",

src/Terminal.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ export default {
9191
}, // 命令行搜索以及help指令用
9292
commandStore: {
9393
type: Array
94+
}, // 命令行排序方式
95+
commandStoreSort: {
96+
type: Function
9497
}, // 记录大小超出此限制会发出警告,单位byte
9598
warnLogByteLimit: {
9699
type: Number, default: 1024 * 1024 * 10
@@ -110,6 +113,10 @@ export default {
110113
showHeader: {
111114
type: Boolean,
112115
default: true
116+
},
117+
helpStyle:{
118+
type: String,
119+
default: ''
113120
}
114121
},
115122
created() {
@@ -129,6 +136,9 @@ export default {
129136
}
130137

131138
if (this.commandStore != null) {
139+
if (this.commandStoreSort != null) {
140+
this.commandStore.sort(this.commandStoreSort)
141+
}
132142
this.allCommandStore = this.allCommandStore.concat(this.commandStore)
133143
}
134144
},

src/Terminal.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
<span v-show="showLogTime">{{ item.time == null ? "" : (item.time + " ") }}</span>
6464
<span :class="item.class"
6565
style="margin-right: 10px">{{ item.tag == null ? item.class : item.tag }}</span>
66-
<span v-html="item.content" @click="_activeCursor"></span>
66+
<span v-html="item.content"></span>
6767
</span>
6868
<span v-else-if="item.type === 'json'" style="position: relative">
6969
<json-viewer :expand-depth="item.depth"
@@ -108,7 +108,7 @@
108108
</table>
109109
</div>
110110
</div>
111-
<div v-else-if="item.type === 'html'" v-html="item.content"></div>
111+
<div v-else-if="item.type === 'html'" v-html="item.content" @click.self="_activeCursor"></div>
112112
</div>
113113
</div>
114114
<p class="terminal-last-line crude-font" v-show="showInputLine" @click.self="_activeCursor">
@@ -135,7 +135,7 @@
135135
<p class="help-msg" v-if="searchCmd.item != null" @click.self="_activeCursor">{{ searchCmd.item.usage }}</p>
136136
</div>
137137
</div>
138-
<div class="cmd-help" :style="`${showHeader ? '' : 'top:10px'}`"
138+
<div class="cmd-help" :style="helpStyle"
139139
v-if="searchCmd.item != null && !(require('./Util.js'))._screenType().xs">
140140
<p class="text" v-if="searchCmd.item.description != null" style="margin: 15px 0"
141141
v-html="searchCmd.item.description"></p>
@@ -193,7 +193,7 @@ export default TerminalJs
193193
}
194194
195195
.terminal-container {
196-
position: absolute;
196+
position: relative;
197197
width: 100%;
198198
min-height: 100%;
199199
margin: 0;

0 commit comments

Comments
 (0)