1
0
mirror of https://github.com/PanJiaChen/vue-element-admin.git synced 2025-04-06 03:57:53 +08:00

add terminal

This commit is contained in:
handsomewu 2024-11-13 21:34:47 +08:00
parent 99f710a909
commit 1242d2d3f2

View File

@ -1,101 +1,52 @@
<template> <template>
<div class="icons-container"> <div class="icons-container">
<aside> <div ref="terminalContainer" style="height:90vh; width: 100%;" />
<a href="https://panjiachen.github.io/vue-element-admin-site/guide/advanced/icon.html" target="_blank">Add and use
</a>
</aside>
<el-tabs type="border-card">
<el-tab-pane label="Icons">
<div class="grid">
<div v-for="item of svgIcons" :key="item" @click="handleClipboard(generateIconCode(item),$event)">
<el-tooltip placement="top">
<div slot="content">
{{ generateIconCode(item) }}
</div>
<div class="icon-item">
<svg-icon :icon-class="item" class-name="disabled" />
<span>{{ item }}</span>
</div>
</el-tooltip>
</div>
</div>
</el-tab-pane>
<el-tab-pane label="Element-UI Icons">
<div class="grid">
<div v-for="item of elementIcons" :key="item" @click="handleClipboard(generateElementIconCode(item),$event)">
<el-tooltip placement="top">
<div slot="content">
{{ generateElementIconCode(item) }}
</div>
<div class="icon-item">
<i :class="'el-icon-' + item" />
<span>{{ item }}</span>
</div>
</el-tooltip>
</div>
</div>
</el-tab-pane>
</el-tabs>
</div> </div>
</template> </template>
<script> <script>
import clipboard from '@/utils/clipboard' import { Terminal } from 'xterm'
import svgIcons from './svg-icons' import { FitAddon } from 'xterm-addon-fit'
import elementIcons from './element-icons' import 'xterm/css/xterm.css'
export default { export default {
name: 'Icons', name: 'TerminalComponent',
data() { mounted() {
return { this.initTerminal()
svgIcons,
elementIcons
}
}, },
methods: { methods: {
generateIconCode(symbol) { initTerminal() {
return `<svg-icon icon-class="${symbol}" />` const terminal = new Terminal()
}, const fitAddon = new FitAddon()
generateElementIconCode(symbol) {
return `<i class="el-icon-${symbol}" />` terminal.loadAddon(fitAddon)
}, terminal.open(this.$refs.terminalContainer)
handleClipboard(text, event) { fitAddon.fit()
clipboard(text, event)
// WebSocket
const socket = new WebSocket('ws://localhost:2999')
socket.onopen = () => {
console.log('WebSocket 连接已建立')
}
socket.onmessage = (event) => {
//
terminal.write(event.data)
}
terminal.onData(data => {
//
socket.send(data)
})
} }
} }
} }
</script> </script>
<style lang="scss" scoped> <style lang="css" scoped>
.icons-container { .icons-container {
margin: 10px 20px 0; margin: 10px 20px 0;
overflow: hidden; overflow: hidden;
.grid {
position: relative;
display: grid;
grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
}
.icon-item {
margin: 20px;
height: 85px;
text-align: center;
width: 100px;
float: left;
font-size: 30px;
color: #24292e;
cursor: pointer;
}
span {
display: block;
font-size: 16px;
margin-top: 10px;
}
.disabled {
pointer-events: none;
}
} }
</style> </style>