tencent.jquery.pix.devtool
v1.0.5
Published
通用调试工具与缓存管理模块,适用于 Gamelet/PixUI 项目
Readme
tencent.jquery.pix.devtool
通用调试工具与缓存管理 npm 包,适用于 Gamelet / PixUI 项目。
特性
- 🛠 悬浮调试面板:可拖拽、可最小化,支持控制台日志拦截、JS 代码执行
- 📦 缓存管理:查看 / 删除 / 清空由
setNoteCacheInfo注册的所有缓存
安装
npm install tencent.jquery.pix.devtoolpeerDependencies:项目中需自行安装
gamelet-pixui-frame和tencent.jquery.pix
快速上手
// 1. 引入样式(在项目入口)
import 'tencent.jquery.pix.devtool/src/devtool.scss';
// 2. 初始化(可选配置)
import { initDevTool } from 'tencent.jquery.pix.devtool';
initDevTool({
proxyConsole: true, // 是否默认拦截 console(默认 true)
});面板 API
| 函数 | 说明 |
|------|------|
| initDevTool(options?) | 初始化面板,接受可选配置项 |
| show(visible?) | 显示或隐藏面板,默认 true |
| toggle() | 切换面板显示状态 |
| enableShortcut() | 注册 Ctrl+Shift+D 快捷键切换面板 |
| log(message) | 向面板控制台输出日志(面板未显示时自动打开) |
initDevTool 配置项
| 参数 | 类型 | 默认值 | 说明 |
|------|------|--------|------|
| proxyConsole | boolean | true | 是否拦截 console.log/warn/error 并显示在面板中 |
| appId | string | "" | app 环境下剪贴板写入所需的 appId |
| appName | string | "" | app 环境下剪贴板写入所需的 appName |
缓存 API
基础读写
import { setNoteCacheInfo, getNoteCacheInfo, clearNoteCacheInfo } from 'tencent.jquery.pix.devtool';
// 写入
setNoteCacheInfo('myKey', { foo: 'bar' });
// 读取
const val = await getNoteCacheInfo('myKey');
// 删除
await clearNoteCacheInfo('myKey');批量操作
import { clearAllNoteCacheInfo, clearMultipleNoteCacheInfo } from 'tencent.jquery.pix.devtool';
// 清空所有已注册的缓存
const count = await clearAllNoteCacheInfo();
// 清空指定前缀的缓存
await clearAllNoteCacheInfo('user_');
// 批量删除指定 key
const result = await clearMultipleNoteCacheInfo(['key1', 'key2']);
// result: { success: 2, failed: 0 }带过期时间的读写
import {
setNoteCacheInfoWithHours,
setNoteCacheInfoWithDays,
getNoteCacheInfoWithExpire,
clearExpiredNoteCacheInfo,
} from 'tencent.jquery.pix.devtool';
// 写入 2 小时后过期
setNoteCacheInfoWithHours('myKey', data, 2);
// 写入 3 天后过期(支持 0.5 表示半天)
setNoteCacheInfoWithDays('myKey', data, 3);
// 读取(自动处理过期,过期返回 null)
const val = await getNoteCacheInfoWithExpire('myKey');
// 清除一批 key 中已过期的缓存
const cleared = await clearExpiredNoteCacheInfo(['key1', 'key2']);Key 注册表
import { registerCacheKeys, getAllRegisteredCacheKeys, removeCacheKeys } from 'tencent.jquery.pix.devtool';
// 手动注册历史遗留的 key(使其出现在面板缓存列表中)
registerCacheKeys(['legacyKey1', 'legacyKey2']);
// 获取所有已注册的 key
const keys = getAllRegisteredCacheKeys();
// 从注册表中移除(不删除实际缓存数据)
removeCacheKeys(['legacyKey1']);通过
setNoteCacheInfo写入的 key 会自动注册,无需手动调用registerCacheKeys。
环境说明
| 环境 | 缓存底层 |
|------|---------|
| app(jssdk-appwindow / preprocessor) | GameletAPI.readCookie / writeCookie |
| 浏览器 / 模拟器 | sessionStorage |
开发技术细节请参阅 DEVELOPMENT.md
