From ddd1cb8cc17860a0ae8003f6f80f324fb2188346 Mon Sep 17 00:00:00 2001 From: vapao Date: Thu, 9 Dec 2021 22:23:50 +0800 Subject: [PATCH] =?UTF-8?q?U=20=E4=BC=98=E5=8C=96=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E6=89=A7=E8=A1=8CUX?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- spug_api/apps/exec/executors.py | 4 +-- spug_web/src/pages/exec/task/Output.js | 8 ++++-- spug_web/src/pages/exec/task/index.js | 25 +++++++++++-------- .../src/pages/exec/task/index.module.less | 9 ++++++- spug_web/src/pages/exec/task/store.js | 2 +- 5 files changed, 31 insertions(+), 17 deletions(-) diff --git a/spug_api/apps/exec/executors.py b/spug_api/apps/exec/executors.py index be5739d..7183004 100644 --- a/spug_api/apps/exec/executors.py +++ b/spug_api/apps/exec/executors.py @@ -38,7 +38,7 @@ class Job: def _handle_command(self, command, interpreter): if interpreter == 'python': - return f'python << EOF\n{command}\nEOF' + return f'python << EOF\n# -*- coding: UTF-8 -*-\n{command}\nEOF' return command def send(self, data): @@ -53,7 +53,7 @@ class Job: if not self.token: with self.ssh: return self.ssh.exec_command(self.command, self.env) - self.send('\r\33[K\x1b[36m### Executing ...\x1b[0m\r\n') + self.send('\r\n\x1b[36m### Executing ...\x1b[0m\r\n') code = -1 try: with self.ssh: diff --git a/spug_web/src/pages/exec/task/Output.js b/spug_web/src/pages/exec/task/Output.js index 8e85ffa..75e33ff 100644 --- a/spug_web/src/pages/exec/task/Output.js +++ b/spug_web/src/pages/exec/task/Output.js @@ -36,7 +36,7 @@ function OutView(props) { term.loadAddon(fitPlugin) term.open(el.current) fitPlugin.fit() - term.write('WebSocket connecting ... ') + term.write('\x1b[36m### WebSocket connecting ...\x1b[0m') const resize = () => fitPlugin.fit(); window.addEventListener('resize', resize) setTerm(term) @@ -49,7 +49,11 @@ function OutView(props) { const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:'; const socket = new WebSocket(`${protocol}//${window.location.host}/api/ws/exec/${store.token}/?x-token=${X_TOKEN}`); socket.onopen = () => { - term.write('\r\x1b[K\x1b[36m### Waiting for scheduling ...\x1b[0m') + const message = '\r\x1b[K\x1b[36m### Waiting for scheduling ...\x1b[0m' + for (let key of Object.keys(store.outputs)) { + store.outputs[key].data = message + } + term.write(message) socket.send('ok'); } socket.onmessage = e => { diff --git a/spug_web/src/pages/exec/task/index.js b/spug_web/src/pages/exec/task/index.js index 714c7df..1e66629 100644 --- a/spug_web/src/pages/exec/task/index.js +++ b/spug_web/src/pages/exec/task/index.js @@ -5,7 +5,7 @@ */ import React, { useState, useEffect } from 'react'; import { observer } from 'mobx-react'; -import { PlusOutlined, ThunderboltOutlined, QuestionCircleOutlined } from '@ant-design/icons'; +import { PlusOutlined, ThunderboltOutlined, BulbOutlined, QuestionCircleOutlined } from '@ant-design/icons'; import { Form, Button, Alert, Radio, Tooltip } from 'antd'; import { ACEditor, AuthDiv, Breadcrumb } from 'components'; import Selector from 'pages/host/Selector'; @@ -68,14 +68,19 @@ function TaskIndex() { } + onClick={() => store.showHost = true}/> + ) : ( + )} - + Python 全局变量 + className={style.tips}> 使用全局变量? + - - - diff --git a/spug_web/src/pages/exec/task/index.module.less b/spug_web/src/pages/exec/task/index.module.less index 5d1d476..fc0af32 100644 --- a/spug_web/src/pages/exec/task/index.module.less +++ b/spug_web/src/pages/exec/task/index.module.less @@ -8,14 +8,21 @@ padding: 24px; width: 60%; + .area { + cursor: pointer; + width: 200px; + height: 32px; + } + .tips { position: absolute; top: 10px; left: 180px; + color: #999; } .editor { - height: calc(100vh - 588px) !important; + height: calc(100vh - 482px) !important; } } diff --git a/spug_web/src/pages/exec/task/store.js b/spug_web/src/pages/exec/task/store.js index ad20a71..0d0a8b8 100644 --- a/spug_web/src/pages/exec/task/store.js +++ b/spug_web/src/pages/exec/task/store.js @@ -67,7 +67,7 @@ class Store { const host = hostStore.idMap[id]; this.outputs[host.id] = { title: `${host.name}(${host.hostname}:${host.port})`, - data: '', + data: '\x1b[36m### WebSocket connecting ...\x1b[0m', status: -2 } }