vite-uni-dev-tool 1.0.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +54 -0
- package/dist/const.cjs +1 -1
- package/dist/const.d.ts +13 -0
- package/dist/const.d.ts.map +1 -1
- package/dist/const.js +1 -1
- package/dist/core-shared.d.ts +1 -1
- package/dist/core-shared.d.ts.map +1 -1
- package/dist/core-shared.js +1 -1
- package/dist/core.d.ts +10 -3
- package/dist/core.d.ts.map +1 -1
- package/dist/core.js +2 -2
- package/dist/i18n/locales/en.cjs +1 -1
- package/dist/i18n/locales/en.d.ts +86 -0
- package/dist/i18n/locales/en.d.ts.map +1 -1
- package/dist/i18n/locales/en.js +1 -1
- package/dist/i18n/locales/zh-Hans.cjs +1 -1
- package/dist/i18n/locales/zh-Hans.d.ts +87 -1
- package/dist/i18n/locales/zh-Hans.d.ts.map +1 -1
- package/dist/i18n/locales/zh-Hans.js +1 -1
- package/dist/modules/devConsole/index.cjs +1 -1
- package/dist/modules/devConsole/index.js +3 -3
- package/dist/modules/devEvent/index.cjs +3 -3
- package/dist/modules/devEvent/index.d.ts +1 -0
- package/dist/modules/devEvent/index.d.ts.map +1 -1
- package/dist/modules/devEvent/index.js +3 -3
- package/dist/modules/devIntercept/index.cjs +14 -13
- package/dist/modules/devIntercept/index.d.ts +20 -1
- package/dist/modules/devIntercept/index.d.ts.map +1 -1
- package/dist/modules/devIntercept/index.js +14 -13
- package/dist/modules/devStore/index.cjs +1 -1
- package/dist/modules/devStore/index.d.ts +21 -0
- package/dist/modules/devStore/index.d.ts.map +1 -1
- package/dist/modules/devStore/index.js +1 -1
- package/dist/plugins/uniDevTool/transform/transformMain.cjs +3 -3
- package/dist/plugins/uniDevTool/transform/transformMain.d.ts +2 -1
- package/dist/plugins/uniDevTool/transform/transformMain.d.ts.map +1 -1
- package/dist/plugins/uniDevTool/transform/transformMain.js +3 -3
- package/dist/plugins/uniDevTool/transform/transformVue.cjs +31 -25
- package/dist/plugins/uniDevTool/transform/transformVue.d.ts +2 -1
- package/dist/plugins/uniDevTool/transform/transformVue.d.ts.map +1 -1
- package/dist/plugins/uniDevTool/transform/transformVue.js +30 -24
- package/dist/plugins/uniDevTool/uniDevTool.cjs +3 -3
- package/dist/plugins/uniDevTool/uniDevTool.d.ts +3 -1
- package/dist/plugins/uniDevTool/uniDevTool.d.ts.map +1 -1
- package/dist/plugins/uniDevTool/uniDevTool.js +3 -3
- package/dist/type.d.ts +50 -2
- package/dist/type.d.ts.map +1 -1
- package/dist/utils/language.cjs +1 -1
- package/dist/utils/language.d.ts.map +1 -1
- package/dist/utils/language.js +1 -1
- package/dist/utils/object.cjs +1 -1
- package/dist/utils/object.d.ts.map +1 -1
- package/dist/utils/object.js +1 -1
- package/dist/v3/DevTool/components/BluetoothList/BluetoothItem.vue +199 -0
- package/dist/v3/DevTool/components/BluetoothList/BluetoothTool.vue +730 -0
- package/dist/v3/DevTool/components/BluetoothList/index.vue +167 -0
- package/dist/v3/{CaptureScreen → DevTool/components/CaptureScreen}/index.vue +4 -4
- package/dist/v3/{ConsoleList → DevTool/components/ConsoleList}/ConsoleItem.vue +22 -16
- package/dist/v3/{ConsoleList → DevTool/components/ConsoleList}/RunJSInput.vue +4 -6
- package/dist/v3/{ConsoleList → DevTool/components/ConsoleList}/index.vue +21 -10
- package/dist/v3/{DevToolButton → DevTool/components/DevToolButton}/index.vue +7 -4
- package/dist/v3/{DevToolWindow → DevTool/components/DevToolWindow}/DevToolOverlay.vue +17 -2
- package/dist/v3/{DevToolWindow → DevTool/components/DevToolWindow}/const.ts +28 -5
- package/dist/v3/{DevToolWindow → DevTool/components/DevToolWindow}/hooks/dataUtils.ts +1 -1
- package/dist/v3/{DevToolWindow → DevTool/components/DevToolWindow}/hooks/useDevToolData.ts +55 -6
- package/dist/v3/{DevToolWindow → DevTool/components/DevToolWindow}/hooks/useDevToolHandlers.ts +85 -5
- package/dist/v3/{DevToolWindow → DevTool/components/DevToolWindow}/hooks/useDevToolOverlay.ts +25 -8
- package/dist/v3/{DevToolWindow → DevTool/components/DevToolWindow}/index.vue +67 -16
- package/dist/v3/{ElEvent → DevTool/components/ElEvent}/ElEventItem.vue +3 -3
- package/dist/v3/{ElEvent → DevTool/components/ElEvent}/index.vue +10 -13
- package/dist/v3/{Instance → DevTool/components/Instance}/index.vue +1 -1
- package/dist/v3/{Instance → DevTool/components/Instance}/transformTree.ts +1 -1
- package/dist/v3/{Instance → DevTool/components/Instance}/transformTreeCtx.ts +1 -1
- package/dist/v3/{InstanceDetail → DevTool/components/InstanceDetail}/index.vue +4 -4
- package/dist/v3/{JsonDetail → DevTool/components/JsonDetail}/index.vue +4 -4
- package/dist/v3/{NFCList → DevTool/components/NFCList}/NFCItem.vue +4 -5
- package/dist/v3/{NFCList → DevTool/components/NFCList}/NFCTool.vue +33 -57
- package/dist/v3/{NFCList → DevTool/components/NFCList}/index.vue +12 -16
- package/dist/v3/{NetworkList → DevTool/components/NetworkList}/InterceptConfig.vue +20 -4
- package/dist/v3/{NetworkList → DevTool/components/NetworkList}/InterceptItem.vue +3 -3
- package/dist/v3/{NetworkList → DevTool/components/NetworkList}/NetworkDetail.vue +18 -27
- package/dist/v3/{NetworkList → DevTool/components/NetworkList}/NetworkIntercept.vue +11 -16
- package/dist/v3/{NetworkList → DevTool/components/NetworkList}/NetworkItem.vue +10 -14
- package/dist/v3/{NetworkList → DevTool/components/NetworkList}/NetworkSend.vue +67 -34
- package/dist/v3/{NetworkList → DevTool/components/NetworkList}/index.vue +8 -8
- package/dist/v3/{Performance → DevTool/components/Performance}/index.vue +7 -4
- package/dist/v3/{Performance → DevTool/components/Performance}/modules/PerformanceWidget.vue +12 -9
- package/dist/v3/{Performance → DevTool/components/Performance}/modules/usePerformanceChart.ts +1 -1
- package/dist/v3/{Performance → DevTool/components/Performance}/modules/usePerformanceData.ts +2 -2
- package/dist/v3/{PiniaList → DevTool/components/PiniaList}/index.vue +5 -6
- package/dist/v3/{RouteList → DevTool/components/RouteList}/index.vue +21 -24
- package/dist/v3/{RunJS → DevTool/components/RunJS}/index.vue +3 -3
- package/dist/v3/{ScanCodeList → DevTool/components/ScanCodeList}/ScanCodeItem.vue +3 -4
- package/dist/v3/{ScanCodeList → DevTool/components/ScanCodeList}/index.vue +12 -16
- package/dist/v3/{SettingList → DevTool/components/SettingList}/index.vue +68 -0
- package/dist/v3/DevTool/components/SettingList/modules/SettingBarrage.vue +304 -0
- package/dist/v3/{SettingList → DevTool/components/SettingList}/modules/SettingDevTool.vue +8 -4
- package/dist/v3/{SettingList → DevTool/components/SettingList}/modules/SettingInfo.vue +47 -9
- package/dist/v3/{SettingList → DevTool/components/SettingList}/modules/SettingLanguage.vue +2 -2
- package/dist/v3/{SettingList → DevTool/components/SettingList}/modules/SettingLog.vue +2 -2
- package/dist/v3/{SettingList → DevTool/components/SettingList}/modules/SettingNetwork.vue +3 -3
- package/dist/v3/{SettingList → DevTool/components/SettingList}/modules/SettingTheme.vue +37 -7
- package/dist/v3/{SourceCode → DevTool/components/SourceCode}/Line.vue +22 -11
- package/dist/v3/{SourceCode → DevTool/components/SourceCode}/index.vue +8 -8
- package/dist/v3/{SourceCode → DevTool/components/SourceCode}/parseCode.ts +136 -228
- package/dist/v3/{StorageList → DevTool/components/StorageList}/index.vue +7 -7
- package/dist/v3/{TransferList → DevTool/components/TransferList}/TransferDetail.vue +6 -6
- package/dist/v3/{TransferList → DevTool/components/TransferList}/TransferItem.vue +4 -4
- package/dist/v3/{TransferList → DevTool/components/TransferList}/index.vue +8 -8
- package/dist/v3/{UniEvent → DevTool/components/UniEvent}/UniEventItem.vue +6 -7
- package/dist/v3/{UniEvent → DevTool/components/UniEvent}/index.vue +6 -6
- package/dist/v3/{VuexList → DevTool/components/VuexList}/index.vue +3 -3
- package/dist/v3/{WebSocket → DevTool/components/WebSocket}/WebSocketDetail.vue +8 -8
- package/dist/v3/{WebSocket → DevTool/components/WebSocket}/WebSocketItem.vue +4 -4
- package/dist/v3/{WebSocket → DevTool/components/WebSocket}/index.vue +8 -8
- package/dist/v3/DevTool/index.vue +179 -4
- package/dist/v3/{AppTransition → components/AppTransition}/index.vue +6 -0
- package/dist/v3/components/Barrage/BarrageItem.vue +137 -0
- package/dist/v3/components/Barrage/index.vue +202 -0
- package/dist/v3/components/DevErrorBoundary/index.vue +380 -0
- package/dist/v3/{DraggableContainer → components/DraggableContainer}/index.vue +1 -1
- package/dist/v3/{FilterInput → components/FilterInput}/index.vue +1 -1
- package/dist/v3/{JsonPretty → components/JsonPretty}/components/CheckController/index.vue +1 -1
- package/dist/v3/{JsonPretty → components/JsonPretty}/components/TreeNode/index.vue +11 -5
- package/dist/v3/{JsonPretty → components/JsonPretty}/index.vue +16 -13
- package/dist/v3/{JsonPretty → components/JsonPretty}/type.ts +1 -0
- package/dist/v3/{JsonPretty → components/JsonPretty}/utils/index.ts +1 -1
- package/dist/v3/{MovableContainer → components/MovableContainer}/index.vue +9 -5
- package/dist/v3/{Pick → components/Pick}/index.vue +1 -1
- package/dist/v3/{Tabs → components/Tabs}/index.vue +30 -4
- package/dist/v3/{VirtualList → components/VirtualList}/AutoSize.vue +1 -1
- package/dist/v3/{VirtualList → components/VirtualList}/index.vue +4 -0
- package/dist/v3/hooks/useBluetooth/index.ts +561 -0
- package/dist/v3/hooks/useRequest/index.ts +33 -20
- package/dist/v3/hooks/useWebsocket/README.md +79 -0
- package/dist/v3/hooks/useWebsocket/index.ts +253 -0
- package/dist/v3/styles/theme.css +17 -10
- package/package.json +67 -64
- package/dist/plugins/uniParseStock/index.d.ts +0 -10
- package/dist/plugins/uniParseStock/index.d.ts.map +0 -1
- /package/dist/v3/{ConsoleList → DevTool/components/ConsoleList}/staticTips.ts +0 -0
- /package/dist/v3/{DevToolTitle → DevTool/components/DevToolTitle}/index.vue +0 -0
- /package/dist/v3/{DevToolWindow → DevTool/components/DevToolWindow}/index.css +0 -0
- /package/dist/v3/{Instance → DevTool/components/Instance}/components/InstanceTreeNode.vue +0 -0
- /package/dist/v3/{Instance → DevTool/components/Instance}/flatten.ts +0 -0
- /package/dist/v3/{Instance → DevTool/components/Instance}/registry.ts +0 -0
- /package/dist/v3/{Instance → DevTool/components/Instance}/typing.d.ts +0 -0
- /package/dist/v3/{NFCList → DevTool/components/NFCList}/const.ts +0 -0
- /package/dist/v3/{NetworkList → DevTool/components/NetworkList}/const.ts +0 -0
- /package/dist/v3/{NetworkList → DevTool/components/NetworkList}/hooks/useNetworkForm.ts +0 -0
- /package/dist/v3/{NetworkList → DevTool/components/NetworkList}/utils.ts +0 -0
- /package/dist/v3/{Performance → DevTool/components/Performance}/modules/PerformanceMetrics.vue +0 -0
- /package/dist/v3/{SettingButton → DevTool/components/SettingButton}/index.vue +0 -0
- /package/dist/v3/{SettingList → DevTool/components/SettingList}/index.css +0 -0
- /package/dist/v3/{SettingList → DevTool/components/SettingList}/typing.d.ts +0 -0
- /package/dist/v3/{AutoSizer → components/AutoSizer}/index.vue +0 -0
- /package/dist/v3/{AutoSizer → components/AutoSizer}/index1.vue +0 -0
- /package/dist/v3/{AutoSizer → components/AutoSizer}/utils.ts +0 -0
- /package/dist/v3/{CircularButton → components/CircularButton}/index.vue +0 -0
- /package/dist/v3/{CustomSwiper → components/CustomSwiper}/CustomSwiperItem.vue +0 -0
- /package/dist/v3/{CustomSwiper → components/CustomSwiper}/index.vue +0 -0
- /package/dist/v3/{Empty → components/Empty}/empty.png +0 -0
- /package/dist/v3/{Empty → components/Empty}/index.vue +0 -0
- /package/dist/v3/{FilterSelect → components/FilterSelect}/index.vue +0 -0
- /package/dist/v3/{JsonPretty → components/JsonPretty}/components/Brackets/index.vue +0 -0
- /package/dist/v3/{JsonPretty → components/JsonPretty}/components/Carets/index.vue +0 -0
- /package/dist/v3/{JsonPretty → components/JsonPretty}/hooks/useClipboard.ts +0 -0
- /package/dist/v3/{JsonPretty → components/JsonPretty}/hooks/useError.ts +0 -0
- /package/dist/v3/{Tag → components/Tag}/index.vue +0 -0
- /package/dist/v3/{VirtualList → components/VirtualList}/readme.md +0 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# useWebsocket
|
|
2
|
+
|
|
3
|
+
一个用于在 uni-app 中处理 WebSocket 的 Vue 3 Hook,设计模式参考了 [ahooks useWebSocket](https://ahooks.js.org/zh-CN/hooks/use-web-socket)。
|
|
4
|
+
|
|
5
|
+
## 作用
|
|
6
|
+
|
|
7
|
+
- **简化连接管理**:封装了 `uni.connectSocket`,自动管理 `SocketTask` 任务的创建与清理。
|
|
8
|
+
- **响应式状态**:通过 Vue 3 的 `ref` 提供连接状态 (`readyState`) 和最新消息 (`latestMessage`)。
|
|
9
|
+
- **自动重连**:内置重连逻辑,当连接因非人为原因(如网络抖动)断开时,支持配置重连次数和间隔。
|
|
10
|
+
- **心跳机制**:支持配置自动心跳包发送,保持长连接活跃,防止被服务器超时剔除。
|
|
11
|
+
- **生命周期集成**:在组件卸载 (`onUnmounted`) 时自动关闭连接,避免内存泄漏和异常监听。
|
|
12
|
+
- **手动控制**:既支持初始自动连接,也支持手动调用 `connect()` 或 `disconnect()`。
|
|
13
|
+
|
|
14
|
+
## 参数
|
|
15
|
+
|
|
16
|
+
```typescript
|
|
17
|
+
const { ... } = useWebsocket(url, options);
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
### Options
|
|
21
|
+
|
|
22
|
+
| 参数 | 说明 | 类型 | 默认值 |
|
|
23
|
+
| ----------------- | ----------------- | ----------------------- | -------- |
|
|
24
|
+
| reconnectLimit | 重连次数限制 | `number` | `3` |
|
|
25
|
+
| reconnectInterval | 重连时间间隔 (ms) | `number` | `3000` |
|
|
26
|
+
| heartbeat | 是否开启心跳检查 | `boolean` | `false` |
|
|
27
|
+
| heartbeatInterval | 心跳检查间隔 (ms) | `number` | `30000` |
|
|
28
|
+
| heartbeatMessage | 心跳发送的内容 | `string \| ArrayBuffer` | `'ping'` |
|
|
29
|
+
| manual | 是否手动控制连接 | `boolean` | `false` |
|
|
30
|
+
| protocols | WebSocket 子协议 | `string[]` | - |
|
|
31
|
+
| onOpen | 连接开启的回调 | `(task, res) => void` | - |
|
|
32
|
+
| onClose | 连接关闭的回调 | `(res) => void` | - |
|
|
33
|
+
| onMessage | 收到消息的回调 | `(res) => void` | - |
|
|
34
|
+
| onError | 连接错误的回调 | `(res) => void` | - |
|
|
35
|
+
|
|
36
|
+
## 返回值
|
|
37
|
+
|
|
38
|
+
| 属性 | 说明 | 类型 |
|
|
39
|
+
| ------------- | ---------------------- | --------------------------------------- |
|
|
40
|
+
| latestMessage | 最近收到的一条消息内容 | `Ref<OnSocketMessageCallbackResult>` |
|
|
41
|
+
| readyState | 当前连接状态 | `Ref<ReadyState>` |
|
|
42
|
+
| connect | 手动连接方法 | `() => void` |
|
|
43
|
+
| disconnect | 手动断开方法 | `() => void` |
|
|
44
|
+
| sendMessage | 发送消息方法 | `(data: string \| ArrayBuffer) => void` |
|
|
45
|
+
|
|
46
|
+
## 状态定义 (ReadyState)
|
|
47
|
+
|
|
48
|
+
- `0`: `Connecting` (连接中)
|
|
49
|
+
- `1`: `Open` (已连接)
|
|
50
|
+
- `2`: `Closing` (关闭中)
|
|
51
|
+
- `3`: `Closed` (已关闭)
|
|
52
|
+
|
|
53
|
+
## 使用示例
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
import useWebsocket, { ReadyState } from '../hooks/useWebsocket';
|
|
57
|
+
|
|
58
|
+
const { readyState, latestMessage, sendMessage, connect, disconnect } =
|
|
59
|
+
useWebsocket('wss://echo.websocket.org', {
|
|
60
|
+
reconnectLimit: 5,
|
|
61
|
+
heartbeat: true, // 开启心跳
|
|
62
|
+
heartbeatInterval: 30000,
|
|
63
|
+
heartbeatMessage: JSON.stringify({ type: 'ping' }),
|
|
64
|
+
onOpen: () => {
|
|
65
|
+
console.log('连接已开启');
|
|
66
|
+
},
|
|
67
|
+
onMessage: (res) => {
|
|
68
|
+
console.log('收到消息:', res.data);
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// 计算属性:判断是否在线
|
|
73
|
+
const isOnline = computed(() => readyState.value === ReadyState.Open);
|
|
74
|
+
|
|
75
|
+
// 发送数据
|
|
76
|
+
const send = () => {
|
|
77
|
+
sendMessage('Hello Antigravity!');
|
|
78
|
+
};
|
|
79
|
+
```
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import { ref, onUnmounted, type Ref } from 'vue';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* WebSocket 连接状态枚举
|
|
5
|
+
*/
|
|
6
|
+
export enum ReadyState {
|
|
7
|
+
Connecting = 0, // 连接中
|
|
8
|
+
Open = 1, // 已连接
|
|
9
|
+
Closing = 2, // 关闭中
|
|
10
|
+
Closed = 3, // 已关闭
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* useWebsocket 配置参数
|
|
15
|
+
*/
|
|
16
|
+
export interface Options {
|
|
17
|
+
/** 重连尝试次数限制,默认为 3 */
|
|
18
|
+
reconnectLimit?: number;
|
|
19
|
+
/** 重连时间间隔 (ms),默认为 3000 */
|
|
20
|
+
reconnectInterval?: number;
|
|
21
|
+
/** 是否开启心跳检查,默认为 false */
|
|
22
|
+
heartbeat?: boolean;
|
|
23
|
+
/** 心跳检查间隔 (ms),默认为 30000 */
|
|
24
|
+
heartbeatInterval?: number;
|
|
25
|
+
/** 心跳发送的内容,默认为 'ping' */
|
|
26
|
+
heartbeatMessage?: string | ArrayBuffer;
|
|
27
|
+
/** 是否手动控制连接,为 true 时需手动调用 connect(),默认为 false */
|
|
28
|
+
manual?: boolean;
|
|
29
|
+
/** 连接开启时的回调 */
|
|
30
|
+
onOpen?: (
|
|
31
|
+
instance: UniApp.SocketTask,
|
|
32
|
+
res: UniApp.OnSocketOpenCallbackResult,
|
|
33
|
+
) => void;
|
|
34
|
+
/** 连接关闭时的回调 */
|
|
35
|
+
onClose?: (event: UniApp.OnSocketCloseOptions) => void;
|
|
36
|
+
/** 收到消息时的回调 */
|
|
37
|
+
onMessage?: (message: UniApp.OnSocketMessageCallbackResult) => void;
|
|
38
|
+
/** 连接发生错误时的回调 */
|
|
39
|
+
onError?: (event: UniApp.GeneralCallbackResult) => void;
|
|
40
|
+
/** WebSocket 子协议 */
|
|
41
|
+
protocols?: string[];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* useWebsocket 返回结果
|
|
46
|
+
*/
|
|
47
|
+
export interface Result {
|
|
48
|
+
/** 最近收到的一条消息 */
|
|
49
|
+
latestMessage: Ref<UniApp.OnSocketMessageCallbackResult | undefined>;
|
|
50
|
+
/** 当前连接状态 */
|
|
51
|
+
readyState: Ref<ReadyState>;
|
|
52
|
+
/** 手动连接方法 */
|
|
53
|
+
connect: () => void;
|
|
54
|
+
/** 手动断开方法 */
|
|
55
|
+
disconnect: () => void;
|
|
56
|
+
/** 发送消息方法 */
|
|
57
|
+
sendMessage: (data: string | ArrayBuffer) => void;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* 封装 uni.connectSocket 的 hook,参考 ahooks useWebSocket
|
|
62
|
+
*
|
|
63
|
+
* @param url WebSocket 地址
|
|
64
|
+
* @param options 配置项
|
|
65
|
+
*/
|
|
66
|
+
const useWebsocket = (url: string, options: Options = {}): Result => {
|
|
67
|
+
const {
|
|
68
|
+
reconnectLimit = 3,
|
|
69
|
+
reconnectInterval = 3000,
|
|
70
|
+
heartbeat = false,
|
|
71
|
+
heartbeatInterval = 30000,
|
|
72
|
+
heartbeatMessage = 'ping',
|
|
73
|
+
manual = false,
|
|
74
|
+
onOpen,
|
|
75
|
+
onClose,
|
|
76
|
+
onMessage,
|
|
77
|
+
onError,
|
|
78
|
+
protocols,
|
|
79
|
+
} = options;
|
|
80
|
+
|
|
81
|
+
// 状态定义
|
|
82
|
+
const readyState = ref<ReadyState>(ReadyState.Closed);
|
|
83
|
+
const latestMessage = ref<UniApp.OnSocketMessageCallbackResult>();
|
|
84
|
+
const socketTask = ref<UniApp.SocketTask | null>(null);
|
|
85
|
+
|
|
86
|
+
// 内部辅助变量
|
|
87
|
+
let reconnectCount = 0;
|
|
88
|
+
let reconnectTimer: any = null;
|
|
89
|
+
let heartbeatTimer: any = null;
|
|
90
|
+
let isManualClose = false;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* 清除心跳定时器
|
|
94
|
+
*/
|
|
95
|
+
const clearHeartbeat = () => {
|
|
96
|
+
if (heartbeatTimer) {
|
|
97
|
+
clearInterval(heartbeatTimer);
|
|
98
|
+
heartbeatTimer = null;
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* 开始心跳
|
|
104
|
+
*/
|
|
105
|
+
const startHeartbeat = () => {
|
|
106
|
+
if (!heartbeat) return;
|
|
107
|
+
clearHeartbeat();
|
|
108
|
+
heartbeatTimer = setInterval(() => {
|
|
109
|
+
if (readyState.value === ReadyState.Open && socketTask.value) {
|
|
110
|
+
// console.log('[useWebsocket] Heartbeat Ping');
|
|
111
|
+
socketTask.value.send({
|
|
112
|
+
data: heartbeatMessage,
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}, heartbeatInterval);
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* 执行连接逻辑
|
|
120
|
+
*/
|
|
121
|
+
const connect = () => {
|
|
122
|
+
// 如果有正在等待的重连,先清除
|
|
123
|
+
if (reconnectTimer) {
|
|
124
|
+
clearTimeout(reconnectTimer);
|
|
125
|
+
reconnectTimer = null;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// 清理旧的心跳
|
|
129
|
+
clearHeartbeat();
|
|
130
|
+
|
|
131
|
+
// 如果当前已有任务,先尝试关闭
|
|
132
|
+
if (socketTask.value) {
|
|
133
|
+
socketTask.value.close({});
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
readyState.value = ReadyState.Connecting;
|
|
137
|
+
isManualClose = false;
|
|
138
|
+
|
|
139
|
+
// 创建 Uni Socket 任务
|
|
140
|
+
const task = uni.connectSocket({
|
|
141
|
+
url,
|
|
142
|
+
protocols,
|
|
143
|
+
complete: () => {},
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
socketTask.value = task;
|
|
147
|
+
|
|
148
|
+
// 监听开启事件
|
|
149
|
+
task.onOpen((res) => {
|
|
150
|
+
readyState.value = ReadyState.Open;
|
|
151
|
+
reconnectCount = 0; // 重连计数归零
|
|
152
|
+
startHeartbeat(); // 开始心跳
|
|
153
|
+
onOpen?.(task, res);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
// 监听消息事件
|
|
157
|
+
task.onMessage((res) => {
|
|
158
|
+
latestMessage.value = res;
|
|
159
|
+
onMessage?.(res);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
// 监听错误事件
|
|
163
|
+
task.onError((res) => {
|
|
164
|
+
readyState.value = ReadyState.Closed;
|
|
165
|
+
clearHeartbeat();
|
|
166
|
+
onError?.(res);
|
|
167
|
+
|
|
168
|
+
// 只有非手动关闭才会尝试重连
|
|
169
|
+
if (!isManualClose) {
|
|
170
|
+
reconnect();
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
// 监听关闭事件
|
|
175
|
+
task.onClose((res) => {
|
|
176
|
+
readyState.value = ReadyState.Closed;
|
|
177
|
+
clearHeartbeat();
|
|
178
|
+
onClose?.(res);
|
|
179
|
+
|
|
180
|
+
// 如果非用户手动关闭,尝试重连
|
|
181
|
+
if (!isManualClose) {
|
|
182
|
+
reconnect();
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* 重连逻辑
|
|
189
|
+
*/
|
|
190
|
+
const reconnect = () => {
|
|
191
|
+
if (reconnectCount < reconnectLimit && !isManualClose) {
|
|
192
|
+
reconnectTimer = setTimeout(() => {
|
|
193
|
+
reconnectCount++;
|
|
194
|
+
connect();
|
|
195
|
+
}, reconnectInterval);
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* 断开连接
|
|
201
|
+
*/
|
|
202
|
+
const disconnect = () => {
|
|
203
|
+
isManualClose = true;
|
|
204
|
+
reconnectCount = reconnectLimit; // 标记停止重连循环
|
|
205
|
+
clearHeartbeat();
|
|
206
|
+
if (reconnectTimer) {
|
|
207
|
+
clearTimeout(reconnectTimer);
|
|
208
|
+
reconnectTimer = null;
|
|
209
|
+
}
|
|
210
|
+
if (socketTask.value) {
|
|
211
|
+
socketTask.value.close({});
|
|
212
|
+
socketTask.value = null;
|
|
213
|
+
}
|
|
214
|
+
readyState.value = ReadyState.Closed;
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* 发送消息
|
|
219
|
+
* @param data 字符串或二进制数据
|
|
220
|
+
*/
|
|
221
|
+
const sendMessage = (data: string | ArrayBuffer) => {
|
|
222
|
+
if (readyState.value === ReadyState.Open && socketTask.value) {
|
|
223
|
+
socketTask.value.send({
|
|
224
|
+
data,
|
|
225
|
+
});
|
|
226
|
+
} else {
|
|
227
|
+
console.error(
|
|
228
|
+
'[useWebsocket] WebSocket is not open. Current state:',
|
|
229
|
+
readyState.value,
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
// 默认自动开始连接
|
|
235
|
+
if (!manual) {
|
|
236
|
+
connect();
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// 组件卸载时自动清理
|
|
240
|
+
onUnmounted(() => {
|
|
241
|
+
disconnect();
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
return {
|
|
245
|
+
latestMessage,
|
|
246
|
+
readyState,
|
|
247
|
+
connect,
|
|
248
|
+
disconnect,
|
|
249
|
+
sendMessage,
|
|
250
|
+
};
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
export default useWebsocket;
|
package/dist/v3/styles/theme.css
CHANGED
|
@@ -3,15 +3,20 @@
|
|
|
3
3
|
.dev-tool {
|
|
4
4
|
/* Generic Colors */
|
|
5
5
|
--dev-tool-main-color: #9254de;
|
|
6
|
+
--dev-tool-main-color-rgb: 146, 84, 222;
|
|
6
7
|
--dev-tool-warn-color: #ffa940;
|
|
7
8
|
--dev-tool-error-color: #ff4d4f;
|
|
8
9
|
--dev-tool-success-color: #bae637;
|
|
9
|
-
|
|
10
|
+
|
|
10
11
|
/* Shared Base Tokens */
|
|
11
12
|
--dev-tool-text-color-placeholder: #8c8c8c;
|
|
12
13
|
|
|
13
14
|
-webkit-tap-highlight-color: transparent;
|
|
14
|
-
transition:
|
|
15
|
+
transition:
|
|
16
|
+
color 0.3s,
|
|
17
|
+
background-color 0.3s,
|
|
18
|
+
border-color 0.3s,
|
|
19
|
+
box-shadow 0.3s;
|
|
15
20
|
}
|
|
16
21
|
|
|
17
22
|
/* Light Theme */
|
|
@@ -20,6 +25,7 @@
|
|
|
20
25
|
--dev-tool-bg2-color: rgb(252 252 252 / 95%);
|
|
21
26
|
--dev-tool-bg3-color: #fff;
|
|
22
27
|
--dev-tool-text-color: #1f1f1f;
|
|
28
|
+
--dev-tool-text-color-secondary: #595959;
|
|
23
29
|
--dev-tool-border-color: #f0f0f0;
|
|
24
30
|
--dev-tool-info-color: #8c8c8c;
|
|
25
31
|
--dev-tool-log-color: #f5f5f5;
|
|
@@ -50,11 +56,12 @@
|
|
|
50
56
|
--dev-tool-bg2-color: #1a1a1a;
|
|
51
57
|
--dev-tool-bg3-color: #242424;
|
|
52
58
|
--dev-tool-text-color: rgb(255 255 255 / 85%);
|
|
59
|
+
--dev-tool-text-color-secondary: rgb(255 255 255 / 45%);
|
|
53
60
|
--dev-tool-border-color: #333;
|
|
54
61
|
--dev-tool-info-color: #8c8c8c;
|
|
55
62
|
--dev-tool-log-color: #202020;
|
|
56
63
|
--dev-tool-nil-color: #bfbfbf;
|
|
57
|
-
|
|
64
|
+
|
|
58
65
|
/* Syntax Highlighting */
|
|
59
66
|
--dev-tool-number-color: #40a9ff;
|
|
60
67
|
--dev-tool-boolean-color: #40a9ff;
|
|
@@ -69,7 +76,7 @@
|
|
|
69
76
|
--dev-tool-function-color: #40a9ff;
|
|
70
77
|
--dev-tool-attribute-color: #ff7eb6;
|
|
71
78
|
--dev-tool-operator-color: #5cdbd3;
|
|
72
|
-
|
|
79
|
+
|
|
73
80
|
/* Status Backgrounds */
|
|
74
81
|
--dev-tool-warn-bg-color: rgb(255 169 64 / 20%);
|
|
75
82
|
--dev-tool-error-bg-color: rgb(255 77 79 / 20%);
|
|
@@ -198,7 +205,7 @@
|
|
|
198
205
|
--dev-tool-log-color: #0f172a;
|
|
199
206
|
--dev-tool-nil-color: #64748b;
|
|
200
207
|
--dev-tool-main-color: #82aaff;
|
|
201
|
-
|
|
208
|
+
|
|
202
209
|
/* Syntax Highlighting */
|
|
203
210
|
--dev-tool-number-color: #7dd3fc;
|
|
204
211
|
--dev-tool-boolean-color: #7dd3fc;
|
|
@@ -213,7 +220,7 @@
|
|
|
213
220
|
--dev-tool-function-color: #82aaff;
|
|
214
221
|
--dev-tool-attribute-color: #c792ea;
|
|
215
222
|
--dev-tool-operator-color: #2dd4bf;
|
|
216
|
-
|
|
223
|
+
|
|
217
224
|
/* Status Backgrounds */
|
|
218
225
|
--dev-tool-warn-bg-color: rgb(251 191 36 / 15%);
|
|
219
226
|
--dev-tool-error-bg-color: rgb(244 63 94 / 15%);
|
|
@@ -232,7 +239,7 @@
|
|
|
232
239
|
--dev-tool-log-color: #0a1b35;
|
|
233
240
|
--dev-tool-nil-color: #38bdf8;
|
|
234
241
|
--dev-tool-main-color: #38bdf8;
|
|
235
|
-
|
|
242
|
+
|
|
236
243
|
/* Syntax Highlighting (Ocean Blue) */
|
|
237
244
|
--dev-tool-number-color: #7dd3fc;
|
|
238
245
|
--dev-tool-boolean-color: #7dd3fc;
|
|
@@ -247,7 +254,7 @@
|
|
|
247
254
|
--dev-tool-function-color: #38bdf8;
|
|
248
255
|
--dev-tool-attribute-color: #c084fc;
|
|
249
256
|
--dev-tool-operator-color: #2dd4bf;
|
|
250
|
-
|
|
257
|
+
|
|
251
258
|
/* Status Backgrounds */
|
|
252
259
|
--dev-tool-warn-bg-color: rgb(245 158 11 / 15%);
|
|
253
260
|
--dev-tool-error-bg-color: rgb(244 63 94 / 15%);
|
|
@@ -266,7 +273,7 @@
|
|
|
266
273
|
--dev-tool-log-color: #fff7ed;
|
|
267
274
|
--dev-tool-nil-color: #c2410c;
|
|
268
275
|
--dev-tool-main-color: #ef5350;
|
|
269
|
-
|
|
276
|
+
|
|
270
277
|
/* Syntax Highlighting */
|
|
271
278
|
--dev-tool-number-color: #ffab91;
|
|
272
279
|
--dev-tool-boolean-color: #ffab91;
|
|
@@ -281,7 +288,7 @@
|
|
|
281
288
|
--dev-tool-function-color: #ef5350;
|
|
282
289
|
--dev-tool-attribute-color: #be123c;
|
|
283
290
|
--dev-tool-operator-color: #c2410c;
|
|
284
|
-
|
|
291
|
+
|
|
285
292
|
/* Warm Status Backgrounds */
|
|
286
293
|
--dev-tool-warn-bg-color: #fff7ed;
|
|
287
294
|
--dev-tool-error-bg-color: #fef2f2;
|
package/package.json
CHANGED
|
@@ -1,64 +1,67 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "vite-uni-dev-tool",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "vite-uni-dev-tool, debug, uni-app, 一处编写,到处调试",
|
|
5
|
-
"keywords": [
|
|
6
|
-
"vite",
|
|
7
|
-
"debugger",
|
|
8
|
-
"dev-tool",
|
|
9
|
-
"vite-uni-dev-tool",
|
|
10
|
-
"uni-app",
|
|
11
|
-
"调试",
|
|
12
|
-
"插件",
|
|
13
|
-
"一处编写,到处调试"
|
|
14
|
-
],
|
|
15
|
-
"repositories": [
|
|
16
|
-
{
|
|
17
|
-
"type": "gitee",
|
|
18
|
-
"url": "https://gitee.com/cloud_l/vite-uni-dev-tool.git"
|
|
19
|
-
}
|
|
20
|
-
],
|
|
21
|
-
"license": "MIT",
|
|
22
|
-
"type": "module",
|
|
23
|
-
"main": "dist/index.cjs",
|
|
24
|
-
"module": "dist/index.js",
|
|
25
|
-
"types": "dist/index.d.ts",
|
|
26
|
-
"exports": {
|
|
27
|
-
".": {
|
|
28
|
-
"types": "./dist/index.d.ts",
|
|
29
|
-
"import": "./dist/index.js",
|
|
30
|
-
"require": "./dist/index.cjs"
|
|
31
|
-
},
|
|
32
|
-
"./core": {
|
|
33
|
-
"types": "./dist/core.d.ts",
|
|
34
|
-
"import": "./dist/core.js"
|
|
35
|
-
},
|
|
36
|
-
"./
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
"./dist/"
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
},
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
"
|
|
60
|
-
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
|
|
64
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "vite-uni-dev-tool",
|
|
3
|
+
"version": "1.2.0",
|
|
4
|
+
"description": "vite-uni-dev-tool, debug, uni-app, 一处编写,到处调试",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"vite",
|
|
7
|
+
"debugger",
|
|
8
|
+
"dev-tool",
|
|
9
|
+
"vite-uni-dev-tool",
|
|
10
|
+
"uni-app",
|
|
11
|
+
"调试",
|
|
12
|
+
"插件",
|
|
13
|
+
"一处编写,到处调试"
|
|
14
|
+
],
|
|
15
|
+
"repositories": [
|
|
16
|
+
{
|
|
17
|
+
"type": "gitee",
|
|
18
|
+
"url": "https://gitee.com/cloud_l/vite-uni-dev-tool.git"
|
|
19
|
+
}
|
|
20
|
+
],
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"type": "module",
|
|
23
|
+
"main": "dist/index.cjs",
|
|
24
|
+
"module": "dist/index.js",
|
|
25
|
+
"types": "dist/index.d.ts",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"import": "./dist/index.js",
|
|
30
|
+
"require": "./dist/index.cjs"
|
|
31
|
+
},
|
|
32
|
+
"./core": {
|
|
33
|
+
"types": "./dist/core.d.ts",
|
|
34
|
+
"import": "./dist/core.js"
|
|
35
|
+
},
|
|
36
|
+
"./hooks/*": {
|
|
37
|
+
"types": "./dist/v3/hooks/*/index.d.ts",
|
|
38
|
+
"import": "./dist/v3/hooks/*/index.ts"
|
|
39
|
+
},
|
|
40
|
+
"./dist/v3/hooks/*": {
|
|
41
|
+
"types": "./dist/v3/hooks/*/index.d.ts",
|
|
42
|
+
"import": "./dist/v3/hooks/*/index.ts"
|
|
43
|
+
},
|
|
44
|
+
"./dist/*": "./dist/*",
|
|
45
|
+
"./shims-uni.d.ts": "./dist/shims-uni.d.ts"
|
|
46
|
+
},
|
|
47
|
+
"files": [
|
|
48
|
+
"./dist/",
|
|
49
|
+
"README.md"
|
|
50
|
+
],
|
|
51
|
+
"scripts": {
|
|
52
|
+
"build": "vite build",
|
|
53
|
+
"build:lib": "vite build"
|
|
54
|
+
},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"@dcloudio/uni-app": ">=3.0.0-4020920240930001",
|
|
57
|
+
"@dcloudio/uni-components": "3.0.0-4020920240930001",
|
|
58
|
+
"@dcloudio/uni-h5": ">=3.0.0-4020920240930001",
|
|
59
|
+
"vue": ">=3.4.21"
|
|
60
|
+
},
|
|
61
|
+
"authors": [
|
|
62
|
+
"1264174856@qq.com"
|
|
63
|
+
],
|
|
64
|
+
"publishConfig": {
|
|
65
|
+
"access": "public"
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/uniParseStock/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAcnC;;;;;GAKG;AACH,MAAM,CAAC,OAAO,UAAU,aAAa,IAAI,MAAM,CAoL9C"}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/dist/v3/{Performance → DevTool/components/Performance}/modules/PerformanceMetrics.vue
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|