From 1d25240d8cb28df5fa9b6b756247f220bc420c92 Mon Sep 17 00:00:00 2001 From: Mg Pig Date: Wed, 4 Mar 2026 09:49:15 +0800 Subject: [PATCH] refactor(ui): extract URL input components and enhance UI responsiveness (#1819) --- .../frontend-lib/src/components/Config.vue | 116 +++-------- .../frontend-lib/src/components/UrlInput.vue | 185 ++++++++++++++++++ .../src/components/UrlListInput.vue | 38 ++++ easytier-web/frontend-lib/src/locales/cn.yaml | 5 + easytier-web/frontend-lib/src/locales/en.yaml | 5 + 5 files changed, 256 insertions(+), 93 deletions(-) create mode 100644 easytier-web/frontend-lib/src/components/UrlInput.vue create mode 100644 easytier-web/frontend-lib/src/components/UrlListInput.vue diff --git a/easytier-web/frontend-lib/src/components/Config.vue b/easytier-web/frontend-lib/src/components/Config.vue index eaa14286..0e49ada4 100644 --- a/easytier-web/frontend-lib/src/components/Config.vue +++ b/easytier-web/frontend-lib/src/components/Config.vue @@ -11,6 +11,8 @@ import { } from '../types/network' import { ref, onMounted, onUnmounted } from 'vue' import { useI18n } from 'vue-i18n' +import UrlInput from './UrlInput.vue' +import UrlListInput from './UrlListInput.vue' const props = defineProps<{ configInvalid?: boolean @@ -32,57 +34,18 @@ const networking_methods = ref([ { value: NetworkingMethod.Standalone, label: () => t('standalone') }, ]) -const protos: { [proto: string]: number } = { tcp: 11010, udp: 11010, wg: 11011, ws: 11011, wss: 11012 } - -function searchUrlSuggestions(e: { query: string }): string[] { - const query = e.query - const ret = [] - // if query match "^\w+:.*", then no proto prefix - if (query.match(/^\w+:.*/)) { - // if query is a valid url, then add to suggestions - try { - // eslint-disable-next-line no-new - new URL(query) - ret.push(query) - } - catch { } - } - else { - for (const proto in protos) { - let item = `${proto}://${query}` - // if query match ":\d+$", then no port suffix - if (!query.match(/:\d+$/)) { - item += `:${protos[proto]}` - } - ret.push(item) - } - } - - return ret -} - -const publicServerSuggestions = ref(['']) - -function searchPresetPublicServers(e: { query: string }) { - const presetPublicServers = [ - 'tcp://public.easytier.top:11010', - ] - - const query = e.query - // if query is sub string of presetPublicServers, add to suggestions - let ret = presetPublicServers.filter(item => item.includes(query)) - // add additional suggestions - if (query.length > 0) { - ret = ret.concat(searchUrlSuggestions(e)) - } - - publicServerSuggestions.value = ret -} - -const peerSuggestions = ref(['']) - -function searchPeerSuggestions(e: { query: string }) { - peerSuggestions.value = searchUrlSuggestions(e) +const protos: { [proto: string]: number } = { + tcp: 11010, + udp: 11010, + wg: 11011, + ws: 11011, + wss: 11012, + quic: 11012, + faketcp: 11013, + http: 80, + https: 443, + txt: 0, + srv: 0, } const inetSuggestions = ref(['']) @@ -99,34 +62,6 @@ function searchInetSuggestions(e: { query: string }) { } } -const listenerSuggestions = ref(['']) - -function searchListenerSuggestions(e: { query: string }) { - const ret = [] - - for (const proto in protos) { - let item = `${proto}://0.0.0.0:` - // if query is a number, use it as port - if (e.query.match(/^\d+$/)) { - item += e.query - } - else { - item += protos[proto] - } - - if (item.includes(e.query)) { - ret.push(item) - } - } - - if (ret.length === 0) { - ret.push(e.query) - } - - listenerSuggestions.value = ret -} - - const exitNodesSuggestions = ref(['']) function searchExitNodesSuggestions(e: { query: string }) { @@ -266,14 +201,12 @@ onMounted(() => { -
- +
+ - +
@@ -345,10 +278,8 @@ onMounted(() => {
- +
@@ -443,9 +374,8 @@ onMounted(() => { - + diff --git a/easytier-web/frontend-lib/src/components/UrlInput.vue b/easytier-web/frontend-lib/src/components/UrlInput.vue new file mode 100644 index 00000000..503b269a --- /dev/null +++ b/easytier-web/frontend-lib/src/components/UrlInput.vue @@ -0,0 +1,185 @@ + + + + + diff --git a/easytier-web/frontend-lib/src/components/UrlListInput.vue b/easytier-web/frontend-lib/src/components/UrlListInput.vue new file mode 100644 index 00000000..8f58c5a7 --- /dev/null +++ b/easytier-web/frontend-lib/src/components/UrlListInput.vue @@ -0,0 +1,38 @@ + + + diff --git a/easytier-web/frontend-lib/src/locales/cn.yaml b/easytier-web/frontend-lib/src/locales/cn.yaml index 6e01a8b6..f641e793 100644 --- a/easytier-web/frontend-lib/src/locales/cn.yaml +++ b/easytier-web/frontend-lib/src/locales/cn.yaml @@ -18,12 +18,16 @@ advanced_settings: 高级设置 basic_settings: 基础设置 listener_urls: 监听地址 rpc_port: RPC端口 +port: 端口 rpc_portal_whitelists: RPC白名单 config_network: 配置网络 running: 运行中 error_msg: 错误信息 detail: 详情 add_new_network: 添加新网络 +add_peer_url: 添加节点 +add_listener_url: 添加监听地址 +add_mapped_listener: 添加监听映射 del_cur_network: 删除当前网络 select_network: 选择网络 network_instances: 网络实例 @@ -337,6 +341,7 @@ web: info: 提示 enable: 开启 disable: 关闭 + address: 地址 settings: title: 设置 diff --git a/easytier-web/frontend-lib/src/locales/en.yaml b/easytier-web/frontend-lib/src/locales/en.yaml index 6f54c3c1..ebf22840 100644 --- a/easytier-web/frontend-lib/src/locales/en.yaml +++ b/easytier-web/frontend-lib/src/locales/en.yaml @@ -18,12 +18,16 @@ advanced_settings: Advanced Settings basic_settings: Basic Settings listener_urls: Listener URLs rpc_port: RPC Port +port: Port rpc_portal_whitelists: RPC Whitelist config_network: Config Network running: Running error_msg: Error Message detail: Detail add_new_network: New Network +add_peer_url: Add Peer +add_listener_url: Add Listener +add_mapped_listener: Add Mapped Listener del_cur_network: Delete Current Network select_network: Select Network network_instances: Network Instances @@ -337,6 +341,7 @@ web: info: Info enable: Enable disable: Disable + address: Address settings: title: Settings