From b9b440497eab9de91394fd782f57514a1db2fd37 Mon Sep 17 00:00:00 2001 From: meetqy Date: Tue, 2 Jan 2024 10:33:52 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20FIX:=20=E8=87=AA=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E5=9F=9F=E5=90=8DBUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/electron/package.json | 2 +- apps/electron/src/renderer/src/hooks/index.ts | 18 ------------------ .../src/renderer/src/pages/basic/index.tsx | 15 ++++++++++++--- .../src/renderer/src/pages/setting/index.tsx | 18 ++++++++++++------ 4 files changed, 25 insertions(+), 28 deletions(-) diff --git a/apps/electron/package.json b/apps/electron/package.json index da38926f..5305a490 100644 --- a/apps/electron/package.json +++ b/apps/electron/package.json @@ -1,6 +1,6 @@ { "name": "@rao-pics/electron", - "version": "1.0.0-alpha.12", + "version": "1.0.0-alpha.13", "description": "远程访问 Eagle 素材资源", "homepage": "https://rao.pics", "repository": { diff --git a/apps/electron/src/renderer/src/hooks/index.ts b/apps/electron/src/renderer/src/hooks/index.ts index a4e561cf..29bf1d0c 100644 --- a/apps/electron/src/renderer/src/hooks/index.ts +++ b/apps/electron/src/renderer/src/hooks/index.ts @@ -45,21 +45,3 @@ export function useDebounce(value: string, delay = 500) { return debouncedValue; } - -/** - * 获取站点地址 - * @returns 站点地址 - */ -export function useSite() { - const { data: config } = trpc.config.findUnique.useQuery(); - - if (config) { - if (config.clientSite) { - return config.clientSite; - } - - return `http://${config.ip}:${config.clientPort}`; - } - - return ""; -} diff --git a/apps/electron/src/renderer/src/pages/basic/index.tsx b/apps/electron/src/renderer/src/pages/basic/index.tsx index 34a902d6..4b909a76 100644 --- a/apps/electron/src/renderer/src/pages/basic/index.tsx +++ b/apps/electron/src/renderer/src/pages/basic/index.tsx @@ -1,4 +1,4 @@ -import { useEffect, useState } from "react"; +import { useEffect, useMemo, useState } from "react"; import { ClockIcon, EyeIcon, @@ -8,7 +8,6 @@ import { import Content from "@renderer/components/Content"; import Row from "@renderer/components/Row"; import Title from "@renderer/components/Title"; -import { useSite } from "@renderer/hooks"; import { QRCodeSVG } from "qrcode.react"; import { trpc } from "@rao-pics/trpc"; @@ -47,7 +46,17 @@ const BasicPage = () => { setBtnState(library && library.pendingCount > 0 ? 2 : 1); }, [library, config]); - const site = useSite(); + const site = useMemo(() => { + if (config) { + if (config.clientSite) { + return config.clientSite; + } + + return `http://${config.ip}:${config.clientPort}`; + } + + return ""; + }, [config]); const onBeforeDeleteLibrary = () => { window.dialog diff --git a/apps/electron/src/renderer/src/pages/setting/index.tsx b/apps/electron/src/renderer/src/pages/setting/index.tsx index 4809f194..7e92f9fd 100644 --- a/apps/electron/src/renderer/src/pages/setting/index.tsx +++ b/apps/electron/src/renderer/src/pages/setting/index.tsx @@ -9,7 +9,6 @@ import { } from "@heroicons/react/24/outline"; import Content from "@renderer/components/Content"; import Title from "@renderer/components/Title"; -import { useSite } from "@renderer/hooks"; import { trpc } from "@rao-pics/trpc"; @@ -28,8 +27,6 @@ const SettingPage = () => { const { data: config } = trpc.config.findUnique.useQuery(); - const site = useSite(); - return ( 通用}>
@@ -141,14 +138,23 @@ const SettingPage = () => { } right={ { + const value = e.target.value.trim(); + // 校验域名 + if (value && !/^((https|http)?:\/\/)[^\s]+/.test(value)) { + window.dialog.showErrorBox( + "自定义域名", + "请输入正确的域名", + ); + return; + } configUpsert.mutate({ clientSite: e.target.value, }); }} - className="input-ghost input input-sm w-full !pr-0 text-right font-mono transition-all focus:!pr-4 focus:outline-none" - placeholder="eg: https://desktop.rao.pics" + className="input input-ghost input-sm w-full !pr-0 text-right font-mono transition-all focus:!pr-4 focus:outline-none" + placeholder="输入域名,清空则使用默认值" /> } />