From 1b646df908f79c5e61d401205ba5216e69a13ab2 Mon Sep 17 00:00:00 2001 From: Gabe Date: Sat, 25 Oct 2025 23:18:39 +0800 Subject: [PATCH] feat: Remember the tranbox position and size --- src/config/storage.js | 1 + src/libs/storage.js | 8 ++++++++ src/views/Selection/index.js | 24 ++++++++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/src/config/storage.js b/src/config/storage.js index b5e5227..3920524 100644 --- a/src/config/storage.js +++ b/src/config/storage.js @@ -16,6 +16,7 @@ export const STOKEY_RULES = `${APP_NAME}_rules_v${APP_VERSION[0]}`; export const STOKEY_WORDS = `${APP_NAME}_words`; export const STOKEY_SYNC = `${APP_NAME}_sync`; export const STOKEY_FAB = `${APP_NAME}_fab`; +export const STOKEY_TRANBOX = `${APP_NAME}_tranbox`; export const STOKEY_RULESCACHE_PREFIX = `${APP_NAME}_rulescache_`; export const CACHE_NAME = `${APP_NAME}_cache`; diff --git a/src/libs/storage.js b/src/libs/storage.js index a451b20..62a319e 100644 --- a/src/libs/storage.js +++ b/src/libs/storage.js @@ -5,6 +5,7 @@ import { STOKEY_RULES_OLD, STOKEY_WORDS, STOKEY_FAB, + STOKEY_TRANBOX, STOKEY_SYNC, STOKEY_MSAUTH, STOKEY_BDAUTH, @@ -135,6 +136,13 @@ export const getFabWithDefault = async () => (await getFab()) || {}; export const setFab = (obj) => setObj(STOKEY_FAB, obj); export const putFab = (obj) => putObj(STOKEY_FAB, obj); +/** + * tranbox位置大小 + */ +export const getTranBox = () => getObj(STOKEY_TRANBOX); +export const putTranBox = (obj) => putObj(STOKEY_TRANBOX, obj); +export const debouncePutTranBox = debounce(putTranBox, 300); + /** * 数据同步 */ diff --git a/src/views/Selection/index.js b/src/views/Selection/index.js index b54f827..afe6501 100644 --- a/src/views/Selection/index.js +++ b/src/views/Selection/index.js @@ -15,6 +15,7 @@ import { import { isMobile } from "../../libs/mobile"; import { kissLog } from "../../libs/log"; import { useLangMap } from "../../hooks/I18n"; +import { debouncePutTranBox, getTranBox } from "../../libs/storage"; export default function Slection({ contextMenuType, @@ -107,6 +108,29 @@ export default function Slection({ return "onMouseUp"; }, [triggerMode]); + useEffect(() => { + (async () => { + try { + const { w, h, x, y } = (await getTranBox()) || {}; + if (w !== undefined && h !== undefined) { + setBoxSize({ w, h }); + } + if (x !== undefined && y !== undefined) { + setBoxPosition({ + x: limitNumber(x, 0, window.innerWidth), + y: limitNumber(y, 0, window.innerHeight), + }); + } + } catch (err) { + // + } + })(); + }, []); + + useEffect(() => { + debouncePutTranBox({ ...boxSize, ...boxPosition }); + }, [boxSize, boxPosition]); + useEffect(() => { async function handleMouseup(e) { e.stopPropagation();