NEZ-1196 fix: terminal支持https
This commit is contained in:
@@ -196,16 +196,17 @@ export default {
|
||||
this.term.focus()
|
||||
const token = sessionStorage.getItem('nz-token')
|
||||
let baseUrl = JSON.parse(JSON.stringify(this.$axios.defaults.baseURL))
|
||||
const protocol = window.location.protocol.indexOf('https') > -1 ? 'wss' : 'ws'
|
||||
if (baseUrl.startsWith('/')) {
|
||||
baseUrl = 'ws://' + window.location.host + baseUrl
|
||||
baseUrl = `${protocol}://` + window.location.host + baseUrl
|
||||
} else {
|
||||
baseUrl = baseUrl.replace('http://', 'ws://').replace('https://', 'ws://')
|
||||
baseUrl = baseUrl.replace('http://', 'ws://').replace('https://', 'wss://')
|
||||
}
|
||||
let url = ''
|
||||
if (this.terminal.type === 'asset') {
|
||||
url = baseUrl + '/terminal.ws?width=' + this.terminal.width + '&height=' + this.terminal.height + '&cols=' + this.terminal.cols + '&rows=' + this.terminal.rows + '&token=' + token + '&assetId=' + this.terminal.assetId + '&accountId=' + this.terminal.accountId + '&uuid=' + this.terminal.uuid
|
||||
url = baseUrl + `/terminal.${protocol}?width=` + this.terminal.width + '&height=' + this.terminal.height + '&cols=' + this.terminal.cols + '&rows=' + this.terminal.rows + '&token=' + token + '&assetId=' + this.terminal.assetId + '&accountId=' + this.terminal.accountId + '&uuid=' + this.terminal.uuid
|
||||
} else if (this.terminal.type === 'custom') {
|
||||
url = baseUrl + '/terminal.ws?width=' + this.terminal.width + '&height=' + this.terminal.height + '&cols=' + this.terminal.cols + '&rows=' + this.terminal.rows + '&token=' + token + '&accountId=' + this.terminal.accountId + '&uuid=' + this.terminal.uuid
|
||||
url = baseUrl + `/terminal.${protocol}?width=` + this.terminal.width + '&height=' + this.terminal.height + '&cols=' + this.terminal.cols + '&rows=' + this.terminal.rows + '&token=' + token + '&accountId=' + this.terminal.accountId + '&uuid=' + this.terminal.uuid
|
||||
Object.keys(this.terminal.custom).forEach(key => {
|
||||
if (this.terminal.custom[key]) {
|
||||
url += '&' + key + '=' + this.terminal.custom[key]
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
<template>
|
||||
<div>
|
||||
<div class="console" id="terminal"></div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import Terminal from '../../common/js/Xterm'
|
||||
export default {
|
||||
name: 'Console',
|
||||
props: ['terminal', 'token'],
|
||||
data () {
|
||||
return {
|
||||
term: null,
|
||||
terminalSocket: null,
|
||||
obj: {
|
||||
id: 2
|
||||
}
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
token: {
|
||||
immediate: true,
|
||||
handler (val) {
|
||||
if (val) {
|
||||
this.create()
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
create () {
|
||||
const terminalContainer = document.getElementById('terminal')
|
||||
this.term = new Terminal()
|
||||
this.term.open(terminalContainer)
|
||||
this.terminalSocket = new WebSocket('ws://192.168.40.247:8080/nz-admin/terminal.ws?width=1&height=1&cols=225&rows=200&token=' + this.token)
|
||||
// this.terminalSocket = new WebSocket("ws://192.168.41.101:8088/nz-admin/terminal.ws?width=1600&height=1005&cols=225&rows=58&token="+this.token);
|
||||
this.term.attach(this.terminalSocket)
|
||||
this.term._initialized = true
|
||||
}
|
||||
},
|
||||
mounted () {
|
||||
|
||||
},
|
||||
beforeDestroy () {
|
||||
this.terminalSocket.close()
|
||||
this.term.destroy()
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<style scoped>
|
||||
.header {
|
||||
position: relative;
|
||||
box-sizing: border-box;
|
||||
width: 100%;
|
||||
height: 60px;
|
||||
font-size: 22px;
|
||||
background-color: #ffffff;
|
||||
z-index: 510;
|
||||
box-shadow: 0px 20px 13px -19px #5E5E5E;
|
||||
}
|
||||
</style>
|
||||
@@ -1,181 +0,0 @@
|
||||
<template>
|
||||
<div>
|
||||
<div class="title">
|
||||
<div class="submenu">
|
||||
<el-menu class="el-menu-demo" mode="horizontal">
|
||||
<el-submenu index="1">
|
||||
<template slot="title">操作</template>
|
||||
<el-menu-item index="1-1">
|
||||
<template>
|
||||
<span @click="cloneChat">克隆会话</span>
|
||||
</template>
|
||||
</el-menu-item>
|
||||
<el-menu-item index="1-2">
|
||||
<template>
|
||||
<span @click="dialogVisible = true">上传文件</span>
|
||||
</template>
|
||||
</el-menu-item>
|
||||
</el-submenu>
|
||||
<el-submenu index="2">
|
||||
<template slot="title">打开</template>
|
||||
<template v-for="(item, index) in enableAsset">
|
||||
<el-menu-item :key="index" :index="'2-' + index" @click="createCli(item)">{{item.host}}</el-menu-item>
|
||||
</template>
|
||||
</el-submenu>
|
||||
</el-menu>
|
||||
</div>
|
||||
<div class="title-input">
|
||||
<input style="height: 20px;width: 250px"></input>
|
||||
<button>发送</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<el-dialog
|
||||
:visible="dialogVisible"
|
||||
width="30%"
|
||||
:modal="true">
|
||||
<label>文件路径</label>
|
||||
<el-input v-model="uploadFile.path"></el-input>
|
||||
<div style="padding-top: 20px">
|
||||
<el-upload
|
||||
drag
|
||||
class="upload-demo"
|
||||
ref="upload"
|
||||
action=""
|
||||
:on-change="handleChange"
|
||||
:auto-upload="false"
|
||||
>
|
||||
<!-- <el-button size="small" type="primary">{{$t('asset.createAssetTab.clickToUpload')}}</el-button>-->
|
||||
<i class="nz-icon nz-icon-upload"></i>
|
||||
<div class="el-upload__text">{{$t('overall.dragFileTip')}},{{$t('overall.or')}} <em>{{$t('overall.clickUpload')}}</em></div>
|
||||
</el-upload>
|
||||
</div>
|
||||
<span slot="footer" class="dialog-footer">
|
||||
<el-button @click="dialogVisible = false">取 消</el-button>
|
||||
<el-button type="primary" @click="upload">确 定</el-button>
|
||||
</span>
|
||||
</el-dialog>
|
||||
<my-terminal :terminal="terminal" :token="token"></my-terminal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import Console from './Console'
|
||||
export default {
|
||||
name: 'cloneChat',
|
||||
components: {
|
||||
'my-terminal': Console
|
||||
},
|
||||
data () {
|
||||
return {
|
||||
dialogVisible: false,
|
||||
terminal: {
|
||||
pid: 1,
|
||||
name: 'terminal',
|
||||
cols: 400,
|
||||
rows: 400
|
||||
},
|
||||
obj: {
|
||||
id: ''
|
||||
},
|
||||
uploadFile: {
|
||||
file: '',
|
||||
path: '',
|
||||
token: ''
|
||||
},
|
||||
pageObj: {
|
||||
pageNo: 1,
|
||||
pageSize: 100
|
||||
},
|
||||
enableAsset: '',
|
||||
host: '',
|
||||
token: '',
|
||||
routeData: this.$route.query
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
},
|
||||
methods: {
|
||||
createCli (item) {
|
||||
const routeData = this.$router.resolve({
|
||||
name: 'newChat',
|
||||
query: {
|
||||
host: item.host,
|
||||
accountId: item.accounts[0].id
|
||||
}
|
||||
})
|
||||
window.open(routeData.href)
|
||||
},
|
||||
cloneChat () {
|
||||
const routeData = this.$router.resolve({
|
||||
name: 'cloneChat',
|
||||
query: {
|
||||
host: this.routeData.host,
|
||||
accountId: this.routeData.accountId
|
||||
}
|
||||
})
|
||||
window.open(routeData.href)
|
||||
},
|
||||
getConnect (id, token) {
|
||||
this.$get('account/reopen.do?id=' + id + '&token=' + token).then(res => {
|
||||
if (res.code === 200) {
|
||||
this.token = res.data.token
|
||||
sessionStorage.setItem('cliToken', this.token)
|
||||
}
|
||||
})
|
||||
},
|
||||
handleChange (file) {
|
||||
this.uploadFile.file = file.raw
|
||||
},
|
||||
upload () {
|
||||
this.uploadFile.token = this.token
|
||||
const form = new FormData()
|
||||
form.append('token', this.token)
|
||||
form.append('file', this.uploadFile.file)
|
||||
form.append('path', this.uploadFile.path)
|
||||
this.$post('account/upload.do', form).then(res => {
|
||||
if (res.code === 200) {
|
||||
// console.log(res)
|
||||
}
|
||||
})
|
||||
},
|
||||
getAssetData () {
|
||||
this.$get('asset', this.pageObj).then(response => {
|
||||
if (response.code === 200) {
|
||||
this.assetData = response.data.list
|
||||
this.enableAsset = this.assetData.filter(item => {
|
||||
return item.accounts.length > 0
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
mounted () {
|
||||
if (this.routeData) {
|
||||
this.host = this.routeData.host
|
||||
document.title = this.host
|
||||
}
|
||||
this.getAssetData()
|
||||
if (sessionStorage.getItem('cliToken')) {
|
||||
this.getConnect(this.routeData.accountId, sessionStorage.getItem('cliToken'))
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.title{
|
||||
display: inline-block;
|
||||
}
|
||||
.submenu {
|
||||
float: left;
|
||||
width: 500px;
|
||||
font-size: 22px;
|
||||
|
||||
}
|
||||
.title-input{
|
||||
position: absolute;
|
||||
left: 300px;
|
||||
top:19px
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user