Skip to content

Commit

Permalink
perf: Code formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhaoJiSen committed Nov 13, 2024
1 parent ec2c555 commit 409c223
Show file tree
Hide file tree
Showing 51 changed files with 4,380 additions and 4,409 deletions.
2 changes: 1 addition & 1 deletion ui/.prettierrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = {
// 指定最大换行长度
printWidth: 110,
// 缩进制表符宽度 | 空格数
tabWidth: 4,
tabWidth: 2,
// 使用制表符而不是空格缩进行 (true:制表符,false:空格)
useTabs: false,
// 结尾不用分号 (true:有,false:没有)
Expand Down
48 changes: 24 additions & 24 deletions ui/src/App.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<template>
<n-config-provider :theme="darkTheme" :locale="zhCN" :date-locale="dateZhCN" class="overflow-hidden">
<n-dialog-provider>
<n-notification-provider>
<n-message-provider>
<router-view v-if="i18nLoaded" />
</n-message-provider>
</n-notification-provider>
</n-dialog-provider>
</n-config-provider>
<n-config-provider :theme="darkTheme" :locale="zhCN" :date-locale="dateZhCN" class="overflow-hidden">
<n-dialog-provider>
<n-notification-provider>
<n-message-provider>
<router-view v-if="i18nLoaded" />
</n-message-provider>
</n-notification-provider>
</n-dialog-provider>
</n-config-provider>
</template>

<script setup lang="ts">
Expand All @@ -30,28 +30,28 @@ const globalStore = useGlobalStore();
const { i18nLoaded } = storeToRefs(globalStore);
const setLanguage = async (lang: string): Promise<void> => {
try {
const res = await alovaInstance
.Get(`${BASE_URL}/api/v1/settings/i18n/koko/?lang=${lang}&flat=0`)
.then(response => (response as Response).json());
mergeLocaleMessage(lang, res[lang]);
} catch (e) {
error(`${e}`);
} finally {
globalStore.setI18nLoaded(true);
}
try {
const res = await alovaInstance
.Get(`${BASE_URL}/api/v1/settings/i18n/koko/?lang=${lang}&flat=0`)
.then(response => (response as Response).json());
mergeLocaleMessage(lang, res[lang]);
} catch (e) {
error(`${e}`);
} finally {
globalStore.setI18nLoaded(true);
}
};
onMounted(() => {
// 设置语言
setLanguage(lang);
// 设置语言
setLanguage(lang);
});
</script>

<style scoped lang="scss">
.n-config-provider {
width: 100%;
height: 100%;
width: 100%;
height: 100%;
}
</style>
2 changes: 1 addition & 1 deletion ui/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import { createAlova } from 'alova';
import fetchAdapter from 'alova/fetch';

export const alovaInstance = createAlova({
requestAdapter: fetchAdapter()
requestAdapter: fetchAdapter()
});
110 changes: 55 additions & 55 deletions ui/src/components/CustomTerminal/helper/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { useLogger } from '@/hooks/useLogger.ts';
const { info } = useLogger('HelperFunctions');

interface LunaEventMessage {
name: string;
id?: string;
data?: any;
name: string;
id?: string;
data?: any;
}

/**
Expand All @@ -19,16 +19,16 @@ interface LunaEventMessage {
* @param {string | null} [origin=null] - 消息的来源。
*/
export const sendEventToLuna = (
name: string,
data: any,
lunaId: string | null = '',
origin: string | null = ''
name: string,
data: any,
lunaId: string | null = '',
origin: string | null = ''
) => {
if (lunaId !== null && origin !== null) {
try {
window.parent.postMessage({ name, id: lunaId, data }, origin);
} catch (e) {}
}
if (lunaId !== null && origin !== null) {
try {
window.parent.postMessage({ name, id: lunaId, data }, origin);
} catch (e) {}
}
};

/**
Expand All @@ -42,36 +42,36 @@ export const sendEventToLuna = (
* @param {(data: any) => void} sendDataFromWindow - 从窗口发送数据的函数。
*/
export const handleEventFromLuna = (
e: MessageEvent,
emits: (event: 'event', eventName: string, data: string) => void,
lunaId: Ref<string | null>,
origin: Ref<string | null>,
terminal: Terminal,
sendDataFromWindow: (data: any) => void
e: MessageEvent,
emits: (event: 'event', eventName: string, data: string) => void,
lunaId: Ref<string | null>,
origin: Ref<string | null>,
terminal: Terminal,
sendDataFromWindow: (data: any) => void
) => {
const msg: LunaEventMessage = e.data;
const msg: LunaEventMessage = e.data;

info('Received post message:', msg);
info('Received post message:', msg);

switch (msg.name) {
case 'PING':
if (lunaId.value != null) return;
switch (msg.name) {
case 'PING':
if (lunaId.value != null) return;

lunaId.value = msg.id || null;
origin.value = e.origin;
lunaId.value = msg.id || null;
origin.value = e.origin;

sendEventToLuna('PONG', '', lunaId.value, origin.value);
break;
case 'CMD':
sendDataFromWindow(msg.data);
break;
case 'FOCUS':
terminal.focus();
break;
case 'OPEN':
emits('event', 'open', '');
break;
}
sendEventToLuna('PONG', '', lunaId.value, origin.value);
break;
case 'CMD':
sendDataFromWindow(msg.data);
break;
case 'FOCUS':
terminal.focus();
break;
case 'OPEN':
emits('event', 'open', '');
break;
}
};

/**
Expand All @@ -81,7 +81,7 @@ export const handleEventFromLuna = (
* @returns 如果 WebSocket 已激活则返回 true,否则返回 false。
*/
export const wsIsActivated = (ws: WebSocket | undefined) => {
return ws ? !(ws.readyState === WebSocket.CLOSING || ws.readyState === WebSocket.CLOSED) : false;
return ws ? !(ws.readyState === WebSocket.CLOSING || ws.readyState === WebSocket.CLOSED) : false;
};

/**
Expand All @@ -90,7 +90,7 @@ export const wsIsActivated = (ws: WebSocket | undefined) => {
* @param {Event} e - 错误事件。
*/
export const handleError = (e: any) => {
info(e);
info(e);
};

/**
Expand All @@ -102,11 +102,11 @@ export const handleError = (e: any) => {
* @returns 格式化的 JSON 字符串。
*/
export const formatMessage = (id: string, type: string, data: any) => {
return JSON.stringify({
id,
type,
data
});
return JSON.stringify({
id,
type,
data
});
};

/**
Expand All @@ -115,15 +115,15 @@ export const formatMessage = (id: string, type: string, data: any) => {
* @param {any} setting - 包含 LOGO_URLS 配置的设置对象。
*/
export const updateIcon = (setting: any) => {
const faviconURL = setting.INTERFACE.favicon;
let link = document.querySelector("link[rel*='icon']") as HTMLLinkElement;
if (!link) {
link = document.createElement('link') as HTMLLinkElement;
link.type = 'image/x-icon';
link.rel = 'shortcut icon';
document.getElementsByTagName('head')[0].appendChild(link);
}
if (faviconURL) {
link.href = faviconURL;
}
const faviconURL = setting.INTERFACE.favicon;
let link = document.querySelector("link[rel*='icon']") as HTMLLinkElement;
if (!link) {
link = document.createElement('link') as HTMLLinkElement;
link.type = 'image/x-icon';
link.rel = 'shortcut icon';
document.getElementsByTagName('head')[0].appendChild(link);
}
if (faviconURL) {
link.href = faviconURL;
}
};
80 changes: 40 additions & 40 deletions ui/src/components/CustomTerminal/index.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<template>
<n-layout :native-scrollbar="false">
<n-scrollbar trigger="hover">
<div :id="indexKey" class="terminal-container"></div>
</n-scrollbar>
</n-layout>
<n-layout :native-scrollbar="false">
<n-scrollbar trigger="hover">
<div :id="indexKey" class="terminal-container"></div>
</n-scrollbar>
</n-layout>
</template>

<script setup lang="ts">
Expand All @@ -19,64 +19,64 @@ import mittBus from '@/utils/mittBus.ts';
const { t } = useI18n();
const props = withDefaults(defineProps<ITerminalProps>(), {
themeName: 'Default',
terminalType: 'common'
themeName: 'Default',
terminalType: 'common'
});
const emits = defineEmits<{
(e: 'event', event: string, data: string): void;
(e: 'background-color', backgroundColor: string): void;
(e: 'socketData', msgType: string, msg: any, terminal: Terminal): void;
(e: 'event', event: string, data: string): void;
(e: 'background-color', backgroundColor: string): void;
(e: 'socketData', msgType: string, msg: any, terminal: Terminal): void;
}>();
const terminalRef = ref<Terminal | undefined>(undefined);
onMounted(async () => {
const theme = props.themeName;
const el: HTMLElement = document.getElementById(props.indexKey as string)!;
const theme = props.themeName;
const el: HTMLElement = document.getElementById(props.indexKey as string)!;
const { terminal, setTerminalTheme } = await useTerminal(el, {
type: props.terminalType,
transSocket: props.socket ? props.socket : undefined,
i18nCallBack: (key: string) => t(key),
emitCallback: (e: string, type: string, msg: any, terminal?: Terminal) => {
switch (e) {
case 'event': {
emits('event', type, msg);
break;
}
case 'socketData': {
emits('socketData', type, msg, terminal!);
break;
}
}
const { terminal, setTerminalTheme } = await useTerminal(el, {
type: props.terminalType,
transSocket: props.socket ? props.socket : undefined,
i18nCallBack: (key: string) => t(key),
emitCallback: (e: string, type: string, msg: any, terminal?: Terminal) => {
switch (e) {
case 'event': {
emits('event', type, msg);
break;
}
});
case 'socketData': {
emits('socketData', type, msg, terminal!);
break;
}
}
}
});
terminalRef.value = terminal;
terminalRef.value = terminal;
// 设置主题
setTerminalTheme(theme, terminal!, emits);
// 设置主题
setTerminalTheme(theme, terminal!, emits);
// 修改主题
mittBus.on('set-theme', ({ themeName }) => {
setTerminalTheme(themeName as string, terminal!, emits);
});
// 修改主题
mittBus.on('set-theme', ({ themeName }) => {
setTerminalTheme(themeName as string, terminal!, emits);
});
});
defineExpose({
terminalRef
terminalRef
});
onUnmounted(() => {
mittBus.off('set-theme');
mittBus.off('set-theme');
});
</script>

<style lang="scss" scoped>
:deep(.terminal-container) {
.xterm {
padding: 10px 0 10px 10px;
}
.xterm {
padding: 10px 0 10px 10px;
}
}
</style>
Loading

0 comments on commit 409c223

Please sign in to comment.