mirror of
https://github.com/labring/sealos.git
synced 2026-10-28 02:27:18 +08:00
feat(terminal):auto switch namespace (#3961)
This commit is contained in:
@@ -18,6 +18,7 @@ function Terminal({ url, site }: { url: string; site: string }) {
|
||||
const iframeRef = useRef<HTMLIFrameElement>(null);
|
||||
const { query } = router;
|
||||
const session = useSessionStore((s) => s.session);
|
||||
const nsid = session.user.nsid;
|
||||
const [tabContents, setTabContents] = useState<Terminal[]>([
|
||||
{
|
||||
id: tabId,
|
||||
@@ -37,14 +38,20 @@ function Terminal({ url, site }: { url: string; site: string }) {
|
||||
newTerminal(decodeURIComponent(e.data.command));
|
||||
}
|
||||
if (e.data?.ttyd === 'ready') {
|
||||
const command = iframeRef.current?.getAttribute('data-command');
|
||||
iframeRef?.current?.contentWindow?.postMessage({ command }, url);
|
||||
iframeRef.current?.contentWindow?.postMessage(
|
||||
{
|
||||
command: `kubectl config set-context --current --namespace=${session.user.nsid}`
|
||||
command: `kubectl config set-context --current --namespace=${nsid} && export PS1="\\u@(${nsid}) \\W\\$ " && clear`
|
||||
},
|
||||
url
|
||||
);
|
||||
iframeRef.current?.contentWindow?.postMessage(
|
||||
{
|
||||
command: `echo -e "\\e[A\\e[K 👉 Switched to namespace \\e[1;4;32m${nsid}\\e[0m"`
|
||||
},
|
||||
url
|
||||
);
|
||||
const command = iframeRef.current?.getAttribute('data-command');
|
||||
iframeRef?.current?.contentWindow?.postMessage({ command }, url);
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error, 'error');
|
||||
|
||||
Reference in New Issue
Block a user