From c5d1f11017c2f81210f4ddf97cdaa221e463bee7 Mon Sep 17 00:00:00 2001 From: CrescentLeaf Date: Sat, 6 Sep 2025 14:32:56 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E9=80=9A=E9=81=8E=20ESM=20=E5=BC=95?= =?UTF-8?q?=E5=85=A5=E5=A4=96=E9=83=A8=E8=84=9A=E6=9C=AC=20*=20React,=20Re?= =?UTF-8?q?actDOM=20=E5=92=8C=20CryptoES=20*=20=E9=9B=86=E4=B8=AD=E5=9C=A8?= =?UTF-8?q?=20Imports.ts=20=E4=B8=AD=20*=20=E5=90=91=E6=AF=8F=E4=B8=80?= =?UTF-8?q?=E5=80=8B=20JSX=20=E6=B7=BB=E5=8A=A0=20React=20=E7=9A=84=20impo?= =?UTF-8?q?rt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/Data.ts | 6 +- client/Imports.ts | 9 ++ client/ui/App.jsx | 127 +++++++++++++++------------- client/ui/Avatar.jsx | 2 + client/ui/chat/ChatFragment.jsx | 8 +- client/ui/chat/Message.jsx | 2 + client/ui/chat/MessageContainer.jsx | 2 + client/ui/chat/SystemMessage.jsx | 2 + client/ui/dialog/LoginDialog.jsx | 6 +- client/ui/main/ContactsListItem.jsx | 2 + client/ui/main/RecentsListItem.jsx | 2 + client/ui/snackbar.js | 2 +- client/ui/useEventListener.js | 2 + 13 files changed, 104 insertions(+), 68 deletions(-) create mode 100644 client/Imports.ts diff --git a/client/Data.ts b/client/Data.ts index dcef42e..17ed9a3 100644 --- a/client/Data.ts +++ b/client/Data.ts @@ -1,8 +1,10 @@ +import { CryptoES } from './Imports.ts' + const dataIsEmpty = !localStorage.tws_data || localStorage.tws_data == '' const aes = { - enc: (m: string, k: string) => CryptoJS.AES.encrypt(m, k).toString(), - dec: (m: string, k: string) => CryptoJS.AES.decrypt(m, k).toString(CryptoJS.enc.Utf8), + enc: (m: string, k: string) => CryptoES.AES.encrypt(m, k).toString(CryptoES.enc.Utf8), + dec: (m: string, k: string) => CryptoES.AES.decrypt(m, k).toString(CryptoES.enc.Utf8), } const key = location.host + '_TWS_姐姐' diff --git a/client/Imports.ts b/client/Imports.ts new file mode 100644 index 0000000..48847a1 --- /dev/null +++ b/client/Imports.ts @@ -0,0 +1,9 @@ +import * as React from 'https://esm.sh/react@18.3.1' +import * as ReactDOM from 'https://esm.sh/react-dom@18.3.1' +import CryptoES from 'https://unpkg.com/crypto-es@3.0.4/dist/index.mjs' + +export { + React, + ReactDOM, + CryptoES, +} diff --git a/client/ui/App.jsx b/client/ui/App.jsx index d75624b..3ad18b0 100644 --- a/client/ui/App.jsx +++ b/client/ui/App.jsx @@ -1,12 +1,14 @@ -import Client from "../api/Client.ts"; -import data from "../Data.ts"; +import Client from "../api/Client.ts" +import data from "../Data.ts" import ChatFragment from "./chat/ChatFragment.jsx" import LoginDialog from "./dialog/LoginDialog.jsx" import ContactsListItem from "./main/ContactsListItem.jsx" import RecentsListItem from "./main/RecentsListItem.jsx" -import snackbar from "./snackbar.js"; +import snackbar from "./snackbar.js" import useEventListener from './useEventListener.js' +import { React } from '../Imports.ts' + export default function App() { const [recentsList, setRecentsList] = React.useState([ /* { @@ -51,16 +53,19 @@ export default function App() { loginButtonRef ] = [React.useRef(null), React.useRef(null), React.useRef(null), React.useRef(null), React.useRef(null)] - React.useEffect(async () => { - Client.connect() - const re = await Client.invoke("User.auth", { - access_token: data.access_token, - }) - if (re.code == 401) - loginDialogRef.current.show() - else if (re.code != 200) - snackbar("驗證失敗: " + re.msg) - }) + React.useEffect(() => { + ; (async () => { + Client.connect() + const re = await Client.invoke("User.auth", { + access_token: data.access_token, + }) + if (re.code == 401) + loginDialogRef.current.show() + else if (re.code != 200) + snackbar("驗證失敗: " + re.msg) + })() + return () => { } + }, []) return (
- { - recentsList.map((v) => - - ) - } - - } - { - // 联系人列表 - - + { // 分割线 } -
-
+
*/} { // 聊天页面 } - + ) } \ No newline at end of file diff --git a/client/ui/Avatar.jsx b/client/ui/Avatar.jsx index 619410b..3913857 100644 --- a/client/ui/Avatar.jsx +++ b/client/ui/Avatar.jsx @@ -1,3 +1,5 @@ +import { React } from '../Imports.ts' + export default function Avatar({ src, text, icon = 'person', ...props } = {}) { return ( src ? diff --git a/client/ui/chat/ChatFragment.jsx b/client/ui/chat/ChatFragment.jsx index 15b1ee7..2dd7fd6 100644 --- a/client/ui/chat/ChatFragment.jsx +++ b/client/ui/chat/ChatFragment.jsx @@ -1,7 +1,9 @@ import Message from "./Message.jsx" import MessageContainer from "./MessageContainer.jsx" -export default function ChatFragment() { +import { React } from '../../Imports.ts' + +export default function ChatFragment({ ...props } = {}) { return (
+ }} {...props}> @@ -48,7 +50,7 @@ export default function ChatFragment() { bottom: '0', backgroundColor: 'rgb(var(--mdui-color-background))', }}> - +